Bad documentation on CMD_SECURITY_QUESTIONS. Can anyone explain this ?

MaXi32

Verified User
Joined
Jul 25, 2016
Messages
658
Location
The Earth
This is the hardest documentation I'm trying to understand. I followed every word that it said but I failed to understand how to use this API. I could not agree anymore that directadmin has a very bad documentation on API:

Code:
https://www.directadmin.com/features.php?id=1439

Firstly it talks about the security question in here but this location does not exist: /usr/local/directadmin/data/skins/enhanced/lang/en/internal/security_questions.txt

Then it talks about index 1=22, what is this number?

My aim is that I just want to create security question and answer using API (So, I want to make sure that I fully understand this API) but the above link did not help. It also does mentioned about CMD_API_SECURITY_QUESTIONS (but as far as I know this CMD_API_SECURITY_QUESTIONS does not exist yet as confirmed by staff here: https://forum.directadmin.com/threa...p-version-of-unique-account.62965/post-327446). So for now I can only use CMD_SECURITY_QUESTIONS and I expect I would see this example in the debug mode but nope.

Also there is no single example that I found in the internet or even in this forum how to use this even the latest directadmin debug mode just returned weird json output for the POST. So, that is the extra frustrated how to learn and use API. But I actually did learn myself and try this in curl. Look at my full code example below:


Code:
#!/bin/bash
# Script name: test.sh

# If you want to test change change this login information:
server="http://server.bigdata.com:2222"
username="admin"
password="12321aa"

# Create sample question and answer 1
question1="What are you doing?"
answer1="Nothing"

# Create sample question and answer 2
question2="How are you"
answer2="Ok"

# CMD_API_SECURITY_QUESTIONS does not work or maybe has not been release so I use CMD_SECURITY_QUESTIONS
cmd_api="CMD_SECURITY_QUESTIONS"
data="type=custom&value=${answer1}&json=yes&action=add&custom_question=${question1}"

# Calling API to add the security question above

curl --silent --request "POST" --user "${username}":"${password}" --data "${data}" "${server}/${cmd_api}"

# second call for second data

data="type=custom&value=${answer2}&json=yes&action=add&custom_question=${question2}"

# Calling API for second data to add the security question above

curl --silent --request "POST" --user "${username}":"${password}" --data "${data}" "${server}/${cmd_api}"

So, now if I run the above script, ./test.sh I will get this message (the first question is added but the 2nd question is not added with this error):

Code:
{
        "result": "",
        "success": "Security Question set"
}




{
        "error": "Error with Security Questions",
        "result": "Error writing (null) : Unable to b64 encode the session password\n\n"
}

So, I run another second time this script and now both got error (even both of the question text have changed)

Code:
{
        "error": "Error with Security Questions",
        "result": "Error writing (null) : Unable to b64 encode the session password\n\n"
}




{
        "error": "Error with Security Questions",
        "result": "Error writing (null) : Unable to b64 encode the session password\n\n"
}

So, I can only add 1 question per time. If I delete the question in directadmin web UI, I can add again 1 question and the second question is not added. Why? Can anyone kindly help me on this? I found no documentation to understand this how do I add multiple questions and what the errors above mean?
 
Last edited:
Can someone run the code that I written above in terminal and see if the error appear the same. Just change authentication url to your server with port, and change your username and password to your da admin login. Can @smtalk kindly explain why this error happen?


EDIT:

This is weird, I just finished reinstall directadmin and when I re-run the above code i have no more error. I still want to understand what the error above is about. So, I hope the documentation is improved because it is not easy to understand.
 
Last edited:
Back
Top