add cmd handling
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
VER = 1.36
|
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
|
from subprocess import Popen, STDOUT, PIPE
|
||||||
|
|
||||||
@@ -42,7 +42,6 @@ msgw = None
|
|||||||
msgwB = None
|
msgwB = None
|
||||||
msgwHeight = 10
|
msgwHeight = 10
|
||||||
|
|
||||||
|
|
||||||
def handler(signum, frame):
|
def handler(signum, frame):
|
||||||
global up, sig
|
global up, sig
|
||||||
if up == 0:
|
if up == 0:
|
||||||
@@ -81,6 +80,7 @@ class Host:
|
|||||||
self.statetime = self.lastbeat
|
self.statetime = self.lastbeat
|
||||||
self.interval = 0
|
self.interval = 0
|
||||||
self.doesack = -1
|
self.doesack = -1
|
||||||
|
self.cmds = []
|
||||||
num += 1
|
num += 1
|
||||||
|
|
||||||
def getstate(self):
|
def getstate(self):
|
||||||
@@ -386,10 +386,6 @@ def fromaddr(name, addr, boot, interval, acks):
|
|||||||
def readsock():
|
def readsock():
|
||||||
global htab, win
|
global htab, win
|
||||||
data, addr = sock.recvfrom(1024)
|
data, addr = sock.recvfrom(1024)
|
||||||
try:
|
|
||||||
sock.sendto("ACK", addr)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
pairs = string.split(data, ';')
|
pairs = string.split(data, ';')
|
||||||
boot = 0
|
boot = 0
|
||||||
shutdown = 0
|
shutdown = 0
|
||||||
@@ -459,6 +455,16 @@ def readsock():
|
|||||||
except:
|
except:
|
||||||
pass
|
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":
|
if r[0] == "GET":
|
||||||
uri = r[1]
|
uri = r[1]
|
||||||
html = r[2]
|
html = r[2]
|
||||||
if uri != "/":
|
upar=string.split(uri,"?")
|
||||||
code = 404
|
if len(upar) == 1:
|
||||||
cause = "Not Found"
|
uarg=[]
|
||||||
else:
|
else:
|
||||||
|
uargs=string.split(upar[1],"&")
|
||||||
|
|
||||||
|
code = 404
|
||||||
|
cause = "Not Found"
|
||||||
|
if uri == "/":
|
||||||
code = 200
|
code = 200
|
||||||
cause = "OK"
|
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("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)))
|
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