"http: //$http_url/userRpm/WlanSecurityRpm.htm? wepSecOpt = 3 and wpaSecOpt = 3and
"http: //$http_url/userRpm/SysRebootRpm.htm? Reboot = Reboot"
"location.href =" / userRpm / WlanSecurityRpm.htm ";"- and to reboot:
"<TD class = h2 id =" t_restart "> Restarting ... </ TD>"
#!/bin/bash -e # Description: script is purposed for automatic changing WPA2 key on TP-LINK WR1043ND (Wi-Fi router) using curl # Common variables proxy_url=proxy.company.lan:3128 proxy_username=proxy-user proxy_password=proxy-pass http_url=ggw.company.lan http_username=http-user http_password=http-pass # Define email message title smtp_title="Guest Wi-Fi password has been changed" # Define smtp server and email addresses smtp_server=10.10.10.10 smtp_send_from=notificaions@company.com smtp_send_to=admins@company.com smtp_links="Password link: http://wifi-guest.company.lan\nAdmin link: http://$http_url" webpage_path=/opt/company/wifi-guest/index.html # Special variables set_password_successfuly='location.href="/userRpm/WlanSecurityRpm.htm";' perform_reboot_successfuly='<TD class=h2 id="t_restart">Restarting...</TD>' stat_begin='^var hostList = new Array\($' stat_end='.*\);' # Core variables CURL="curl --silent --proxy $proxy_url --proxy-user $proxy_username:$proxy_password --user $http_username:$http_password" # Generate 8-digit password (from 00000000 to 99999999) NEW_WPA_PASSWORD=$( printf "%04d%04d" $(($RANDOM%10000)) $(($RANDOM%10000)) ) # Date and time DATE_TIME="$(date +"%F %T")" # Set password $CURL "http://$http_url/userRpm/WlanSecurityRpm.htm?wepSecOpt=3&wpaSecOpt=3&wpaCipher=1&intervalWpa=0&secType=3&pskSecOpt=3&pskCipher=1&interval=0&Save=Save&pskSecret=$NEW_WPA_PASSWORD" | grep "$set_password_successfuly" > /dev/null && SET_PASS="OK" || SET_PASS="ERR" [[ $SET_PASS != "OK" ]] && echo "Set password error" && exit 1 # Reboot $CURL "http://$http_url/userRpm/SysRebootRpm.htm?Reboot=Reboot" | grep "$perform_reboot_successfuly" > /dev/null && REBOOT="OK" || REBOOT="ERR" [[ $REBOOT != "OK" ]] && echo "Reboot error" && exit 1 # Update web page echo " <html> <head> <meta http-equiv=\"Pragma\" content=\"no-cache\"> <meta http-equiv=\"Cache-Control\" content=\"no-cache\"> </head> <body> <center> <p>New Wi-Fi password:<br>$NEW_WPA_PASSWORD</p> <p>Generated: $DATE_TIME</p> </center> </body> </html> " > $webpage_path # Send password and statistics to admins wifi_stat=$($CURL "http://$http_url/userRpm/WlanStationRpm.htm" | awk "/$stat_begin/,/$stat_end/") smtp_message="New Wi-Fi password: $NEW_WPA_PASSWORD\n\nWi-Fi statistics:\n$wifi_stat\n\n$smtp_links" echo -e "$smtp_message" | \ env smtp=$smtp_server from=$smtp_send_from \ /usr/bin/mail -v \ -s "$smtp_title" \ $smtp_send_to
NUMPASS_MIN=10000000 NUMPASS_MAX=99999999 NEW_WPA_PASSWORD="$(( ($RANDOM*($NUMPASS_MAX-$NUMPASS_MIN)/32767)+$NUMPASS_MIN ))"
NEW_WPA_PASSWORD=$( printf "%04d%04d" $(($RANDOM%10000)) $(($RANDOM%10000)) )
Source: https://habr.com/ru/post/149495/
All Articles