使用 CMD_SKINS 的 Directadmin 上传徽标时出错,无法获取 mime-type

问题描述

我正在尝试使用 CMD_API_SKINS 上传自定义徽标

这是我使用 curl + 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}"

在调试这个 API 时,我得到了这样的错误

text='An Error Occurred'

        result='Cannot get mime-type for log<br>

似乎 DA 正在尝试解析并获取文件logo.png”的扩展名,但它不能

完整的错误日志:

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

我也尝试像这样对查询进行编码,但仍然出现相同的错误

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

这里有什么解释吗?是否可以使用此 API 上传徽标?

解决方法

好的,我找到了没有在任何地方记录的技巧。上传的文件需要附加一个随机字符串。所以我改变了这个:

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

进入这个:

RANDOM_STR="EbYIES"

default_logo_file_home="/home/tmp/logo.png${RANDOM_STR}"

现在完美运行