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

📄 arnoldhandler.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
📖 第 1 页 / 共 2 页
字号:
    page.headersList = ['ip','dns','mac','netbios','orgid','status','reason','lastchanged','details']    page.headers = { 'ip': 'Ip', 'dns':'Dns', 'mac':'Mac','netbios':'Netbios', 'orgid':'Orgid', 'status':'Status' ,'reason':'Reason', 'lastchanged':'Lastchanged', 'details':'&nbsp;', '':''}    if days < '0':        days = '0'            page.days = days    page.headertext = "History"    page.hitstext = "hits in history based on activity the last " + days + " days"    page.sort = 1    try:        cur.execute("SELECT DISTINCT identityid, ip, mac, dns, netbios, orgid, text AS reason, multiple, starttime, swsysname AS sysname, swmodule, swport, blocked_status AS status, to_char(lastchanged,'YYYY-MM-DD HH24:MI:SS') as lastchanged FROM identity LEFT JOIN blocked_reason USING (blocked_reasonid) WHERE lastchanged > current_date + integer '-" + days + "'  ORDER BY " + sort)        list = cur.dictfetchall()    except psycopg.DatabaseError, e:        list = {}    for item in list:        item['details'] = "<a href='showdetails?id=" + str(item['identityid']) +"'>Details</a>"    page.hits = cur.rowcount    page.list = list    page.section = section############################################################def printBlocked(cur, page, sort, section):    page.headersList = ['ip','dns','netbios','orgid','reason','sysname','lastchanged','activate','details']    page.headers = { 'ip': 'Ip', 'dns':'Dns', 'netbios':'Netbios', 'orgid':'Orgid','reason':'Reason', 'sysname':'Switch', 'lastchanged':'Lastchanged', 'activate':'&nbsp;', 'details':'&nbsp;'}    cur.execute("SELECT DISTINCT identityid,orgid,ip,mac,dns,netbios,text as reason, multiple,starttime,lastchanged,swsysname as sysname, swmodule,swport,userlock,secret FROM identity LEFT JOIN blocked_reason USING (blocked_reasonid) WHERE blocked_status='disabled' ORDER BY " + sort)    page.hits = cur.rowcount    page.headertext = "List of ports currently blocked"    page.hitstext = "ports blocked"        list = cur.dictfetchall()    for item in list:        item['lastchanged'] = item['lastchanged'].strftime('%Y-%m-%d %k:%M:%S')        item['activate'] = "<a href='arnold/doenable?id=" + str(item['identityid']) + "'>Activate port</a>"        item['details'] = "<a href='showdetails?id=" + str(item['identityid']) +"'>Details</a>"    page.sort = 1    page.list = list    page.section = section############################################################def printSearch(cur, page, searchfield, searchtext, status, days):    searchfields = ['IP','MAC','Netbios','dns','Orgid']    page.statusfields = ['disabled','enabled','both']    page.searchfields = searchfields    page.searchfield = searchfield    page.searchtext = searchtext    page.days = days or '7'    if days < '0':        days = '0'    page.status = status or 'both'    if searchtext:                page.headersList = ['ip','dns','mac','netbios','orgid','status','reason','lastchanged','history']        page.headers = { 'ip': 'Ip', 'dns':'Dns', 'mac':'Mac', 'netbios':'Netbios', 'orgid':'Organization', 'status':'Status' ,'reason':'Reason', 'lastchanged':'Lastchanged', 'history':'&nbsp;'}        whereclause = ''        # Check searchfield        if searchfield.lower() == 'ip':            whereclause = " WHERE " + searchfield.lower() + " <<= inet '" + searchtext + "' "        else:            whereclause = " WHERE " + searchfield.lower() + " LIKE '%" + searchtext + "%' "        # Status - radiobuttons        if status == 'disabled':            whereclause += " AND blocked_status = 'disabled' "        elif status == 'enabled':            whereclause += " AND blocked_status = 'enabled' "        else:            pass        # Days        days = days or 7        q = "SELECT DISTINCT identityid, ip, mac, dns, netbios, orgid, text AS reason, multiple, starttime, swsysname AS sysname, swmodule, swport, blocked_status AS status, to_char(lastchanged,'YYYY-MM-DD HH24:MI:SS') as lastchanged FROM identity LEFT JOIN blocked_reason USING (blocked_reasonid)" + whereclause + " AND lastchanged > current_date + integer '-" + days + "' "        try:            cur.execute(q)            searchresults = cur.dictfetchall()            numresults = cur.rowcount                        if numresults == 0:                page.headertext = "Search for " + searchfield + " = \"" + searchtext + "\", status = " + page.status + ", last changed " + page.days + " days ago, did not return anything."                page.searchresults = {}            else:                for element in searchresults:                    element['history'] = "<a href='showdetails?id=" + str(element['identityid']) + "'>History</a>"                page.headertext = "Searchresults when searching for " + searchfield + " with value '" + searchtext + "'"                page.searchresults = searchresults                page.hits = cur.rowcount                page.hitstext = "result(s) found"                        except psycopg.DatabaseError:            page.searchresults = {}            page.headertext = "<!-- " + q + "-->DBError. Search for " + searchfield + " = \"" + searchtext + "\", status = " + page.status + ", last changed " + page.days + " days ago, did not return anything."    else:        page.searchresults = {}    page.sort = 0        ############################################################def printBlocks(cur, page, sort, section):    page.headersList = ['blockid', 'blocktitle', 'blockdesc', 'active', 'edit']    page.headers = {'blockid': 'ID', 'blocktitle': 'Title', 'blockdesc': 'Description', 'active': 'Active', 'edit':'&nbsp;'}    cur.execute("SELECT * FROM block ORDER BY " + sort)    list = cur.dictfetchall()    for element in list:        element['edit'] = "<a href='addBlocktype?blockid=%s'>Edit</a>" %element['blockid']        if element['active'] == 'y':            element['active'] = 'Yes'        else:            element['active'] = 'No'    page.hits = cur.rowcount    page.headertext = "List of current blocktypes"    page.hitstext = "blocktypes registered"    page.sort = 1    page.list = list    page.section = section############################################################def showDetails (cur, page, section, id):    page.headersList = ['ip', 'dns', 'netbios', 'mac', 'sysname', 'modport', 'status', 'starttime', 'lastchanged', 'autoenable', 'mail']    page.headers = {'ip':'Ip', 'dns':'Dns', 'netbios':'Netbios', 'mac':'Mac', 'sysname':'Switch', 'modport':'Port', 'status':'Status', 'starttime':'Starttime', 'lastchanged':'Lastchanged', 'autoenable':'Autoenable', 'mail':'Mail'}    cur.execute("SELECT ip,dns,netbios,mac,swsysname as sysname,swmodule,swport,lastchanged,starttime,mail,blocked_status as status,autoenable FROM identity WHERE identityid = " + id)    list = cur.dictfetchall()    for element in list:        element['modport'] = str(element['swmodule']) + ":" + str(element['swport'])        element['starttime'] = element['starttime'].strftime('%Y-%m-%d %k:%M:%S')        element['lastchanged'] = element['lastchanged'].strftime('%Y-%m-%d %k:%M:%S')        if element['autoenable']:            element['autoenable'] = element['autoenable'].strftime('%Y-%m-%d %k:%M:%S')        else:            element['autoenable'] = '&nbsp;'    page.list = list    page.section = section    page.sort = 0    page.headertext = "Details for " + list[0]['ip']    cur.execute("SELECT eventtime,event_comment as comment,blocked_status as action,text as reason, username FROM event LEFT JOIN blocked_reason USING (blocked_reasonid) WHERE identityid=" + id + " ORDER BY eventtime")    page.headersList2 = ['eventtime','action','reason','comment','username']    page.headers2 = {'eventtime':'Eventtime', 'action':'Action', 'reason':'Reason', 'comment':'Comment', 'username':'User'}    list2 = cur.dictfetchall()    for element in list2:        element['reason'] = element['reason'] or "&nbsp;"        element['comment'] = element['comment'] or "&nbsp;"    page.hits2 = cur.rowcount    page.hitstext2 = "entries in history"    page.headertext2 = "History"    page.list2 = list2############################################################def printBlockreasons(cur, page,section):    page.blockreasonheadersList = ['text']    page.blockreasonheaders = {'text':'Reason'}    cur.execute("SELECT blocked_reasonid as id, text FROM blocked_reason");    page.blockreasons = cur.dictfetchall()    page.hits = cur.rowcount    page.sort = 0    page.hitstext = "reasons in the database"    page.headertext = "Existing reasons for blocking"############################################################def printManualblock(cur,page,sort,section):    cur.execute("SELECT blocked_reasonid AS id, text FROM blocked_reason ORDER BY text");    page.reasons = cur.dictfetchall()############################################################def printAddblocktype (cur, page, id):    cur.execute("SELECT blocked_reasonid as id, text FROM blocked_reason ORDER BY text");    page.blockreasons = cur.dictfetchall()    blockinfo = {'blockid':'', 'blocktitle':'', 'blockdesc':'', 'mailfile':'', 'reasonid':0, 'determined':'n', 'incremental':'n', 'blocktime':'', 'userid':'cron', 'active':'n', 'inputfile':''}    if id:        cur.execute("SELECT * FROM block WHERE blockid=%s" %id)        blockinfo = cur.dictfetchone()        blockinfo['lastedited'] = blockinfo['lastedited'].strftime('%Y-%m-%d %k:%M:%S')    page.blockinfo = blockinfo            ############################################################# A helpful function for redirecting a web-page to another one.def redirect(req, url):    req.headers_out.add("Location", url)    raise apache.SERVER_RETURN, apache.HTTP_MOVED_TEMPORARILYdef readConfig(path):    try:        file = open (path)        lines = file.readlines()        file.close()    except IOError:        return        config = {}    for line in lines:        if re.search("(^#|^\s+)", line):            continue        (var,val) = line.split("=")        var = var.strip()        val = val.strip()        config[var] = val    return config

⌨️ 快捷键说明

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