Router Wi-Fi Password Change & Display

Ok, I need to clarify this a bit, because it’s confusing now. @emre, you may want to take a look into this…

As of v4.1.39, I can access a Program Setting from the Account Screen. Yes, great! However

When used in a Rule or as an Argument to Start Process Action, the following works:

{:WiFiPW}

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

{SETTING:WiFiPW}

And then it’s backwards in the following case…
When used in a Printer Template, the following works:

{SETTING:WiFiPW}

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

{:WiFiPW}

Here is the currently working setup.

It does not use a Printer Template, and does not use a .sh file. I found the .sh file to be very unreliable when through PLINK.

The Automation Command can be placed virtually anywhere: on the Ticket, on an Entity Screen, or on an Account Screen (as of v4.1.39).

This set up only uses the following .bat file (and some Actions and Rules of course).


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

BAT file: _wifi_change_guest1.bat
Updated 2014-06-30 to contain some error checking on the supplied new password.

@echo off
cls

::
:: Set Router Information
::
set rHOST=192.168.0.1
set rPORT=23
set rUSER=admin
set rPASS=<router administrative password>

::
:: Set WiFi Network Information as found in NVRAM
::
set rGUEST24net1=wl0.1_wpa_psk
set rGUEST24net2=wl0.2_wpa_psk
set rGUEST24net3=wl0.3_wpa_psk
set rGUEST50net1=wl1.1_wpa_psk
set rGUEST50net2=wl1.2_wpa_psk
set rGUEST50net3=wl1.3_wpa_psk

::
:: Set a LOGFILE and ERRMSG
::
set LOGFILE=_LOGFILE_Router.txt
set ERRMSG=

::
:: Go to PLINK location
::
C:
CD\
CD C:\D\Programs\POS\router


::
:: Set variables for new passwords (get the %1 argument and use it for all networks)
::
set newpass=%1

::
:: Start Logging
::
@echo. >> %LOGFILE% 2>&1
@echo ******************************************************* >> %LOGFILE% 2>&1
@echo -- BAT BEG ----------------- %date%_%time:~0,2%.%time:~3,2%.%time:~6,2% >> %LOGFILE% 2>&1


::
:: Check password variable to ensure it is Ok
::
IF [%newpass%] NEQ [] @echo Password is not blank
IF [%newpass%] == [] set ERRMSG=ERROR:Password is BLANK
IF [%newpass%] == [] goto ERRORPROCESS

IF "%newpass:~7,1%"=="" (
  set ERRMSG=ERROR:Password less than 8 characters
  goto ERRORPROCESS
) ELSE (
  @echo Password is at least 8 characters
)

set PAT=SETTING
echo.%newpass% | findstr /C:"%PAT%" 1>nul
if errorlevel 1 (
  @echo Password does not Contain Printer Template Tag '%PAT%'
) ELSE (
  set ERRMSG=ERROR:Password contains Printer Template Tag' %PAT%'
)
set errorlevel=

set PAT="^{"
echo.%newpass% | findstr /C:"%PAT%" 1>nul
if errorlevel 1 (
  @echo Password does not Contain Printer Template 'Start Tag'
) ELSE (
  set ERRMSG=%ERRMSG% ERROR:Password contains Printer Template 'Open Tag'
)
set errorlevel=

set PAT="^}"
echo.%newpass% | findstr /C:"%PAT%" 1>nul
if errorlevel 1 (
  @echo Password does not Contain Printer Template 'End Tag'
) ELSE (
  set ERRMSG=%ERRMSG% ERROR:Password contains Printer Template 'Close Tag'
)
set errorlevel=

set PAT="^:"
echo.%newpass% | findstr /C:"%PAT%" 1>nul
if errorlevel 1 (
  @echo Password does not Contain Printer Template 'Separator'
) ELSE (
  set ERRMSG=%ERRMSG% ERROR:Password contains Printer Template 'Separator'
)
set errorlevel=


::
:: If there is a problem with the given password, %ERRMSG% will contain a value, and we abandon the script
::
IF "%ERRMSG%" NEQ "" GOTO ERRORPROCESS


::
:: If password variable is Ok, we continue...
::
::
:: Set variables for new passwords (get the %1 argument and use it for all networks)
::
set pw24_1=%newpass%
set pw24_2=%newpass%
set pw24_3=%newpass%
set pw50_1=%newpass%
set pw50_2=%newpass%
set pw50_3=%newpass%


