⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form.cgi

📁 嵌入式无线路由系统openwrt的web配置工具
💻 CGI
字号:
#!/usr/bin/haserl# Copyright (C) 2008 OpenRB.comcontent-type: text/html(function(){  var moduleId = 'interfaces_form', elems = FlashSYS.getCache( moduleId ), formAddChange = true, extraTable = null, i = 0, j = 0;  var formOptions = <? /lib/flashsys/modules/interfaces/form.lua ?>, bridges = <? br-json ?>, ifaces = <? if-json -e ?>,      ifName = formOptions && formOptions.params && formOptions.params.ifname ? formOptions.params.ifname : '';  if (!elems) {    var isBridge = (formOptions.params && formOptions.values['type'] == 'bridge'), ifBridges = {}, brName = null,        ifaceIp = (ifName && ifaces[ ifName ] && ifaces[ ifName ]['inetaddr']) ? ifaces[ ifName ]['inetaddr'] : $TR('unknown');    for (brName in bridges) {      var ifNames = bridges[ brName ].ifnames;      for (i = 0, j = ifNames.length; i < j; i++) {        ifBridges[ ifNames[ i ] ] = brName;      }    }    // check that there are enough interfaces for bridging    if (isBridge) {      brName = formOptions.params['new_bridge'] ? '' : formOptions.params.ifname, freeIfaces = [];      for (var iface in ifaces) {        if (iface.match(/^br-/) || (ifBridges[ iface ] && ifBridges[ iface ] != brName)) {          continue;        }        freeIfaces.push(iface);      }    }    var window = FlashSYS.newWindow({      id: moduleId,      title: $TR( moduleId ) + (ifName ? ' ' + ifName : ''),      width: 420,      height: 290,      canReload: false,      type: 'modal'    });    var formTabs = ['general'];    var formElems = [      { type: 'select', name: 'proto', values: ['none','static','dhcp','pppoe'], translate: true,        blocks: {          def: {'static': 0, 'pppoe': 0, 'misc': 0, 'dchp': 0},          change: {            'static': {'static': 1, 'pppoe': 0, 'misc': 1, 'dchp': 0},            'dhcp':   {'static': 0, 'pppoe': 0, 'misc': 1, 'dchp': 1},            'pppoe':  {'static': 0, 'pppoe': 1, 'misc': 1, 'dchp': 0}          }        }      },      { type: 'blockStart', name: 'static' },        { type: 'text', name: 'ipaddr', validate: 'ip' },        { type: 'text', name: 'netmask', def: '255.255.255.0', validate: 'ip' },        { type: 'text', name: 'gateway' },      'blockEnd',      { type: 'blockStart', name: 'pppoe' },        { type: 'text', name: 'username' },        { type: 'text', name: 'password' },        { type: 'text', name: 'keepalive' },        { type: 'text', name: 'demand' },        { type: 'text', name: 'server' },      'blockEnd',      { type: 'blockStart', name: 'dchp' },        { type: 'plain', name: 'currip', text: ifaceIp },      'blockEnd',      { type: 'blockStart', name: 'misc' },        { type: 'text', name: 'dns' },        { type: 'text', name: 'mtu', def: '1500', cls: 'w20p', addChange: false },      'blockEnd'    ];    // check that interface is already bridged    if (!isBridge) {      var bridgedToName = ifBridges[ formOptions.params.ifname ];      // bridged, show notice intead of general settings      if (bridgedToName) {        formOptions.params.bridged = true;        formElems = [          { type: 'plain', name: 'hint', text: $TR('interfaces_hint_bridged').replace('%0', bridgedToName), skipLabel: true, wrapCls: 'FSFormHint' }        ];      }    }    // check that wireless is supported    if (formOptions && formOptions.params && formOptions.params.wifidevice && formOptions.iwinfo) {      formTabs.push('wireless', 'advanced', 'security');      // format channel list      var chan2g = [['0', 'Auto']], chan5g = [['0', 'Auto']], txpowers = [['', 'Auto']], bitrates = [['', 'Auto']], mcastrates = [['', 'Auto']];      formOptions.wifidevice.channel_2g = formOptions.wifidevice.channel;      formOptions.wifidevice.channel_5g = formOptions.wifidevice.channel;      function formatFreq(freq) {        var f = freq.toString();        return [ f + 'M', f.substring(0, 1) + '.' + f.substring(1) + ' GHz' ];      }      // special case: superchannel      if (formOptions.wificcode && formOptions.wificcode == '513') {        for (i = 2312, j = 2502; i <= j; i += 5) {          chan2g.push(formatFreq(i));        }        for (i = 4915, j = 6085; i <= j; i += 5) {          chan5g.push(formatFreq(i));        }      }      // convert raw channel data to separate 2g and 5g lists      else if (formOptions.iwinfo.channels) {        var chan2gRaw = [], chan5gRaw = [];        for (var chan in formOptions.iwinfo.channels) {          var freq = formOptions.iwinfo.channels[ chan ];          if (freq < 3000) {            chan2gRaw.push(freq);          }          else {            chan5gRaw.push(freq);          }        }        chan2gRaw.sort();        chan5gRaw.sort();        for (i = 0, j = chan2gRaw.length; i < j; i++) {          chan2g.push(formatFreq( chan2gRaw[ i ] ));        }        for (i = 0, j = chan5gRaw.length; i < j; i++) {          chan5g.push(formatFreq( chan5gRaw[ i ] ));        }      }      // add tx powers in reverse order      if (formOptions.iwinfo.txpowers) {        for (var i = formOptions.iwinfo.txpowers.length - 1; i >= 0; i--) {          var txpower = formOptions.iwinfo.txpowers[ i ].toString();          txpowers.push([txpower, txpower + ' dBm']);        }      }      // add rates reverse order      if (formOptions.iwinfo.bitrates) {        for (var i = formOptions.iwinfo.bitrates.length - 1; i >= 0; i--) {          var bitrate = formOptions.iwinfo.bitrates[ i ].toString();          bitrates.push([bitrate + 'M', bitrate + ' Mb/s']);          mcastrates.push([bitrate * 1000, bitrate + ' Mb/s']);        }      }      // detect available modes for given interface      var agmodes = [['','Auto']];      if (formOptions.wifidevice['11a'] != '0') agmodes.push(['11a','5 GHz']);      if (formOptions.wifidevice['11b'] != '0') agmodes.push(['11b','2.4 GHz B']);      if (formOptions.wifidevice['11g'] != '0') agmodes.push(['11bg','2.4 GHz BG'], ['11g','2.4 GHz G']);      formElems.extend([        'tab',        { type: 'select', name: 'agmode', values: agmodes,          blocks: {            def: {'channel_2g': 0, 'channel_5g': 1 },            change: {              '11b':  {'channel_2g': 1, 'channel_5g': 0 },              '11bg': {'channel_2g': 1, 'channel_5g': 0 },              '11g':  {'channel_2g': 1, 'channel_5g': 0 }            }          }        },        { type: 'text', name: 'ssid' },        { type: 'select', name: 'mode', values: ['ap','sta','adhoc','wds'], translate: true,          blocks: {            def: {'channel_2g': 1, 'channel_5g': 1, 'hide_ssid': 0},            change: {              'sta':  {'channel_2g': 0, 'channel_5g': 0, 'hide_ssid': 0},              'ap': {'channel_2g': 1, 'channel_5g': 1, 'hide_ssid': 1}            },            useCls: true          }        },        { type: 'blockStart', name: 'channel_2g' },          { type: 'select', name: 'channel_2g', values: chan2g },        'blockEnd',        { type: 'blockStart', name: 'channel_5g' },          { type: 'select', name: 'channel_5g', values: chan5g },        'blockEnd',        { type: 'select', name: 'txpower', values: txpowers },        { type: 'select', name: 'rate', values: bitrates },        { type: 'blockStart', name: 'wds' },          { type: 'checkbox', name: 'wds' },        'blockEnd',        'tab',        { type: 'select', name: 'mcast_rate', values: mcastrates },        { type: 'text', name: 'distance', cls: 'w10p', postfix: $TR('meters'), 'validate': { 'required': false, 'digit': true } },        { type: 'checkbox', name: 'compression', falseValue: '0' },        { type: 'checkbox', name: 'bursting', falseValue: '0' },        { type: 'checkbox', name: 'bgscan', falseValue: '0' },        { type: 'checkbox', name: 'ff', falseValue: '0' },        { type: 'checkbox', name: 'xr', falseValue: '0' },        { type: 'checkbox', name: 'ar', falseValue: '0' },        'tab',        { type: 'select', name: 'encryption', values: ['none','wep','psk','psk2','wpa','wpa2'], translate: true,          blocks: {            def: {'psk_key': 0, 'wep_key': 0, 'radius': 0 },            change: {              'wep':  {'psk_key': 0, 'wep_key': 1, 'radius': 0 },              'psk':  {'psk_key': 1, 'wep_key': 0, 'radius': 0 },              'psk2': {'psk_key': 1, 'wep_key': 0, 'radius': 0 },              'wpa':  {'psk_key': 0, 'wep_key': 0, 'radius': 1 },              'wpa2': {'psk_key': 0, 'wep_key': 0, 'radius': 1 }            }          }        },        { type: 'blockStart', name: 'psk_key' },          { type: 'text', name: 'key' },        'blockEnd',        { type: 'blockStart', name: 'wep_key' },          { type: 'text', name: 'key1' },          { type: 'text', name: 'key2' },          { type: 'text', name: 'key3' },          { type: 'text', name: 'key4' },        'blockEnd',        { type: 'blockStart', name: 'radius' },          { type: 'text', name: 'server' },          { type: 'text', name: 'port' },        'blockEnd',        { type: 'blockStart', name: 'hide_ssid' },          { type: 'checkbox', name: 'hidden' },        'blockEnd'      ]);      var wifimode = formOptions.wifimode || '', wifiinfo = formOptions.wifiinfo;      // station list      if (wifimode == 'ap') {        formTabs.push('stalist');        var tableValues = {};        for (i = 0, j = wifiinfo.length; i < j; i++) {          var items = wifiinfo[i].clean().split(' ');          var id = items[0].replace(/\D/, '');          if (!id || items.length < 6) {            continue;          }          tableValues[ id ] = [ items[0].toUpperCase(), items[3], items[4], items[5] ];        }        extraTable = {          tab: 'stalist',          head: {            mac:  { width: 40 },            rate: { width: 20 },            rssi: { width: 20 },            dbm:  { width: 20 }          },          values: tableValues,          click: null        };      }      // access point list      else if (wifimode == 'sta') {        formTabs.push('aplist');        var tableValues = {};        var setSsid = function(params) {          var formElem = FlashSYS.getCache(params.moduleId).form;          formElem.tabs.tabClick(1);          formElem.getElement('ssid').set('value', params.ssid).focus();        }        for (i = 0, j = wifiinfo.length; i < j; i++) {          var items = wifiinfo[i].clean().split(' ');          // check for blank ssid          if (wifiinfo[i].substr(0, 1) == '') {            items.unshift('');          }          var id = items[1].replace(/\D/, '');          if (!id || items.length < 6) {            continue;          }          tableValues[ id ] = {            cells: [ items[0], items[1].toUpperCase(), items[2], items[3], (-95 + items[4].split(':')[0].toInt()) ],            params: {ssid: items[0], moduleId: moduleId}          }        }        extraTable = {          tab: 'aplist',          head: {            ssid: { width: 25 },            mac:  { width: 30 },            chan: { width: 15 },            rate: { width: 15 },            dbm: { width: 15 }          },          values: tableValues,          click: setSsid        };      }      formOptions.values = $merge(formOptions.values, formOptions.wifidevice, formOptions.wifiiface);    }    // check if interface is a bridge    else if (isBridge) {      var ifname = '';      formTabs.push('interfaces');      formOptions.params['bridge'] = true;      formElems.push();      if (formOptions.params['new_bridge']) {        formElems.unshift({ 'type': 'text', 'name': 'brname', 'validate': { 'required': true, 'alphanum': true, 'length': [2,5] } });        formAddChange = false;      }      formElems.push({ 'type': 'checkbox', 'name': 'stp' }, 'tab');      // add interfaces to second tab      for (i = 0, j = freeIfaces.length; i < j; i++) {        ifname = freeIfaces[ i ];        formElems.push({          'type': 'checkbox',          'name': 'if_' + ifname,          'value': ifname,          'title': ifname,          'noTranslate': true        });      }      // set bridged interfaces      if (formOptions.values.ifname) {        var bridged = formOptions.values.ifname.split(' ');        for (i = 0, j = bridged.length; i < j; i++) {          ifname = bridged[ i ];          formOptions.values[ 'if_' + ifname ] = ifname;        }      }    }    var form = new FlashSYS.Form(window.contentEl, {      module: moduleId,      saveModule: 'interfaces',      reload: 'interfaces',      trPrefix: 'interfaces_',      tabs: formTabs,      elements: formElems,      submitEl: window.footerEl,      addChange: formAddChange,      changeModule: 'interfaces',      changeAction: 'restart'    });    if (extraTable) {      var table = new FlashSYS.Table(form.tabs.getPanelByName(extraTable.tab), {        trPrefix: 'interfaces_',        tableHead: extraTable.head,        click: extraTable.click      });      table.loadValues(extraTable.values);    }    elems = FlashSYS.setCache( moduleId, { window: window, form: form });  }  elems.form.loadValues(formOptions.values, formOptions.params);})();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -