Commit 624fdfe5 by Owo Sugiana

Bug fixed bila /var/log/openvpn/ipp.txt karena IP-nya tidak perlu ditambah 2

1 parent 7a478559
1.0.1 19-10-2026
----------------
- Bug fixed bila /var/log/openvpn/ipp.txt karena IP-nya tidak perlu ditambah 2.
1.0.0 30-1-2026 1.0.0 30-1-2026
--------------- ---------------
- Tambah VPN Checker - Tambah VPN Checker
......
...@@ -3,11 +3,10 @@ requires = ['setuptools >= 64'] ...@@ -3,11 +3,10 @@ requires = ['setuptools >= 64']
[project] [project]
name = 'maintenance' name = 'maintenance'
version = '1.0.0' version = '1.0.1'
dependencies = [ dependencies = [
'sqlalchemy', 'psycopg',
'zope.sqlalchemy', 'zope.sqlalchemy',
'psycopg2-binary',
'opensipkd-hitung @ git+https://git.opensipkd.com/sugiana/opensipkd-hitung.git', 'opensipkd-hitung @ git+https://git.opensipkd.com/sugiana/opensipkd-hitung.git',
] ]
requires-python = '>= 3.9' requires-python = '>= 3.9'
......
...@@ -39,10 +39,12 @@ def init_db(argv=sys.argv[1:]): ...@@ -39,10 +39,12 @@ def init_db(argv=sys.argv[1:]):
def get_ipp_file(): def get_ipp_file():
files = ['/etc/openvpn/ipp.txt', '/var/log/openvpn/ipp.txt'] files = [
for filename in files: ('/etc/openvpn/ipp.txt', 2),
('/var/log/openvpn/ipp.txt', 0)]
for filename, increment_for_ip in files:
if os.path.exists(filename): if os.path.exists(filename):
return filename return filename, increment_for_ip
def get_db_session(engine): def get_db_session(engine):
...@@ -72,14 +74,14 @@ def init_ip(argv=sys.argv[1:]): ...@@ -72,14 +74,14 @@ def init_ip(argv=sys.argv[1:]):
conf.read(conf_file) conf.read(conf_file)
cf = dict(conf.items('main')) cf = dict(conf.items('main'))
engine = engine_from_config(cf, 'sqlalchemy.') engine = engine_from_config(cf, 'sqlalchemy.')
ipp_file = get_ipp_file() ipp_file, increment_for_ip = get_ipp_file()
db_session = get_db_session(engine) db_session = get_db_session(engine)
base_q = db_session.query(VPN) base_q = db_session.query(VPN)
with open(ipp_file) as f: with open(ipp_file) as f:
for line in f.readlines(): for line in f.readlines():
nama, ip = line.strip().split(',')[:2] nama, ip = line.strip().split(',')[:2]
i = int(ip.split('.')[-1]) i = int(ip.split('.')[-1])
i += 2 i += increment_for_ip
ip = '.'.join(ip.split('.')[:-1]) + '.%d' % i ip = '.'.join(ip.split('.')[:-1]) + '.%d' % i
q = base_q.filter_by(ip=ip) q = base_q.filter_by(ip=ip)
row = q.first() row = q.first()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!