Exemplo n.º 1
0
def deliface(id):
    s = request.environ.get('beaker.session')
    sql = " DELETE FROM netiface WHERE id=%s "
    sql2 = " select ifacename FROM netiface WHERE id=%s "
    ifacename = readDb(sql2, (id, ))
    result = writeDb(sql, (id, ))
    if result == True:
        writeNIconf(action='uptconf')
        cmds.servboot('networks', action='uptconf')
        writeUTMconf(action='uptconf')
        msg = {'color': 'green', 'message': u'删除成功'}
        cmds.gettuplerst('ip addr flush dev %s' %
                         ifacename[0].get('ifacename'))
        #如果是PPP类型接口,停用ADSL
        cmds.gettuplerst('ip link set %s down' % ifacename[0].get('ifacename'))
        cmds.gettuplerst(
            'ps aux|grep -e \'xdsl.*%s\'|grep -v grep|awk \'{print $2}\' |xargs -i kill -9 {}'
            % id)
        #恢复绑定
        sql2 = "update sysattr set status='1' where attr=%s"
        writeDb(sql2, (ifacename[0].get('ifacename'), ))
        return template('networkconf', session=s, msg=msg)
    else:
        msg = {'color': 'red', 'message': u'删除失败'}
        return template('networkconf', session=s, msg=msg)
Exemplo n.º 2
0
def do_additem():
    s = request.environ.get('beaker.session')
    ifacename = request.forms.get("ifacename")
    ifacetype = request.forms.get("ifacetype")
    ipaddr = request.forms.get("ipaddr")
    netmask = request.forms.get("netmask")
    gateway = request.forms.get("gateway")
    defaultgw = request.forms.get("defaultgw")
    extip = request.forms.get("extip").replace('\r\n','\n')
    # 判断填写网关和没有填写网关的情况
    if ipaddr == '' or netmask == '' :
       msg = {'color':'red','message':u'地址不合法,添加失败'}
       return(template('networkconf',session=s,msg=msg))
    if gateway != '' :
       if netmod.checkip(ipaddr) == False or netmod.checkmask(netmask) == False or netmod.checkip(gateway) == False or netmod.checknet(gateway,ipaddr,netmask) == False :
          msg = {'color':'red','message':u'地址不合法,添加失败'}
          return(template('networkconf',session=s,msg=msg))
    else :
         if netmod.checkip(ipaddr) == False or netmod.checkmask(netmask) == False :
            msg = {'color':'red','message':u'地址不合法,添加失败'}
            return(template('networkconf',session=s,msg=msg))
    for extlist in extip.split('\n'):
        if len(extlist.split('/')) == 3:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           extgw=extlist.split('/')[2]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False or netmod.checkip(extgw) == False or netmod.checknet(extgw,extsip,extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
        elif len(extlist.split('/')) == 2:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
           elif extlist == u'':
              True
           else :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))

    if ifacename == u'' :
       msg = {'color':'red','message':u'物理接口未选择,添加失败'}
       return(template('networkconf',session=s,msg=msg))

    sql = "INSERT INTO netiface (ifacename,ifacetype,ipaddr,netmask,gateway,defaultgw,extip) VALUES (%s,%s,%s,%s,%s,%s,%s)"
    data = (ifacename,ifacetype,ipaddr,netmask,gateway,defaultgw,extip)
    result = writeDb(sql,data)
    if result == True:
       writeNIconf(action='uptconf')
       cmds.servboot('networks',action='uptconf')
       writeUTMconf(action='uptconf')
       msg = {'color':'green','message':u'添加成功'}
       #已绑定的网卡禁止再次绑定
       sql2 = """ update sysattr set status="0" where attr=%s """
       writeDb(sql2,(ifacename,))
    return template('networkconf',session=s,msg=msg)
