Пример #1
0
    def func_handler(self, chat_id, message_type, message_text, message_id,
                     user_id):
        if chat_id in groups:
            # 有新人加入
            if message_type == 'messageChatAddMembers':
                note = '''
Hola,%s
能否做出以下约定:
- 敬党爱国,不发表过激言论
感谢、
请在30s内回复(reply)此信息
(是/否) 
                ''' % getUsername(user_id)

                sendMessage(chat_id, note, user_id=user_id, mention=True)
                wait[str(user_id)] = '是'
                # 线程等待,程序继续运行
                p = threading.Thread(target=self.__slience, args=(chat_id, ))
                p.setDaemon(True)
                p.start()
            else:
                ms = getMessage(chat_id, message_id)
                # 消息是否是回复类消息
                if ms['reply_to_message_id'] != 0:
                    new_ms = getMessage(chat_id, ms['reply_to_message_id'])
                    # 消息是回复机器人的消息
                    if new_ms['sender_user_id'] == userId:
                        # 发消息人是否在等待列表
                        if str(user_id) in wait.keys():
                            if re.findall(wait[str(user_id)], message_text)[0]:
                                wait.pop(str(user_id))
Пример #2
0
def addServer():
    '''
    Добавление сервера
    :return:
    '''

    try:
        db_session.add(Server())
        db_session.commit()
        return getMessage('Server created.')
    except:
        return getMessage('Error creation of server.')
Пример #3
0
    def run(self):
        process = Process.Process()
        response = ''
        authorized = False
        username = ""
        password = ""
        host = "127.0.0.1"
        self.modem.write('AT+CMGF=1\r')
        time.sleep(1)
        self.modem.write('AT+CNMI=2,1,0,0,0\r\n');
        time.sleep(1)
        #self.modem.write('AT+CMGL="ALL"r\r');
        while True:
            out = self.modem.readline();
            if (out != ''):
                print(out)
            if "+CMTI" in out:
                utils.getMessage(self.modem, utils.getMessageIndex(out))
            elif "REC UNREAD" in out:
            #else:
                body = self.modem.readline()

                if (not authorized):
                    try:
                        username = body.split(' ')[0]
                        password = body.split(' ')[1]
                        response = process.process.authorize(username, password)
                    except:
                        response = "Please send your username and password, split by a whitespace"
                    if (process.process.authorized):
                        authorized = True
                        host = process.getUserInfo(username)[1]
                else:
                    if host != '127.0.0.1':
                        process = RemoteProcess.RemoteProcess('root', 'v@(qbU7Cx7T7', "112.78.3.74")
                        host = '127.0.0.1'
                    response = process.execute(body.splitlines()[0])
                    if (response==''):
                        response = body.splitlines()[0] + " was successfully called"

                utils.sendLongMessage(self.modem, ngoc, response)
                # count = 0
                # while True:
                #     count += 160
                #     if (count > len(response)):
                #         break

                # clear mem
                self.modem.write('AT+CMGD=1,2\r\n')
                time.sleep(0.5)
Пример #4
0
 def forward_handler(self, chat_id, message_type, message_text, message_id,
                     user_id):
     if chat_id != master:
         forwardMessage(master, chat_id, message_id)
     else:
         cur_message = getMessage(chat_id, message_id)
         reply_to = cur_message['reply_to_message_id']
         if reply_to != 0:
             repl_message = getMessage(chat_id, reply_to)
             chat_id_reply = repl_message['forward_info']['origin'][
                 'sender_user_id']
             forwardMessage(chat_id_reply,
                            chat_id,
                            message_id,
                            send_copy=True)
Пример #5
0
def deleteRack(id):
    '''
    Удаление стойки
    :return:
    '''

    rack = Rack.query.filter(Rack.id == id)
    if rack:
        if rack.getBuzySlots():
            return getMessage('Error: rack have servers')
        else:
            try:
                db_session.delete(rack)
                return getMessage('Server deleted')
            except:
                return getMessage('Error deleting of rack')
    else:
        return getMessage('Error: rack with id %s not found' % id)
Пример #6
0
def deleteServerFromRack(id):
    '''
    Удаление сервера из стойки
    :param: id of server
    :return:
    '''

    server = Server.query.filter(Server.id == id).first()
    if not server:
        return getMessage('Error: server with id %s not found' % id)
    elif not server.getStatus() in ['Unpaid', 'Deleted', 'Without status']:
        return getMessage('Error: cannot use server in status %s' %
                          server.getStatus())

    try:
        server.rack_id = None
        db_session.commit()
        return getMessage('Server deleted from rack')
    except:
        return getMessage('Error deleting server from rack')
Пример #7
0
def addRack():
    '''
    Добавление стойки
    :return:
    '''

    if not request.json or not request.json['size']:
        return jsonify({'message': 'Error: need size'})

    size = RbSize.query.filter(RbSize.value == request.json['size']).first()
    if size:
        try:
            db_session.add(Rack(size.id))
            db_session.commit()
            return getMessage('Rack created.')
        except:
            return getMessage('Error creation of rack')
    else:
        return getMessage('Error: size with value %s not found' %
                          request.json['size'])
