Solved CMD_API_SKINS upload skin logo via curl issue

MaXi32

Verified User
Joined
Jul 25, 2016
Messages
645
Location
The Earth
I'm trying to upload a custom logo using CMD_API_SKINS

Here is my full code using curl + bash:

Bash:
#/bin/bash

# DA needs this path
mkdir -p /home/tmp

# Assume my logo file is already here:
default_logo_file_home="/home/tmp/logo.png"
# The logo file is set to nobody:nogroup
chown nobody:nogroup "${default_logo_file_home}"

# # Setup query data for curl:
username="admin"
password="12321aa"
da_port="2222"
host_server="server.domain.com"
ssl="https"
skin_name="evolution"
command="CMD_API_SKINS"
data="action=upload_logo&file=${default_logo_file_home}&json=yes&name=${skin_name}&which=1"
method="POST"

curl --silent --request "${method}" --user "${username}":"${password}" --data "${data}" "${ssl}://${host_server}:${da_port}/${command}"

When debugging this API, I got an error like this:

Code:
text='An Error Occurred'
        result='Cannot get mime-type for log<br>

It seems like DA is trying to parse and obtain the extension name for the file "logo.png" but it couldn't

Full error logs:

Code:
DirectAdmin 1.61.5
Accepting Connections on port 2222
Sockets::handshake - begin
Sockets::handshake - end
/CMD_API_SKINS
0: Accept: */*
1: Authorization: Basic bWF4aW93bng3OnhGVEVHe***jUSg/UTRTfVdHYW0+fWNURn5ATWN***HFbZGpMezlQZ***=
2: Content-Length: 75
3: Content-Type: application/x-www-form-urlencoded
4: Host: server.domain.com:2222
5: User-Agent: curl/7.75.0
Post string: action=upload_logo&file=/home/tmp/logo2.png&json=yes&name=evolution&which=2
auth.authenticated
User::deny_override:/CMD_API_SKINS:  call_level=2, depth1: aborting due to do depth
User::deny_override:/CMD_DOMAIN:  call_level=2, depth1: aborting due to do depth
User::deny_override:/CMD_DOMAIN:  call_level=1, depth2: aborting due to do depth
Plugin::addHooks: start
Plugin::addHooks: end
Command::doCommand(/CMD_API_SKINS)
cannot get mime type for log
Dynamic(api=1, error=1):
        text='An Error Occurred'
        result='Cannot get mime-type for log<br>
'
Command::doCommand(/CMD_API_SKINS) : finished
Command::run: finished /CMD_API_SKINS


Is there any explanations what is going on here? I appreciate if somebody can guide me on this.
 
Last edited:
I also try to encode the query like this:

default_logo_file_home="%2Fhome%2Ftmp%2Flogo%2Epng"
data="action=upload%5Flogo&file=${default_logo_file_home}&json=yes&name=${skin_name}&which=%31"

Then, the post string returns exactly the same like in the DA debug mode when uploading through GUI:

Code:
Post string: action=upload%5Flogo&file=%2Fhome%2Ftmp%2Flogo%2Epng&json=yes&name=evolution&which=%31

But I got the same error message:

Code:
text='An Error Occurred'
        result='Cannot get mime-type for log<br>

Does DA support uploading skin logo using this API ? Maybe it works only using PHP form not through curl ?
 
Last edited:
Ok, I found the trick which is not documented anywhere. The uploaded file need to have a random string append to it (I thought that is an optional string but DA needs this to read the extension type). So I changed this:

Code:
default_logo_file_home="/home/tmp/logo.png"

into this:

Code:
# A random function that returns lowercase and uppercase letter for given length
function get_rnd_alpha() {
  local length
  length="$1"
  tr -dc A-Za-z </dev/urandom | head -c "${length}"
  echo ''
}


default_logo_file_home="/home/tmp/logo.png$(get_rnd_alpha 6)"


Now it's working perfectly
 
Last edited:
Back
Top