Exemplo n.º 3
0
def do_additem():
    s = request.environ.get('beaker.session')
    ifacename = request.forms.get("ifacename")
    ifacetype = request.forms.get("ifacetype")
    ipaddr = request.forms.get("ipaddr")
    netmask = request.forms.get("netmask")
    gateway = request.forms.get("gateway")
    defaultgw = request.forms.get("defaultgw")
    extip = request.forms.get("extip").replace('\r\n','\n')
    # 判断填写网关和没有填写网关的情况
    if ipaddr == '' or netmask == '' :
       msg = {'color':'red','message':u'地址不合法,添加失败'}
       return(template('networkconf',session=s,msg=msg))
    if gateway != '' :
       if netmod.checkip(ipaddr) == False or netmod.checkmask(netmask) == False or netmod.checkip(gateway) == False or netmod.checknet(gateway,ipaddr,netmask) == False :
          msg = {'color':'red','message':u'地址不合法,添加失败'}
          return(template('networkconf',session=s,msg=msg))
    else :
         if netmod.checkip(ipaddr) == False or netmod.checkmask(netmask) == False :
            msg = {'color':'red','message':u'地址不合法,添加失败'}
            return(template('networkconf',session=s,msg=msg))
    for extlist in extip.split('\n'):
        if len(extlist.split('/')) == 3:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           extgw=extlist.split('/')[2]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False or netmod.checkip(extgw) == False or netmod.checknet(extgw,extsip,extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
        elif len(extlist.split('/')) == 2:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
           elif extlist == u'':
              True
           else :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))

    if ifacename == u'' :
       msg = {'color':'red','message':u'物理接口未选择,添加失败'}
       return(template('networkconf',session=s,msg=msg))

    sql = "INSERT INTO netiface (ifacename,ifacetype,ipaddr,netmask,gateway,defaultgw,extip) VALUES (%s,%s,%s,%s,%s,%s,%s)"
    data = (ifacename,ifacetype,ipaddr,netmask,gateway,defaultgw,extip)
    result = writeDb(sql,data)
    if result == True:
       writeNIconf(action='uptconf')
       cmds.servboot('networks',action='uptconf')
       writeUTMconf(action='uptconf')
       msg = {'color':'green','message':u'添加成功'}
       #已绑定的网卡禁止再次绑定
       sql2 = """ update sysattr set status="0" where attr=%s """
       writeDb(sql2,(ifacename,))
    return template('networkconf',session=s,msg=msg)
