class TMAuthenticationProvider(AuthenticationProvider): id = 'tm' name = 'TM Users' def __init__(self, context): self.context = context self.mysql = MySQLConnector() def authenticate(self, username, password): mysql_result = self.mysql.get("tm_users", ["id", "username", "firstname", "lastname", "mail", "password"], "WHERE username LIKE '" + username + "'") if len(mysql_result) != 0: mysql_result = mysql_result[0] password = hashlib.sha512(password.encode('utf-8') + mysql_result["username"].encode('utf-8')).hexdigest() if mysql_result["password"] == password: del mysql_result["password"] return True else: return False else: return False def authorize(self, username, permission): return True def get_isolation_uid(self, username): return 0 def get_isolation_gid(self, username): return None def get_profile(self, username): if username in ["root", None]: return { "id": 0 } mysql_result = self.mysql.get("tm_users", ["id", "username", "firstname", "lastname", "mail"], "WHERE username LIKE '" + username + "'") if len(mysql_result) != 0: return mysql_result[0]
def handle_api_tm_projects_get(self, http_context): mysql = MySQLConnector() if http_context.method == 'POST': project_id = http_context.json_body()['project_id'] result = mysql.get("tm_projects", ["id", "name", "description", "permission", "created", "author", "global_username", "global_password", "global_sshkey"], "WHERE id LIKE '" + str(project_id) + "'") return result
def handle_api_tm_hosts_list(self, http_context): mysql = MySQLConnector() if http_context.method == 'POST': project_id = http_context.json_body()['project_id'] result = mysql.get("tm_hosts", ["id", "name", "address", "description"], "WHERE project LIKE '" + project_id + "'") return result
def handle_api_tm_projects_list(self, http_context): mysql = MySQLConnector() if http_context.method == 'GET': result = mysql.get("tm_projects", ["id", "name", "description"]) return result