SharkRF openSPOT API Menu

work in progress 🙂

looking nice, alot of functions already build in



sh code below :


#!/bin/sh
password="openspot"
server="openspot.local"
token="Login first (1) !!"
show_menu(){
NORMAL=`echo "\033[m"`
MENU=`echo "\033[36m"` #Blue
NUMBER=`echo "\033[33m"` #yellow
FGRED=`echo "\033[41m"`
RED_TEXT=`echo "\033[31m"`
ENTER_LINE=`echo "\033[33m"`
echo "${MENU}************************************************${NORMAL}"
echo " SharkRF openSPOT Menu "
echo " script made by PD2EMC"
echo " "
echo "${NUMBER} Server: ${RED_TEXT}" $server
echo "${NUMBER} Password: ${RED_TEXT}" $password
echo "${NUMBER} Token: ${RED_TEXT}" $token
echo " "
echo "${MENU}*******************Main Menu********************${NORMAL}"
echo "${MENU}**${NUMBER} 1)${MENU} Login to openSPOT ${NORMAL}"
echo "${MENU}**${NUMBER} 2)${MENU} Check Authorisation ${NORMAL}"
echo "${MENU}**${NUMBER} 3)${MENU} openSPOT Info Menu ${NORMAL}"
echo "${MENU}**${NUMBER} 4)${MENU} openSPOT Profiles Menu${NORMAL}"
echo "${MENU}**${NUMBER} 5)${MENU} nothing yet ${NORMAL}"
echo "${MENU}**${NUMBER} 6)${MENU} nothing yet ${NORMAL}"
echo "${MENU}**${NUMBER} 7)${MENU} nothing yet ${NORMAL}"
echo "${MENU}**${NUMBER} 8)${MENU} Logout openSPOT ${NORMAL}"
echo "${MENU}**${NUMBER} 9)${MENU} Reboot openSPOT ${NORMAL}"
echo "${MENU}**${NUMBER} 0)${MENU} Exit Menu ${NORMAL}"
echo "${MENU}************************************************${NORMAL}"
echo "${ENTER_LINE}Choose a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}"
read opt
while [ opt != '' ] do
if [[ $opt = "" ]]; then
exit;
else
case $opt in
1)
option_picked "Login to SharkRF openSPOT ...";
tokenurl=`curl http://$server/gettok.cgi| sed 's/{"token":"//'|sed 's/"}//'`;
token=${tokenurl};
tokenpass=$token$password;
digest=`printf ${tokenpass} | shasum -a 256 | sed 's/-//'`;
jwt=`curl -X POST --header "Content-Type: application/json" --data "{\"token\":\"$token\",\"digest\":\"$digest\"}" "http://$server/login.cgi" | sed 's/{"hostname":"openspot","jwt":"//'|sed 's/"}//'`;
clear;
show_menu;
;;
2)
#clear;
option_picked "Checking Autorization";
#echo "Checking authorisation";
curl -H "Authorization: Bearer $jwt" http://$server/checkauth.cgi | json_pp;
echo "Press [enter] key to continue. . .";
read enterKey;
clear;
show_menu;
;;
3) clear;
#submenu 1 is the openSPOT Information menu
sub_menu1;
;;
4) clear;
# Submenu 2 #profiles menu option_picked "Sub Menu 2";
sub_menu2;
;;
5) clear;
option_picked "Option 5 Picked";
show_menu;
;;
6) clear;
option_picked "Option 6 Picked";
show_menu;
;;
7) clear;
option_picked "Option 7 Picked";
show_menu;
;;
8)
option_picked "Logout openSPOT ...";
curl -H "Authorization: Bearer $jwt" http://$server/logout.cgi | json_pp;
token="Login first (1) !!";
digest="";
jwt="";
clear;
show_menu;
;;
9)
option_picked "Rebooting openSPOT";
curl -H "Authorization: Bearer $jwt" http://$server/reboot.cgi | json_pp
token="Login first (1) !!";
digest="";
jwt="";
clear;
show_menu;;
0)
echo "Bye bye $USER";
exit ;;
x)exit;
;;
\n)exit;
;;
*)clear;
option_picked "Pick an option from the menu";
show_menu;
;;
esac
fi
done
}

