def post(self): params = self.get_params() domain_code = params.pop('domain_code') domain = self.db.query( models.TrDomain).filter_by(domain_code=domain_code).first() for attr_name in params: if attr_name in ('active', 'submit', 'domain_code', 'tpl_name'): continue domain_attr = self.db.query(models.TrDomainAttr).filter_by( domain_code=domain_code, attr_name=attr_name).first() if not domain_attr: domain_attr = models.TrDomainAttr() domain_attr.id = tools.gen_num_id(16) domain_attr.domain_code = domain_code domain_attr.attr_name = attr_name domain_attr.attr_value = self.get_argument(attr_name) domain_attr.attr_desc = '' domain_attr.sync_ver = tools.gen_sync_ver() self.db.add(domain_attr) else: domain_attr.attr_value = self.get_argument(attr_name) dispatch.pub(db_cache.CACHE_SET_EVENT, settings.wlanattr_cache_key(domain_attr.attr_name), domain_attr.attr_value, 600) self.add_oplog(u'操作员(%s)修改wlan参数' % self.current_user.username) self.db.commit() self.redirect('/admin/wlan/domain/detail?domain_id=%s' % domain.id)
def pub_notify(self, issues): builder = self.get_builder(issues.builder_name) if not builder: return dispatch.pub(ISSUES_ASSIGN_EVENT, issues.account_number, builder_phone=builder.builder_phone, wechat_oid=builder.wechat_oid)
def post(self): if os.environ.get('DEMO_VER'): self.redirect('/admin/config?active=syslog') return self.settings.config['syslog']['enable'] = int(self.get_argument('enable')) self.settings.config['syslog']['server'] = self.get_argument('server') self.settings.config['syslog']['port'] = int(self.get_argument('port', 514)) self.settings.config['syslog']['level'] = self.get_argument('level') self.settings.config.save() dispatch.pub(logger.EVENT_SETUP, self.settings.config) self.redirect('/admin/config?active=syslog')
def post(self): if os.environ.get('DEMO_VER'): self.write(u'这是一个演示版本,不提供此功能') return backup_path = self.settings.config.database.backup_path bakfs = self.get_argument('bakfs') try: os.remove(os.path.join(backup_path, bakfs)) return self.render_json(code=0, msg='delete done!') except Exception as err: dispatch.pub(logger.EVENT_EXCEPTION, err) return self.render_json(code=1, msg='delete fail! %s' % err)
def post(self): if os.environ.get('DEMO_VER'): self.render_json(code=1, msg=u'这是一个演示版本,不支持此功能') return backup_path = self.settings.config.database.backup_path backup_file = 'taurusxradius_db_%s.json.gz' % utils.gen_backep_id() try: self.db_backup.dumpdb(os.path.join(backup_path, backup_file)) return self.render_json(code=0, msg='backup done!') except Exception as err: dispatch.pub(logger.EVENT_EXCEPTION, err) return self.render_json(code=1, msg='backup fail! %s' % err)
def update_routeros_sync_event(self, name, pwd, profile, node_id): dispatch.pub(evset.ROSSYNC_SET_PPPOE_USER, name, pwd, profile, node_id=node_id, async=True) dispatch.pub(evset.ROSSYNC_SET_HOTSPOT_USER, name, pwd, profile, node_id=node_id, async=True)
def event_mail_account_expire(self, account_number): userinfo = self.get_customer_info(account_number) content_tpl = self.get_content_template(ExpireNotify) if not content_tpl: return content = content_tpl.replace('{customer_name}', utils.safeunicode(userinfo.realname)) content = content.replace('{product_name}', utils.safeunicode(userinfo.product_name)) content = content.replace('{username}', account_number) content = content.replace('{expire_date}', userinfo.expire_date) dispatch.pub(EVENT_SENDMAIL, userinfo.email, u'用户到期通知邮件', utils.safeunicode(content))
def event_wechat_account_open(self, account_number): """客户账号开户微信通知 """ userinfo = self.get_customer_info(account_number) content_tpl = self.get_content_template(OpenNotify) if not content_tpl: return content = content_tpl.replace('{customer_name}', utils.safeunicode(userinfo.realname)) content = content.replace('{product_name}', utils.safeunicode(userinfo.product_name)) content = content.replace('{username}', account_number) content = content.replace('{expire_date}', userinfo.expire_date) dispatch.pub(EVENT_SEND_WECHAT, userinfo.wechat_oid, utils.safeunicode(content))
def post(self): try: if os.environ.get('DEMO_VER'): self.write(u'这是一个演示版本,不提供上传功能') return f = self.request.files['Filedata'][0] savename = os.path.split(f['filename'])[1] save_path = os.path.join(self.settings.config.database.backup_path, savename) logger.info('upload dbfile {}'.format(save_path), eslog=True) tf = open(save_path, 'wb') tf.write(f['body']) tf.close() self.write('upload success') except Exception as err: dispatch.pub(logger.EVENT_EXCEPTION, err) self.write('upload fail %s' % str(err))
def post(self): if os.environ.get('DEMO_VER'): self.render_json(code=1, msg=u'这是一个演示版本,不支持此功能') return backup_path = self.settings.config.database.backup_path backup_file = 'taurusxradius_db_%s.before_restore.json.gz' % utils.gen_backep_id() rebakfs = self.get_argument('bakfs') try: self.db_backup.dumpdb(os.path.join(backup_path, backup_file)) if 'trv1' in rebakfs: self.db_backup.restoredbv1(os.path.join(backup_path, rebakfs)) else: self.db_backup.restoredb(os.path.join(backup_path, rebakfs)) return self.render_json(code=0, msg='restore done!') except Exception as err: dispatch.pub(logger.EVENT_EXCEPTION, err) return self.render_json(code=1, msg='restore fail! %s' % err)
def event_sms_account_expire(self, account_number): userinfo = self.get_customer_info(account_number) tplid = self.get_tpl_id(ExpireNotify) if not tplid: return args = [ utils.safestr(userinfo.realname), account_number, utils.safestr(userinfo.product_name), userinfo.expire_date ] kwargs = {} kwargs['customer'] = utils.safestr(userinfo.realname) kwargs['username'] = account_number kwargs['product'] = utils.safestr(userinfo.product_name) kwargs['expire'] = userinfo.expire_date dispatch.pub(EVENT_SENDSMS, userinfo.mobile, tplid, args=args, kwargs=kwargs)
def post(self): issues_id = self.get_argument('issues_id') builder_name = self.get_argument('builder_name') issues = self.db.query(models.TrIssues).get(issues_id) if builder_name == issues.builder_name: self.redirect('/admin/issues/detail?issues_id=%s' % issues_id) return issues.builder_name = builder_name issues.sync_ver = tools.gen_sync_ver() self.add_oplog(u'转派工单%s给%s' % (issues_id, builder_name)) builder = self.get_builder(issues.builder_name) if builder: dispatch.pub(ISSUES_ASSIGN, issues.account_number, builder_phone=builder.builder_phone, wechat_oid=builder.wechat_oid, content=issues.content) self.db.commit() self.redirect('/admin/issues/detail?issues_id=%s' % issues_id)
def post(self): active = self.get_argument('active', 'syscfg') for param_name in self.get_params(): if param_name in ('active', 'submit'): continue param = self.db.query( models.TrParam).filter_by(param_name=param_name).first() if not param: param = models.TrParam() param.param_name = param_name param.param_value = self.get_argument(param_name) param.sync_ver = tools.gen_sync_ver() self.db.add(param) else: param.param_value = self.get_argument(param_name) dispatch.pub(db_cache.CACHE_SET_EVENT, param_cache_key(param.param_name), param.param_value, 600) self.add_oplog(u'操作员(%s)修改参数' % self.current_user.username) self.db.commit() self.redirect('/admin/param?active=%s' % active)
def process(self, *args, **kwargs): self.logtimes() next_interval = self.get_next_interval() billtask_last_day = int(self.get_param_value('billtask_last_day', 3)) if billtask_last_day > 28: billtask_last_day = 28 _now = datetime.datetime.now() if _now.day > billtask_last_day: return next_interval cmonth = _now.strftime('%Y-%m') with make_db(self.db) as db: try: uquery = db.query(models.TrAccount).filter( models.TrAccount.product_id == models.TrProduct.id, models.TrAccount.balance > 0, models.TrAccount.status == 1, models.TrProduct.product_policy == PPMFlows, models.TrAccount.create_time < cmonth + '-01 00:00:00') for account in uquery: alog = db.query(models.TrAcceptLog).filter( models.TrAcceptLog.accept_type == 'auto_renew', models.TrAcceptLog.account_number == account.account_number, models.TrAcceptLog.accept_time >= cmonth + '-01 00:00:00') if alog.count() == 0: rets = dispatch.pub('ppmf_user_renew', account.account_number, account.product_id) except Exception as err: next_interval = 120 logger.info(u'预付费流量包月续费执行失败,%s, 下次执行还需等待 %s' % (repr(err), self.format_time(next_interval)), trace='task') logger.exception(err) return next_interval