Script for importing DirectAdmin backups

For modifications in and around KeyHelp.
Post Reply
RikkerdNL
Posts: 15
Joined: Mon 27. May 2024, 10:05

Script for importing DirectAdmin backups

Post by RikkerdNL »

Hello Keyhelp,

I am busy with a script that can import backups from DirectAdmin. But I have a few questions.
  • Can we write the SQL hashed password to a config file so that mysql(keyhelp) can use this password file? We can for example do this in Hestiacp via:

    Code: Select all

    "DB='$db' DBUSER='$db_user' MD5='$md5' HOST='localhost' TYPE='mysql' CHARSET='UTF8' U_DISK='0' SUSPENDED='no' TIME='$time' DATE='$date'" >> /usr/local/hestia/data/users/"$directadmin_user"/db.conf
    
  • Can we see via a API call when the created user/website is done processing (wrench icon)? At this time I look for the folders we need to write and wait till the folder is created.
Thank you for the help.
User avatar
Alexander
Keyweb AG
Posts: 4448
Joined: Wed 20. Jan 2016, 02:23

Re: Script for importing DirectAdmin backups

Post by Alexander »

Hello,
Can we write the SQL hashed password to a config file so that mysql(keyhelp) can use this password file? We can for example do this in Hestiacp via:
This passwords should than be used for the databases of client accounts?
If I understand you correctly, you can send hashed passwords through the KeyHelp API - you just need to enable "Configuration -> API -> Options -> Use password hashes". Than you can utilize the "password_hash" field in requests to get or set the passwords by a password hash.
Be aware that the password hash of other control panels may use a weaker algorithm than KeyHelp. But it should work.

Can we see via a API call when the created user/website is done processing (wrench icon)? At this time I look for the folders we need to write and wait till the folder is created.
Have a look at https://api.keyhelp.de -> Hints
Some object schemas contain a read-only "status" field. The meaning of these values is as follows:
0 = "unknown", 1 = "okay", 2 = "error", 3 = "config_new", 4 = "config_update"
So if an object has "status" = 1 than you can go on ( == check-mark icon).
If it has "status" = 3 or 4, than this would represent the wrench icon.
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
RikkerdNL
Posts: 15
Joined: Mon 27. May 2024, 10:05

Re: Script for importing DirectAdmin backups

Post by RikkerdNL »

Thank you for the reply.
This passwords should than be used for the databases of client accounts?
If I understand you correctly, you can send hashed passwords through the KeyHelp API - you just need to enable "Configuration -> API -> Options -> Use password hashes". Than you can utilize the "password_hash" field in requests to get or set the passwords by a password hash.
Be aware that the password hash of other control panels may use a weaker algorithm than KeyHelp. But it should work.
Sorry for the confusion, I want to restore the hashed password for the user databases from Directadmin. For HestiaCP we can write a db.cnf file in the user home folder, so it uses that file for the hashed password. But I don't know how this works in Keyhelp. When I check the database create API

Code: Select all

{
  "id_user": 2,
  "database_name": "alex_db1",
  "database_username": "alex_db1",
  "password": "qwertz",
  "description": "This is the database for my Wordpress installation.",
  "remote_hosts": [
    "93.152.27.25",
    "120.237.75.141"
  ],
  "password_hash": "*3B501FC38B83F25B219D020656A7C104960C33E7"
}
I can see that there is a password_hash, do I leave password empty or do I not need this line when using password_hash? We already use password_hash for creating the email boxes in the migration, this works. I can see I also have password in there and password_hash does the password_hash overwrite the password when used both?

At this time, I got the following migration script functions working, transferring the files to the user www folder, migrating the mailboxes with data with orginal password from DA. Creating the databases with migration data ( only password needs some work )
User avatar
Alexander
Keyweb AG
Posts: 4448
Joined: Wed 20. Jan 2016, 02:23

Re: Script for importing DirectAdmin backups

Post by Alexander »

This will use the "password_hash" as it has the highest priority:

Code: Select all

{
  "password": "qwertz",
  "password_hash": "*3B501FC38B83F25B219D020656A7C104960C33E7"
}

This will use "password":

Code: Select all

{
  "password": "qwertz",
  "password_hash": ""
}

This will create a random password and will output it in the response:

Code: Select all

{
  "password": "",
  "password_hash": ""
}

You also do not need to specify the fields you don't need, so just use "password" or "password_hash" is just fine. For completeness-sake, omitting "password" and "password_hash" will generate a new password.
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
RikkerdNL
Posts: 15
Joined: Mon 27. May 2024, 10:05