Exemplo n.º 4
0
def do_editiface(id):
    s = request.environ.get('beaker.session')
    ifacename = request.forms.get("ifacename")
    ifacetype = request.forms.get("ifacetype")
    ipaddr = request.forms.get("ipaddr")
    netmask = request.forms.get("netmask")
    gateway = request.forms.get("gateway")
    defaultgw = request.forms.get("defaultgw")
    extip = request.forms.get("extip").replace('\r\n', '\n')
    # 判断提交异常
    if ipaddr == '' or netmask == '' :
       msg = {'color':'red','message':u'地址不合法,添加失败1'}
       return(template('networkconf',session=s,msg=msg))
    if gateway != '' :
       if netmod.checkipmask('%s/%s' % (ipaddr,netmask)) == False or netmod.checknet(gateway,ipaddr,netmask) == False :
          msg = {'color':'red','message':u'地址不合法,添加失败%s,%s,%s' % (gateway,ipaddr,netmask)}
          return(template('networkconf',session=s,msg=msg))
    else :
        if netmod.checkip(ipaddr) == False or netmod.checkmask(netmask) == False :
           msg = {'color':'red','message':u'地址不合法,添加失败3'}
           return(template('networkconf',session=s,msg=msg))

    for extlist in extip.split('\n'):
        if len(extlist.split('/')) == 3:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           extgw=extlist.split('/')[2]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False or netmod.checkip(extgw) == False or netmod.checknet(extgw,extsip,extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
        elif len(extlist.split('/')) == 2:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
        elif extlist == u'':
              True
        else :
           msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
           return(template('networkconf',session=s,msg=msg))

    if ifacename == u'' :
       msg = {'color':'red','message':u'物理接口未选择,更新失败'}
       return(template('addinterface',session=s,msg=msg))
    sql = "UPDATE netiface SET ifacename=%s,ifacetype=%s,ipaddr=%s,netmask=%s,gateway=%s,defaultgw=%s,extip=%s WHERE id=%s"
    data = (ifacename,ifacetype,ipaddr,netmask,gateway,defaultgw,extip,id)
    result = writeDb(sql,data)
    if result == True:
       writeNIconf(action='uptconf')
       cmds.servboot('networks',action='uptconf')
       writeUTMconf(action='uptconf')
       msg = {'color':'green','message':u'更新成功'}
    return template('networkconf',session=s,msg=msg)
Exemplo n.º 5
0
def do_editiface(id):
    s = request.environ.get('beaker.session')
    ifacename = request.forms.get("ifacename")
    ifacetype = request.forms.get("ifacetype")
    ipaddr = request.forms.get("ipaddr")
    netmask = request.forms.get("netmask")
    gateway = request.forms.get("gateway")
    defaultgw = request.forms.get("defaultgw")
    extip = request.forms.get("extip").replace('\r\n', '\n')
    # 判断提交异常
    if ipaddr == '' or netmask == '' :
       msg = {'color':'red','message':u'地址不合法,添加失败1'}
       return(template('networkconf',session=s,msg=msg))
    if gateway != '' :
       if netmod.checkipmask('%s/%s' % (ipaddr,netmask)) == False or netmod.checknet(gateway,ipaddr,netmask) == False :
          msg = {'color':'red','message':u'地址不合法,添加失败%s,%s,%s' % (gateway,ipaddr,netmask)}
          return(template('networkconf',session=s,msg=msg))
    else :
        if netmod.checkip(ipaddr) == False or netmod.checkmask(netmask) == False :
           msg = {'color':'red','message':u'地址不合法,添加失败3'}
           return(template('networkconf',session=s,msg=msg))

    for extlist in extip.split('\n'):
        if len(extlist.split('/')) == 3:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           extgw=extlist.split('/')[2]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False or netmod.checkip(extgw) == False or netmod.checknet(extgw,extsip,extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
        elif len(extlist.split('/')) == 2:
           extsip=extlist.split('/')[0]
           extmask=extlist.split('/')[1]
           if netmod.checkip(extsip) == False or netmod.checkmask(extmask) == False :
              msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
              return(template('networkconf',session=s,msg=msg))
        elif extlist == u'':
              True
        else :
           msg = {'color':'red','message':u'扩展IP地址不合法,更新失败'}
           return(template('networkconf',session=s,msg=msg))

    if ifacename == u'' :
       msg = {'color':'red','message':u'物理接口未选择,更新失败'}
       return(template('addinterface',session=s,msg=msg))
    sql = "UPDATE netiface SET ifacename=%s,ifacetype=%s,ipaddr=%s,netmask=%s,gateway=%s,defaultgw=%s,extip=%s WHERE id=%s"
    data = (ifacename,ifacetype,ipaddr,netmask,gateway,defaultgw,extip,id)
    result = writeDb(sql,data)
    if result == True:
       writeNIconf(action='uptconf')
       cmds.servboot('networks',action='uptconf')
       writeUTMconf(action='uptconf')
       msg = {'color':'green','message':u'更新成功'}
    return template('networkconf',session=s,msg=msg)
Exemplo n.º 6
0
def deliface(id):
    s = request.environ.get('beaker.session')
    sql = " DELETE FROM netiface WHERE id=%s "
    sql2 = " select ifacename FROM netiface WHERE id=%s "
    ifacename = readDb(sql2,(id,))
    result = writeDb(sql,(id,))
    if result == True :
       writeNIconf(action='uptconf')
       cmds.servboot('networks',action='uptconf')
       writeUTMconf(action='uptconf')
       msg = {'color':'green','message':u'删除成功'}
       cmds.gettuplerst('ip addr flush dev %s' % ifacename[0].get('ifacename'))
       #恢复绑定
       sql2 = "update sysattr set status='1' where attr=%s"
       writeDb(sql2,(ifacename[0].get('ifacename'),))
       return template('networkconf',session=s,msg=msg)
    else:
       msg = {'color':'red','message':u'删除失败'}
       return template('networkconf',session=s,msg=msg)
Exemplo n.º 7
0
def deliface(id):
    s = request.environ.get('beaker.session')
    sql = " DELETE FROM netiface WHERE id=%s "
    sql2 = " select ifacename FROM netiface WHERE id=%s "
    ifacename = readDb(sql2,(id,))
    result = writeDb(sql,(id,))
    if result == True :
       writeNIconf(action='uptconf')
       cmds.servboot('networks',action='uptconf')
       writeUTMconf(action='uptconf')
       msg = {'color':'green','message':u'删除成功'}
       cmds.gettuplerst('ip addr flush dev %s' % ifacename[0].get('ifacename'))
       #恢复绑定
       sql2 = "update sysattr set status='1' where attr=%s"
       writeDb(sql2,(ifacename[0].get('ifacename'),))
       return template('networkconf',session=s,msg=msg)
    else:
       msg = {'color':'red','message':u'删除失败'}
       return template('networkconf',session=s,msg=msg)