From 6b7b3f9cce9428e86ea1ca4c8fbcd92c45286e7a Mon Sep 17 00:00:00 2001 From: LV-426 Date: Tue, 13 Jan 2015 16:54:44 +0200 Subject: rz_cli_tool: mv under local/ --- src/local/rz_cli_tool.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/server/rz_cli_tool.py | 54 ----------------------------------------------- 2 files changed, 54 insertions(+), 54 deletions(-) create mode 100644 src/local/rz_cli_tool.py delete mode 100644 src/server/rz_cli_tool.py (limited to 'src') diff --git a/src/local/rz_cli_tool.py b/src/local/rz_cli_tool.py new file mode 100644 index 00000000..1dea8559 --- /dev/null +++ b/src/local/rz_cli_tool.py @@ -0,0 +1,54 @@ +import argparse +import os +import pickle +import re + +import crypt_util +from rz_server import init_config + + +def init_pw_db(cfg, user_pw_list_file): + htpasswd_path = cfg.htpasswd_path + + if os.path.exists(htpasswd_path): + print('htpasswd_path already exists, aborting: ' + htpasswd_path) + return + + with open(htpasswd_path, 'wb') as f: # init file + pickle.dump({}, f) + + salt = cfg.secret_key + assert len(salt) > 8, 'server-key not found or too short' + print('using config secret_key for salt generation: ' + salt[:3] + '...') + + u_count = 0 + with open(user_pw_list_file, 'r') as f: + for line in f: + if re.match('(^#)|(\s+$)', line): + continue + + kv_arr = line.split(',') + if 2 != len(kv_arr): + raise Exception('failed to parse user,pw line: ' + line) + + user, pw = map(str.strip, kv_arr) + crypt_util.add_user_login(htpasswd_path, salt, user, pw) + print('added user: u: ' + user) + u_count = u_count + 1 + print('htpasswd generated: path: %s, user-count: %d' % (htpasswd_path, u_count)) + +def main(): + p = argparse.ArgumentParser(description='rz-cli tool') + p.add_argument('--config-dir', help='path to Rhizi config dir', default='res/etc') + p.add_argument('--init-htpasswd-db', help='init login htpasswd db', action='store_const', const=True) + p.add_argument('--htpasswd-init-file', help='htpasswd db initialization file in \'user,pw\' format') + + args = p.parse_args() + cfg = init_config(args.config_dir) + + if args.init_htpasswd_db: + init_pw_db(cfg, args.htpasswd_init_file) + exit(0) + +if __name__ == '__main__': + main() diff --git a/src/server/rz_cli_tool.py b/src/server/rz_cli_tool.py deleted file mode 100644 index 1dea8559..00000000 --- a/src/server/rz_cli_tool.py +++ /dev/null @@ -1,54 +0,0 @@ -import argparse -import os -import pickle -import re - -import crypt_util -from rz_server import init_config - - -def init_pw_db(cfg, user_pw_list_file): - htpasswd_path = cfg.htpasswd_path - - if os.path.exists(htpasswd_path): - print('htpasswd_path already exists, aborting: ' + htpasswd_path) - return - - with open(htpasswd_path, 'wb') as f: # init file - pickle.dump({}, f) - - salt = cfg.secret_key - assert len(salt) > 8, 'server-key not found or too short' - print('using config secret_key for salt generation: ' + salt[:3] + '...') - - u_count = 0 - with open(user_pw_list_file, 'r') as f: - for line in f: - if re.match('(^#)|(\s+$)', line): - continue - - kv_arr = line.split(',') - if 2 != len(kv_arr): - raise Exception('failed to parse user,pw line: ' + line) - - user, pw = map(str.strip, kv_arr) - crypt_util.add_user_login(htpasswd_path, salt, user, pw) - print('added user: u: ' + user) - u_count = u_count + 1 - print('htpasswd generated: path: %s, user-count: %d' % (htpasswd_path, u_count)) - -def main(): - p = argparse.ArgumentParser(description='rz-cli tool') - p.add_argument('--config-dir', help='path to Rhizi config dir', default='res/etc') - p.add_argument('--init-htpasswd-db', help='init login htpasswd db', action='store_const', const=True) - p.add_argument('--htpasswd-init-file', help='htpasswd db initialization file in \'user,pw\' format') - - args = p.parse_args() - cfg = init_config(args.config_dir) - - if args.init_htpasswd_db: - init_pw_db(cfg, args.htpasswd_init_file) - exit(0) - -if __name__ == '__main__': - main() -- cgit v1.3.1