Router Wi-Fi Password Change & Display

This Tutorial aims to provide a simple method to change the WiFi Access Password, and save the Password within SambaPOS so that we may use it for Display or Printing purposes.


::::: SETUP Begin ::::::::::::::::::::

Automation Command - WiFiPW Update

Automation Command can be mapped as a button (i.e. to the Ticket screen), or no mapping is necessary if you want to place it on an Entity Screen or Account Screen.

Name: AU WiFiPW Update
Button Header: Change WiFi )))
Mappings: (choose what is suitable for your setup)


Action to Update Program Setting for variable WiFiPW:

Action Update Program Setting will store the password in the DB which can later be referenced using notation {:WiFiPW}.

Name: AC WiFiPW Update
Type: Update Program Setting
Setting Name: WiFiPW
Setting Value: [:WiFiPW]
Update Type: Update
Is Local: False


Action to Start Process to launch Browser: (optional)

Action Start Process can launch an external program or open a file through association. In this case, we use an URL as the File Name which should cause the Default Browser to Launch, and go to the page specified by the URL.

Using the following notation in the URL can be used for some password-protected pages to pass the credentials (username:password) to the page, which will bypass the requirement to login manually.

http://username:password@website.com/

Name: AC Run Browser WiFi
File Name: http://admin:routerpw@192.168.1.1/
Arguments: ``
Use Shell Execute: False
Is Hidden: False


Rule to capture click-event of Automation Command and fire our Actions:

Name: RU WiFiPW Update
Event Name: Automation Command Executed
Custom Constraints: Execute rule if Matches
Automation Command Name Equals AU WiFiPW Update

Actions:

Name: AC WiFiPW Update
Constraint: ``
WiFiPW: [?WiFiPW]

Name: AC Run Browser WiFi
Constraint: ``

::::: SETUP End ::::::::::::::::::::


The notation [?WiFiPW] used in the above Action will invoke a prompt for user-input. This could even be written as something like: [?Please Enter a New Password for the Guest Wi-Fi].

The input is then passed to the Action which updates the Program Setting named WiFiPW, which can then be referenced with the notation {SETTING:WiFiPW}.

For example, the Show Message Action can reference this Program Setting to display the value stored in WiFiPW, using the reference notation {SETTING:WiFiPW}:

Even this Printer Template (which is for a Pole Display) can reference the password:

<XCT>31,20,17
<C>:: WiFi Password ::
<C>{SETTING:WiFiPW}

NOTE: There is a more advance method in a post near the end of the thread…

1 Like

Printing Bill with or without WiFi Password

You can choose to print the WiFi Password on the Ticket (Bill) by cloning a few things and making some small modifications.

:question: To Clone something (an Action, Rule, Template, Print Job, etc.) simply Right-click on the object and select Clone ....


Clone Ticket Template:

Add Tag to new Template: {SETTING:WiFiPW}

Clone Print Job and change the Printer Template for the new Job:

Clone Print Bill Action and change the Print Job for the new Action:

Clone Print Bill Rule and change the Print Action for the new Rule:
Also add a Constraint to the Old Rule and the New Rule to determine which Rule will fire Actions.

Left side of Constraint for both Rules: [=TN('{BALANCE}')]
Condition for New Rule (with WiFi): Greater 99
Condition for Old Rule: Less 100

Many router brands (if not most) have Terminal or SSH access.

I just don’t know the scripting well enough to login, change the WiFi access password (main or guest) and logout. I don’t even know where to start. I can login through PuTTY, but I don’t know what commands to issue; there is no built-in help, and G00gle has come up empty.

REQUEST: if anyone knows how to write a SH/SSH script to change the Wi-Fi access password (including router login), or can get me started, please let me know!

P.S. I use an ASUS RT-AC66U

Thanks @emre!

"nvram set ath0_wpa_psk="your_key_without_quotes"" for WPA personal or "nvram set ath0_key1="as_above"" for WEP - not sure about the other encryption methods though. Check "nvram show | grep ath" for more options!

I managed to find the following for my router (using WPA2 - AES). Assuming 2.4 radio and 5.0 radio both have main password “12345”, and 2.4 Guest Network 1 has password “guestpassword”, here is what I’m seeing:

