Chinaunix

标题: 服务器管理系统-手机终端[原创] [打印本页]

作者: phpcool    时间: 2010-01-08 13:04
标题: 服务器管理系统-手机终端[原创]
原文:http://blog.liuts.com/post/177/

        每逢佳节回老家不知道孩子们是否都安康,这回好了,3G时代已经到来,不用带上那笨重的本本也能够管理服务器了,只要有手机信号就行,呵呵。系统基于pys60+socket开发,需要什么样的功能,在服务器端写相应的模块即可,客户端升级也比较方便。安全方面使用加密传输+IP限制就差不多了。
default.py代码
# -*- coding: utf-8 -*-
import appuifw
import e32
import string
import graphics
import md5
from appuifw import *
from graphics import *
from moni import monitor

"""
作者:刘天斯
邮箱:liutiansi@gmail.com
最后更新:2008-01-26 11:27
BLOG:http://blog.liuts.com
功能:Linux服务器手机版(客户端脚本),系统基于pys60+socket开发;
"
""

def handle_redraw(rect):
    canvas.blit(bgimage)

def exit_key_handler():
    app_lock.signal()
    appuifw.app.set_exit()
    
def handle_tab(index):
    global app
    global lb
    global canvas
    if index == 0:
        appuifw.app.body = canvas
    else:
        appuifw.app.body = app.getgetinfo(index)

if __name__ == '__main__':
    appuifw.app.set_tabs(["主界面".decode("utf8"), "数据区".decode("utf8"), "实时区".decode("utf8"), "帮助".decode("utf8")],handle_tab)
    app = monitor()
    #系统环境初始化;
    img=Image.new((208,196))
    try:
        bgimage=Image.open(u"e:\\System\\Apps\\monitor\\monitor.jpg")
    except IOError,e:
        appuifw.note(u"ERROR:"+e,"error")
    canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
    appuifw.app.body = canvas
    appuifw.app.screen = 'normal'
    appuifw.app.title = "服务器管理1.0".decode("utf8")
    appuifw.app.exit_key_handler = exit_key_handler
    app_lock = e32.Ao_lock()
    

    #用户验证;
    Inputpasswd=appuifw.query("请输入管理密码:".decode("utf8"), "code")
    usermm=md5.new()
    usermm.update(Inputpasswd)
    if usermm.hexdigest()==app.sys_passwd():
        appuifw.note("验证通过!".decode("utf8"), "conf")
    else:
        appuifw.note("密码错误。".decode("utf8"), "error")
        app_lock.signal()
        appuifw.app.set_exit()
    app_lock.wait()


[ 本帖最后由 phpcool 于 2010-1-11 20:14 编辑 ]
作者: phpcool    时间: 2010-01-08 13:07
加上代码格式超出字符数限制,只好用无格式的了。
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 编辑 ]
作者: phpcool    时间: 2010-01-08 13:08
支持手机
S60 1st:
7650、3650、3660、N-GAGE、N-GAGE QD、松下X700、西门子SX1

S60 2nd:
6600

S60 2nd FP1:
6620(6600美版)、6260、3230、6670、7610、松下X800、联想P930、三星SGH-D728、摩托罗拉V1000

S60 2nd FP2:
6681、6682(6681美版)、6680、6630

S60 2nd FP3:
N70、N70音乐版、N70 IE版、N72、N90

S60 3rd:
3250、3250XM、5500 sport、5500 sport音乐版、E50、E60、E61、E62(E61大陆行)、E61i、E65、E70、N71、N73、N73音乐版、N73 IE版、N75、N77、N80、N91、N91 8GB、N92、N93、N93i、三星SGH-i400、LG KS10

S60 3rd FP1:
5700 XpressMusic、6110 Navigator、6120 classic、6121 classic(6120美版)、6290、N76、N95、E90 Communicator、三星SGH-i520


平台截图
我的手机MAIN

主界面


部分功能菜单





打包下载:
http://blog.liuts.com/post/177/
作者: int32    时间: 2010-01-08 13:17
赞一个!~  

建议楼主打包一下,提供下载。
作者: Mylib    时间: 2010-01-08 13:18
看起来不错,有空试试。
作者: phpcool    时间: 2010-01-08 15:29
打包下载地址:
http://blog.liuts.com/attachment.php?fid=55
有兴趣可以继续讨论。
作者: dooros    时间: 2010-01-08 19:28
不错不错,学习了。
作者: dongnanyanhai    时间: 2010-01-08 22:40
留个位置慢慢看,开玩笑的,楼主好强大,学习了!
作者: 为什么删我号    时间: 2010-01-09 14:41
学习!
作者: 小飞爱使申华    时间: 2010-01-09 15:17
的确很强大!
作者: liuerguying    时间: 2010-01-10 17:47
楼主   好强大呀         、、、、、、、、、、
作者: skynet    时间: 2010-02-10 09:12
LZ牛。希望共享一些有关python手机开发方面资料出来。这样就太感谢了。
作者: 为什么删我号    时间: 2010-02-11 15:54
支持原创
作者: tony_413    时间: 2010-02-12 23:05
牛,向楼主学习
作者: 为什么删我号    时间: 2010-02-16 10:05
支持!
作者: 23号    时间: 2010-02-16 22:49
谢谢共享!
作者: jjj137    时间: 2010-02-17 09:53
可惜啊,又是 s60 ……




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2