python 运维平台agent_用python写的agent

解决apache+python无法执行一些root命令的问题

用root启动python服务器端,远程可以执行任何root命令

#/usr/bin/python

#Filename:agent.py

#siyu@2012-6-29

#example:

#curl hostname:PORT_NUMBER/?PASSWORD?COMMAND?OPTION

#

import time

import BaseHTTPServer

import urlparse

import os

PASSWORD = 'hello1234'

HOST_NAME = 'sqa.broom.cm4' # !!!REMEMBER TO CHANGE THIS!!!

PORT_NUMBER = 8082 # Maybe set this to 9000.

def testcommand(c):

commandzoo = ('ls','fdisk')

if c not in commandzoo:

return 1

return 0

class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):

def do_HEAD(s):

s.send_response(200)

s.send_header("Content-type", "text/html")

s.end_headers()

def do_GET(s):

"""Respond to a GET request."""

s.send_response(200)

s.send_header("Content-type", "text/html")

s.end_headers()

#s.wfile.write("

ngis agent")

print s.path

string = s.path

string = string.split('?')

passwd = string[1]

command = string[2]

option = string[3]

if passwd == PASSWORD:

if testcommand(command) == 1:

s.wfile.write("command not found")

else:

x = ""

#x = "/bin/"

x = command

x += " "

x += option

print x

output = os.system(x)

print "result",output

s.wfile.write(output)

else:

s.wfile.write("password error")

#s.wfile.write("

You accessed path: %s

" % s.path)

#s.wfile.write("

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值