wl_wpa_psk=12345 (??? overall 2.4/5.0 main network)
wl0_wpa_psk=12345 (2.4 main network)
wl0.1_wpa_psk=guestpassword (2.4 guest network 1)
wl0.2_wpa_psk=  (2.4 guest network 2)
wl0.3_wpa_psk=  (2.4 guest network 3)
wl1_wpa_psk=12345 (5.0 main network)
wl1.1_wpa_psk=  (5.0 guest network 1)
wl1.2_wpa_psk=  (5.0 guest network 2)
wl1.3_wpa_psk=  (5.0 guest network 3)
wlc_wpa_psk= (???)

I have question marks beside 2 of them, since I’m not sure what they’re for, but I’m interested in the Guest network anyway (wl0.1_wpa_psk).

So assuming I want to run this command,

nvram set wl0.1_wpa_psk=newguestpassword

What would the rest of the script look like to login, and pass {:WiFiPW} to the script to set the password, and logout, using Start Process with something like:

Start Process: PuTTY.exe
Arguments: <script> {:WiFiPW}

… or …

Start Process: PuTTY.exe <script>
Arguments: {:WiFiPW}

… or …

Start Process: <script> (through PuTTY association with .sh)
Arguments: {:WiFiPW}

There is a tool called plink.exe on putty download page. I’ve never tried it but from description I assume that might be useful.

Plink (a command-line interface to the PuTTY back ends) 

Download
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Usage
http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html

Oh boy, time for some fun experimenting :smile:. I’ve been wanting to be able to do this for a long time… thanks again @emre!

I will post back with my findings and setup when I get it all working…

@QMcKay, it varies from one router to another. Most of them support Telnet. New routers support SSH. With SSH, you will need the to use the key if you want to run an auto command, command line are also different from one router to another.

Just use putty to do the scripting.

I have a solution, but it’s a bit ugly.

I’m having to build a .sh dynamically on-the-fly using .bat file echo statements, because I can’t figure out how to retrieve the parameters/arguments (i.e. $1 $2) in the .sh script when executed as such…

plink.exe -ssh %rHOST% -P %rPORT% -l %rUSER% -pw %rPW% -m "script.sh" "ARG1 ARG2"

The above works with either PUTTY or PLINK, however, in script.sh, the arguments are missing… that is, $1, $2, etc. are empty. Anyone know how to send them through PLINK (or PUTTY) so they are available to script.sh?


The BAT file _wifi_change_guest1.bat dynamically builds _wifi_change_guest1.sh which is subsequently passed to PLINK.

@echo off
cls

set rHOST=192.168.0.1
set rPORT=23
set rUSER=admin
set rPASS=<router admin password>
set rGUEST24net1=wl0.1_wpa_psk
set rGUEST50net1=wl1.1_wpa_psk
set rGUESTpw1=%1
set rSCRIPT=_wifi_change_guest1.sh
set LOGFILE=_LOGFILE_Router.txt

:: go to where PLINK is located    
C:
CD\
CD C:\D\Programs\POS\router

:: Delete previous LOGFILE
if exist %LOGFILE% del %LOGFILE%

:: Delete previous rSCRIPT
if exist %rSCRIPT% del %rSCRIPT%

:: Build the Script into file %rSCRIPT% using ECHO statements
echo #!/bin/sh> %rSCRIPT%
echo guestnet241=%rGUEST24net1%>> %rSCRIPT%
echo guestnet501=%rGUEST50net1%>> %rSCRIPT%
echo guestpw1=%rGUESTpw1%>> %rSCRIPT%
echo echo ---------->> %rSCRIPT%
echo echo Shell Script BEG>> %rSCRIPT%
echo echo >> %rSCRIPT%
echo echo n241 $guestnet241>> %rSCRIPT%
echo echo n501 $guestnet501>> %rSCRIPT%
echo echo pwch $guestpw1>> %rSCRIPT%
echo echo >> %rSCRIPT%

echo echo ---------->> %rSCRIPT%
echo echo CURRENT password for $guestnet241 ...>> %rSCRIPT%
echo nvram show ^| grep $guestnet241>> %rSCRIPT%
echo echo >> %rSCRIPT%
echo echo Changing password for $guestnet241 to -$guestpw1- ...>> %rSCRIPT%
echo nvram set $guestnet241=$guestpw1>> %rSCRIPT%
echo echo >> %rSCRIPT%
echo echo NEW password for $guestnet241 ...>> %rSCRIPT%
echo nvram show ^| grep $guestnet241>> %rSCRIPT%
echo echo ---------->> %rSCRIPT%
echo echo >> %rSCRIPT%