Пример #8
0
def deleteServer(id):
    '''
    Удаление сервера
    :return:
    '''

    server = Server.query.filter(Server.id == id).first()
    if server:
        if not server.getStatus() in ['Deleted', 'Without status']:
            return getMessage(
                'Error: server must be in status "Deleted" or "Without status"'
            )
        else:
            try:
                db_session.delete(server)
                db_session.commit()
                return getMessage('Server deleted')
            except:
                return getMessage('Error deleting server')
    else:
        return getMessage('Error: server with id %s not found' % id)
Пример #9
0
def getServerById(id):
    '''
    Информация о сервере
    :param id: Id сервера
    :return:
    '''

    server = Server.query.filter(Server.id == id).first()
    if server:
        return jsonify(server.serialize())
    else:
        return getMessage('Error: server with id %s not found' % id)
Пример #10
0
def getRackById(id):
    '''
    Информация о скойке
    :param id: Id стойки
    :return:
    '''

    rack = Rack.query.filter(Rack.id == id).first()
    if rack:
        return jsonify(rack.serialize())
    else:
        return getMessage('Error: rack with id %s not found' % id)
Пример #11
0
def changeServerStatus():
    '''
    Смена статуса сервера
    :param server_id: id of server
    :param status: value RbStatus
    :param expDate: expiration Date
    :return:
    '''
    if not request.json or not 'server_id' in request.json.keys(
    ) or not 'status' in request.json.keys():
        return getMessage('Error: not enough arguments')

    server_id = request.json['server_id']
    status = request.json['status']
    server = Server.query.filter(Server.id == server_id).first()
    status_id = RbStatus.query.filter(RbStatus.value == status).first().id
    if not server:
        return getMessage('Error: server with id %s not found' % server_id)
    elif not status_id:
        return getMessage('Error: status with value %s not found' % status)
    elif server.getStatus() == 'Deleted':
        return getMessage('Error: server in status "Deleted"')
    elif not server.rack_id:
        return getMessage('Error: server not in rack')
    elif status == 'Paid' and not 'expDate' in request.json.keys():
        return getMessage('For this status need expirationDate')
    elif not server.getStatus() == 'Unpaid':
        return getMessage('Error: cannot change to this status from %s' %
                          server.getStatus())

    if server.getStatus() == 'Unpaid':
        server.status_id = status_id
        server.expirationDate = forceDateTime(request.json['expDate'])
        server.modifyDatetime = func.now()
        db_session.commit()
        activateServer.delay(server.id)
        return getMessage('Status change to "Paid"')
    elif status == 'Deleted':
        server.status_id = status_id
        server.expirationDate = None
        server.modifyDatetime = func.now()
        db_session.commit()
        return getMessage('Status change to "Deleted"')
Пример #12
0
 def test(self):
     while True:
         cmd = raw_input("Enter command or 'exit':")
         if cmd == 'exit':
             self.modem.close()
             exit()
         elif cmd == 'unread':
             self.modem.write('AT+CMGL="REC UNREAD"\r')
         elif 'send' in cmd:
             message = cmd.split(':')[1]
             utils.send(self.modem, vuBinh, message)
         elif cmd == 'listen':
             self.modem.write('AT+CNMI=2,1,0,0,0\r');
             while True:
                 out = self.modem.readline();
                 #print(out)
                 if "+CMTI" in out:
                     utils.getMessage(self.modem, utils.getMessageIndex(out))
                 elif "REC UNREAD" in out:
                     body = self.modem.readline()
                     print(body)
         else:
             print "wrong cmd"
Пример #13
0
  def listenChat(self):
    while True:
      try:
        self.readBuffer = self.readBuffer + (self.socket.recv(1024)).decode()
        temp = self.readBuffer.split("\r\n")
        self.readBuffer = temp.pop()
      except:
        print("Decode error.")

      for line in temp:
        user = getUser(line)
        message = getMessage(line)

        if user is not None and message is not None:
          self.listener(user, message, self.socket)
Пример #14
0
def addServerToRack():
    '''
    Добавление сервера в стойку
    :param server_id: id of server
    :param rack_id: id of rack
    :return:
    '''

    if not request.json or not request.json['server_id'] or not request.json[
            'rack_id']:
        return getMessage('Error: not enough arguments')

    server_id = request.json['server_id']
    rack_id = request.json['rack_id']
    server = Server.query.filter(Server.id == server_id).first()
    rack = Rack.query.filter(Rack.id == rack_id).first()

    if not server:
        return getMessage('Error: server with id %s not found' % server_id)
    elif not rack:
        return getMessage('Error: rack with id %s not found' % rack_id)
    elif not server.getStatus() in ['Unpaid', 'Deleted', 'Without status']:
        return getMessage('Error: cannot use server in status %s' %
                          server.getStatus())
    elif server.rack_id:
        return getMessage('Error: server already in rack with id %s' %
                          server.rack_id)
    elif rack.getSize() == rack.getBuzySlots():
        return getMessage('Error: rack is full')

    try:
        server.status_id = RbStatus.query.filter(
            RbStatus.value == 'Unpaid').first().id
        server.rack_id = rack.id
        server.modifyDatetime = func.now()
        rack.modifyDatetime = func.now()
        db_session.commit()
        return getMessage('Server added to rack')
    except:
        return getMessage('Error adding server to rack')