<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';
try {
$util = new RouterOS\Util(
$client = new RouterOS\Client('192.168.88.1', 'admin', '')
);
$passAlphabet = 'abcdefghikmnpqrstuvxyz23456789';
$passLength = 8;
$passAlphabetLimit = strlen($passAlphabet)-1;
$pass = '';
for ($i = 0; $i < $passLength; ++$i) {
$pass .= $passAlphabet[mt_rand(0, $passAlphabetLimit)];
}
$util
->setMenu('/interface wireless security-profiles')
->set(
'default',
array(
'wpa-pre-shared-key' => $pass,
'wpa2-pre-shared-key' => $pass
)
);
echo 'New Wi-Fi password: ', $pass;
exit(0);
} catch (Exception $e) {
echo $e;
exit(1);
}
/tool fetch url="http://www.random.org/strings/\?num=1&len=8&digits=on&loweralpha=on&unique=off&format=plain&rnd=new" keep-result=yes dst-path="pass.txt"
/tool fetch url="https://www.random.org/passwords/\?num=1&len=8&format=plain&rnd=new" keep-result=yes dst-path="pass.txt"
I built such a script for a customer that needed the WiFi password to change weekly. In my situation the router generates a password based on some variables and sets the new password. it then emails and also hooks into my SMS gateway via API and sends the employees the password for that week. All within the router itself. If you still need something like that hit me up.Is there any way or a script that I can look at that will create a random password for the wifi every week? We have a timeshare building where there is a routerboard in each unit, but they all have their own SSID. We would like them to change the password every week on their own. We thought about using user manager somehow with radius, but not sure how to handle assigning a user to an individual ssid or access point.
In my situation a person that owned some Coffee shops wanted to make sure that people didn't camp out all day and not buy anything as his locations were not very big. So he gives out the WiFi password for the week printed on the receipt. He preferred a weekly change vs daily and he also wanted the the password to start with coffee and have a variation of 3-4 numbers. Example: coffee1839@jspool That will be great, can you post your solution to have a look at it?
Glad you were able to modify it to fit your needs.Thx jspool for the script, I have change it to Work on CAPsMAN to.
In my situation a person that owned some Coffee shops wanted to make sure that people didn't camp out all day and not buy anything as his locations were not very big. So he gives out the WiFi password for the week printed on the receipt. He preferred a weekly change vs daily and he also wanted the the password to start with coffee and have a variation of 3-4 numbers. Example: coffee1839@jspool That will be great, can you post your solution to have a look at it?
#######################################
###VoIP Squared WiFi Password Generator Script###
#######################################
:local toEmail youremail@domain.com
:local fromEmail router@yourdomain.com
:local prepend coffee
:local wifiprofile profile33
:local secr [/system resource get write-sect-since-reboot];
/log info message="Sector Writes Since Reboot=$secr"
:local runc [/system script get WiFiPasswordGenerator run-count];
/log info message="WiFiPasswordGenerator Run Count=$runc"
:local date1 [:pick [/system clock get date] 4 6];
/log info message="Month=$date1"
:local time1 [:pick [/system clock get time] 6 8];
/log info message="Seconds=$time1"
:local time2 [:pick [/system clock get time] 3 5];
/log info message="Minute=$time2"
:if ($date1 < 02) do={
:set date1 ("03");
};
:if ($time1 < 10) do={
:set time1 ("12");
};
:if ($time2 < 10) do={
:set time2 ("15");
};
:if ($runc < 10) do={
:set runc ("19");
}
:if ($secr < 10) do={
:set secr ("25");
}
###Remove if you want longer password###
:if ($secr > 99) do={
:set secr ("9");
};
###Remove if you want longer password###
####Use commented line below instead of the one below if you desire a longer password####
#:local newPassword ($date1 * $time1 * $time2 * $secr);
:local newPassword ($date1 * $time1 * $secr);
/log info message="Month x Seconds x Sector Writes Since Reboot=$newPassword"
:set newPassword ($prepend . $newPassword);
:interface wireless security-profiles set $wifiprofile wpa-pre-shared-key="$newPassword";
:interface wireless security-profiles set $wifiprofile wpa2-pre-shared-key="$newPassword";
:log info message="New WiFi Password Set To=$newPassword"
:log info message="Preparing To Email New WiFi Password"
delay 2
:tool e-mail send user=$fromEmail to=$toEmail subject="$[/system identity get name] WiFi Password" body="This Week's Wireless Password Is: $newPassword";
delay 2
:log info message="New WiFi Password Has Been Emailed"
:log info message="See You Next Week"
#######################################
### WiFi Password Generator Script###
#######################################
# mail recipients
:local recipients { "user1@gmail.com "; "user2@gmail.com"; "user3@gmail.com"; "user5@gmail.com"; "user1@yahoo.com" }
:local fromEmail ************@gmail.com
:local prepend home
# :local wifiprofile WifiPass
:local wifiprofile 0
:local secr [/system resource get write-sect-since-reboot];
/log info message="Sector Writes Since Reboot=$secr"
:local runc [/system script get WiFiPasswordGenerator run-count];
/log info message="WiFiPasswordGenerator Run Count=$runc"
:local date1 [:pick [/system clock get date] 4 6];
/log info message="Month=$date1"
:local time1 [:pick [/system clock get time] 6 8];
/log info message="Seconds=$time1"
:local time2 [:pick [/system clock get time] 3 5];
/log info message="Minute=$time2"
:if ($date1 < 02) do={
:set date1 ("03");
};
:if ($time1 < 10) do={
:set time1 ("12");
};
:if ($time2 < 10) do={
:set time2 ("15");
};
:if ($runc < 10) do={
:set runc ("19");
}
:if ($secr < 10) do={
:set secr ("25");
}
###Remove if you want longer password###
:if ($secr > 99) do={
:set secr ("9");
};
###Remove if you want longer password###
####Use commented line below instead of the one below if you desire a longer password####
#:local newPassword ($date1 * $time1 * $time2 * $secr); or :local newPassword ($date1 * $time1 * $secr);
:local newPassword ($date1 * $time1 * $secr);
/log info message="Month x Seconds x Sector Writes Since Reboot=$newPassword"
:set newPassword ($prepend . $newPassword);
:log info message="Preparing To Email New WiFi Password to users"
:foreach r in=$recipients do={
:put ("Sending email to " . [:tostr $r])
/tool e-mail send from=***********@gmail.com to=[:tostr $r] subject="WiFi AP Password" body="This Week's Wireless Password Is: $newPassword " server=173.194.67.108 port=587 start-tls=yes user=*********@gmail.com password=*******
}
# The delay 300 is for the users that is on the WiFi to get the mail before it gets change.
delay 300
#
/caps-man security set $wifiprofile passphrase="$newPassword";
#
:log info message="New WiFi Password Set To=$newPassword"
:log info message="New WiFi Password Has Been Emailed"
:log info message="See You Next Week"
:set newPassword ($prepend . $newPassword);
#
:log info message="New WiFi Password Set To :$newPassword"
delay 2
/caps-man security print file=WifiPassword
:local wifiprofile "You wireless security-profiles name"
# "len=" in the url it is the number of characters for in the generated password
/tool fetch url="https://www.random.org/passwords/\?num=1&len=10&format=plain&rnd=new" keep-result=yes dst-path="pass.txt"
delay 3
# The last digit before the closing square bracket must be "len=" from url
:local newPassword [put [pick ([/file get [/file find name=pass.txt] contents]) 0 10]];
:interface wireless security-profiles set $wifiprofile wpa-pre-shared-key="$newPassword";
:interface wireless security-profiles set $wifiprofile wpa2-pre-shared-key="$newPassword";
/file remove [find name="pass.txt"];
/log info message="New Wi-Fi Pass = $newPassword"