def summaryHandler(self, **kwargs): self.msg = [] pos = kwargs['position'] summary_jcfg = xte_summary.get() tmp = controller.lookup.get_template("summary.mako") for index in const.ALL_NICS: if index == pos: ret = xte_summary.reconnect_dynamic_wan(pos) if ret[0]: # reconnect successfully self.addMsg(_("Reconnect successfully")) else: self.addMsg(lang.change_error_msg(ret[1])) for index in const.ALL_USBS: if index == pos: ret = xte_summary.reconnect_dynamic_usb_wan(pos) if ret[0]: # reconnect successfully self.addMsg(_("Reconnect successfully")) else: self.addMsg(lang.change_error_msg(ret[1])) if summary_jcfg[0]: # load successfully return tmp.render(summary_args = summary_jcfg[1], msg_list = self.msg) else: self.addMsg(str(summary_jcfg[1])) return tmp.render(summary_args = {}, msg_list = self.msg)
def restore_cfg(self, cfgFile=None): CfgPath = "/tmp/cfgfile" lcHDRS = {} for key, val in cherrypy.request.headers.iteritems(): lcHDRS[key.lower()] = val formFields = myFieldStorage(fp=cherrypy.request.rfile, headers=lcHDRS, environ={'REQUEST_METHOD':'POST'}, keep_blank_values=True) cfgFile = formFields['cfgFile'] os.link(cfgFile.file.name, CfgPath) ret = xte_administration.importing(CfgPath, str(cherrypy.request.login)) login_name = cherrypy.session.get("LoginName") administration_jcfg = xte_administration.get() for dirPath, dirNames, fileNames in os.walk(controller.acc_online_dir): accName = fileNames tmp = controller.lookup.get_template("administration.mako") self.msg = [] if ret[0]: self.addMsg(_("Restore Configuration successfully")) return tmp.render(administration_args = administration_jcfg[1], acc_list = accName, user_name = login_name, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(administration_args = administration_jcfg[1], acc_list = accName, user_name = login_name, msg_list = self.msg)
def natHandler(self, **kwargs): self.msg = [] group_jcfg = info.getGroupJcfg() nat_jcfg = json.loads(kwargs['NatSetting']) summary_jcfg = xte_summary.get() if not summary_jcfg[0]: summary_jcfg[1] = {}; ret = xte_nat.set(nat_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("nat.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page Service -> NAT")) return tmp.render(nat_args = nat_jcfg, ipgroup_args = group_jcfg[0], servicegroup_args = group_jcfg[1], fqdn_args = group_jcfg[2], summary_args = summary_jcfg[1], msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(nat_args = nat_jcfg, ipgroup_args = group_jcfg[0], servicegroup_args = group_jcfg[1], fqdn_args = group_jcfg[2], summary_args = summary_jcfg[1], msg_list = self.msg)
def firmware_update(self, fwupfile=None): global firmware_updatekey CfgPath = "/tmp/updatefile" lcHDRS = {} for key, val in cherrypy.request.headers.iteritems(): lcHDRS[key.lower()] = val formFields = myFieldStorage(fp=cherrypy.request.rfile, headers=lcHDRS, environ={'REQUEST_METHOD':'POST'}, keep_blank_values=True) fwupfile = formFields['fwupfile'] os.link(fwupfile.file.name, CfgPath) ret = xte_administration.firmware_update(firmware_updatekey, CfgPath) login_name = cherrypy.session.get("LoginName") administration_jcfg = xte_administration.get() for dirPath, dirNames, fileNames in os.walk(controller.acc_online_dir): accName = fileNames tmp = controller.lookup.get_template("administration.mako") self.msg = [] if ret[0]: self.addMsg(_("Firmware update successfully, system rebooting...")) return tmp.render(administration_args = administration_jcfg[1], acc_list = accName, user_name = login_name, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(administration_args = administration_jcfg[1], acc_list = accName, user_name = login_name, msg_list = self.msg)
def dnsHandler(self, **kwargs): self.msg = [] dns_jcfg = json.loads(kwargs['DnsSetting']) ret = xte_dns.set(dns_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("dns.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page System -> DNS")) return tmp.render(dnsargs = dns_jcfg, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(dnsargs = dns_jcfg, msg_list = self.msg)
def fqdnHandler(self, **kwargs): self.msg = [] fqdn_jcfg = json.loads(kwargs["FqdnSetting"]) ret = xte_fqdn.set(fqdn_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("fqdn.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page System -> FQDN")) return tmp.render(fqdnargs=fqdn_jcfg, msg_list=self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(fqdnargs=fqdn_jcfg, msg_list=self.msg)
def servicegroupHandler(self, **kwargs): self.msg = [] servicegroup_jcfg = json.loads(kwargs['ServicegroupSetting']) ret = xte_service_group.set(servicegroup_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("service_group.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page System -> Service Group")) return tmp.render(servicegroup_args = servicegroup_jcfg, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(servicegroup_args = servicegroup_jcfg, msg_list = self.msg)
def wan_detHandler(self, **kwargs): self.msg = [] wandet_jcfg = json.loads(kwargs['WanDetSetting']) ret = xte_wan_detection.set(wandet_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("wan_detection.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page System -> WAN Detection")) return tmp.render(wandet_args = wandet_jcfg, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(wandet_args = wandet_jcfg, msg_list = self.msg)
def arptableHandler(self, **kwargs): self.msg = [] arp_table_jcfg = json.loads(kwargs["ArptableSetting"]) ret = xte_arp_table.set(arp_table_jcfg, str(cherrypy.request.login)) arp_table_new_jcfg = xte_arp_table.get() tmp = controller.lookup.get_template("arp_table.mako") if ret[0] and arp_table_new_jcfg[0]: # save successfully self.addMsg(_("Settings are applied for page System -> ARP Table")) return tmp.render(arptable_args=arp_table_new_jcfg[1], msg_list=self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(arptable_args=arp_table_jcfg, msg_list=self.msg)
def syslogHandler(self, **kwargs): self.msg = [] syslog_jcfg = json.loads(kwargs['SyslogSetting']) syslog_jcfg['server'] = str(syslog_jcfg['server']) ret = xte_syslog.set(syslog_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("syslog.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page Log -> Syslog")) return tmp.render(syslogargs = syslog_jcfg, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(syslogargs = syslog_jcfg, msg_list = self.msg)
def ipgroupHandler(self, **kwargs): self.msg = [] fqdn_jcfg = info.getGroupJcfg()[2] ipgroup_jcfg = json.loads(kwargs['IpgroupSetting']) ret = xte_ip_group.set(ipgroup_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("ip_group.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page System -> IP Group")) return tmp.render(ipgroup_args = ipgroup_jcfg, fqdn_args = fqdn_jcfg, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(ipgroup_args = ipgroup_jcfg, fqdn_args = fqdn_jcfg, msg_list = self.msg)
def dhcpHandler(self, **kwargs): self.msg = [] dhcp_jcfg = json.loads(kwargs['DhcpSetting']) ret = xte_dhcp_dmz.set(dhcp_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("dhcp.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page Service -> DHCP (DMZ)")) return tmp.render(dhcpargs = dhcp_jcfg, dhcp_caption = self.caption, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(dhcpargs = dhcp_jcfg, dhcp_caption = self.caption, msg_list = self.msg)
def timeHandler(self, **kwargs): self.msg = [] time_jcfg = json.loads(kwargs['TimeSetting']) tmp = controller.lookup.get_template("date_time.mako") ret = xte_date_and_time.set(time_jcfg, str(cherrypy.request.login)) date_time = xte_date_and_time.get() if date_time[0]: time_jcfg["date"] = date_time[1]["date"] if ret[0] and date_time[0]: # save successfully self.addMsg(_("Settings are applied for page System -> Date/Time")) return tmp.render(timeargs = time_jcfg, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(timeargs = time_jcfg, msg_list = self.msg)
def virtualserverHandler(self, **kwargs): self.msg = [] group_jcfg = info.getGroupJcfg() vs_jcfg = json.loads(kwargs['VirtualserverSetting']) ret = xte_virtual_server.set(vs_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("virtual_server.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page Service -> Virtual Server")) return tmp.render(vsargs = vs_jcfg, servicegroup_args = group_jcfg[1], msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(vsargs = vs_jcfg, servicegroup_args = group_jcfg[1], msg_list = self.msg)
def ddnsHandler(self, **kwargs): self.msg = [] ddns_jcfg = json.loads(kwargs['DDnsSetting']) ret = xte_ddns.set(ddns_jcfg, str(cherrypy.request.login)) # To avoid password wrong ddns_cfg = xte_ddns.get() for i in const.ALL_WANS: ddns_jcfg[i]["password"] = ddns_cfg[1][i]["password"] tmp = controller.lookup.get_template("ddns.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page System -> DDNS")) return tmp.render(ddns_args = ddns_jcfg, msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(ddns_args = ddns_jcfg, msg_list = self.msg)
def networkHandler(self, **kwargs): self.msg = [] network_jcfg = json.loads(kwargs['NetworkSetting']) ret = xte_network.set(network_jcfg, str(cherrypy.request.login)) # To avoid password wrong network_cfg = xte_network.get() usb_jcfg = xte_network.getusb() for i in const.ALL_NICS: network_jcfg[i]["pppoe-mode"]["password"] = network_cfg[1][i]["pppoe-mode"]["password"] tmp = controller.lookup.get_template("network.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page System -> Network Setting")) return tmp.render(network_args = network_jcfg, usb_args = usb_jcfg[1], msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(network_args = network_jcfg, usb_args = usb_jcfg[1], msg_list = self.msg)
def connlimitHandler(self, **kwargs): self.msg = [] group_jcfg = info.getGroupJcfg() connlimit_jcfg = json.loads(kwargs['ConnlimitSetting']) ret = xte_connection_limit.set(connlimit_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("connection_limit.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page Service -> Connection Limit")) return tmp.render(connlimit_args = connlimit_jcfg, ipgroup_args = group_jcfg[0], servicegroup_args = group_jcfg[1], fqdn_args = group_jcfg[2], msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(connlimit_args = connlimit_jcfg, ipgroup_args = group_jcfg[0], servicegroup_args = group_jcfg[1], fqdn_args = group_jcfg[2], msg_list = self.msg)
def firewallHandler(self, **kwargs): self.msg = [] group_jcfg = info.getGroupJcfg() fw_jcfg = json.loads(kwargs['FirewallSetting']) ret = xte_firewall.set(fw_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("firewall.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page Service -> Firewall")) return tmp.render(fwargs = fw_jcfg, ipgroup_args = group_jcfg[0], servicegroup_args = group_jcfg[1], fqdn_args = group_jcfg[2], msg_list = self.msg) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render(fwargs = fw_jcfg, ipgroup_args = group_jcfg[0], servicegroup_args = group_jcfg[1], fqdn_args = group_jcfg[2], msg_list = self.msg)
def autoroutingHandler(self, **kwargs): self.msg = [] group_jcfg = info.getGroupJcfg() ar_jcfg = json.loads(kwargs["AutoroutingSetting"]) ret = xte_auto_routing.set(ar_jcfg, str(cherrypy.request.login)) tmp = controller.lookup.get_template("auto_routing.mako") if ret[0]: # save successfully self.addMsg(_("Settings are applied for page Service -> Auto Routing")) return tmp.render( arargs=ar_jcfg, ipgroup_args=group_jcfg[0], servicegroup_args=group_jcfg[1], fqdn_args=group_jcfg[2], msg_list=self.msg, ) else: self.addMsg(lang.change_error_msg(ret[1])) return tmp.render( arargs=ar_jcfg, ipgroup_args=group_jcfg[0], servicegroup_args=group_jcfg[1], fqdn_args=group_jcfg[2], msg_list=self.msg, )
def reboot(self): ret = xte_administration.reboot() return (lang.change_error_msg(ret[1]))