Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from contrib.saas.config import Config
- from contrib.saas.server_name import ServerName
- from contrib.saas.state import AccountState
- __author__ = 'Igor Katrichenko'
- class Task(ITask):
- @property
- def name(self):
- return os.path.splitext(os.path.basename(__file__))[0]
- def __get_client_info(self, login):
- server_id, server_name = ServerName.get_saas_name()
- command = {
- 'module': 'user',
- 'task': 'info',
- 'parameters':
- {
- 'login': login,
- 'server_name': server_name,
- }
- }
- url = self.config['manage_url']
- headers = {'content-type': 'application/json'}
- response = requests.post(url, data=json.dumps(command), headers=headers, timeout=5)
- result = json.loads(response.text)
- if result['code'] != 0:
- raise Exception("Can't get domains for client '{}'".format(login))
- user_info = result['data'][login]
- return user_info
- def do(self):
- if self.config['type'] != 'free':
- login = self._parameters['login']
- # Получение ключа программы
- acc = AccountState(self.config)
- user_info = acc.get(login)
- force = self.parameters.setdefault('force', False)
- if user_info == {} or force:
- user_info = acc.get_client_info(login, self.config['manage_url'])
- acc.set(login, user_info)
- if int(user_info['tariff_id']) != 1 or int(user_info['revision']) >= int('19455'):
- key = AccountState.generate_license_key(user_info)
- config_file = self.config['client_config_file'].format(login)
- config = Config.get(config_file)
- connection = pymysql.connect(
- host=self.config['db_host'],
- user=self.config['db_user'],
- password=self.config['db_password'],
- db=config['dbname'],
- charset='utf8',
- cursorclass=pymysql.cursors.DictCursor
- )
- # Установка ключа программы
- cursor = connection.cursor()
- table_prefix = config['table_prefix']
- sql = "DELETE FROM {}key;".format(table_prefix)
- cursor.execute(sql)
- if int(user_info['tariff_id']) != 1:
- sql = "INSERT INTO {}key (`code`) VALUES (%s);".format(table_prefix)
- cursor.execute(sql, (key,))
- connection.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement