API command to enforce SSL

AXQ73

Verified User
Joined
Jul 13, 2021
Messages
37
Hey all,
we've setup an API to install our certs and cacerts. All working like a charm. I however would like to add the option 'Force SSL' but can't find the POST/GET key to put through the API. I found 'force_ssl' set to 'yes' somewhere but that does not work, at least not via /CMD_API_SSL.

Does someone know which key/value pair will take care of this?

EDIT: i see when you activate this option the /directadmin/data/users/user/httpd.conf is changed, a few lines added in a VirtualHost block. Maybe not via /CMD_API_SSL but another method?
 
It is under /CMD_DOMAIN or /CMD_API_DOMAIN (i'm not sure which one is less buggy)


You can also find this information from directadmin debug mode log, when I do debug mode and execute directadmin force ssl via UI, I got the following nice log:

Code:
Post string: domain=test.com&val=symlink&force_ssl=yes&json=yes&action=private_html
 
Dear Maxi32,

that is indeed the key/value pair i'm using. Unfortunately it does not work in my case.

Thx anyway
 
Dear Maxi32,

that is indeed the key/value pair i'm using. Unfortunately it does not work in my case.

Thx anyway
If it is not working, there might be an error message from the debug mode. You can run directadmin in debug mode and try calling the API again:

# Put directadmin in debug mode:

Code:
cd /usr/local/directadmin/directadmin
./directadmin b2000


Edit (Just sharing for productivity) When dealing a lot with API, you need a shortcut to put directadmin in debug mode and return directadmin process to normal. What I did was to create a shortcut script like below so I can just trigger in the terminal dadebug and directadmin will be in debug mode. Pressing CTRL+C it will end the debug mode and automatically start the normal directadmin process.

# 1) First create a new bash script and paste the following content and name it as debugda


Code:
#!/bin/bash
# Author: MaXi32
# Put directadmin in debug mode:
# usage: debugda <filter output text>
# example: debugda "POST"
# For debian / ubuntu (might work with most of systemd)


text_output="$1"
function _traps() {
        local clean_func
        clean_func="$1"
        shift
        for sig; do
                # Test each signal from function called
                trap "${clean_func} ${sig}" "${sig}"
        done
}


# Directadmin debug exit trap
function end_da_debug() {
        # echo "Trapped: $1"
        ((CTRL_C_COUNT++))
        if [[ $CTRL_C_COUNT == 1 ]]; then
                echo ""
                if [ "$1" == "INT" ]; then
                        echo "*** Warning, Directadmin debug mode has been terminated by ${USER}! ***"
                fi
                echo "Starting directadmin in normal mode ..."
                systemctl restart directadmin
                echo "Directadmin running status is: $(systemctl is-active directadmin)"
                echo ""
                echo "                             **END DEBUG**                        "
                echo "=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~"
                fi
                # clean exit
                exit 1
        }




da_bin="/usr/local/directadmin/directadmin"
# This trap function is used to restore directadmin service back to normal once this debugging status is terminated
_traps end_da_debug INT
killall -9 directadmin
if [ -n "${text_output}" ]; then
        echo ""
        echo "=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~"
        echo "                            **STARTING DIRECTADMIN DEBUG MODE**                       "
        echo ""
        echo "Running directadmin debug mode with filtered output ..."
        echo "FILTERED OUTPUT:"
        echo "${text_output}"
        echo ""
        echo "Press CTRL+C to exit debug mode"
        echo ""
        ${da_bin} b3000 | grep "${text_output}"
else
        echo "=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~"
        echo "                            **STARTING DIRECTADMIN DEBUG MODE**                       "
        echo ""
        echo "Running directadmin debug mode with full output ..."
        echo ""
        echo "Press CTRL+C to exit debug mode"
        echo ""
        ${da_bin} b3000
fi


# 2) Make the script executable and put it in /usr/local/bin/debugda

Code:
chmod +x debugda
mv debugda /usr/local/bin/debugda


Now when you want to debug directadmin, you can just trigger this command in terminal:

Code:
debugda

To filter some output use this:

Code:
debugda "Some output"

To quit debug mode press CTRL+C. When you press CTRL+C it will automatically start directadmin in normal process

Hopefully that this will be put in directamdin feature here as directadmin-cli (please vote this):

 
Last edited:
Back
Top