::
:: Set up Commands
::
set cShowNets="nvram show | grep wl..._wpa_psk | sort | sed 's/wl/\r\nwl/g'"
set cCommitNVRAM="nvram commit"
set cRESTARTwifi="service restart_wireless"
set cREBOOT="reboot"
set cSetNet24_1="nvram set %rGUEST24net1%=%pw24_1%"
set cSetNet24_2="nvram set %rGUEST24net2%=%pw24_2%"
set cSetNet24_3="nvram set %rGUEST24net3%=%pw24_3%"
set cSetNet50_1="nvram set %rGUEST50net1%=%pw50_1%"
set cSetNet50_2="nvram set %rGUEST50net2%=%pw50_2%"
set cSetNet50_3="nvram set %rGUEST50net3%=%pw50_3%"


::
:: Show us what we are about to do
::
@echo rHOST: %rHOST%
@echo rPORT: %rPORT%
@echo pw24_1: %pw24_1%
@echo pw50_1: %pw50_1%




::
:: Run COMMANDS through PLINK
::
@echo on

:: If we get this far, it's time to run the commands to the Router
@echo -- ROUTER CHANGE BEG ------- %date%_%time:~0,2%.%time:~3,2%.%time:~6,2% >> %LOGFILE% 2>&1
@echo rHOST: %rHOST%>> %LOGFILE% 2>&1
@echo rPORT: %rPORT%>> %LOGFILE% 2>&1
@echo net24_1: %rGUEST24net1%>> %LOGFILE% 2>&1
@echo net50_1: %rGUEST50net1%>> %LOGFILE% 2>&1
@echo pwd24_1: %pw24_1%>> %LOGFILE% 2>&1
@echo pwd50_1: %pw50_1%>> %LOGFILE% 2>&1
@echo.>> %LOGFILE% 2>&1

:: Show CURRENT Passwords
@echo ----- Guest Networks CURRENT ...>> %LOGFILE% 2>&1
plink.exe -ssh %rHOST% -P %rPORT% -l %rUSER% -pw %rPASS% -batch %cShowNets% >> %LOGFILE% 2>&1
@echo.>> %LOGFILE% 2>&1

:: Set the Passwords for the desired Networks and Commit NVRAM
@echo ----- SETTING NEW PASSWORDS ...>> %LOGFILE% 2>&1
:: this line currently sets GuestNetwork #1 for both 2.4GHz and 5.0GHz bands and commits them to NVRAM
:: add more Networks if so desired (i.e. cSetNet24_2), and ensure the cCommitNVRAM command is retained
plink.exe -ssh %rHOST% -P %rPORT% -l %rUSER% -pw %rPASS% -batch %cSetNet24_1% %cSetNet50_1% %cCommitNVRAM% >> %LOGFILE% 2>&1
@echo.>> %LOGFILE% 2>&1

:: Show UPDATED Passwords
@echo ----- Guest Networks UPDATED ...>> %LOGFILE% 2>&1
plink.exe -ssh %rHOST% -P %rPORT% -l %rUSER% -pw %rPASS% -batch %cShowNets% >> %LOGFILE% 2>&1
@echo.>> %LOGFILE% 2>&1
@echo.>> %LOGFILE% 2>&1

:: Restart the WIFI Service for new passwords to take effect
@echo ----- RESTARTING WIFI SERVICE ...>> %LOGFILE% 2>&1
plink.exe -ssh %rHOST% -P %rPORT% -l %rUSER% -pw %rPASS% -batch %cRESTARTwifi% >> %LOGFILE% 2>&1
@echo.>> %LOGFILE% 2>&1

:: End Router Changes
@echo -- ROUTER CHANGE END ------- %date%_%time:~0,2%.%time:~3,2%.%time:~6,2% >> %LOGFILE% 2>&1

@echo off



::
:: We are almost done. Test for Errors.
::
IF [%ERRMSG%] == [] GOTO finished


:ERRORPROCESS
@echo %ERRMSG% 
@echo %ERRMSG% >> %LOGFILE% 2>&1 
@echo -- BAT END ----------------- %date%_%time:~0,2%.%time:~3,2%.%time:~6,2% >> %LOGFILE% 2>&1
:: Open the LOGFILE
@notepad %LOGFILE%
goto endoffile