Re: Script for importing DirectAdmin backups

Post by RikkerdNL »

Thank you for the clarification, will make some update in the code and report back.
RikkerdNL
Posts: 15
Joined: Mon 27. May 2024, 10:05

Re: Script for importing DirectAdmin backups

Post by RikkerdNL »

Alexander wrote: Tue 4. Feb 2025, 11:42 This will use the "password_hash" as it has the highest priority:

Code: Select all

{
  "password": "qwertz",
  "password_hash": "*3B501FC38B83F25B219D020656A7C104960C33E7"
}

This will use "password":

Code: Select all

{
  "password": "qwertz",
  "password_hash": ""
}

This will create a random password and will output it in the response:

Code: Select all

{
  "password": "",
  "password_hash": ""
}

You also do not need to specify the fields you don't need, so just use "password" or "password_hash" is just fine. For completeness-sake, omitting "password" and "password_hash" will generate a new password.
Again thank you for the help setting the password via password_hash does work great. Another question, can we check via the API if password_hash is enabled in the api options? So we can show a error when we have not enabled this option.

Am I true I always can use this followiun file for the sql credentials: "/etc/keyhelp/config/config.json"
User avatar
Alexander
Keyweb AG
Posts: 4448
Joined: Wed 20. Jan 2016, 02:23

Re: Script for importing DirectAdmin backups

Post by Alexander »

Again thank you for the help setting the password via password_hash does work great. Another question, can we check via the API if password_hash is enabled in the api options? So we can show a error when we have not enabled this option.
The password_hash field is only present on GET requests, when the option is enabled.
You can not check it directly, but with a little trick you can check it:

Just query GET /admins and check, if the returned records contain the "password_hash" field. There is always at least one admin account on the server. So this is reliable.
Am I true I always can use this followiun file for the sql credentials: "/etc/keyhelp/config/config.json"
Yes, you can use that. This file will be created during the KeyHelp installation.
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
RikkerdNL
Posts: 15
Joined: Mon 27. May 2024, 10:05

Re: Script for importing DirectAdmin backups

Post by RikkerdNL »

I am busy with fixing the import script so we can import more then 1 domain/subdomain. But I use the domain api to create the domains, how can I set the path for the domain via the API? When I check the API:

Code: Select all

{
  "id_user": 4,
  "id_parent_domain": 0,
  "domain": "example.com",
  "php_version": "",
  "traffic": 32434624,
  "is_disabled": false,
  "delete_on": "2019-08-15T11:29:13+02:00",
  "dkim_selector": "default",
  "is_dns_disabled": false,
  "is_email_domain": true,
  "is_email_sending_only": false,
  "create_www_subdomain": true,
  "target": {
    "target": "https://www.keyhelp.de",
    "forwarding_type": 301
  },
  "security": {
    "id_certificate": 0,
    "lets_encrypt": true,
    "is_prefer_https": true,
    "is_hsts": true,
    "hsts_max_age": 10368000,
    "hsts_include": true,
    "hsts_preload": true
  },
  "apache": {
    "http_directives": "# My custom HTTP directives",
    "https_directives": "# My custom HTTPS directives"
  }
}
I dont see where I can set the website directory path like /www/domainname.com am I overlooking or missing something?
User avatar
Alexander
Keyweb AG
Posts: 4448
Joined: Wed 20. Jan 2016, 02:23

Re: Script for importing DirectAdmin backups

Post by Alexander »

Please have a look into the "Schema" section of the API documentation. There you will find explanations for each field.
"target"
Either a relative path to target folder (relative from clients /www/ folder), or an URL.
When specifying a URL, they have to start with "http://" or "https://."

Code: Select all

 "target": {
    "target": "/relative/path/my/website/starting/from/the/users/www/directory",
  },
A general note: if you prefer a more practical solution, instead of reading through the documentation, just create the desired resource in KeyHelp and check the API GET response - this way you can see in action what data you can pass.
(Reading the documentation is of course also recommended ;))
Mit freundlichen Grüßen / Best regards
Alexander Mahr

**************************************************************
Keyweb AG - Die Hosting Marke
Neuwerkstr. 45/46, 99084 Erfurt / Germany
http://www.keyweb.de - http://www.keyhelp.de
**************************************************************
RikkerdNL
Posts: 15
Joined: Mon 27. May 2024, 10:05

Re: Script for importing DirectAdmin backups

Post by RikkerdNL »

Ah sorry I overlooked the schema part of the API page totally, this explains it a lot. Thank you, thought it was only for the domain redirects. Thank you for the quick help now I can continue.
Post Reply