mirror of
https://github.com/ArcticFoxes-net/ONC-Converter
synced 2024-12-22 00:11:33 -05:00
Code for basic structure of ONC file
This commit is contained in:
parent
9183ba841f
commit
6660c1e2dd
11
index.html
11
index.html
@ -1,20 +1,21 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
|
||||||
<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">
|
||||||
|
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script type="module" src="js/scripts.js"></script>
|
<script type="module" src="js/main.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<h1>ovpn2onc</h1>
|
<h1>ovpn2onc</h1>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>Name for connection: <input type="text" id="connname"></li>
|
||||||
<li>OpenVPN config file (*.ovpn): <input type="file" id="inputopenvpn"></li>
|
<li>OpenVPN config file (*.ovpn): <input type="file" id="inputopenvpn"></li>
|
||||||
<li>Certificates: <input mutliple type="file" id="inputcertificate"></li>
|
<li>Certificates: <input mutliple type="file" id="inputcertificate"></li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -24,5 +25,5 @@
|
|||||||
<p>Output</p>
|
<p>Output</p>
|
||||||
<textarea readonly id="output" wrap="off" rows="10" cols="50"></textarea>
|
<textarea readonly id="output" wrap="off" rows="10" cols="50"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,3 +1,56 @@
|
|||||||
export function convert(parsed) {
|
/**
|
||||||
return {"test": "great content"}
|
* Convert the parsed OpenVPN config to ONC.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const oncBasics = {
|
||||||
|
'Type': 'UnencryptedConfiguration',
|
||||||
|
'Certificates': [],
|
||||||
|
'NetworkConfigurations': []
|
||||||
|
}
|
||||||
|
|
||||||
|
export function convert(name, ovpn) {
|
||||||
|
if (!ovpn.client) {
|
||||||
|
console.warn('Is this a server file?')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check parameters
|
||||||
|
let params = {}
|
||||||
|
let remote = ovpn.remote.split(' ')
|
||||||
|
const host = remote[0]
|
||||||
|
if (remote[1]) {
|
||||||
|
params['Port'] = remote[1]
|
||||||
|
}
|
||||||
|
if (ovpn.proto) {
|
||||||
|
params['Proto'] = ovpn.proto
|
||||||
|
}
|
||||||
|
if (ovpn['tls-auth']) {
|
||||||
|
params['TLSAuthContents'] = convertKey(ovpn['tls-auth'])
|
||||||
|
}
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
'GUID': `{${uuidv4()}}`,
|
||||||
|
'Name': name,
|
||||||
|
'Type': 'VPN',
|
||||||
|
'VPN': {
|
||||||
|
'Type': 'OpenVPN',
|
||||||
|
'Host': host,
|
||||||
|
'OpenVPN': params
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let onc = Object.assign({}, oncBasics) // create copy
|
||||||
|
onc.NetworkConfigurations = [config]
|
||||||
|
return onc
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create UUID (from Stackoverflow).
|
||||||
|
*/
|
||||||
|
function uuidv4() {
|
||||||
|
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c=>
|
||||||
|
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertKey(key) {
|
||||||
|
return key.replace(/\n/g, '\n') + '\n'
|
||||||
}
|
}
|
||||||
|
29
js/main.js
Normal file
29
js/main.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import {decode} from './parser.js'
|
||||||
|
import {convert} from './converter.js'
|
||||||
|
|
||||||
|
let clickButton = document.getElementById('clickbutton')
|
||||||
|
clickButton.addEventListener('click', main, false)
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
let selectedFile = document.getElementById('inputopenvpn').files[0]
|
||||||
|
let connName = document.getElementById('connname').value
|
||||||
|
if (connName === '') {
|
||||||
|
alert('Please specify a name for the connection.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log(selectedFile.size + ' bytes')
|
||||||
|
let reader = new FileReader()
|
||||||
|
// callback for when reader is done
|
||||||
|
reader.onload = (e => {
|
||||||
|
let content = e.target.result
|
||||||
|
// remove windows-style newlines
|
||||||
|
content = content.replace(/\r/g, '')
|
||||||
|
let parsed = decode(content)
|
||||||
|
console.log(parsed)
|
||||||
|
let onc = convert(connName, parsed)
|
||||||
|
let output = document.getElementById('output')
|
||||||
|
output.value = JSON.stringify(onc, null, 2)
|
||||||
|
});
|
||||||
|
// start reading
|
||||||
|
reader.readAsText(selectedFile)
|
||||||
|
}
|
@ -44,8 +44,8 @@ export function decode (str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) === "'"))
|
||||||
}
|
}
|
||||||
|
|
||||||
function unsafe (val, doUnesc) {
|
function unsafe (val, doUnesc) {
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
import {decode} from '/js/parser.js';
|
|
||||||
import {convert} from '/js/converter.js';
|
|
||||||
|
|
||||||
let clickButton = document.getElementById('clickbutton');
|
|
||||||
clickButton.addEventListener("click", main, false);
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
let selectedFile = document.getElementById('inputopenvpn').files[0];
|
|
||||||
console.log(selectedFile.size + " bytes");
|
|
||||||
let reader = new FileReader();
|
|
||||||
reader.onload = (e => {
|
|
||||||
let content = e.target.result;
|
|
||||||
// remove windows-style newlines
|
|
||||||
content = content.replace(/\r/g, "");
|
|
||||||
let parsed = decode(content);
|
|
||||||
console.log(parsed);
|
|
||||||
let onc = convert(parsed);
|
|
||||||
let output = document.getElementById('output');
|
|
||||||
output.value = JSON.stringify(onc);
|
|
||||||
});
|
|
||||||
// start reading
|
|
||||||
reader.readAsText(selectedFile);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user