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