Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
37339dda
Unverified
Commit
37339dda
authored
May 27, 2021
by
neil
Committed by
GitHub
May 27, 2021
Browse files
Merge pull request #3525 from tresni/synology_dsm
Synology DSM - Make certificate descriptions sed safe
parents
7909273a
dcb51683
Changes
1
Hide whitespace changes
Inline
Side-by-side
deploy/synology_dsm.sh
View file @
37339dda
...
@@ -66,6 +66,12 @@ synology_dsm_deploy() {
...
@@ -66,6 +66,12 @@ synology_dsm_deploy() {
_getdeployconf SYNO_Certificate
_getdeployconf SYNO_Certificate
_debug SYNO_Certificate
"
${
SYNO_Certificate
:-}
"
_debug SYNO_Certificate
"
${
SYNO_Certificate
:-}
"
# shellcheck disable=SC1003 # We are not trying to escape a single quote
if
printf
"%s"
"
$SYNO_Certificate
"
|
grep
'\\'
;
then
_err
"Do not use a backslash (
\)
in your certificate description"
return
1
fi
_base_url
=
"
$SYNO_Scheme
://
$SYNO_Hostname
:
$SYNO_Port
"
_base_url
=
"
$SYNO_Scheme
://
$SYNO_Hostname
:
$SYNO_Port
"
_debug _base_url
"
$_base_url
"
_debug _base_url
"
$_base_url
"
...
@@ -110,7 +116,9 @@ synology_dsm_deploy() {
...
@@ -110,7 +116,9 @@ synology_dsm_deploy() {
_info
"Getting certificates in Synology DSM"
_info
"Getting certificates in Synology DSM"
response
=
$(
_post
"api=SYNO.Core.Certificate.CRT&method=list&version=1&_sid=
$sid
"
"
$_base_url
/webapi/entry.cgi"
)
response
=
$(
_post
"api=SYNO.Core.Certificate.CRT&method=list&version=1&_sid=
$sid
"
"
$_base_url
/webapi/entry.cgi"
)
_debug3 response
"
$response
"
_debug3 response
"
$response
"
id
=
$(
echo
"
$response
"
|
sed
-n
"s/.*
\"
desc
\"
:
\"
$SYNO_Certificate
\"
,
\"
id
\"
:
\"\(
[^
\"
]*
\)
.*/
\1
/p"
)
escaped_certificate
=
"
$(
printf
"%s"
"
$SYNO_Certificate
"
|
sed
's/\([].*^$[]\)/\\\1/g;s/"/\\\\"/g'
)
"
_debug escaped_certificate
"
$escaped_certificate
"
id
=
$(
echo
"
$response
"
|
sed
-n
"s/.*
\"
desc
\"
:
\"
$escaped_certificate
\"
,
\"
id
\"
:
\"\(
[^
\"
]*
\)
.*/
\1
/p"
)
_debug2
id
"
$id
"
_debug2
id
"
$id
"
if
[
-z
"
$id
"
]
&&
[
-z
"
${
SYNO_Create
:-}
"
]
;
then
if
[
-z
"
$id
"
]
&&
[
-z
"
${
SYNO_Create
:-}
"
]
;
then
...
@@ -119,7 +127,7 @@ synology_dsm_deploy() {
...
@@ -119,7 +127,7 @@ synology_dsm_deploy() {
fi
fi
# we've verified this certificate description is a thing, so save it
# we've verified this certificate description is a thing, so save it
_savedeployconf SYNO_Certificate
"
$SYNO_Certificate
"
_savedeployconf SYNO_Certificate
"
$SYNO_Certificate
"
"base64"
_info
"Generate form POST request"
_info
"Generate form POST request"
nl
=
"
\0
015
\0
012"
nl
=
"
\0
015
\0
012"
...
@@ -129,7 +137,7 @@ synology_dsm_deploy() {
...
@@ -129,7 +137,7 @@ synology_dsm_deploy() {
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
inter_cert
\"
; filename=
\"
$(
basename
"
$_cca
"
)
\"
${
nl
}
Content-Type: application/octet-stream
${
nl
}${
nl
}
$(
cat
"
$_cca
"
)
\0
012"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
inter_cert
\"
; filename=
\"
$(
basename
"
$_cca
"
)
\"
${
nl
}
Content-Type: application/octet-stream
${
nl
}${
nl
}
$(
cat
"
$_cca
"
)
\0
012"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
id
\"
${
nl
}${
nl
}
$id
"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
id
\"
${
nl
}${
nl
}
$id
"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
desc
\"
${
nl
}${
nl
}${
SYNO_Certificate
}
"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
desc
\"
${
nl
}${
nl
}${
SYNO_Certificate
}
"
if
echo
"
$response
"
|
sed
-n
"s/.*
\"
desc
\"
:
\"
$
SYNO_C
ertificate
\"
,
\(
[^{]*
\)
.*/
\1
/p"
|
grep
--
'is_default":true'
>
/dev/null
;
then
if
echo
"
$response
"
|
sed
-n
"s/.*
\"
desc
\"
:
\"
$
escaped_c
ertificate
\"
,
\(
[^{]*
\)
.*/
\1
/p"
|
grep
--
'is_default":true'
>
/dev/null
;
then
_debug2 default
"this is the default certificate"
_debug2 default
"this is the default certificate"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
as_default
\"
${
nl
}${
nl
}
true"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
as_default
\"
${
nl
}${
nl
}
true"
else
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment