def cmd_message(opts, args, overDict): if len(args) < 2 or args[1] == 'list': url = webcontrol._PAGE_MESSAGES + '?conversations=0' run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 if len(args) >= 4 and args[1] in [ 'send', ]: url = webcontrol._PAGE_NEW_MESSAGE + '?conversations=0&action=send&recipient=%s&subject=%s&body=%s' % ( misc.pack_url_param(args[2]), misc.pack_url_param(args[3]), misc.pack_url_param(args[4])) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 return 2
def cmd_restore(opts, args, overDict): if len(args) == 2: url = webcontrol._PAGE_BACKUPS+'?action=restoresingle&backupid='+args[1] elif len(args) == 3: url = webcontrol._PAGE_BACKUPS+('?action=restoresingle&backupid=%s&dest=%s' % ( args[1], misc.pack_url_param(args[2]))) else: return 2 run_url_command(url).addCallback(print_and_stop) reactor.run() return 0
def cmd_customers(opts, args, overDict): def _wait_remove_customer_and_stop(src, customer_name, count=0): customers = [] for s in find_comments(src): if s.count('[online ]') or s.count('[offline]'): customers.append(s[18:38].strip()) if customer_name not in customers: print ' customer %s is removed !' % customer_name print_and_stop(src) return if count >= 20: print ' time is out\n' reactor.stop() return else: def _check_again(customer_name, count): sys.stdout.write('.') run_url_command(webcontrol._PAGE_CUSTOMERS).addCallback(_wait_remove_customer_and_stop, customer_name, count) reactor.callLater(1, _check_again, customer_name, count+1) if len(args) < 2 or args[1] in [ 'list', 'ls', ]: url = webcontrol._PAGE_CUSTOMERS run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'call', 'cl', ]: url = webcontrol._PAGE_CUSTOMERS + '?action=call' run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'remove', 'rm', ] and len(args) >= 3: contactsdb.init() idurl = args[2].strip() if not idurl.startswith('http://'): try: idurl = contactsdb.customer(int(idurl)) except: idurl = '' if not idurl: print 'customer IDURL is unknown\n' return 0 name = nameurl.GetName(idurl) url = webcontrol._PAGE_CUSTOMERS + '?action=remove&idurl=%s' % misc.pack_url_param(idurl) run_url_command(url).addCallback(_wait_remove_customer_and_stop, name, 0) reactor.run() return 0 return 2
def cmd_schedule(opts, args, overDict): if len(args) < 2: return 2 if not os.path.isdir(os.path.abspath(args[1])): print 'folder %s not exist\n' % args[1] return 1 backupDir = os.path.abspath(args[1]) if len(args) < 3: url = webcontrol._PAGE_BACKUP_SHEDULE + '?backupdir=%s' % ( misc.pack_url_param(backupDir),) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 shed = schedule.from_compact_string(args[2]) if shed is None: print schedule.format() print return 0 url = webcontrol._PAGE_BACKUP_SHEDULE + '?action=save&submit=save&backupdir=%s&type=%s&interval=%s&daytime=%s&details=%s' % ( misc.pack_url_param(backupDir), shed.type, shed.interval, shed.daytime, misc.pack_url_param(shed.details),) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0
def cmd_set_request(opts, args, overDict): name = args[1].lower() if name in [ 'list' ]: return print_all_settings_and_stop() path = '' if len(args) < 2 else args[1] path = option_name_to_path(name, path) if len(args) == 2: return print_single_setting_and_stop(path) action = 'action=' leafs = path.split('.') name = leafs[-1] webcontrol.InitSettingsTreePages() cls = webcontrol._SettingsTreeNodesDict.get(name, None) input = ' '.join(args[2:]) #print cls, name, path, input if cls is None: return 2 if cls in [ webcontrol.SettingsTreeTextNode, webcontrol.SettingsTreeUStringNode, webcontrol.SettingsTreePasswordNode, webcontrol.SettingsTreeNumericNonZeroPositiveNode, webcontrol.SettingsTreeNumericPositiveNode,] : action = 'text=' + misc.pack_url_param(input) elif cls in [ webcontrol.SettingsTreeDiskSpaceNode, ]: number = misc.DigitsOnly(input, '.') suffix = input.lstrip('0123456789.-').strip() action = 'number=%s&suffix=%s' % (number, suffix) elif cls in [ webcontrol.SettingsTreeComboboxNode, ]: number = misc.DigitsOnly(input) action = 'choice=%s' % number elif cls in [ webcontrol.SettingsTreeYesNoNode, ]: trueORfalse = 'True' if input.lower().strip() == 'true' else 'False' action = 'choice=%s' % trueORfalse url = webcontrol._PAGE_SETTINGS + '/' + path + '?' + action run_url_command(url).addCallback(lambda src: print_single_setting_and_stop(path, False)) #.addCallback(print_and_stop) reactor.run() return 0
def cmd_money(opts, args, overDict): if len(args) == 1: url = webcontrol._PAGE_MONEY run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif len(args) >= 2 and args[1] == 'receipts': url = webcontrol._PAGE_RECEIPTS run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif len(args) >= 3 and args[1] == 'receipt': url = '%s/%s' % (webcontrol._PAGE_RECEIPTS, args[2]) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif len(args) >= 4 and args[1] == 'transfer': recipient = args[2].strip() url = '%s?action=commit&recipient=%s&amount=%s' % (webcontrol._PAGE_TRANSFER, misc.pack_url_param(recipient), args[3]) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 return 2
def cmd_suppliers(opts, args, overDict): def _wait_replace_supplier_and_stop(src, supplier_name, count=0): suppliers = [] for s in find_comments(src): if s.count('[online ]') or s.count('[offline]'): suppliers.append(s[18:38].strip()) if supplier_name not in suppliers: print ' supplier %s is fired !' % supplier_name print_and_stop(src) return if count >= 60: print ' time is out\n' reactor.stop() return else: def _check_again(supplier_name, count): sys.stdout.write('.') run_url_command(webcontrol._PAGE_SUPPLIERS).addCallback(_wait_replace_supplier_and_stop, supplier_name, count) reactor.callLater(1, _check_again, supplier_name, count+1) if len(args) < 2 or args[1] in [ 'list', 'ls' ]: url = webcontrol._PAGE_SUPPLIERS run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'call', 'cl' ]: url = webcontrol._PAGE_SUPPLIERS + '?action=call' run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'replace', 'rep', 'rp' ] and len(args) >= 3: contactsdb.init() idurl = args[2].strip() if not idurl.startswith('http://'): try: idurl = contactsdb.supplier(int(idurl)) except: idurl = '' if not idurl: print 'supplier IDURL is unknown\n' return 0 name = nameurl.GetName(idurl) url = webcontrol._PAGE_SUPPLIERS + '?action=replace&idurl=%s' % misc.pack_url_param(idurl) run_url_command(url).addCallback(_wait_replace_supplier_and_stop, name, 0) reactor.run() return 0 elif args[1] in [ 'change', 'ch' ] and len(args) >= 4: contactsdb.init() idurl = args[2].strip() if not idurl.startswith('http://'): try: idurl = contactsdb.supplier(int(idurl)) except: idurl = '' if not idurl: print 'supplier IDURL is unknown\n' return 0 newidurl = args[3].strip() name = nameurl.GetName(idurl) newname = nameurl.GetName(newidurl) url = webcontrol._PAGE_SUPPLIERS + '?action=change&idurl=%s&newidurl=%s' % (misc.pack_url_param(idurl), misc.pack_url_param(newidurl)) run_url_command(url).addCallback(_wait_replace_supplier_and_stop, name, 0) reactor.run() return 0 return 2
def cmd_backups(opts, args, overDict): if len(args) < 2 or args[1] == 'list': run_url_command(webcontrol._PAGE_BACKUPS+'?action=list').addCallback(print_and_stop) reactor.run() return 0 elif len(args) < 2 or args[1] == 'idlist': url = webcontrol._PAGE_BACKUPS+'?action=idlist' run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] == 'start' and len(args) >= 3: if packetid.Valid(args[2]): url = webcontrol._PAGE_BACKUPS+'?action=startid&pathid='+misc.pack_url_param(args[2]) else: if not os.path.exists(os.path.abspath(args[2])): print 'path %s not exist\n' % args[2] return 1 url = webcontrol._PAGE_BACKUPS+'?action=startpath&path='+misc.pack_url_param(os.path.abspath(args[2])) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] == 'add' and len(args) >= 3: localpath = os.path.abspath(args[2]) if not os.path.exists(localpath): print 'path %s not exist\n' % args[2] return 1 if os.path.isdir(localpath): url = webcontrol._PAGE_BACKUPS+'?action=diradd&opendir='+misc.pack_url_param(localpath) else: url = webcontrol._PAGE_BACKUPS+'?action=fileadd&openfile='+misc.pack_url_param(localpath) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] == 'addtree' and len(args) >= 3: localpath = os.path.abspath(args[2]) if not os.path.isdir(os.path.abspath(args[2])): print 'folder %s not exist\n' % args[2] return 1 url = webcontrol._PAGE_BACKUPS+'?action=diraddrecursive&opendir='+misc.pack_url_param(localpath) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] == 'starttree' and len(args) >= 3: localpath = os.path.abspath(args[2]) if not os.path.isdir(os.path.abspath(args[2])): print 'folder %s not exist\n' % args[2] return 1 url = webcontrol._PAGE_BACKUPS+'?action=startpathrecursive&path='+misc.pack_url_param(localpath) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] == 'delete' and len(args) >= 3: if args[2] == 'local': if len(args) >= 4: url = webcontrol._PAGE_BACKUPS+'/'+webcontrol._PAGE_BACKUP+args[3].replace('/','_')+'?action=delete.local' else: return 2 else: if packetid.Valid(args[2]): url = webcontrol._PAGE_BACKUPS+'?action=deleteid&pathid='+args[2].replace('/','_') else: url = webcontrol._PAGE_BACKUPS+'?action=deletepath&path='+misc.pack_url_param(os.path.abspath(args[2])) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] == 'update': url = webcontrol._PAGE_BACKUPS+'?action=update' run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 return 2
def cmd_money(opts, args, overDict): if len(args) == 1: url = webcontrol._PAGE_MONEY run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif len(args) >= 2 and args[1] == 'receipts': url = webcontrol._PAGE_RECEIPTS run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif len(args) >= 3 and args[1] == 'receipt': url = '%s/%s' % (webcontrol._PAGE_RECEIPTS, args[2]) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif len(args) >= 4 and args[1] == 'transfer': recipient = args[2].strip() if not recipient.startswith('http://'): recipient = 'http://'+settings.IdentityServerName()+'/'+recipient+'.xml' url = '%s?action=commit&recipient=%s&amount=%s' % (webcontrol._PAGE_TRANSFER, misc.pack_url_param(recipient), args[3]) run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 return 2