add cmd handling
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#
|
||||
VER = 1.36
|
||||
|
||||
import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal, cPickle, smtplib, traceback
|
||||
import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal, cPickle, smtplib, traceback, urllib
|
||||
|
||||
from subprocess import Popen, STDOUT, PIPE
|
||||
|
||||
@@ -42,7 +42,6 @@ msgw = None
|
||||
msgwB = None
|
||||
msgwHeight = 10
|
||||
|
||||
|
||||
def handler(signum, frame):
|
||||
global up, sig
|
||||
if up == 0:
|
||||
@@ -81,6 +80,7 @@ class Host:
|
||||
self.statetime = self.lastbeat
|
||||
self.interval = 0
|
||||
self.doesack = -1
|
||||
self.cmds = []
|
||||
num += 1
|
||||
|
||||
def getstate(self):
|
||||
@@ -386,10 +386,6 @@ def fromaddr(name, addr, boot, interval, acks):
|
||||
def readsock():
|
||||
global htab, win
|
||||
data, addr = sock.recvfrom(1024)
|
||||
try:
|
||||
sock.sendto("ACK", addr)
|
||||
except:
|
||||
pass
|
||||
pairs = string.split(data, ';')
|
||||
boot = 0
|
||||
shutdown = 0
|
||||
@@ -459,6 +455,16 @@ def readsock():
|
||||
except:
|
||||
pass
|
||||
|
||||
rmsg="ACK"
|
||||
if len(hosts[name].cmds) then
|
||||
rmsg=hosts[name].cmds[0]
|
||||
email("%s cmd exec" % name, "command '%s' initiated" % hosts[name].cmds[0])
|
||||
del hosts[name].cmds[0]
|
||||
try:
|
||||
sock.sendto(rmsg, addr)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
@@ -496,12 +502,30 @@ class HtmlHandler(SocketServer.BaseRequestHandler):
|
||||
if r[0] == "GET":
|
||||
uri = r[1]
|
||||
html = r[2]
|
||||
if uri != "/":
|
||||
upar=string.split(uri,"?")
|
||||
if len(upar) == 1:
|
||||
uarg=[]
|
||||
else:
|
||||
uargs=string.split(upar[1],"&")
|
||||
|
||||
code = 404
|
||||
cause = "Not Found"
|
||||
else:
|
||||
if uri == "/":
|
||||
code = 200
|
||||
cause = "OK"
|
||||
elif upar[0] == "/c": # /c?h=melschserver&c=sudo%20ls
|
||||
uname=""
|
||||
ucmd=""
|
||||
if uarg[0][:2] == "h=":
|
||||
uname=uarg[0][2:]
|
||||
if uarg[1][:2] == "c=":
|
||||
ucmd=uarg[1][2:]
|
||||
if ucmd != "" and uname != "" and hosts.has_key(uname):
|
||||
hosts[uname].cmds.append(urllib.unquote(ucmd))
|
||||
code = 200
|
||||
cause = "OK"
|
||||
|
||||
|
||||
|
||||
self.request.send("HTTP/1.0 %s %s\r\n" % (code, cause))
|
||||
self.request.send("Date: %s\r\n" % time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now)))
|
||||
|
||||
Reference in New Issue
Block a user