8 db_config_path
= '/etc/0tdns/db_connection_config.yml'
10 ovpn_config_path
= argv
[1]
12 with
open(ovpn_config_path
) as file:
13 ovpn_config_text
= file.read()
15 ovpn_config_raw
= bytearray(ovpn_config_text
, encoding
='utf-8')
17 ovpn_config_hash
= hashlib
.sha256(ovpn_config_raw
).hexdigest()
19 config
= yaml
.safe_load(open(db_config_path
, 'r'))
20 connection
= psycopg2
.connect(user
=config
['user'], password
=config
['password'],
21 host
=config
['host'], port
=config
['port'],
22 database
=config
['database'])
23 cursor
= connection
.cursor()
26 INSERT INTO vpn (location_id, ovpn_config, ovpn_config_sha256)
27 VALUES(%s, %s, %s)''', (11, ovpn_config_text
, ovpn_config_hash
))