Beispiel #1
0
def resolve(args):
    if len(args) == 1 and args[0] == "help":
        return (0, help_info())
    if len(args) != 2:
        return (0, PF.normal_info("input arguments error, input 'login help' to get help"))
    try:
        sql_connect = pymysql.connect(
            host=SQL.Sql_Host,
            user=SQL.Sql_User,
            passwd=SQL.Sql_Password,
            database=SQL.Sql_Database,
            charset=SQL.Sql_Charset,
            connect_timeout=SQL.Sql_TimeOut,
        )
    except Exception:
        return (0, PF.error_info("sql connect error"))
    event_handler = sql_connect.cursor()
    query_string = SQL.Sql_Select_User % (args[0])
    # print(query_string)
    if not event_handler.execute(query_string):
        return (0, PF.normal_info("user " + args[0] + " dose not exist"))
    try:
        user_info = event_handler.fetchall()[0]
        # print(user_info[1])
        # print(Hash.hash(args[1]))
        if user_info[1] == Hash.hash(args[1]):
            return (user_info[2], PF.normal_info("login successfully"))
        else:
            return (0, PF.normal_info("wrong password"))
    except:
        return PF.error_info("unexpect")
Beispiel #2
0
def resolve(args):
    if len(args)==1 and args[0]=='help':
        return help_info()
    if len(args)!=2:
        return PF.normal_info("input arguments error, input 'timer help' to get help");
    if re.search(RE.Re_User_Date,args[0])==None:
        return PF.normal_info('date fromat is wrong.')
    if re.search(RE.Re_User_Time,args[1])==None:
        return PF.normal_info('time fromat is wrong.')
    try:
        #y-m-d
        date=args[0].split('-')
        #h-m-s
        time=args[1].split(':')
        #print(date)
        #print(time)
        #8/08/2008 20:00:00
        time_output0=args[0]+' '+args[1]
        time_output1=date[1]+'/'+date[2]+'/'+date[0]+' '+time[0]+':'+time[1]+':'+time[2]
        #output=content1+args[0]+' '+args[1]+content2+time_output+content3
        dom_id0=str(random.randint(0,2147483648))
        dom_id1=str(random.randint(0,2147483648))
        output=content%(time_output0,dom_id0,dom_id1,time_output1,dom_id0,dom_id1)
        #output="""<div align="center" class="STYLE3">距'%s'还有</div>"""%(time_output0)
        return output
    except:
        return PF.error_info('error')
Beispiel #3
0
def order_resolve(cmd,args,sockethandler):
    """

    """
    try:
        if cmd =='help':
            return  shell_help()
        if cmd == 'login' :
            temp=Function_Dict[cmd][1].resolve(args)
            sockethandler.user_state=temp[0]
            return temp[1]
        if cmd == 'logout':
            sockethandler.user_state=0
            return Function_Dict[cmd][1].resolve(args)
        if cmd =='registr':
            return Function_Dict[cmd][1].resolve(args)
        if cmd not in Function_Dict:
            return PF.normal_info('Sorry , command '+cmd+' is not found. Input help to see more. Or contact [email protected]')

        if Function_Dict[cmd][0]==0 or (Function_Dict[cmd][0] & sockethandler.user_state):
            return Function_Dict[cmd][1].resolve(args)
        else:
            return 'Sorry , '+User_Privilege[sockethandler.user_state]+' , your permission level is not high enough to use this command'
    except all:
        return PF.error_info('resolve')
Beispiel #4
0
def resolve(args):
    if len(args)==1 and args[0]=='help':
        return help_info()
    if len(args)!=1:
        return PF.normal_info("input arguments error, input 'eval help' to get help")
    try:
        return PF.normal_info(eval(args[0]))
    except Exception:
        return PF.error_info('wrong expression')
Beispiel #5
0
def time(info,args):
    try:
        if len(info)!=0 and info[0]=='help':
            return help_info()
        nowzone=pytz.timezone(args['-timezone'])
        dt=datetime.datetime.now(nowzone)
        output=dt.strftime(OutPatternHead)+str(args['-timezone'])+' '+dt.strftime(OutPatternTail)[:3]
        return PF.normal_info(output)
    except :
        return PF.error_info('inside '+str(args))
Beispiel #6
0
def resolve(args):
    try:

        cmd=''
        for i in args:
            cmd+=str(i)+' '
        result=os.popen(cmd).readlines()
        output=''
        for i in result:
            output+="<span class='info'>"+i[:len(i)-1]+"</span><br />"
        return output
    except:
        return PF.error_info('excute error')
Beispiel #7
0
def resolve(args):
    if len(args)==1 and args[0]=='help':
        return help_info()
    if len(args)!=3:
        return PF.normal_info("input arguments error, input 'registr help' to get help");

#    if re.search(RE.Re_User_Name,args[0])==None:
#        return PF.normal_info('username fromat is wrong.')
#    if re.search(RE.Re_User_Password,args[1])==None:
#        return PF.normal_info('password fromat is wrong.')
#    if re.search(RE.Re_User_Email,args[2])==None:
#        return PF.normal_info('email fromat is wrong.')
    try:
        sql_connect=pymysql.connect(
            host=SQL.Sql_Host,
            user=SQL.Sql_User,
            passwd=SQL.Sql_Password,
            database=SQL.Sql_Database,
            charset=SQL.Sql_Charset,
            connect_timeout=SQL.Sql_TimeOut
        )
    except:
        return PF.error_info('sql connect error')
    event_handler=sql_connect.cursor()
    query_string=SQL.Sql_Select_User%(args[0])
    #print(query_string)
    if event_handler.execute(query_string):
        return PF.normal_info('user name '+args[0]+' has existed.')
    try:
        time_now=datetime.datetime.now()
        time_now=time_now.strftime('%Y-%m-%d %H:%M:%S')
        # user_id email password reg_time privilege
        query_string=SQL.Sql_Add_User%(args[0],args[2],Hash.hash(args[1]),time_now,1)
        print(query_string)
        event_handler.execute(query_string)
        return PF.normal_info('regist sucessfuly. Pleaee login')
    except:
        return  PF.error_info('unexpect')
Beispiel #8
0
 def on_message(self, message):
     time_now=datetime.datetime.now()
     time_now=time_now.strftime('%Y-%m-%d %H:%M:%S')
     ##print(str(id(self)) + " sent " +message +"  "+ time_now)
     try:
         medict=json.loads(message)
         #output=str(medict['cmd'])+str(medict['args'])
         medict['cmd']=medict['args'][0]
         medict['args']=medict['args'][1:]
         print(medict)
         output=order_resolve(medict['cmd'],medict['args'],self)
     except Exception:
         output=PF.error_info('error @ receive')
     if not output:
         output=PF.normal_info('No out put')
     #print(output)
     self.write_message(output)
Beispiel #9
0
def resolve(args):

    default_args={
        '-timezone':'Asia/Shanghai',
        }
    default_info=[]


    try:
        for i in args:
            if i[0]=='-':
                [option,value]=i.split('=')
                #return error_info(str(option)+str(value))
                if option in default_args:
                    default_args[option]=value
                else:
                    return PF.normal_info("input arguments error, input 'help' to help")
            else:
                default_info.append(i)

        return time(default_info,default_args)
    except :
        return PF.error_info('exception')