├── README.md ├── nodejs ├── add_domain.js ├── add_email_account.js ├── check_user_account.js ├── create_database.js ├── create_user.js ├── delete_email_account.js ├── delete_user.js └── list_web_domains.js └── php ├── add_database.php ├── add_domain.php ├── add_email_account.php ├── check_user_account.php ├── create_user.php ├── delete_email_account.php ├── delete_user.php └── list_web_domains.php /README.md: -------------------------------------------------------------------------------- 1 | # hestiacp-api-examples 2 | Examples for Hestia API 3 | -------------------------------------------------------------------------------- /nodejs/add_domain.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring'); 5 | 6 | //Admin Credentials 7 | const hst_hostname = 'server.hestiacp.com' 8 | const hst_port = 8083 9 | const hst_username = 'admin' 10 | const hst_password = 'p4ssw0rd' 11 | const hst_returncode = 'yes' 12 | const hst_command = 'v-add-domain' 13 | 14 | //Domain details 15 | const username = 'demo'; //username to associate the domain 16 | const domain = 'domain.tld'; //domain 17 | 18 | const data_json = { 19 | 'user': hst_username, 20 | 'password': hst_password, 21 | 'returncode': hst_returncode, 22 | 'cmd': hst_command, 23 | 'arg1': username, 24 | 'arg2': domain 25 | } 26 | 27 | const data = querystring.stringify(data_json) 28 | 29 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 30 | .then(function (response) { 31 | console.log(response.data); 32 | console.log("0 means successful") 33 | }) 34 | .catch(function (error) { 35 | console.log(error); 36 | }); -------------------------------------------------------------------------------- /nodejs/add_email_account.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring'); 5 | 6 | //Admin Credentials 7 | const hst_hostname = 'server.hestiacp.com' 8 | const hst_port = 8083 9 | const hst_username = 'admin' 10 | const hst_password = 'p4ssw0rd' 11 | const hst_returncode = 'yes' 12 | const hst_command = 'v-add-mail-account' // Refer: https://github.com/hestiacp/hestiacp/blob/release/bin/v-add-mail-account & https://hestiacp.com/docs/reference/cli.html#v-add-mail-account 13 | 14 | //Domain details 15 | const username = 'demo'; //username to associate the domain 16 | const domain = 'domain.tld'; //domain 17 | 18 | const data_json = { 19 | 'user': hst_username, 20 | 'password': hst_password, 21 | 'returncode': hst_returncode, 22 | 'cmd': hst_command, 23 | 'arg1': user, 24 | 'arg2': domain, 25 | 'arg3': account, 26 | 'arg4': password, 27 | 'arg5': $quota // {5-unlimited} 28 | } 29 | 30 | const data = querystring.stringify(data_json) 31 | 32 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 33 | .then(function (response) { 34 | console.log(response.data); 35 | console.log("0 means successful") 36 | }) 37 | .catch(function (error) { 38 | console.log(error); 39 | }); 40 | -------------------------------------------------------------------------------- /nodejs/check_user_account.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring') 5 | //Admin Credentials 6 | const hst_hostname = 'server.hestiacp.com' 7 | const hst_port = 8083 8 | const hst_username = 'admin' 9 | const hst_password = 'p4ssw0rd' 10 | const hst_returncode = 'yes' 11 | const hst_command = 'v-check-user-password' 12 | 13 | //Account details 14 | const username = 'demo'; 15 | const password = 'demopassword'; 16 | 17 | const data_json = { 18 | 'user': hst_username, 19 | 'password': hst_password, 20 | 'returncode': hst_returncode, 21 | 'cmd': hst_command, 22 | 'arg1': username, 23 | 'arg2': password 24 | } 25 | 26 | const data = querystring.stringify(data_json) 27 | 28 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 29 | .then(function (response) { 30 | console.log(response.data); 31 | console.log("0 means successful") 32 | }) 33 | .catch(function (error) { 34 | console.log(error); 35 | }); -------------------------------------------------------------------------------- /nodejs/create_database.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring'); 5 | 6 | //Admin Credentials 7 | const hst_hostname = 'server.hestiacp.com' 8 | const hst_port = 8083 9 | const hst_username = 'admin' 10 | const hst_password = 'p4ssw0rd' 11 | const hst_returncode = 'yes' 12 | const hst_command = 'v-add-databse' 13 | 14 | //Domain details 15 | const username = 'demo' 16 | const db_name = 'wordpress' 17 | const db_user = 'wordpress' 18 | const db_pass = 'wpbl0gp4s' 19 | 20 | const data_json = { 21 | 'user': hst_username, 22 | 'password': hst_password, 23 | 'returncode': hst_returncode, 24 | 'cmd': hst_command, 25 | 'arg1': username, 26 | 'arg2': db_name, 27 | 'arg3': db_user, 28 | 'arg4': db_pass 29 | } 30 | 31 | const data = querystring.stringify(data_json) 32 | 33 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 34 | .then(function (response) { 35 | console.log(response.data); 36 | console.log("0 means successful") 37 | }) 38 | .catch(function (error) { 39 | console.log(error); 40 | }); -------------------------------------------------------------------------------- /nodejs/create_user.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring'); 5 | 6 | //Admin Credentials 7 | const hst_hostname = 'server.hestiacp.com' 8 | const hst_port = 8083 9 | const hst_username = 'admin' 10 | const hst_password = 'p4ssw0rd' 11 | const hst_returncode = 'yes' 12 | const hst_command = 'v-add-user' 13 | 14 | //New account details 15 | const username = 'demo'; 16 | const password = 'd3m0p4ssw0rd'; 17 | const email = 'demo@gmail.com'; 18 | const package = 'default'; 19 | const first_name = 'Rust'; 20 | const last_name = 'Cohle'; 21 | 22 | const data_json = { 23 | 'user': hst_username, 24 | 'password': hst_password, 25 | 'returncode': hst_returncode, 26 | 'cmd': hst_command, 27 | 'arg1': username, 28 | 'arg2': password, 29 | 'arg3': email, 30 | 'arg4': package, 31 | 'arg5': first_name, 32 | 'arg6': last_name 33 | } 34 | 35 | const data = querystring.stringify(data_json) 36 | 37 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 38 | .then(function (response) { 39 | console.log(response.data); 40 | console.log("0 means successful") 41 | }) 42 | .catch(function (error) { 43 | console.log(error); 44 | }); -------------------------------------------------------------------------------- /nodejs/delete_email_account.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring'); 5 | 6 | //Admin Credentials 7 | const hst_hostname = 'server.hestiacp.com' 8 | const hst_port = 8083 9 | const hst_username = 'admin' 10 | const hst_password = 'p4ssw0rd' 11 | const hst_returncode = 'yes' 12 | const hst_command = 'v-delete-mail-account' // Refer: https://github.com/hestiacp/hestiacp/blob/release/bin/v-delete-mail-account & https://hestiacp.com/docs/reference/cli.html#v-delete-mail-account 13 | 14 | //Domain details 15 | const username = 'demo'; //username to associate the domain 16 | const domain = 'domain.tld'; //domain 17 | 18 | const data_json = { 19 | 'user': hst_username, 20 | 'password': hst_password, 21 | 'returncode': hst_returncode, 22 | 'cmd': hst_command, 23 | 'arg1': user, 24 | 'arg2': domain, 25 | 'arg3': account 26 | } 27 | 28 | const data = querystring.stringify(data_json) 29 | 30 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 31 | .then(function (response) { 32 | console.log(response.data); 33 | console.log("0 means successful") 34 | }) 35 | .catch(function (error) { 36 | console.log(error); 37 | }); 38 | -------------------------------------------------------------------------------- /nodejs/delete_user.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring') 5 | //Admin Credentials 6 | const hst_hostname = 'server.hestiacp.com' 7 | const hst_port = 8083 8 | const hst_username = 'admin' 9 | const hst_password = 'p4ssw0rd' 10 | const hst_returncode = 'yes' 11 | const hst_command = 'v-delete-user' 12 | 13 | //Account 14 | const username = 'demo'; 15 | 16 | const data_json = { 17 | 'user': hst_username, 18 | 'password': hst_password, 19 | 'returncode': hst_returncode, 20 | 'cmd': hst_command, 21 | 'arg1': username 22 | } 23 | 24 | const data = querystring.stringify(data_json) 25 | 26 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 27 | .then(function (response) { 28 | console.log(response.data); 29 | console.log("0 means successful") 30 | }) 31 | .catch(function (error) { 32 | console.log(error); 33 | }); -------------------------------------------------------------------------------- /nodejs/list_web_domains.js: -------------------------------------------------------------------------------- 1 | //NodeJS Script 2 | //You must have the axios module installed 3 | const axios = require('axios') 4 | const querystring = require('querystring'); 5 | 6 | //Admin Credentials 7 | const hst_hostname = 'server.hestiacp.com' 8 | const hst_port = 8083 9 | const hst_returncode = 'no' 10 | const hst_username = 'admin' 11 | const hst_password = 'p4ssw0rd' 12 | const hst_command = 'v-list-web-domain' 13 | 14 | //Domain details 15 | const username = 'demo'; 16 | const domain = 'demo.hestiacp.com'; 17 | const format = 'json'; 18 | 19 | const data_json = { 20 | 'user': hst_username, 21 | 'password': hst_password, 22 | 'returncode': hst_returncode, 23 | 'cmd': hst_command, 24 | 'arg1': username, 25 | 'arg2': domain, 26 | 'arg3': format 27 | } 28 | 29 | const data = querystring.stringify(data_json) 30 | 31 | axios.post('https://'+hst_hostname+':'+hst_port+'/api/', data) 32 | .then(function (response) { 33 | console.log(JSON.stringify(response.data)); 34 | 35 | }) 36 | .catch(function (error) { 37 | console.log(error); 38 | }); -------------------------------------------------------------------------------- /php/add_database.php: -------------------------------------------------------------------------------- 1 | $hst_username, 20 | 'password' => $hst_password, 21 | 'returncode' => $hst_returncode, 22 | 'cmd' => $hst_command, 23 | 'arg1' => $username, 24 | 'arg2' => $db_name, 25 | 'arg3' => $db_user, 26 | 'arg4' => $db_pass 27 | ); 28 | 29 | // Send POST query via cURL 30 | $postdata = http_build_query($postvars); 31 | $curl = curl_init(); 32 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); 33 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 34 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 35 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 36 | curl_setopt($curl, CURLOPT_POST, true); 37 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 38 | $answer = curl_exec($curl); 39 | 40 | // Check result 41 | if($answer === 0) { 42 | echo "Database has been successfuly created\n"; 43 | } else { 44 | echo "Query returned error code: " .$answer. "\n"; 45 | } -------------------------------------------------------------------------------- /php/add_domain.php: -------------------------------------------------------------------------------- 1 | $hst_username, 18 | 'password' => $hst_password, 19 | 'returncode' => $hst_returncode, 20 | 'cmd' => $hst_command, 21 | 'arg1' => $username, 22 | 'arg2' => $domain 23 | ); 24 | 25 | // Send POST query via cURL 26 | $postdata = http_build_query($postvars); 27 | $curl = curl_init(); 28 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); 29 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 30 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 31 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 32 | curl_setopt($curl, CURLOPT_POST, true); 33 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 34 | $answer = curl_exec($curl); 35 | 36 | // Check result 37 | if($answer === 0) { 38 | echo "Domain has been successfuly created\n"; 39 | } else { 40 | echo "Query returned error code: " .$answer. "\n"; 41 | } -------------------------------------------------------------------------------- /php/add_email_account.php: -------------------------------------------------------------------------------- 1 | $hst_username, 18 | 'password' => $hst_password, 19 | 'returncode' => $hst_returncode, 20 | 'cmd' => $hst_command, 21 | 'arg1' => $user, 22 | 'arg2' => $domain, 23 | 'arg3' => $account, 24 | 'arg4' => $password, 25 | 'arg5' => $quota // {5-unlimited} 26 | ); 27 | 28 | // Send POST query via cURL 29 | $postdata = http_build_query($postvars); 30 | $curl = curl_init(); 31 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); 32 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 33 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 34 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 35 | curl_setopt($curl, CURLOPT_POST, true); 36 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 37 | $answer = curl_exec($curl); 38 | 39 | // Check result 40 | if($answer === 0) { 41 | echo "Added new mail account.\n"; 42 | } else { 43 | echo "Query returned error code: " .$answer. "\n"; 44 | } 45 | -------------------------------------------------------------------------------- /php/check_user_account.php: -------------------------------------------------------------------------------- 1 | $hstadmin, 12 | 'password' => $hstadminpw, 13 | 'returncode' => 'no', 14 | 'cmd' => 'v-check-user-password', 15 | 'arg1' => $username, 16 | 'arg2' => $password, 17 | ); 18 | 19 | // Send POST query via cURL 20 | $postdata = http_build_query($postvars); 21 | $curl = curl_init(); 22 | curl_setopt($curl, CURLOPT_HEADER, false); 23 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hostname . ':' . $port . '/api/'); 24 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 25 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 26 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 27 | curl_setopt($curl, CURLOPT_POST, true); 28 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 29 | $answer = curl_exec($curl); 30 | 31 | //var_dump($answer); 32 | // Check result 33 | 34 | if($answer == 'OK') { 35 | echo "OK: User can login\n"; 36 | } else { 37 | echo "Error: Username or password is incorrect\n"; 38 | } 39 | -------------------------------------------------------------------------------- /php/create_user.php: -------------------------------------------------------------------------------- 1 | $hst_username, 22 | 'password' => $hst_password, 23 | 'returncode' => $hst_returncode, 24 | 'cmd' => $hst_command, 25 | 'arg1' => $username, 26 | 'arg2' => $password, 27 | 'arg3' => $email, 28 | 'arg4' => $package, 29 | 'arg5' => $first_name, 30 | 'arg6' => $last_name 31 | ); 32 | 33 | // Send POST query via cURL 34 | $postdata = http_build_query($postvars); 35 | $curl = curl_init(); 36 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); 37 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 38 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 39 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 40 | curl_setopt($curl, CURLOPT_POST, true); 41 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 42 | $answer = curl_exec($curl); 43 | 44 | // Check result 45 | if($answer === 0) { 46 | echo "User account has been successfuly created\n"; 47 | } else { 48 | echo "Query returned error code: " .$answer. "\n"; 49 | } -------------------------------------------------------------------------------- /php/delete_email_account.php: -------------------------------------------------------------------------------- 1 | $hst_username, 18 | 'password' => $hst_password, 19 | 'returncode' => $hst_returncode, 20 | 'cmd' => $hst_command, 21 | 'arg1' => $user, 22 | 'arg2' => $domain, 23 | 'arg3' => $account 24 | ); 25 | 26 | // Send POST query via cURL 27 | $postdata = http_build_query($postvars); 28 | $curl = curl_init(); 29 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); 30 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 31 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 32 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 33 | curl_setopt($curl, CURLOPT_POST, true); 34 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 35 | $answer = curl_exec($curl); 36 | 37 | // Check result 38 | if($answer === 0) { 39 | echo "Mail account removed.\n"; 40 | } else { 41 | echo "Query returned error code: " .$answer. "\n"; 42 | } 43 | -------------------------------------------------------------------------------- /php/delete_user.php: -------------------------------------------------------------------------------- 1 | $hst_username, 17 | 'password' => $hst_password, 18 | 'returncode' => $hst_returncode, 19 | 'cmd' => $hst_command, 20 | 'arg1' => $username 21 | ); 22 | 23 | // Send POST query via cURL 24 | $postdata = http_build_query($postvars); 25 | $curl = curl_init(); 26 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); 27 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 28 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 29 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 30 | curl_setopt($curl, CURLOPT_POST, true); 31 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 32 | $answer = curl_exec($curl); 33 | 34 | // Parse JSON output 35 | $data = json_decode($answer, true); 36 | 37 | // Check result 38 | if(is_numeric($answer) && $answer === '0') { 39 | echo "User account has been successfuly deleted\n"; 40 | } else { 41 | echo "Query returned error code: " .$answer. "\n"; 42 | } -------------------------------------------------------------------------------- /php/list_web_domains.php: -------------------------------------------------------------------------------- 1 | $hst_username, 19 | 'password' => $hst_password, 20 | 'returncode' => $hst_returncode, 21 | 'cmd' => $hst_command, 22 | 'arg1' => $username, 23 | 'arg2' => $domain, 24 | 'arg3' => $format 25 | ); 26 | 27 | // Send POST query via cURL 28 | $postdata = http_build_query($postvars); 29 | $curl = curl_init(); 30 | curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/'); 31 | curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); 32 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 33 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 34 | curl_setopt($curl, CURLOPT_POST, true); 35 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 36 | $answer = curl_exec($curl); 37 | 38 | // Parse JSON output 39 | $data = json_decode($answer, true); 40 | 41 | // Print result 42 | print_r($data); --------------------------------------------------------------------------------