From 8dc4a6efa9a6a363bc58c4b4867402a891293ec0 Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Sun, 13 Oct 2024 21:27:13 +0300 Subject: [PATCH] Added sources --- README.md | 2 ++ nodejs/add_domain.js | 36 ++++++++++++++++++++++++++ nodejs/check_user_account.js | 35 ++++++++++++++++++++++++++ nodejs/create_database.js | 40 +++++++++++++++++++++++++++++ nodejs/create_user.js | 44 ++++++++++++++++++++++++++++++++ nodejs/delete_user.js | 33 ++++++++++++++++++++++++ nodejs/list_web_domains.js | 38 ++++++++++++++++++++++++++++ php/add_database.php | 45 +++++++++++++++++++++++++++++++++ php/add_domain.php | 41 ++++++++++++++++++++++++++++++ php/check_user_account.php | 38 ++++++++++++++++++++++++++++ php/create_user.php | 49 ++++++++++++++++++++++++++++++++++++ php/delete_user.php | 42 +++++++++++++++++++++++++++++++ php/list_web_domains.php | 42 +++++++++++++++++++++++++++++++ 13 files changed, 485 insertions(+) create mode 100644 README.md create mode 100644 nodejs/add_domain.js create mode 100644 nodejs/check_user_account.js create mode 100644 nodejs/create_database.js create mode 100644 nodejs/create_user.js create mode 100644 nodejs/delete_user.js create mode 100644 nodejs/list_web_domains.js create mode 100644 php/add_database.php create mode 100644 php/add_domain.php create mode 100644 php/check_user_account.php create mode 100644 php/create_user.php create mode 100644 php/delete_user.php create mode 100644 php/list_web_domains.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..3cf8bb9 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# hestiacp-api-examples +Examples for Hestia API diff --git a/nodejs/add_domain.js b/nodejs/add_domain.js new file mode 100644 index 0000000..7958e73 --- /dev/null +++ b/nodejs/add_domain.js @@ -0,0 +1,36 @@ +//NodeJS Script +//You must have the axios module installed +const axios = require('axios') +const querystring = require('querystring'); + +//Admin Credentials +const hst_hostname = 'server.hestiacp.com' +const hst_port = 8083 +const hst_username = 'admin' +const hst_password = 'p4ssw0rd' +const hst_returncode = 'yes' +const hst_command = 'v-add-domain' + +//Domain details +const username = 'demo'; //username to associate the domain +const domain = 'domain.tld'; //domain + +const data_json = { +'user': hst_username, +'password': hst_password, +'returncode': hst_returncode, +'cmd': hst_command, +'arg1': username, +'arg2': domain +} + +const data = querystring.stringify(data_json) + +axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) +.then(function (response) { + console.log(response.data); + console.log("0 means successful") +}) +.catch(function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/nodejs/check_user_account.js b/nodejs/check_user_account.js new file mode 100644 index 0000000..3cc0283 --- /dev/null +++ b/nodejs/check_user_account.js @@ -0,0 +1,35 @@ +//NodeJS Script +//You must have the axios module installed +const axios = require('axios') +const querystring = require('querystring') +//Admin Credentials +const hst_hostname = 'server.hestiacp.com' +const hst_port = 8083 +const hst_username = 'admin' +const hst_password = 'p4ssw0rd' +const hst_returncode = 'yes' +const hst_command = 'v-check-user-password' + +//Account details +const username = 'demo'; +const password = 'demopassword'; + +const data_json = { +'user': hst_username, +'password': hst_password, +'returncode': hst_returncode, +'cmd': hst_command, +'arg1': username, +'arg2': password +} + +const data = querystring.stringify(data_json) + +axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) + .then(function (response) { + console.log(response.data); + console.log("0 means successful") + }) + .catch(function (error) { + console.log(error); + }); \ No newline at end of file diff --git a/nodejs/create_database.js b/nodejs/create_database.js new file mode 100644 index 0000000..0558656 --- /dev/null +++ b/nodejs/create_database.js @@ -0,0 +1,40 @@ +//NodeJS Script +//You must have the axios module installed +const axios = require('axios') +const querystring = require('querystring'); + +//Admin Credentials +const hst_hostname = 'server.hestiacp.com' +const hst_port = 8083 +const hst_username = 'admin' +const hst_password = 'p4ssw0rd' +const hst_returncode = 'yes' +const hst_command = 'v-add-databse' + +//Domain details +const username = 'demo' +const db_name = 'wordpress' +const db_user = 'wordpress' +const db_pass = 'wpbl0gp4s' + +const data_json = { +'user': hst_username, +'password': hst_password, +'returncode': hst_returncode, +'cmd': hst_command, +'arg1': username, +'arg2': db_name, +'arg3': db_user, +'arg4': db_pass +} + +const data = querystring.stringify(data_json) + +axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) +.then(function (response) { + console.log(response.data); + console.log("0 means successful") +}) +.catch(function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/nodejs/create_user.js b/nodejs/create_user.js new file mode 100644 index 0000000..1302c5f --- /dev/null +++ b/nodejs/create_user.js @@ -0,0 +1,44 @@ +//NodeJS Script +//You must have the axios module installed +const axios = require('axios') +const querystring = require('querystring'); + +//Admin Credentials +const hst_hostname = 'server.hestiacp.com' +const hst_port = 8083 +const hst_username = 'admin' +const hst_password = 'p4ssw0rd' +const hst_returncode = 'yes' +const hst_command = 'v-add-user' + +//New account details +const username = 'demo'; +const password = 'd3m0p4ssw0rd'; +const email = 'demo@gmail.com'; +const package = 'default'; +const first_name = 'Rust'; +const last_name = 'Cohle'; + +const data_json = { +'user': hst_username, +'password': hst_password, +'returncode': hst_returncode, +'cmd': hst_command, +'arg1': username, +'arg2': password, +'arg3': email, +'arg4': package, +'arg5': first_name, +'arg6': last_name +} + +const data = querystring.stringify(data_json) + +axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) +.then(function (response) { + console.log(response.data); + console.log("0 means successful") +}) +.catch(function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/nodejs/delete_user.js b/nodejs/delete_user.js new file mode 100644 index 0000000..610c835 --- /dev/null +++ b/nodejs/delete_user.js @@ -0,0 +1,33 @@ +//NodeJS Script +//You must have the axios module installed +const axios = require('axios') +const querystring = require('querystring') +//Admin Credentials +const hst_hostname = 'server.hestiacp.com' +const hst_port = 8083 +const hst_username = 'admin' +const hst_password = 'p4ssw0rd' +const hst_returncode = 'yes' +const hst_command = 'v-delete-user' + +//Account +const username = 'demo'; + +const data_json = { +'user': hst_username, +'password': hst_password, +'returncode': hst_returncode, +'cmd': hst_command, +'arg1': username +} + +const data = querystring.stringify(data_json) + +axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) + .then(function (response) { + console.log(response.data); + console.log("0 means successful") + }) + .catch(function (error) { + console.log(error); + }); \ No newline at end of file diff --git a/nodejs/list_web_domains.js b/nodejs/list_web_domains.js new file mode 100644 index 0000000..006bf9a --- /dev/null +++ b/nodejs/list_web_domains.js @@ -0,0 +1,38 @@ +//NodeJS Script +//You must have the axios module installed +const axios = require('axios') +const querystring = require('querystring'); + +//Admin Credentials +const hst_hostname = 'server.hestiacp.com' +const hst_port = 8083 +const hst_returncode = 'no' +const hst_username = 'admin' +const hst_password = 'p4ssw0rd' +const hst_command = 'v-list-web-domain' + +//Domain details +const username = 'demo'; +const domain = 'demo.hestiacp.com'; +const format = 'json'; + +const data_json = { +'user': hst_username, +'password': hst_password, +'returncode': hst_returncode, +'cmd': hst_command, +'arg1': username, +'arg2': domain, +'arg3': format +} + +const data = querystring.stringify(data_json) + +axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) +.then(function (response) { + console.log(JSON.stringify(response.data)); + +}) +.catch(function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/php/add_database.php b/php/add_database.php new file mode 100644 index 0000000..1ede104 --- /dev/null +++ b/php/add_database.php @@ -0,0 +1,45 @@ + $hst_username, + 'password' => $hst_password, + 'returncode' => $hst_returncode, + 'cmd' => $hst_command, + 'arg1' => $username, + 'arg2' => $db_name, + 'arg3' => $db_user, + 'arg4' => $db_pass +); + +// Send POST query via cURL +$postdata = http_build_query($postvars); +$curl = curl_init(); +curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); +curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); +curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); +curl_setopt($curl, CURLOPT_POST, true); +curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); +$answer = curl_exec($curl); + +// Check result +if($answer === 0) { + echo "Database has been successfuly created\n"; +} else { + echo "Query returned error code: " .$answer. "\n"; +} \ No newline at end of file diff --git a/php/add_domain.php b/php/add_domain.php new file mode 100644 index 0000000..55b1149 --- /dev/null +++ b/php/add_domain.php @@ -0,0 +1,41 @@ + $hst_username, + 'password' => $hst_password, + 'returncode' => $hst_returncode, + 'cmd' => $hst_command, + 'arg1' => $username, + 'arg2' => $domain +); + +// Send POST query via cURL +$postdata = http_build_query($postvars); +$curl = curl_init(); +curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); +curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); +curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); +curl_setopt($curl, CURLOPT_POST, true); +curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); +$answer = curl_exec($curl); + +// Check result +if($answer === 0) { + echo "Domain has been successfuly created\n"; +} else { + echo "Query returned error code: " .$answer. "\n"; +} \ No newline at end of file diff --git a/php/check_user_account.php b/php/check_user_account.php new file mode 100644 index 0000000..908d10e --- /dev/null +++ b/php/check_user_account.php @@ -0,0 +1,38 @@ + $hstadmin, + 'password' => $hstadminpw, + 'returncode' => 'no', + 'cmd' => 'v-check-user-password', + 'arg1' => $username, + 'arg2' => $password, + ); + +// Send POST query via cURL +$postdata = http_build_query($postvars); +$curl = curl_init(); +curl_setopt($curl, CURLOPT_HEADER, false); +curl_setopt($curl, CURLOPT_URL, 'https://' . $hostname . ':' . $port . '/api/'); +curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); +curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); +curl_setopt($curl, CURLOPT_POST, true); +curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); +$answer = curl_exec($curl); + +//var_dump($answer); +// Check result + +if($answer == 'OK') { + echo "OK: User can login\n"; +} else { + echo "Error: Username or password is incorrect\n"; +} diff --git a/php/create_user.php b/php/create_user.php new file mode 100644 index 0000000..602710b --- /dev/null +++ b/php/create_user.php @@ -0,0 +1,49 @@ + $hst_username, + 'password' => $hst_password, + 'returncode' => $hst_returncode, + 'cmd' => $hst_command, + 'arg1' => $username, + 'arg2' => $password, + 'arg3' => $email, + 'arg4' => $package, + 'arg5' => $first_name, + 'arg6' => $last_name +); + +// Send POST query via cURL +$postdata = http_build_query($postvars); +$curl = curl_init(); +curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); +curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); +curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); +curl_setopt($curl, CURLOPT_POST, true); +curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); +$answer = curl_exec($curl); + +// Check result +if($answer === 0) { + echo "User account has been successfuly created\n"; +} else { + echo "Query returned error code: " .$answer. "\n"; +} \ No newline at end of file diff --git a/php/delete_user.php b/php/delete_user.php new file mode 100644 index 0000000..69215bc --- /dev/null +++ b/php/delete_user.php @@ -0,0 +1,42 @@ + $hst_username, + 'password' => $hst_password, + 'returncode' => $hst_returncode, + 'cmd' => $hst_command, + 'arg1' => $username +); + +// Send POST query via cURL +$postdata = http_build_query($postvars); +$curl = curl_init(); +curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); +curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); +curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); +curl_setopt($curl, CURLOPT_POST, true); +curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); +$answer = curl_exec($curl); + +// Parse JSON output +$data = json_decode($answer, true); + +// Check result +if(is_numeric($answer) && $answer === '0') { + echo "User account has been successfuly deleted\n"; +} else { + echo "Query returned error code: " .$answer. "\n"; +} \ No newline at end of file diff --git a/php/list_web_domains.php b/php/list_web_domains.php new file mode 100644 index 0000000..19af8b3 --- /dev/null +++ b/php/list_web_domains.php @@ -0,0 +1,42 @@ + $hst_username, + 'password' => $hst_password, + 'returncode' => $hst_returncode, + 'cmd' => $hst_command, + 'arg1' => $username, + 'arg2' => $domain, + 'arg3' => $format +); + +// Send POST query via cURL +$postdata = http_build_query($postvars); +$curl = curl_init(); +curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); +curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); +curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); +curl_setopt($curl, CURLOPT_POST, true); +curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); +$answer = curl_exec($curl); + +// Parse JSON output +$data = json_decode($answer, true); + +// Print result +print_r($data); \ No newline at end of file