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
c2812896
Commit
c2812896
authored
Feb 11, 2020
by
Paul Nguyen
Browse files
Update deployer
parent
d9a9695f
Changes
1
Hide whitespace changes
Inline
Side-by-side
deploy/panos.sh
View file @
c2812896
...
@@ -13,61 +13,75 @@
...
@@ -13,61 +13,75 @@
# This function is to parse the XML
# This function is to parse the XML
parse_response
()
{
parse_response
()
{
status
=
$(
echo
"
$1
"
|
sed
's/^.*"\([a-z]*\)".*/\1/g'
)
type
=
$2
message
=
$(
echo
"
$1
"
|
sed
's/^.*<result>\(.*\)<\/result.*/\1/g'
)
if
[
$type
=
'keygen'
]
;
then
status
=
$(
echo
"
$1
"
|
sed
's/^.*\(['
\'
']\)\([a-z]*\)'
\'
'.*/\2/g'
)
if
[
"
$status
"
=
"success"
]
;
then
panos_key
=
$(
echo
"
$1
"
|
sed
's/^.*\(<key>\)\(.*\)<\/key>.*/\2/g'
)
_panos_key
=
$panos_key
message
=
'PAN-OS key is set.'
else
message
=
"PAN-OS Key could not be set."
fi
else
status
=
$(
echo
"
$1
"
|
sed
's/^.*"\([a-z]*\)".*/\1/g'
)
message
=
$(
echo
"
$1
"
|
sed
's/^.*<result>\(.*\)<\/result.*/\1/g'
)
fi
return
0
return
0
}
}
deployer
()
{
deployer
()
{
type
=
$1
# Types are cert, key, commit
type
=
$1
# Types are
keygen,
cert, key, commit
_debug
"**** Deploying
$type
*****"
_debug
"**** Deploying
$type
*****"
panos_url
=
"https://
$_panos_host
/api/"
#Generate DEIM
delim
=
"-----MultipartDelimiter
$(
date
"+%s%N"
)
"
nl
=
"
\0
15
\0
12"
#Set Header
_H1
=
"Content-Type: multipart/form-data; boundary=
$delim
"
if
[
$type
=
'cert'
]
;
then
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
file
\"
; filename=
\"
$(
basename
"
$_cfullchain
"
)
\"
${
nl
}
Content-Type: application/octet-stream
${
nl
}${
nl
}
$(
cat
"
$_cfullchain
"
)
"
fi
if
[
$type
=
'key'
]
;
then
#Add key
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
file
\"
; filename=
\"
$(
basename
"
$_ckey
"
)
\"
${
nl
}
Content-Type: application/octet-stream
${
nl
}${
nl
}
$(
cat
"
$_ckey
"
)
"
fi
#Close multipart
content
=
"
$content
${
nl
}
--
$delim
--
${
nl
}
"
#Convert CRLF
content
=
$(
printf
%b
"
$content
"
)
if
[
$type
=
'cert'
]
;
then
panos_url
=
"https://
$_panos_host
/api/?type=import&category=certificate&certificate-name=
$_cdomain
&format=pem&key=
$_panos_key
"
fi
if
[
$type
=
'key'
]
;
then
if
[
$type
=
'keygen'
]
;
then
panos_url
=
"https://
$_panos_host
/api/?type=import&category=private-key&certificate-name=
$_cdomain
&format=pem&passphrase=none&key=
$_panos_key
"
_H1
=
"Content-Type: application/x-www-form-urlencoded"
content
=
"type=keygen&user=
$_panos_user
&password=
$_panos_pass
"
# content="$content${nl}--$delim${nl}Content-Disposition: form-data; type=\"keygen\"; user=\"$_panos_user\"; password=\"$_panos_pass\"${nl}Content-Type: application/octet-stream${nl}${nl}"
fi
fi
if
[
$type
=
'commit'
]
;
then
cmd
=
$(
_url_encode
"<commit><partial><
$_panos_user
></
$_panos_user
></partial></commit>"
)
if
[
$type
=
'cert'
]
||
[
$type
=
'key'
]
;
then
panos_url
=
"https://
$_panos_host
/api/?type=commit&cmd=
$cmd
&key=
$_panos_key
"
#Generate DEIM
delim
=
"-----MultipartDelimiter
$(
date
"+%s%N"
)
"
nl
=
"
\0
15
\0
12"
#Set Header
_H1
=
"Content-Type: multipart/form-data; boundary=
$delim
"
if
[
$type
=
'cert'
]
;
then
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
type
\"\r\n\r\n\r\n
import"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
category
\"\r\n\r\n\r\n
certificate"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
certificate-name
\"\r\n\r\n\r\n
$_cdomain
"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
key
\"\r\n\r\n\r\n
$_panos_key
"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
format
\"\r\n\r\n\r\n
pem"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
file
\"
; filename=
\"
$(
basename
"
$_cfullchain
"
)
\"
${
nl
}
Content-Type: application/octet-stream
${
nl
}${
nl
}
$(
cat
"
$_cfullchain
"
)
"
fi
if
[
$type
=
'key'
]
;
then
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
type
\"\r\n\r\n\r\n
import"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
category
\"\r\n\r\n\r\n
private-key"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
certificate-name
\"\r\n\r\n\r\n
$_cdomain
"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
key
\"\r\n\r\n\r\n
$_panos_key
"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
format
\"\r\n\r\n\r\n
pem"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
passphrase
\"\r\n\r\n\r\n
none"
content
=
"
$content
${
nl
}
--
$delim
${
nl
}
Content-Disposition: form-data; name=
\"
file
\"
; filename=
\"
$(
basename
"
$_ckey
"
)
\"
${
nl
}
Content-Type: application/octet-stream
${
nl
}${
nl
}
$(
cat
"
$_ckey
"
)
"
fi
#Close multipart
content
=
"
$content
${
nl
}
--
$delim
--
${
nl
}
"
#Convert CRLF
content
=
$(
printf
%b
"
$content
"
)
fi
fi
if
[
$type
=
'
key'
]
||
[
$type
=
'cer
t'
]
;
then
if
[
$type
=
'
commi
t'
]
;
then
response
=
$(
_post
"
$content
"
"
$panos_url
"
""
"POST"
)
_H1
=
"Content-Type: application/x-www-form-urlencoded"
else
cmd
=
$(
printf
"%s"
"<commit><partial><
$_panos_user
></
$_panos_user
></partial></commit>"
| _url_encode
)
response
=
$(
_get
$panos_url
)
content
=
"type=commit&key=
$_panos_key
&cmd=
$cmd
"
fi
fi
_debug panos_url
$panos_url
_debug
"RESPONSE
$response
"
response
=
$(
_post
"
$content
"
"
$panos_url
"
""
"POST"
)
parse_response
"
$response
"
parse_response
"
$response
"
$type
_debug
"STATUS IS
$status
"
_debug
"MESSAGE IS
$message
"
# Saving response to variables
# Saving response to variables
response_status
=
$status
response_status
=
$status
# Check for cert upload error and handle gracefully.
#DEBUG
#DEBUG
_debug header
"
$_H1
"
# _debug content "$content"
_debug response_status
"
$response_status
"
_debug response_status
"
$response_status
"
if
[
"
$response_status
"
=
"success"
]
;
then
if
[
"
$response_status
"
=
"success"
]
;
then
_debug
"Successfully deployed
$type
"
_debug
"Successfully deployed
$type
"
...
@@ -121,18 +135,8 @@ panos_deploy() {
...
@@ -121,18 +135,8 @@ panos_deploy() {
return
1
return
1
else
else
_debug
"Getting PANOS KEY"
_debug
"Getting PANOS KEY"
panos_key_response
=
$(
_get
"https://
$_panos_host
/api/?type=keygen&user=
$_panos_user
&password=
$_panos_pass
"
)
deployer keygen
_debug
"PANOS KEY FULL RESPONSE
$panos_key_response
"
if
[
-z
"
$_panos_key
"
]
;
then
status
=
$(
echo
"
$panos_key_response
"
|
sed
's/^.*\(['
\'
']\)\([a-z]*\)'
\'
'.*/\2/g'
)
_debug
"STATUS IS
$status
"
if
[
"
$status
"
=
"success"
]
;
then
panos_key
=
$(
echo
"
$panos_key_response
"
|
sed
's/^.*\(<key>\)\(.*\)<\/key>.*/\2/g'
)
_panos_key
=
$panos_key
else
_err
"PANOS Key could not be set. Deploy with --debug to troubleshoot"
return
1
fi
if
[
-z
"
$_panos_host
"
]
&&
[
-z
"
$_panos_key
"
]
&&
[
-z
"
$_panos_user
"
]
;
then
_err
"Missing host, apikey, user."
_err
"Missing host, apikey, user."
return
1
return
1
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