echo echo ---------->> %rSCRIPT%
echo echo CURRENT password for $guestnet501 ...>> %rSCRIPT%
echo nvram show ^| grep $guestnet501>> %rSCRIPT%
echo echo >> %rSCRIPT%
echo echo Changing password for $guestnet501 to -$guestpw1- ...>> %rSCRIPT%
echo #nvram set $guestnet501=$guestpw1>> %rSCRIPT%
echo echo >> %rSCRIPT%
echo echo NEW password for $guestnet501 ...>> %rSCRIPT%
echo nvram show ^| grep $guestnet501>> %rSCRIPT%
echo echo ---------->> %rSCRIPT%
echo echo >> %rSCRIPT%

echo echo Shell Script END>> %rSCRIPT%
echo echo ---------->> %rSCRIPT%
echo echo exiting...>> %rSCRIPT%
echo exit>> %rSCRIPT%

@echo on
:: Run %rSCRIPT% through PLINK
plink.exe -ssh %rHOST% -P %rPORT% -l %rUSER% -pw %rPASS% -m "%rSCRIPT%" >> %LOGFILE% 2>&1

::@notepad %LOGFILE%
::timeout 1

::pause

:end

The SH file _wifi_change_guest1.sh (dynamically built on-the-fly by above .BAT file):

#!/bin/sh
guestnet241=wl0.1_wpa_psk
guestnet501=wl1.1_wpa_psk
guestpw1=newpassword
echo ----------
echo Shell Script BEG
echo 
echo n241 $guestnet241
echo n501 $guestnet501
echo pwch $guestpw1
echo 
echo ----------
echo CURRENT password for $guestnet241 ...
nvram show | grep $guestnet241
echo 
echo Changing password for $guestnet241 to -$guestpw1- ...
nvram set $guestnet241=$guestpw1
echo 
echo NEW password for $guestnet241 ...
nvram show | grep $guestnet241
echo ----------
echo 
echo ----------
echo CURRENT password for $guestnet501 ...
nvram show | grep $guestnet501
echo 
echo Changing password for $guestnet501 to -$guestpw1- ...
#nvram set $guestnet501=$guestpw1
echo 
echo NEW password for $guestnet501 ...
nvram show | grep $guestnet501
echo ----------
echo 
echo Shell Script END
echo ----------
echo exiting...
exit

The Log file _LOGFILE_Router.txt indicates success:

----------
Shell Script BEG

n241 wl0.1_wpa_psk
n501 wl1.1_wpa_psk
pwch newpassword

----------
CURRENT password for wl0.1_wpa_psk ...
size: 42019 bytes (23517 left)
wl0.1_wpa_psk=abracadabra

Changing password for wl0.1_wpa_psk to -newpassword- ...

NEW password for wl0.1_wpa_psk ...
size: 42016 bytes (23520 left)
wl0.1_wpa_psk=newpassword
----------

----------
CURRENT password for wl1.1_wpa_psk ...
size: 42016 bytes (23520 left)
wl1.1_wpa_psk=

Changing password for wl1.1_wpa_psk to -newpassword- ...

NEW password for wl1.1_wpa_psk ...
size: 42016 bytes (23520 left)
wl1.1_wpa_psk=
----------

Shell Script END
----------
exiting...

Action Start Process AC Run Script WiFi

Name: AC Run Script WiFi
Type: Start Process
File Name: C:\D\Programs\POS\router\_wifi_change_guest1.bat
Arguments: {:WiFiPW}
Use Shell Execute: False
Is Hidden: False (or True)


PuTTY Setup (also required when using PLINK):

The setup shown above is required when using SSH, to store the Router rsa2 Fingerprint in the registry. This applies to using PuTTY or PLINK on the command-line with SSH connections, and is only required to be run once. Also, this lets you alternatively call the saved SessionName on the command-line, instead of using the Hostname or IP, as such:

putty.exe -load "mysession"

instead of:

putty.exe -ssh HOSTNAMEorIP

This might help:

I’m excited to see the final solution :slight_smile:

Alternatively it might be possible to generate sh file by using a printer template.

Thanks for that @neko, though what is suggested in that thread doesn’t work in this case.

$ plink user@10.220.60.xx -t /home/user/test/testpgm arg1

This is because plink is being called from the Shell (indicating it is available to the system), while in my case, I’m calling plink from Windows CMD.

