1
0
mirror of https://github.com/ArcticFoxes-net/ONC-Converter synced 2024-09-19 16:14:43 -04:00

Fix whitespace and comments

This commit is contained in:
thomkeh 2018-08-13 13:16:17 +01:00
parent 1b2ed32529
commit 14739a0ae9

View File

@ -13,7 +13,6 @@
}
</style>
<script>
/**
* Register the function `handler` to be called when the `Convert` button is
* pressed.
@ -23,6 +22,7 @@
convertButton.addEventListener('click', handler, false)
}
/**
* Read parameters and pass them to the `main` function. This function is
* called when the `Convert` button is clicked.
@ -35,6 +35,7 @@
main(connName, selectedFile, certificates, output)
}
/**
* Read, convert and print result. This function calls other functions
* to first read everything, then convert it and finally print the result.
@ -62,6 +63,7 @@
output.value = JSON.stringify(onc, null, 2)
}
/**
* Return a promise to read a file as text.
*
@ -81,6 +83,7 @@
})
}
/**
* Parse an OVPN file. Extract all the key-value pairs and keys
* that are written inside XML tags.
@ -153,11 +156,16 @@
return [ovpn, keys]
}
/**
* Check if string is quoted
*/
function isQuoted (val) {
return ((val.charAt(0) === '"' && val.slice(-1) === '"') ||
(val.charAt(0) === "'" && val.slice(-1) === "'"))
}
/**
* This function is supposed to prevent any exploits via the object keys
*
@ -200,11 +208,6 @@
return val
}
const oncBasics = {
'Type': 'UnencryptedConfiguration',
'Certificates': [],
'NetworkConfigurations': []
}
/**
* Convert the keys from the parsed OVPN file into ONC keys
@ -244,7 +247,7 @@
let authKey = ovpn['tls-auth'].split(' ')
let keyString = keys[authKey[0]]
if (!keyString) {
alert("Please provide the file '" + authKey[0] + "' in 'Certificates and keys'")
alert(`Please provide the file '${authKey[0]}' in 'Certificates and keys'`)
}
params['TLSAuthContents'] = convertKey(keyString)
if (authKey[1]) params['KeyDirection'] = authKey[1]
@ -334,12 +337,12 @@
*/
function constructOnc (name, ovpn, keys) {
let [host, params] = convertToOnc(ovpn)
let [certParams, certs] = convertKeys(keys, ovpn)
let [certParams, certificates] = convertKeys(keys, ovpn)
// merge parameters
params = Object.assign({}, params, certParams)
// Put together network configuration
let config = {
let networkConfiguration = {
'GUID': `{${uuidv4()}}`,
'Name': name,
'Type': 'VPN',
@ -351,11 +354,13 @@
}
// Put everything together
let onc = Object.assign({}, oncBasics) // create copy
onc.NetworkConfigurations = [config]
onc.Certificates = certs
return onc
return {
'Type': 'UnencryptedConfiguration',
'Certificates': certificates,
'NetworkConfigurations': [networkConfiguration]
}
}
/**
* Create UUID (from Stackoverflow).
@ -366,6 +371,7 @@
)
}
/**
* Replace newlines with explicit `\n` and filter out comments
*/
@ -380,6 +386,7 @@
return out
}
/**
* Find all certificates in a string and extract them
*/
@ -395,6 +402,7 @@
return cas
}
/**
* Construct certificates in the ONC format
*
@ -410,7 +418,7 @@
if (certName) {
let cert = keys[certName]
if (!cert) {
alert("Please provide the file '" + certName + "' in 'Certificates and keys'")
alert(`Please provide the file '${certName}' in 'Certificates and keys'`)
}
let rawCerts = extractCas(cert)
const format = (certType === 'Authority') ? 'X509' : 'PKCS12'