@@ -25,6 +25,8 @@ def __init__(self):
25
25
self .last_update_transfer = {}
26
26
self .event = threading .Event ()
27
27
self .port_uid_table = {}
28
+ self .uid_port_table = {}
29
+ self .old_md5_users = {}
28
30
self .node_speedlimit = 0.00
29
31
self .traffic_rate = 0.0
30
32
@@ -218,7 +220,7 @@ def pull_db_all_user(self):
218
220
switchrule = importloader .load ('switchrule' )
219
221
keys = switchrule .getKeys ()
220
222
except Exception as e :
221
- keys = ['port' , 'u' , 'd' , 'transfer_enable' , 'passwd' , 'enable' ,'method' ,'protocol' ,'protocol_param' ,'obfs' ,'obfs_param' ,'node_speedlimit' ,'forbidden_ip' ,'forbidden_port' ,'disconnect_ip' ]
223
+ keys = ['id' , ' port' , 'u' , 'd' , 'transfer_enable' , 'passwd' , 'enable' ,'method' ,'protocol' ,'protocol_param' ,'obfs' ,'obfs_param' ,'node_speedlimit' ,'forbidden_ip' ,'forbidden_port' ,'disconnect_ip' , 'is_multi_user ' ]
222
224
223
225
if get_config ().MYSQL_SSL_ENABLE == 1 :
224
226
conn = cymysql .connect (host = get_config ().MYSQL_HOST , port = get_config ().MYSQL_PORT , user = get_config ().MYSQL_USER ,
@@ -353,6 +355,22 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
353
355
logging .error ('load switchrule.py fail' )
354
356
cur_servers = {}
355
357
new_servers = {}
358
+
359
+ md5_users = {}
360
+ for row in rows :
361
+ md5_users [row ['id' ]] = row .copy ()
362
+ del md5_users [row ['id' ]]['u' ]
363
+ del md5_users [row ['id' ]]['d' ]
364
+ if md5_users [row ['id' ]]['disconnect_ip' ] == None :
365
+ md5_users [row ['id' ]]['disconnect_ip' ] = ''
366
+
367
+ if md5_users [row ['id' ]]['forbidden_ip' ] == None :
368
+ md5_users [row ['id' ]]['forbidden_ip' ] = ''
369
+
370
+ if md5_users [row ['id' ]]['forbidden_port' ] == None :
371
+ md5_users [row ['id' ]]['forbidden_port' ] = ''
372
+ md5_users [row ['id' ]]['md5' ] = common .get_md5 (str (row ['id' ]) + row ['passwd' ] + row ['method' ] + row ['obfs' ] + row ['protocol' ])
373
+
356
374
for row in rows :
357
375
try :
358
376
allow = switchrule .isTurnOn (row ) and row ['enable' ] == 1 and row ['u' ] + row ['d' ] < row ['transfer_enable' ]
@@ -364,8 +382,9 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
364
382
cfg = {'password' : passwd }
365
383
366
384
self .port_uid_table [row ['port' ]] = row ['id' ]
385
+ self .uid_port_table [row ['id' ]] = row ['port' ]
367
386
368
- read_config_keys = ['method' , 'obfs' ,'obfs_param' , 'protocol' , 'protocol_param' ,'forbidden_ip' , 'forbidden_port' , 'node_speedlimit' ,'forbidden_ip' ,'forbidden_port' ,'disconnect_ip' ]
387
+ read_config_keys = ['method' , 'obfs' ,'obfs_param' , 'protocol' , 'protocol_param' ,'forbidden_ip' , 'forbidden_port' , 'node_speedlimit' ,'forbidden_ip' ,'forbidden_port' ,'disconnect_ip' , 'is_multi_user' ]
369
388
370
389
for name in read_config_keys :
371
390
if name in row and row [name ]:
@@ -398,6 +417,9 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
398
417
399
418
if 'obfs_param' not in cfg :
400
419
cfg ['obfs_param' ] = ''
420
+
421
+ if 'is_multi_user' not in cfg :
422
+ cfg ['is_multi_user' ] = 0
401
423
402
424
if port not in cur_servers :
403
425
cur_servers [port ] = passwd
@@ -410,7 +432,9 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
410
432
411
433
cfg ['detect_text_list' ] = self .detect_text_list .copy ()
412
434
cfg ['detect_hex_list' ] = self .detect_hex_list .copy ()
413
-
435
+
436
+ cfg ['users_table' ] = md5_users .copy ()
437
+
414
438
415
439
if ServerPool .get_instance ().server_is_run (port ) > 0 :
416
440
if not allow :
@@ -422,6 +446,16 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
422
446
cfgchange = False
423
447
if self .detect_text_ischanged == True or self .detect_hex_ischanged == True :
424
448
cfgchange = True
449
+ if cmp (self .old_md5_users ,md5_users ) != 0 and row ['is_multi_user' ] == 1 :
450
+ if port in ServerPool .get_instance ().tcp_servers_pool :
451
+ ServerPool .get_instance ().tcp_servers_pool [port ].modify_multi_user_table (md5_users )
452
+ if port in ServerPool .get_instance ().tcp_ipv6_servers_pool :
453
+ ServerPool .get_instance ().tcp_ipv6_servers_pool [port ].modify_multi_user_table (md5_users )
454
+ if port in ServerPool .get_instance ().udp_servers_pool :
455
+ ServerPool .get_instance ().udp_servers_pool [port ].modify_multi_user_table (md5_users )
456
+ if port in ServerPool .get_instance ().udp_ipv6_servers_pool :
457
+ ServerPool .get_instance ().udp_ipv6_servers_pool [port ].modify_multi_user_table (md5_users )
458
+
425
459
if port in ServerPool .get_instance ().tcp_servers_pool :
426
460
relay = ServerPool .get_instance ().tcp_servers_pool [port ]
427
461
for name in merge_config_keys :
@@ -436,7 +470,7 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
436
470
break ;
437
471
#config changed
438
472
if cfgchange :
439
- logging .info ('db stop server at port [%s] reason: config changed: %s ' % (port , cfg ))
473
+ logging .info ('db stop server at port [%s] reason: config changed! ' % (port ))
440
474
ServerPool .get_instance ().cb_del_server (port )
441
475
if port in self .last_update_transfer :
442
476
del self .last_update_transfer [port ]
@@ -447,7 +481,9 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
447
481
protocol = cfg .get ('protocol' , ServerPool .get_instance ().config .get ('protocol' , 'origin' ))
448
482
obfs = cfg .get ('obfs' , ServerPool .get_instance ().config .get ('obfs' , 'plain' ))
449
483
logging .info ('db start server at port [%s] pass [%s] protocol [%s] obfs [%s]' % (port , passwd , protocol , obfs ))
450
- ServerPool .get_instance ().new_server (port , cfg , )
484
+ ServerPool .get_instance ().new_server (port , cfg )
485
+
486
+ ServerPool .get_instance ().push_uid_port_table (self .uid_port_table )
451
487
452
488
for row in last_rows :
453
489
if row ['port' ] in cur_servers :
@@ -468,6 +504,8 @@ def del_server_out_of_bound_safe(self, last_rows, rows):
468
504
obfs = cfg .get ('obfs' , ServerPool .get_instance ().config .get ('obfs' , 'plain' ))
469
505
logging .info ('db start server at port [%s] pass [%s] protocol [%s] obfs [%s]' % (port , passwd , protocol , obfs ))
470
506
ServerPool .get_instance ().new_server (port , cfg )
507
+
508
+ self .old_md5_users = md5_users .copy ()
471
509
472
510
@staticmethod
473
511
def del_servers ():
0 commit comments