:finished
@echo -- BAT END ----------------- %date%_%time:~0,2%.%time:~3,2%.%time:~6,2% >> %LOGFILE% 2>&1


:endoffile
::
:: We are done.  Uncomment the following lines if you wish.
::

::@notepad %LOGFILE%

::timeout 2
::pause

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: Update Program Setting

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

Action: Start Process

Name: AC WiFiPW Update Start BAT Script
Type: Start Process
File Name: C:\D\Programs\POS\Router\_wifi_change_guest1.bat
Arguments: [:args]
Use Shell Execute: False
Is Hidden: True

Rule: Update Program Setting and Run BAT file

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

Actions:

Name: AC WiFiPW Update Program Setting
Constraint:
WiFiPW: [?Enter New WiFi Password (8 characters minimum):([a-zA-Z0-9]{8,26})]

Name: AC WiFiPW Update Start BAT Script
Constraint:
args: {:WiFiPW}

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


The Rule captures the click-event of the Automation Command.

First, it fires an Action to Update Program Setting WiFiPW, which asks for input with the prompt “Enter New WiFi Password (8 characters minimum)”. The input box has a mask ([a-zA-Z0-9]{8,26}) which ensures the entered value contains only Alpha-Numeric characters [a-zA-Z0-9], and ensures the value is more than 7 characters and less than 27 characters {8,26}.

Second, it fires the Action Start Process which runs the .bat file.

The .bat file should produce the following log:

Log File: _LOGFILE_Router.txt

******************************************************* 
-- BAT BEG ----------------- 2014-06-30_13.18.56 
-- ROUTER CHANGE BEG ------- 2014-06-30_13.18.57 
rHOST: 192.168.0.1
rPORT: 23
net24_1: wl0.1_wpa_psk
net50_1: wl1.1_wpa_psk
pwd24_1: str0ngpa55word
pwd50_1: str0ngpa55word

----- Guest Networks CURRENT ...
size: 41946 bytes (23590 left)
wl0.1_wpa_psk=goodfriends
wl0.2_wpa_psk=
wl0.3_wpa_psk=
wl1.1_wpa_psk=goodfriends
wl1.2_wpa_psk=
wl1.3_wpa_psk=

----- SETTING NEW PASSWORDS ...

----- Guest Networks UPDATED ...
size: 41952 bytes (23584 left)
wl0.1_wpa_psk=str0ngpa55word
wl0.2_wpa_psk=
wl0.3_wpa_psk=
wl1.1_wpa_psk=str0ngpa55word
wl1.2_wpa_psk=
wl1.3_wpa_psk=

----- RESTARTING WIFI SERVICE ...
Done.
-- ROUTER CHANGE END ------- 2014-06-30_13.19.09 
-- BAT END ----------------- 2014-06-30_13.19.09 

Awesome!!! It automates a common issue really well.

Now I’m wondering what can be an alternative to placing such functions to accounting screen.

We can also improve it by configuring a printer template to print wifi password. When asked waiter can simply print password from bill printer and give it to customer.

I think this works exactly how it implemented.

Since Rules can read Printer template tags these tags are interchangeable in some cases but correct usage is {:WiFiPW} to read setting from rules and {SETTING:WiFiPW} to print.

1 Like

Ok, good. I thought this may be by design. It’s just something to keep in mind when using Program Settings.

You may be able to guess the reasons I want the button(s) on an Account Screen.

  • The POS Ticket Screen already has a lot of buttons, can get crowded, and Changing WiFi Password isn’t related to a Ticket in the first place.
  • When we End WorkPeriod, the POS Ticket Screen and Entity Screens are no longer available/enabled, but the Account Screen is still enabled. It also makes sense to have buttons like Calculator and Open Drawer on an Account Screen, so we can perform Cashout Duties or Payouts to Vendor/Expense Accounts, or even Customer Account functions.

Perhaps if we had another Section in Navigation Screen called Tools or Toolbox which would be available at all times (via Permission), even when no WorkPeriod is is open, we could place Widgets (Automation Commands) on this screen, similar to a Custom Entity Screen.

2 Likes