|
@ -10,6 +10,7 @@ import sys |
|
|
import json |
|
|
import json |
|
|
import base64 |
|
|
import base64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MuJsonLoader(object): |
|
|
class MuJsonLoader(object): |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
self.json = None |
|
|
self.json = None |
|
@ -25,6 +26,7 @@ class MuJsonLoader(object): |
|
|
f.write(output) |
|
|
f.write(output) |
|
|
f.truncate() |
|
|
f.truncate() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MuMgr(object): |
|
|
class MuMgr(object): |
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
self.config_path = get_config().MUDB_FILE |
|
|
self.config_path = get_config().MUDB_FILE |
|
@ -37,7 +39,7 @@ class MuMgr(object): |
|
|
if self.server_addr == '127.0.0.1': |
|
|
if self.server_addr == '127.0.0.1': |
|
|
self.server_addr = self.getipaddr() |
|
|
self.server_addr = self.getipaddr() |
|
|
|
|
|
|
|
|
def getipaddr(self, ifname = 'eth0'): |
|
|
def getipaddr(self, ifname='eth0'): |
|
|
import socket |
|
|
import socket |
|
|
import struct |
|
|
import struct |
|
|
import fcntl |
|
|
import fcntl |
|
@ -59,8 +61,11 @@ class MuMgr(object): |
|
|
obfs = user.get('obfs', '') |
|
|
obfs = user.get('obfs', '') |
|
|
protocol = protocol.replace("_compatible", "") |
|
|
protocol = protocol.replace("_compatible", "") |
|
|
obfs = obfs.replace("_compatible", "") |
|
|
obfs = obfs.replace("_compatible", "") |
|
|
link = "%s:%s:%s:%s:%s:%s" % (self.server_addr, user['port'], protocol, user['method'], obfs, common.to_str(base64.urlsafe_b64encode(common.to_bytes(user['passwd']))).replace("=", "")) |
|
|
link = "%s:%s:%s:%s:%s:%s" % (self.server_addr, user['port'], protocol, user['method'], obfs, |
|
|
return "ssr://" + ( encode and common.to_str(base64.urlsafe_b64encode(common.to_bytes(link))).replace("=", "") or link) |
|
|
common.to_str(base64.urlsafe_b64encode(common.to_bytes(user['passwd']))).replace( |
|
|
|
|
|
"=", "")) |
|
|
|
|
|
return "ssr://" + ( |
|
|
|
|
|
encode and common.to_str(base64.urlsafe_b64encode(common.to_bytes(link))).replace("=", "") or link) |
|
|
|
|
|
|
|
|
def userinfo(self, user): |
|
|
def userinfo(self, user): |
|
|
ret = "" |
|
|
ret = "" |
|
@ -68,18 +73,18 @@ class MuMgr(object): |
|
|
if key in ['enable']: |
|
|
if key in ['enable']: |
|
|
continue |
|
|
continue |
|
|
ret += '\n' |
|
|
ret += '\n' |
|
|
if key in ['transfer_enable', 'u', 'd'] : |
|
|
if key in ['transfer_enable', 'u', 'd']: |
|
|
val = user[key] |
|
|
val = user[key] |
|
|
if val / 1024 < 4: |
|
|
if val / 1024 < 4: |
|
|
ret += " %s : %s" % (key, val) |
|
|
ret += " %s : %s" % (key, val) |
|
|
elif val / 1024**2 < 4: |
|
|
elif val / 1024 ** 2 < 4: |
|
|
val /= float(1024) |
|
|
val /= float(1024) |
|
|
ret += " %s : %s K Bytes" % (key, val) |
|
|
ret += " %s : %s K Bytes" % (key, val) |
|
|
elif val / 1024**3 < 4: |
|
|
elif val / 1024 ** 3 < 4: |
|
|
val /= float(1024**2) |
|
|
val /= float(1024 ** 2) |
|
|
ret += " %s : %s M Bytes" % (key, val) |
|
|
ret += " %s : %s M Bytes" % (key, val) |
|
|
else: |
|
|
else: |
|
|
val /= float(1024**3) |
|
|
val /= float(1024 ** 3) |
|
|
ret += " %s : %s G Bytes" % (key, val) |
|
|
ret += " %s : %s G Bytes" % (key, val) |
|
|
else: |
|
|
else: |
|
|
ret += " %s : %s" % (key, user[key]) |
|
|
ret += " %s : %s" % (key, user[key]) |
|
@ -88,7 +93,9 @@ class MuMgr(object): |
|
|
return ret |
|
|
return ret |
|
|
|
|
|
|
|
|
def rand_pass(self): |
|
|
def rand_pass(self): |
|
|
return ''.join([random.choice('''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~-_=+(){}[]^&%$@''') for i in range(8)]) |
|
|
return ''.join( |
|
|
|
|
|
[random.choice('''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~-_=+(){}[]^&%$@''') for i |
|
|
|
|
|
in range(8)]) |
|
|
|
|
|
|
|
|
def add(self, user): |
|
|
def add(self, user): |
|
|
up = {'enable': 1, 'u': 0, 'd': 0, 'method': "aes-128-cfb", |
|
|
up = {'enable': 1, 'u': 0, 'd': 0, 'method': "aes-128-cfb", |
|
@ -172,6 +179,7 @@ class MuMgr(object): |
|
|
if match: |
|
|
if match: |
|
|
print("### user [%s] info %s" % (row['user'], self.userinfo(row))) |
|
|
print("### user [%s] info %s" % (row['user'], self.userinfo(row))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_server_help(): |
|
|
def print_server_help(): |
|
|
print('''usage: python mujson_manage.py -a|-d|-e|-c|-l [OPTION]... |
|
|
print('''usage: python mujson_manage.py -a|-d|-e|-c|-l [OPTION]... |
|
|
|
|
|
|
|
@ -198,6 +206,7 @@ General options: |
|
|
-h, --help show this help message and exit |
|
|
-h, --help show this help message and exit |
|
|
''') |
|
|
''') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
def main(): |
|
|
shortopts = 'adeclu:p:k:O:o:G:g:m:t:f:h' |
|
|
shortopts = 'adeclu:p:k:O:o:G:g:m:t:f:h' |
|
|
longopts = ['help'] |
|
|
longopts = ['help'] |
|
@ -311,6 +320,6 @@ def main(): |
|
|
elif action is None: |
|
|
elif action is None: |
|
|
print_server_help() |
|
|
print_server_help() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
main() |
|
|
main() |
|
|
|
|
|
|
|
|