mirror of
https://github.com/ArcticFoxes-net/ONC-Converter
synced 2024-12-22 00:11:33 -05:00
Fix whitespace and comments
This commit is contained in:
parent
1b2ed32529
commit
14739a0ae9
@ -3,17 +3,16 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
|
||||||
<title>OpenVPN to ONC</title>
|
<title>OpenVPN to ONC</title>
|
||||||
<meta name="description" content="Convert OpenVPN config files to ONC files">
|
<meta name="description" content="Convert OpenVPN config files to ONC files">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#output {
|
#output {
|
||||||
background-color: lightgray;
|
background-color: lightgray;
|
||||||
}
|
}
|
||||||
</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.
|
||||||
@ -107,7 +110,7 @@
|
|||||||
let xmlContent = ''
|
let xmlContent = ''
|
||||||
|
|
||||||
let lines = str.split(/[\r\n]+/g)
|
let lines = str.split(/[\r\n]+/g)
|
||||||
|
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
// skip line if it is empty or begins with '#' or ';'
|
// skip line if it is empty or begins with '#' or ';'
|
||||||
if (!line || line.match(/^\s*[;#]/)) continue
|
if (!line || line.match(/^\s*[;#]/)) continue
|
||||||
@ -149,15 +152,20 @@
|
|||||||
const value = match[2] ? (match[3] || '') : true
|
const value = match[2] ? (match[3] || '') : true
|
||||||
ovpn[key] = value
|
ovpn[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
*
|
*
|
||||||
@ -199,12 +207,7 @@
|
|||||||
}
|
}
|
||||||
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]
|
||||||
@ -264,7 +267,7 @@
|
|||||||
console.warn('Is this a server file?')
|
console.warn('Is this a server file?')
|
||||||
}
|
}
|
||||||
let params = {}
|
let params = {}
|
||||||
|
|
||||||
// Add parameters
|
// Add parameters
|
||||||
let remote = ovpn.remote.split(' ')
|
let remote = ovpn.remote.split(' ')
|
||||||
const host = remote[0]
|
const host = remote[0]
|
||||||
@ -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',
|
||||||
@ -349,14 +352,16 @@
|
|||||||
'OpenVPN': params
|
'OpenVPN': params
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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'
|
||||||
@ -429,7 +437,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="setHandler()">
|
<body onload="setHandler()">
|
||||||
<div>
|
<div>
|
||||||
<h1>ovpn2onc</h1>
|
<h1>ovpn2onc</h1>
|
||||||
|
Loading…
Reference in New Issue
Block a user