Exemple #1
0
 def handle_api_tm_hosts_create(self, http_context):
     mysql = MySQLConnector()
     if http_context.method == 'POST':
         host = {}
         host["name"] = http_context.json_body()['host_name']
         host["address"] = http_context.json_body()['host_address']
         host["description"] = http_context.json_body()['host_description']
         host["author"] = http_context.json_body()['host_author']
         host["project"] = http_context.json_body()['host_project']
         try:
             host["username"] = http_context.json_body()['project_username']
         except:
             host["username"] = ""
         try:
             host["password"] = http_context.json_body()['project_password']
         except:
             host["password"] = ""
         try:
             host["sshkey"] = http_context.json_body()['project_sshkey']
         except:
             host["sshkey"] = ""
         try:
             host["hophost"] = http_context.json_body()['host_hophost']
         except:
             pass
         result = mysql.insert("tm_hosts", host)
         return result
Exemple #2
0
 def handle_api_tm_projects_create(self, http_context):
     mysql = MySQLConnector()
     if http_context.method == 'POST':
         project = {}
         project["name"] = http_context.json_body()['project_name']
         project["description"] = http_context.json_body()['project_description']
         project["permission"] = http_context.json_body()['project_permission']
         project["author"] = http_context.json_body()['project_author']
         try:
             project["global_username"] = http_context.json_body()['project_global_username']
         except:
             project["global_username"] = ""
         try:
             project["global_password"] = http_context.json_body()['project_global_password']
         except:
             project["global_password"] = ""
         try:
             project["global_sshkey"] = http_context.json_body()['project_global_sshkey']
         except:
             project["global_sshkey"] = ""
         result = mysql.insert("tm_projects", project)
         return result
Exemple #3
0
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]
Exemple #4
0
 def __init__(self, context):
     self.context = context
     self.mysql = MySQLConnector()
Exemple #5
0
 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
Exemple #6
0
 def handle_api_tm_projects_delete(self, http_context):
     mysql = MySQLConnector()
     if http_context.method == 'POST':
         project_id = http_context.json_body()['project_id']
         result = mysql.delete("tm_projects", "id LIKE '" + str(project_id) + "'")
         return result
Exemple #7
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
Exemple #8
0
 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