-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Single quotes #53
Single quotes #53
Changes from 5 commits
aaf5cc6
35ced57
539cbf0
4afb9b2
86d6523
269e13a
2cf9fde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ echo | |
if [ "$(node -v)" = "" ] # If Node.js is not installed | ||
then | ||
clear | ||
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ | ||
You need to complete installation phase 1 first." 9 50 | ||
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ | ||
You need to complete install Nightscout phase 1 first." 9 50 | ||
exit | ||
fi | ||
|
||
|
@@ -43,18 +43,18 @@ echo | |
echo "Setting up startup service" | ||
echo | ||
|
||
if [ ! -s /etc/nsconfig ] # Only if nsconfig does not exist already | ||
if [ ! -s /etc/nsconfig ] # Create a new nsconfig file only if one does not exit already. | ||
then | ||
|
||
cat > /etc/nsconfig << EOF | ||
|
||
export API_SECRET="YOUR_API_SECRET_HERE" | ||
export ENABLE="careportal food boluscalc bwp cob bgi pump openaps rawbg iob upbat cage sage basal" | ||
export AUTH_DEFAULT_ROLES="denied" | ||
export PUMP_FIELDS="reservoir battery clock" | ||
export DEVICESTATUS_ADVANCED="true" | ||
export THEME="colors" | ||
export DBSIZE_MAX="20000" | ||
export API_SECRET='YOUR_API_SECRET_HERE' | ||
export ENABLE='careportal food boluscalc bwp cob bgi pump openaps rawbg iob upbat cage sage basal' | ||
export AUTH_DEFAULT_ROLES='denied' | ||
export PUMP_FIELDS='reservoir battery clock' | ||
export DEVICESTATUS_ADVANCED='true' | ||
export THEME='colors' | ||
export DBSIZE_MAX='20000' | ||
|
||
EOF | ||
|
||
|
@@ -84,31 +84,60 @@ sleep 10 | |
done | ||
EOF | ||
|
||
cs=`grep 'API_SECRET=' /etc/nsconfig | head -1 | cut -f2 -d'"'` | ||
|
||
echo "Current API secret is: $cs" | ||
echo | ||
echo "If you would like to change it please enter the new secret now or hit enter to leave the same" | ||
cs2=`grep 'API_SECRET=' /etc/nsconfig | cut -s -f2 -d'"'` # This is API_SECRET if double quotes are used in nsconfig. | ||
cs1=`grep 'API_SECRET=' /etc/nsconfig | cut -s -f2 -d\'` # This is API_SECRET if single quotes are used in nsconfig. | ||
cs="$cs2" | ||
if [ "$cs2" = "" ] | ||
then | ||
cs="$cs1" # This is the current secret (API_SECRET) from nsconfig. | ||
fi | ||
|
||
for j in {1..1000} | ||
got_it=0 | ||
while [ $got_it -lt 1 ] | ||
do | ||
read -t 0.001 dummy | ||
done | ||
read -p "New secret 12 character minimum length (blank to skip change) : " ns | ||
go_back=0 | ||
clear | ||
exec 3>&1 | ||
Value=$(dialog --colors --ok-label "Submit" --form " \Zr Developed by the xDrip team \Zn\n\n\n\ | ||
Your current API_SECRET is $cs\n\n\ | ||
You can press escape to maintain the existing one. Or, enter a new one with at least 12 characters excluding the following.\n\n\ | ||
$ \" \\\n " 19 50 0 "API_SECRET:" 1 1 "$secr" 1 14 25 0 2>&1 1>&3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when using single quotes the following are allowed: $ " \ \n the only one that is not allowed is ' it self. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought Nightscout itself had difficulty with $. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering we still have systems that have " in their nsconfig, how about this for the exceptions? $ ' " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also be OK. The most important part is to also remove the ' from the text. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what you mean by that. |
||
response=$? | ||
if [ $response = 255 ] || [ $response = 1 ] # cancled or escaped | ||
then | ||
ns="$cs" | ||
else | ||
ns=$(echo "$Value" | sed -n 1p) | ||
fi | ||
exec 3>&- | ||
|
||
if [ "$ns" != "" ] | ||
if [ ${#ns} -lt 12 ] # Reject if the submission has less than 12 characters. | ||
then | ||
while [ ${#ns} -lt 12 ] && [ "$ns" != "" ] | ||
do | ||
read -p "Needs to be at least 12 chars - try again: " ns | ||
done | ||
if [ "$ns" != "" ] | ||
go_back=1 | ||
clear | ||
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ | ||
API_SECRET should have at least 12 characters. Please try again." 8 50 | ||
fi | ||
clear | ||
|
||
if [ $go_back -lt 1 ] | ||
then | ||
sed -i -e "s/API_SECRET=\".*/API_SECRET=\"${ns}\"/g" /etc/nsconfig | ||
echo | ||
echo "Secret changed to: ${ns}" | ||
sleep 3 | ||
if [[ $ns == *[\$]* ]] || [[ $ns == *[\"]* ]] || [[ $ns == *[\\]* ]] # Reject if submission contains unacceptable characters. | ||
then | ||
go_back=1 | ||
clear | ||
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ | ||
API_SECRET should not include $, \" or \\. Please try again." 8 50 | ||
else | ||
got_it=1 | ||
fi | ||
fi | ||
|
||
done | ||
|
||
if [ "$ns" != "$cs" ] # Only if the new secret is different than the current secret (API_SECRET) | ||
then | ||
sed -i -e "s/API_SECRET=.*/API_SECRET=\'${ns}\'/g" /etc/nsconfig # Replace API_SECRET in nsconfig with the new one using single quotes. | ||
fi | ||
|
||
cat > /etc/rc.local << "EOF" | ||
|
@@ -154,7 +183,7 @@ rm -rf /tmp/Logs | |
echo -e "Installation phase 2 completed $(date)\n" | cat - /xDrip/Logs > /tmp/Logs | ||
sudo /bin/cp -f /tmp/Logs /xDrip/Logs | ||
|
||
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ | ||
dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ | ||
Press enter to restart the server. This will result in an expected error message. Wait 30 seconds before clicking on retry to reconnect or using a browser to access your Nightscout." 10 50 | ||
sudo reboot | ||
fi | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happened to this part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're now using a dialog for the API_SECRET.
I understood that was needed when using a text prompt for asking for the API_SECRET.
Did I misunderstand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when someone presses a lot of chars before reaching this stage. Are they being removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a maximum for the number of characters anywhere in any of the dialogs.
Do we need to specify a maximum?
I can add that to the prompt asking user to enter an API_SECRET that has 12-24 characters for example.
Should I do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is not with the length of the API_SECRET but rather with what happens when the scripts are running and someone presses a few keys. Will this keys be part of the dialog, or are they removed automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dialog will take all the keys as intended characters until the user presses enter. Then, all the characters enterd will be accepted as the password.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where that loop is right now before this PR:
![Screenshot 2023-03-18 204532](https://user-images.githubusercontent.com/51497406/226147755-50f62275-90e1-45fc-a16e-e0940534d7ca.png)
It's after the prompt asking for the password is shown on screen not before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the PR that put that loop there: #24
So, it's my fault. I put it in the wrong place.
The loops should be there when a script is running taking a very long time. Then, if the user presses a button by mistake, we need to make sure what comes next will not be broken by those keys.
But, where I have inserted the loop is wrong.