function option_picked() {
COLOR=’\033[01;31m’ # bold red
RESET=’\033[00;00m’ # normal white
MESSAGE=${@:-“${RESET}Error: No message passed”}
echo “${COLOR}${MESSAGE}${RESET}”
}

sub_menu1(){
NORMAL=`echo “\033[m”`
MENU=`echo “\033[36m”` #Blue
NUMBER=`echo “\033[33m”` #yellow
FGRED=`echo “\033[41m”`
RED_TEXT=`echo “\033[31m”`
ENTER_LINE=`echo “\033[33m”`
echo “${MENU}************************************************${NORMAL}”
echo ” SharkRF openSPOT Menu ”
echo ” script made by PD2EMC”
echo ” ”
echo “${NUMBER} Server: ${RED_TEXT}” $server
echo “${NUMBER} Password: ${RED_TEXT}” $password
echo “${NUMBER} Token: ${RED_TEXT}” $token
echo ” ”
echo “${MENU}*******************Info Menu********************${NORMAL}”
echo “${MENU}**${NUMBER} 1)${MENU} Login to openSPOT ${NORMAL}”
echo “${MENU}**${NUMBER} 2)${MENU} Check Authorisation ${NORMAL}”
echo “${MENU}**${NUMBER} 3)${MENU} Show Token Info ${NORMAL}”
echo “${MENU}**${NUMBER} 4)${MENU} openSPOT Info ${NORMAL}”
echo “${MENU}**${NUMBER} 5)${MENU} Networksettings ${NORMAL}”
echo “${MENU}**${NUMBER} 6)${MENU} Radio Status ${NORMAL}”
echo “${MENU}**${NUMBER} 7)${MENU} openSPOT Profiles ${NORMAL}”
echo “${MENU}**${NUMBER} 8)${MENU} Reboot openSPOT ${NORMAL}”
echo “${MENU}**${NUMBER} 9)${MENU} Back to Main Menu ${NORMAL}”
echo “${MENU}**${NUMBER} 0)${MENU} Exit Menu ${NORMAL}”

echo “${MENU}************************************************${NORMAL}”
echo “${ENTER_LINE}Choose a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}”
read sub1
while [ sub1 != ” ] do
if [[ $sub1 = “” ]]; then
exit;
else
case $sub1 in
1)
option_picked “Login to SharkRF openSPOT …”;
tokenurl=`curl http://$server/gettok.cgi| sed ‘s/{“token”:”//’|sed ‘s/”}//’`;
token=${tokenurl};
tokenpass=$token$password;
digest=`printf ${tokenpass} | shasum -a 256 | sed ‘s/-//’`;
jwt=`curl -X POST –header “Content-Type: application/json” –data “{\”token\”:\”$token\”,\”digest\”:\”$digest\”}” “http://$server/login.cgi” | sed ‘s/{“hostname”:”openspot”,”jwt”:”//’|sed ‘s/”}//’`;
clear;
sub_menu1;
;;
2)
#clear;
option_picked “Checking Autorization”;
#echo “Checking authorisation”;
curl -H “Authorization: Bearer $jwt” http://$server/checkauth.cgi | json_pp;
echo “Press [enter] key to continue. . .”;
read enterKey;
clear;
sub_menu1;
;;
3)
option_picked “Show Token Info …”;
echo “Token: ” $token;
echo “Digest: ” $digest;
echo “JWT: ” $jwt;
echo “Press [enter] key to continue. . .”;
read enterKey;
clear;
sub_menu1;
;;

4)
option_picked “openSPOT Information …”;
curl -H “Authorization: Bearer $jwt” http://$server/info.cgi | json_pp;
echo “Press [enter] key to continue. . .”;
read enterKey;
clear;
sub_menu1;
;;
5)
option_picked “Networksettings …”;
curl -H “Authorization: Bearer $jwt” http://$server/netsettings.cgi | json_pp;
echo “Press [enter] key to continue. . .”;
read enterKey;
clear;
sub_menu1;
;;

6)
option_picked “Getting Radio Status …”;
curl -H “Authorization: Bearer $jwt” http://$server/status.cgi | json_pp;
echo “Press [enter] key to continue. . .”;
read enterKey;
clear;
sub_menu1;
;;
7)
option_picked “Getting openSPOT Profiles …”;
curl -H “Authorization: Bearer $jwt” http://$server/cpsettings.cgi | json_pp;
echo “test”
echo “Press [enter] key to continue. . .”;
read enterKey;
clear;
sub_menu1;
;;
8) clear;
option_picked “Reboot openSPOT …”;
curl -H “Authorization: Bearer $jwt” http://$server/reboot.cgi | json_pp;
token=”Login first (1) !!”;
digest=””;
jwt=””;
clear;
show_menu;
;;
9) clear;
show_menu;
;;
0) echo “Bye bye $USER”;
exit 1;;

x)exit;
;;

\n)exit;
;;

*)clear;
option_picked “Pick an option from the menu”;
sub_menu1;
;;
esac
fi
done
}

