Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
opiran-club authored Aug 17, 2024
1 parent 68ea8dd commit c47e859
Showing 1 changed file with 47 additions and 17 deletions.
64 changes: 47 additions & 17 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,53 @@ functionconvertToURL() {

let privateKey = '', publicKey = '', address = '', mtu = '', endpoint = '', port = '';

lines.forEach(line => {
if (line.startsWith('Secret Key ')) {
privateKey = line.split(' ').pop().trim();
}
if (line.startsWith('Public Key ')) {
publicKey = line.split(' ').pop().trim();
}
if (line.startsWith('Address ')) {
address = line.split(' ').pop().trim();
}
if (line.startsWith('Port ')) {
port = line.split(' ').pop().trim();
}
if (line.startsWith('MTU ')) {
mtu = line.split(' ').pop().trim();
}
});
// Determine the formatconst isFormat1 = lines.some(line => line.includes('PrivateKey')) && lines.some(line => line.includes('Endpoint'));
const isFormat2 = lines.some(line => line.includes('Secret Key')) && lines.some(line => line.includes('Address'));

if (isFormat1) {
// Parsing FORMAT1
lines.forEach(line => {
if (line.startsWith('PrivateKey =')) {
privateKey = line.split('=').pop().trim();
}
if (line.startsWith('PublicKey =')) {
publicKey = line.split('=').pop().trim();
}
if (line.startsWith('Address =')) {
address = line.split('=').pop().trim();
}
if (line.startsWith('MTU =')) {
mtu = line.split('=').pop().trim();
}
if (line.startsWith('Endpoint =')) {
const endpointParts = line.split('=').pop().trim().split(':');
endpoint = endpointParts[0];
port = endpointParts[1];
}
});
} elseif (isFormat2) {
// Parsing FORMAT2
lines.forEach(line => {
if (line.startsWith('Secret Key')) {
privateKey = line.split(' ').pop().trim();
}
if (line.startsWith('Public Key')) {
publicKey = line.split(' ').pop().trim();
}
if (line.startsWith('Address')) {
address = line.split(' ').pop().trim();
}
if (line.startsWith('Port')) {
port = line.split(' ').pop().trim();
}
if (line.startsWith('MTU')) {
mtu = line.split(' ').pop().trim();
}
});
} else {
alert('Unsupported configuration format.');
return;
}

// Validate necessary fieldsif (!privateKey || !publicKey || !address || !port) {
alert('Please ensure all required fields (Secret Key, Public Key, Address, Port) are provided in the config.');
Expand Down

0 comments on commit c47e859

Please sign in to comment.