Ejemplo n.º 1
0
 def set_token(self, get):
     if 'request_token' in get:
         return public.returnMsg(
             False, 'Cannot configure API through API interface')
     data = self.get_api_config()
     if get.t_type == '1':
         token = public.GetRandomString(32)
         data['token'] = public.md5(token)
         data['token_crypt'] = public.en_crypt(data['token'],
                                               token).decode('utf-8')
         public.WriteLog('SET_API', 'Regenerate API-Token')
     elif get.t_type == '2':
         data['open'] = not data['open']
         stats = {True: 'Open', False: 'Close'}
         if not 'token_crypt' in data:
             token = public.GetRandomString(32)
             data['token'] = public.md5(token)
             data['token_crypt'] = public.en_crypt(data['token'],
                                                   token).decode('utf-8')
         public.WriteLog('SET_API',
                         '%s API interface' % stats[data['open']])
         token = stats[data['open']] + 'success!'
     elif get.t_type == '3':
         data['limit_addr'] = get.limit_addr.split('\n')
         public.WriteLog('SET_API',
                         'Change IP limit to [%s]' % get.limit_addr)
         token = 'Saved successfully!'
     self.save_api_config(data)
     return public.returnMsg(True, token)
Ejemplo n.º 2
0
 def set_token(self, get):
     if 'request_token' in get:
         return public.returnMsg(False, '不能通过API接口配置API')
     data = self.get_api_config()
     if get.t_type == '1':
         token = public.GetRandomString(32)
         data['token'] = public.md5(token)
         data['token_crypt'] = public.en_crypt(data['token'],
                                               token).decode('utf-8')
         public.WriteLog('API配置', '重新生成API-Token')
     elif get.t_type == '2':
         data['open'] = not data['open']
         stats = {True: '开启', False: '关闭'}
         if not 'token_crypt' in data:
             token = public.GetRandomString(32)
             data['token'] = public.md5(token)
             data['token_crypt'] = public.en_crypt(data['token'],
                                                   token).decode('utf-8')
         public.WriteLog('API配置', '%sAPI接口' % stats[data['open']])
         token = stats[data['open']] + '成功!'
     elif get.t_type == '3':
         data['limit_addr'] = get.limit_addr.split('\n')
         public.WriteLog('API配置', '变更IP限制为[%s]' % get.limit_addr)
         token = '保存成功!'
     self.save_api_config(data)
     return public.returnMsg(True, token)
Ejemplo n.º 3
0
    def set_token(self,get):
        if 'request_token' in get: return public.returnMsg(False,'不能通过API接口配置API')
        save_path = '/www/server/panel/config/api.json'
        data = json.loads(public.ReadFile(save_path))
        if get.t_type == '1':
            token = public.GetRandomString(32)
            data['token'] = public.md5(token)
            data['token_crypt'] = public.en_crypt(data['token'],token).decode('utf-8')
            public.WriteLog('API配置','重新生成API-Token')
        elif get.t_type == '2':
            data['open'] = not data['open']
            stats = {True:'开启',False:'关闭'}
            public.WriteLog('API配置','%sAPI接口' % stats[data['open']])
            token = stats[data['open']] + '成功!'
        elif get.t_type == '3':
            data['limit_addr'] = get.limit_addr.split('\n')
            public.WriteLog('API配置','变更IP限制为[%s]' % get.limit_addr)
            token ='保存成功!'

        public.WriteFile(save_path,json.dumps(data))
        public.ExecShell("chmod 600 " + save_path)
        return public.returnMsg(True,token)
Ejemplo n.º 4
0
    def set_token(self, get):
        if 'request_token' in get: return public.returnMsg(False, 'CANT_SET_API_WIFTH_API')
        save_path = '/www/server/panel/config/api.json'
        data = json.loads(public.ReadFile(save_path))
        if get.t_type == '1':
            token = public.GetRandomString(32)
            data['token'] = public.md5(token)
            data['token_crypt'] = public.en_crypt(data['token'],token).decode('utf-8')
            public.WriteLog('SET_API', 'REGENERATE_API_TOKEN')
        elif get.t_type == '2':
            data['open'] = not data['open']
            stats = {True: public.GetMsg("TURN_ON"), False: public.GetMsg("CLOSE")}
            public.WriteLog('SET_API', '%s API_INTERFACE' % stats[data['open']])
            token = stats[data['open']] + public.GetMsg("SUCCESS")
        elif get.t_type == '3':
            data['limit_addr'] = get.limit_addr.split('\n')
            public.WriteLog('SET_API', 'CHANGE_IP_LIMIT [%s]' % get.limit_addr)
            token = public.GetMsg("SAVE_SUCCESS")

        public.WriteFile(save_path, json.dumps(data))
        os.chmod(save_path,0o600)
        return public.returnMsg(True, token)