Another suggestion I found was this (plink being called from CMD):

plink -T ... $SHELL /dev/stdin arg1 arg2 arg3 < hello.sh

I think the above may work, though I currently get an error to the effect of “can't find /dev/stdin”. Probably because stdin isn’t located in /dev/, rather somewhere else on the router, but I don’t know how to find it’s location. What command can I issue on the router to find a file? I’ve never been much good at *nix command line :wink:

Let me see if I understand the methodology you’re eluding to @emre.

Do you mean to say create a Printer that prints to File (i.e. script.sh), and execute a Print Job using a Template that contains the commands I want to execute?

Interesting… that may be a little more elegant. I will give that a try!

1 Like

Ok @emre, I gave this a try, but something strange is going on that I don’t understand.

Here is a portion of the Printer Template:

    #!/bin/sh
    guestnet241=wl0.1_wpa_psk
    guestnet501=wl1.1_wpa_psk
    guestpw1={:WiFiPW}

If I set up an Automation Command called Router Script and map it to Ticket, then have an Action to Execute the Print Job, which prints to wifichange.sh, and a Rule, then the contents of the file is:

#!/bin/sh
guestnet241=wl0.1_wpa_psk
guestnet501=wl1.1_wpa_psk
guestpw1=abracadabra

Ok, so far so good. It also works if the Automation Command is on a Custom Entity Screen (i.e. my Table Screen). However, if I place the Automation Command on an Account Screen (i.e. General, which is where I like it to be), the {:WiFiPW} setting is being ignored (it’s not being evaluated), so the file contents are:

#!/bin/sh
guestnet241=wl0.1_wpa_psk
guestnet501=wl1.1_wpa_psk
guestpw1={:WiFiPW}

Can you tell me why this is the case? Can I fix it?

I couldn’t understand how {:WiFiPW} tag worked :slight_smile:

Inside template it should be configured as {SETTING:WiFiPW} if it stored as a setting.

I’ve always referenced the Program setting for WiFiPW as {:WiFiPW} in rules, actions, and Templates (it works just fine). I changed it to {SETTING:WiFiPW} (thank-you for providing the correct syntax) in the Template, and it also works when the Command is on the Ticket or Custom (Table) Entity Screen.

However, when the Command is on an Account screen, {SETTING:WiFiPW} isn’t being evaluated, so the output to the .sh file stays as {SETTING:WiFiPW}, instead of the content of the WiFiPW Program Setting, which happens to be “abracadabra”.

This is being written to the .sh file:

#!/bin/sh
guestnet241=wl0.1_wpa_psk
guestnet501=wl1.1_wpa_psk
guestpw1={SETTING:WiFiPW}

The above only occurs when executing the Command from an Account screen. When executing from the Ticket Screen, or Entity Screen, the file correctly contains:

#!/bin/sh
guestnet241=wl0.1_wpa_psk
guestnet501=wl1.1_wpa_psk
guestpw1=abracadabra

@emre, I really want this to work on an Account Screen, and I love the use of the Template rather than the abomination of a .BAT file that I originally posted. The Template is so much more elegant and simple. @emre, is there something I"m missing here, or do I need to wait for an updated version?

Hello @QMcKay. I’ve setup a demo environment to be able to reproduce your issue and I found that printer templates does not work if there is no active ticket. I’ve enabled non ticket related tags for reading settings, date and random numbers. It will work for next version. I’m waiting for an update for the management navigation bar touch issue. I’ll release new version as soon as I receive the update.

1 Like

Thanks for that @emre. Eagerly awaiting :wink: Much appreciated!

Hi @QMcKay, I tested and it works as below:

$ plink user@x.x.x.x "command arg"

@neko, that probably works with a command that is available on the host, but when you want to send a script from windows CMD, the host reports that the script cannot be found, and so is the case when you try to send the script with or without parameters.

Execute from Windows CMD:

plink.exe -v -ssh -P %rPORT% -pw %rPASS% %rUSER%@%rHOST% "wifichange.sh" > %LOGFILE% 2>&1

gives output (from host):

sh: wifichange.sh: not found

I am happy to report that as of v4.1.39, I can access a Program Setting from the Account Screen.

That said, the following works:

{:WiFiPW}

While the following does not (it isn’t being evaluated, and stays as {SETTING:WiFiPW}):

{SETTING:WiFiPW}