#openSPOT Profiles Menu
sub_menu2(){
NORMAL=`echo “\033[m”`
MENU=`echo “\033[36m”` #Blue
NUMBER=`echo “\033[33m”` #yellow
FGRED=`echo “\033[41m”`
RED_TEXT=`echo “\033[31m”`
ENTER_LINE=`echo “\033[33m”`
echo “${MENU}************************************************${NORMAL}”
echo ” SharkRF openSPOT Menu ”
echo ” script made by PD2EMC”
echo ” ”
echo “${NUMBER} Server: ${RED_TEXT}” $server
echo “${NUMBER} Password: ${RED_TEXT}” $password
echo “${NUMBER} Token: ${RED_TEXT}” $token
echo ” ”
echo “${MENU}*****************Profile Menu*******************${NORMAL}”
echo “${MENU}**${NUMBER} 1)${MENU} Login to openSPOT ${NORMAL}”
echo “${MENU}**${NUMBER} 2)${MENU} openSPOT Profiles ${NORMAL}”
echo “${MENU}**${NUMBER} 3)${MENU} Switch to Profile 0 DMR Brandmeister${NORMAL}”
echo “${MENU}**${NUMBER} 4)${MENU} Switch to Profile 1 YSFReflector${NORMAL}”
echo “${MENU}**${NUMBER} 5)${MENU} Switch to Profile 2 FCSReflector${NORMAL}”
echo “${MENU}**${NUMBER} 6)${MENU} Switch to Profile 3 C4FM->DMR${NORMAL}”
echo “${MENU}**${NUMBER} 7)${MENU} Switch to Profile 4 DMR->C4FM${NORMAL}”
echo “${MENU}**${NUMBER} 8)${MENU} Reboot openSPOT ${NORMAL}”
echo “${MENU}**${NUMBER} 9)${MENU} Back to Main Menu ${NORMAL}”
echo “${MENU}**${NUMBER} 0)${MENU} Exit Menu ${NORMAL}”
echo “${MENU}************************************************${NORMAL}”
echo “${ENTER_LINE}Choose a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}”
read sub2
while [ sub2 != ” ] do
if [[ $sub2 = “” ]]; then
exit;
else
case $sub2 in
1)
option_picked “Login to SharkRF openSPOT …”;
tokenurl=`curl http://$server/gettok.cgi| sed ‘s/{“token”:”//’|sed ‘s/”}//’`;
token=${tokenurl};
tokenpass=$token$password;
digest=`printf ${tokenpass} | shasum -a 256 | sed ‘s/-//’`;
jwt=`curl -X POST –header “Content-Type: application/json” –data “{\”token\”:\”$token\”,\”digest\”:\”$digest\”}” “http://$server/login.cgi” | sed ‘s/{“hostname”:”openspot”,”jwt”:”//’|sed ‘s/”}//’`;
clear;
sub_menu2;
;;
2) clear;
option_picked “Getting opSPOT Profile settings …”;
curl -H “Authorization: Bearer $jwt” http://$server/cpsettings.cgi | json_pp;
echo “Press [enter] key to continue. . .”;
read enterKey;
clear;
sub_menu2;
;;

3)
option_picked “Switching to Profile 0”;
curl -X POST -H “Authorization: Bearer $jwt” –data “{\”active_cp\”:\”0\”}” “http://$server/cpsettings.cgi”;
token=”Login first (1) !!”;
digest=””;
jwt=””;
clear;
show_menu;
;;

4)
option_picked “Switching to Profile 1”;
curl -X POST -H “Authorization: Bearer $jwt” –data “{\”active_cp\”:\”1\”}” “http://$server/cpsettings.cgi”;
token=”Login first (1) !!”;
digest=””;
jwt=””;
clear;
show_menu;
;;

5)
option_picked “Switching to Profile 2”;
curl -X POST -H “Authorization: Bearer $jwt” –data “{\”active_cp\”:\”2\”}” “http://$server/cpsettings.cgi”;
token=”Login first (1) !!”;
digest=””;
jwt=””;
clear;
show_menu;
;;

6)
option_picked “Switching to Profile 3”;
curl -X POST -H “Authorization: Bearer $jwt” –data “{\”active_cp\”:\”3\”}” “http://$server/cpsettings.cgi”;
token=”Login first (1) !!”;
digest=””;
jwt=””;
clear;
show_menu;
;;

7)
option_picked “Switching to Profile 4”;
curl -X POST -H “Authorization: Bearer $jwt” –data “{\”active_cp\”:\”4\”}” “http://$server/cpsettings.cgi”;
token=”Login first (1) !!”;
digest=””;
jwt=””;
clear;
show_menu;
;;

8)
option_picked “Rebooting openSPOT”;
curl -H “Authorization: Bearer $jwt” http://$server/reboot.cgi | json_pp
token=”Login first (1) !!”;
digest=””;
jwt=””;
clear;
show_menu;;

9) clear;
show_menu;;

0) echo “Bye bye $USER”;
exit 1;;

x)exit;
;;

\n)exit;
;;

*)clear;
option_picked “Pick an option from the menu”;
sub_menu1;
;;
esac
fi
done
}

clear
show_menu