initial commit

This commit is contained in:
Dominika 2020-09-19 17:21:38 +02:00
commit ba6a05dad1
8 changed files with 137 additions and 0 deletions

28
code/common.sh Normal file
View file

@ -0,0 +1,28 @@
#!/bin/bash
# common.sh - common functions for OPS app
# get_auth_string()
function get_auth_string() {
if ! session_verify ${cookies[sh_session]}; then
exit 0
fi
echo "Authorization: Bearer $(cat secret/authToken)"
}
# add_account_refreshtoken(refreshtoken)
function add_account_refreshtoken() {
if ! session_verify ${cookies[sh_session]}; then
exit 0
fi
echo $(session_get_username ${cookies[sh_session]}):$1 >> secret/refreshTokens.dat
}
# add_account_authtoken(authtoken)
function add_account_authtoken() {
if ! session_verify ${cookies[sh_session]}; then
exit 0
fi
echo $(session_get_username ${cookies[sh_session]}):$1 >> secret/authTokens.dat
}

20
webroot/api/packages.shs Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
if ! session_verify ${cookies[sh_session]}; then
exit 0
fi
source code/common.sh
data=$(curl -s -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/parcel?updatedAfter=1970-01-01T00:00:00.000Z")
IFS=$'\n'
shipmentNumber=($(echo $data | jq -cr .[].shipmentNumber))
expiryDate=($(echo $data | jq -cr .[].expiryDate))
openCode=($(echo $data | jq -cr .[].openCode))
pickupPointLocation=($(echo $data | jq -cr .[].pickupPoint.location))
pickupPointName=($(echo $data | jq -cr .[].pickupPoint.name))
senderName=($(echo $data | jq -cr .[].senderName))
for i in ${pickupPointLocation[@]}; do
echo $i;
done

30
webroot/login.shs Normal file
View file

@ -0,0 +1,30 @@
#!/bin/bash
if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
login ${post_data[login]} ${post_data[password]}
status=$?
if [[ $status == 0 ]]; then
echo ${get_data[r]} > /dev/stderr
if [[ ${get_data[r]} == '' ]]; then
meta[redirect]='/'
else
meta[redirect]="$(echo ${get_data[r]} | sed -s 's/<//g;s/___/?/')"
fi
fi
fi
source templates/head.sh
if [[ $status == 1 && $reason != '' ]]; then
echo $reason
fi
echo "<h1>Log in...</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<input type='submit' value='Login'>
</form>
(please make sure that you're connecting over SSL)"

7
webroot/logout.shs Normal file
View file

@ -0,0 +1,7 @@
#!/bin/bash
logout
meta[redirect]='/'
source templates/head.sh
echo "Logged out successully. Redirecting.."

28
webroot/register.shs Normal file
View file

@ -0,0 +1,28 @@
#!/bin/bash
if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
register ${post_data[login]} ${post_data[password]}
status=$?
if [[ $status == 0 ]]; then
meta[redirect]='/smscode.shs?phone='${post_data[phone]}
fi
fi
source templates/head.sh
if [[ $status == 1 && $reason != '' ]]; then
echo $reason
fi
echo "<h1>Register</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<label for='phone'>Phone:</label>
<input type='tel' name='phone'><br>
<input type='submit' value='Register'>
</form>
(please make sure that you're connecting over SSL)"

21
webroot/smscode.shs Normal file
View file

@ -0,0 +1,21 @@
#!/bin/bash
if ! session_verify ${cookies[sh_session]}; then
exit 0
fi
if [[ ${get_data[phone]} != "" && ${post_data[code]} != "" ]]; then
tokens=$(curl -s -X POST -H "Content-type: application/json" --data '{"phoneOS":"Android"}' "https://api-inmobile-pl.easypack24.net/v1/confirmSMSCode/${get_data[phone]}/${post_data[code]}")
add_account_refreshtoken $(echo $tokens | jq -r .refreshToken)
add_account_authtoken $(echo $tokens | jq -r .authToken)
echo "success! the token was added to the database!"
elif [[ ${get_data[phone]} != "" ]]; then
curl -s "https://api-inmobile-pl.easypack24.net/v1/sendSMSCode/${get_data[phone]}" > /dev/null
echo "<form method='post'>
<label for='code'>SMS code:</label>
<input type='text' name='code'><br>
<input type='submit' value='Send'>
</form>"
fi

View file

@ -0,0 +1 @@

2
workers/updateKeys/worker.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
date