Динамическая отправка маршрутов для openVPN

La única forma que encontré para hacer esto requiere usar un archivo externo para almacenar los resultados temporalmente.

$ cat input.txt 
13
5
29
22
45
64
17
20
69
91
$ ed input.txt 
29
1,3w !sort -n > temp.txt
8
1,3d
0r temp.txt
8
wq
29
1
02.07.2019, 18:51
2 ответа

Ключом пользовательской конфигурации является использование клиента -подключения опции

Выдержка из vpn -endpoint.conf

script-security 2
client-connect /etc/openvpn/up-client

Очень простой скрипт

 #!/bin/sh
 CONFIG_FILE=$1
 ( env ; echo CONFIG_FILE  ${CONFIG_FILE} ) >> /var/log/openvpn-up-client.log
 case "$username" in
    (me)
         echo 'push "route 192.168.168.168 255.255.255.255"' >>${CONFIG_FILE}
         ;;
    (*)
         echo 'push "route 192.168.169.169 255.255.255.255"' >>${CONFIG_FILE}
         ;;
 esac

Выдержка из man openvpn

--client-connect cmd

Run command cmd on client connection.

cmd consists of a path to script (or executable program), optionally followed by arguments.

The path and arguments may be single- or double-quoted and/or escaped using a backslash, and should be separated by one or more spaces.

The command is passed the common name and IP address of the just-authenticated client as environmental variables (see environmental variable section below). The command is also passed the pathname of a freshly created temporary file as the last argument (after any arguments specified in cmd ), to be used by the command to pass dynamically generated config file directives back to OpenVPN.

If the script wants to generate a dynamic config file to be applied on the server when the client connects, it should write it to the file named by the last argument.

See the --client-config-dir option below for options which can be legally used in a dynamically generated config file.

Note that the return value of script is significant. If script returns a non-zero error status, it will cause the client to be disconnected.

3
27.01.2020, 23:30

У меня была такая же проблема. Я пишу скрипт, который вызывает хранимую процедуру из базы данных, которая возвращает Route. в вашем случае API. И пропишите эти маршруты в файл _list (sys.argv[1 :] ).

Этот скрипт передает его как опцию в ваш serverConfig /etc/openvpn/server.conf. ты пишешь эти строки:

скрипт -безопасность 2

клиент -подключение /путь/к/вашему/сценарию

вы можете использовать скрипт python и использовать appendфункцию внутри вашего скрипта:

file_list.append("push \"route %s %s\"\n" % (your_vpn_route, "255.255.255.x"))
0
27.01.2020, 23:30

Теги

Похожие вопросы