-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sacn QR #15
Comments
Реализация сделанная на коленке, но предоставляю как пример для реализации QR под AmneziaVPN - Проверенно работает Кодирование и декодирование для AmneziaVPN import * as zlib from 'zlib';
import base64url from 'base64url';
export namespace AwgDecoder {
// Функция для сжатия данных
function qCompress(data: string): Buffer {
const header = Buffer.alloc(4);
header.writeUInt32BE(data.length, 0);
const compressed = zlib.deflateSync(Buffer.from(data));
return Buffer.concat([header, compressed]);
}
// Функция для распаковки данных
function qDecompress(data: Buffer): string {
const size = data.readUInt32BE(0);
const compressed = data.slice(4);
return zlib.inflateSync(compressed).toString();
}
// Кодирование конфигурации в vpn://
export function encodeConfig(data: string): string {
const compressed = qCompress(data);
const encoded = base64url.encode(compressed);
return `vpn://${encoded}`;
}
// Декодирование vpn:// строки
export function decodeConfig(data: string): string {
const base64Data = data.replace('vpn://', '');
const compressed = base64url.toBuffer(base64Data);
return qDecompress(compressed);
}
} Пример использования в моей программе const config = templateWgClientConfig({
Interface: {
PrivateKey: profile.private_token,
Address: profile.ip + '/32',
DNS: '1.1.1.1, 1.0.0.1',
Jc: server_config.Interface.Jc,
Jmin: server_config.Interface.Jmin,
Jmax: server_config.Interface.Jmax,
S1: server_config.Interface.S1,
S2: server_config.Interface.S2,
H1: server_config.Interface.H1,
H2: server_config.Interface.H2,
H3: server_config.Interface.H3,
H4: server_config.Interface.H4,
},
Peer: {
PublicKey: server_public_key.trim(),
PresharedKey: profile.preshared_token,
AllowedIPs: '0.0.0.0/0',
Endpoint: server_ip + ':' + server_config.Interface.ListenPort,
PersistentKeepalive: '25',
},
});
console.log(config);
const config_url = AwgDecoder.encodeConfig(config); Пример как у меня собирается конфиг по шаблону import Handlebars from 'handlebars';
const template = `[Interface]
{{#wg_interface}}{{key}} = {{{value}}}
{{/wg_interface}}
{{#peers}}[Peer]
{{#peer}}{{key}} = {{{value}}}
{{/peer}}
{{/peers}}
`;
export function templateWgClientConfig(config: WgClientConfigInterface) {
const wg_interface = Object.entries(config.Interface).map(([key, value]) => ({
key,
value,
}));
const peers = [
{
peer: Object.entries(config.Peer).map(([key, value]) => ({ key, value })),
},
];
return compiler({
wg_interface,
peers,
});
} |
same here qr scaning in ios app says Scanned 0 of 0 |
@ron-tayler it doesn't work like that. Could you provide a way to integrate the QR generator into this project? Otherwise an abstract example is totally useless. |
hello When I scan the QR code with the AmneziaVpn program, the configuration is not created I must connect through a file There is a way to solve this problem
The text was updated successfully, but these errors were encountered: