- 论坛徽章:
- 1
|
加上代码格式超出字符数限制,只好用无格式的了。
monitor.py代码
# -*- coding: utf-8 -*-
import appuifw
import e32
import string
import graphics
from appuifw import *
from graphics import *
import socket
import md5
import time
"""
作者:刘天斯
邮箱:liutiansi@gmail.com
BLOG:http://blog.liuts.com
最后更新:2008-01-26 11:27
功能:Linux服务器手机版(客户端脚本),系统基于pys60+socket开发;
"""
class monitor:
#定义退出函数;
def __init__(self):
#IP列表
self.lines=[]
#读取配置文件串
self.configstr=[]
#选择服务器索引
self.index=0
#返回服务器串
self.getinfo=""
#空数据串
self.nullinfo="暂无数据!"
#帮助串
self.helpinfo="Linux服务器管理1.0\n 系统帮助信息:\n状态:检查服务器应用状态。\n管理:对应用进行操作。\n设置:配制系统参数。"
#标签项索引
self.tabsIndex=0
#展示文本对象
self.infotxt= appuifw.Text()
self.infotxt.style=appuifw.STYLE_BOLD
#读取配制文件
self.configfile=file(u"e:\\System\\Apps\\monitor\\config.ini",'r')
self.configstr=string.split(self.configfile.read().strip().decode("utf8"),',')
#实时时间+间隔时间+md5+返回记录数
self.configfile.close()
#菜单项
self.ipfw=[u'192.168.0/24',u'192.168.1/24',u'192.168.2/24',u'192.168.2/24']
appuifw.app.menu = [("状态".decode("utf8"), (("检测".decode("utf8"), self.server_check),("实时".decode("utf8"), self.server_realtime))),
("管理".decode("utf8"), (("应用管理".decode("utf8"), self.server_do),("最新日志".decode("utf8"), self.server_newslog),("选择日志".decode("utf8"), self.server_selelog))),
("设置".decode("utf8"), (("实时时间".decode("utf8"), self.sys_realtime),("实时间隔".decode("utf8"), self.sys_gaptime),("修改密码".decode("utf8"), self.sys_repasswd),("记录数目".decode("utf8"), self.sys_lognum))),
("关于".decode("utf8"), self.sys_about)]
#发送socket指令方法(发送串,显示屏ID);
def server_sendsocket(self,get_sendstr):
if get_sendstr!="":
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('server.sina.com.cn', 80))
#get_sendstr=base64.urlsafe_b64encode(get_sendstr)
sock.send(get_sendstr)
self.getinfo+=sock.recv(1024)+"\n"
sock.close()
except:
appuifw.note("socket异常!".decode("utf8"),"conf")
self.server_listinfo(self.tabsIndex)
#操作方法(操作类型,显示屏ID);
def server_do(self,option=1):
#option=1 检测服务器状态;
#option=2 实时检测服务器状态;
#option=3 最新服务器日志;
#option=4 选择服务器日志;
if self.index==0 and option!=3:
self.server_list()
self.index=appuifw.selection_list(choices=self.lines,search_field=1)
if self.index!=None and option!=3:
#返回简IP;
if self.lines[self.index][:3]=="192":
shortip="1"
if option==3:
self.server_sendsocket(str(option)+",,"+self.configstr[2]+",,"+self.configstr[3])
else:
Alg=Algorithm() #制定自己的算法
self.server_sendsocket(str(option)+","+str(shortip)+","+self.configstr[2]+","+string.split(self.lines[self.index],'.')[3]+","+self.configstr[3])+Alg
#格式:操作ID+IP类型+MD5pw+IP末段+功能码+算法;
#服务器状态检测;
def server_check(self):
self.getinfo=""
self.index=0
self.tabsIndex=1
self.server_do(1)
self.lines=[]
#服务器实时状态检测;
def server_realtime(self):
self.getinfo=""
self.index=0
self.tabsIndex=2
i=0
while 1:
time.sleep(1)
i+=1
if i%int(self.configstr[1])==0 or i==int(self.configstr[0]):
self.server_do(1)
if i==int(self.configstr[0]):
break;
self.lines=[]
#服务器最新日志
def server_newslog(self):
self.getinfo=""
self.index=0
self.tabsIndex=1
self.server_do(3)
self.lines=[]
#选择服务器日志
def server_selelog(self):
self.getinfo=""
self.index=0
self.tabsIndex=1
self.server_do(4)
self.lines=[]
#获取服务器列表;
def server_list(self):
try:
iplistFile=open(u"e:\\System\\Apps\\monitor\\ip.txt",'r')
except IOError,e:
appuifw.note(u"ERROR:"+e,"error")
serverindex=appuifw.selection_list(choices=self.ipfw,search_field=1)
for nowline in [l.strip() for l in iplistFile]:
if nowline[:3]==self.ipfw[serverindex][:3]:
self.lines.append(nowline.decode("utf8"))
del nowline
iplistFile.close()
self.lines.sort()
#写配制文件;
def sys_writesysconfig(self):
try:
f = file(u"e:\\System\\Apps\\monitor\\config.ini",'w+')
except IOError,e:
appuifw.note(u"ERROR:"+e,"error")
print >> f,str(self.configstr[0])+","+str(self.configstr[1])+","+str(self.configstr[2])+","+str(self.configstr[3])
f.seek(0)
f.close()
appuifw.note("数据更新成功!".decode("utf8"), "conf")
#配制实时时间;
def sys_realtime(self):
realtime = appuifw.query("间隔监控时间:".decode("utf8"), "number",int(self.configstr[0]))
if int(realtime)!=int(self.configstr[0]):
self.configstr[0]=realtime
self.sys_writesysconfig()
#配制间隔时间;
def sys_gaptime(self):
gaptime = appuifw.query("实时监控时间:".decode("utf8"), "number",int(self.configstr[1]))
if int(gaptime)!=int(self.configstr[1]):
self.configstr[1]=gaptime
self.sys_writesysconfig()
#修改密码;
def sys_repasswd(self):
passwd = appuifw.query("新密码:".decode("utf8"), "code")
if passwd!="":
usermm=md5.new()
usermm.update(passwd)
self.configstr[2]=usermm.hexdigest()
self.sys_writesysconfig()
#配制返回记录数;
def sys_lognum(self):
lognum = appuifw.query("返回记录数:".decode("utf8"), "number",int(self.configstr[3]))
if int(lognum)!=int(self.configstr[3]):
self.configstr[3]=lognum
self.sys_writesysconfig()
#显示数据
def server_listinfo(self,tabsIndex):
self.infotxt.set(self.getinfo.decode("utf8"))
appuifw.app.body = self.infotxt
appuifw.app.activate_tab(tabsIndex)
#返回PASSWD
def sys_passwd(self):
return self.configstr[2].strip()
#返回文本对象
def getgetinfo(self,tabsIndex):
if tabsIndex==3:
self.infotxt.set(self.helpinfo.decode("utf8"))
elif self.tabsIndex==tabsIndex:
self.infotxt.set(self.getinfo.decode("utf8"))
else:
self.infotxt.set(self.nullinfo.decode("utf8"))
return self.infotxt
#about
def sys_about(self):
appuifw.note(u"Linux Monitor1.0\nAuthor:Liutiansi\nMail:liutiansi@gmail.com\nCopyright:http://blog.liuts.com", "info")
[ 本帖最后由 phpcool 于 2010-1-11 20:15 编辑 ] |
|