Community discussions

 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Change of Password for hotspot users

Wed May 02, 2018 5:15 pm

I am new to mikrotik, i need step by step to create a page where hotspot users will be able to change their password using USER SELF FORM MANAGEMENT. It is very urgent. I got this code online and created a script named changepass.php by clicking on plus button in winbox system and then script.


Please anyone that help. I newly installed mikrotik cloud




<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2/Autoload.php';

$errors = array();

try {
//Adjust RouterOS IP, username and password accordingly.
$client = new RouterOS\Client('192.168.88.1', 'admin', 'password');

$printRequest = new RouterOS\Request(
'/ip hotspot active print .proplist=user',
RouterOS\Query::where('address', $_SERVER['REMOTE_ADDR'])
);
$hotspotUsername = $client->sendSync($printRequest)->getProperty('user');
} catch(Exception $e) {
$errors[] = $e->getMessage();
}

if (isset($_POST['password']) && isset($_POST['password2'])) {
if ($_POST['password'] !== $_POST['password2']) {
$errors[] = 'Passwords do not match.';
} elseif (empty($errors)) {
//Here's the fun part - actually changing the password
$setRequest = new RouterOS\Request('/ip hotspot user set');
$client($setRequest
->setArgument('numbers', $hotspotUsername)
->setArgument('password', $_POST['password'])
);
}
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Change your hotspot password</title>
<style type="text/css">
#errors {background-color: darkred; color: white;}
#success {background-color: darkgreen; color: white;}
</style>
</head>
<body>
<div>
<?php if (!isset($hotspotUsername)) { ?>
<h1>We're sorry, but we can't change your password right now.
Please try again later</h1>
<?php } else { ?>
<h1>
<br> HOTSPOT ... password change FORM <br><br>
You are currently logged in as "<?php
echo $hotspotUsername;
?>"</h1>

<?php if(!empty($errors)) { ?>
<div id="errors"><ul>
<?php foreach ($errors as $error) { ?>
<li><?php echo $error; ?></li>
<?php } ?>
</ul></div>
<?php } elseif (isset($_POST['password'])) { ?>
<div id="success">Your password has been changed.</div>
<?php } ?>

<form action="" method="post">
<ul>
<li>
<label for="password">New password:</label>
<input type="password" id="password" name="password" value="" />
</li>
<li>
<label for="password2">Confirm new password:</label>
<input type="password" id="password2" name="password2" value="" />
</li>
<li>
<input type="submit" id="act" name="act" value="Change password" />
</li>
</ul>
</form>
<?php } ?>
</div>
</body>
</html>
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Thu May 03, 2018 9:02 am

I got this code online and created a script named changepass.php by clicking on plus button in winbox system and then script.
That's not how PHP or even the API in general works. RouterOS can't run PHP. You need to create the file on a separate device (or a KVM/MetaRouter), and have a web server and PHP installed on that device. When users access that device, and more specifically, that web page, they would be able to ask the web server to modify their hotspot password.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Fri May 04, 2018 2:58 pm

How can i use edit in /ip hotspot user edit command?

Any one with help?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Fri May 04, 2018 11:13 pm

The API protocol doesn't support "edit" commands. But to alter a property, you can use "set" as in the example code above.

That API client in particular supports an edit() method that is really an alias for the above type of "set", e.g. the part
$setRequest = new RouterOS\Request('/ip hotspot user set');
$client($setRequest
->setArgument('numbers', $hotspotUsername)
->setArgument('password', $_POST['password'])
);
can be replaced with
$util = new RouterOS\Util($client);
$util->setMenu('/ip hotspot user')->edit($hotspotUsername, 'password', $_POST['password']);
(but under the hood, it would be turned into the first code)
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Mon May 07, 2018 1:16 pm

(but under the hood, it would be turned into the first code)

Thanks for your response, however, what do you mean by (but under the hood, it would be turned into the first code)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Mon May 07, 2018 2:33 pm

Is there a way I can run a script in mikrotik core router box to change hotspot password?

Please i need urgent help.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Mon May 07, 2018 3:13 pm

(but under the hood, it would be turned into the first code)

Thanks for your response, however, what do you mean by (but under the hood, it would be turned into the first code)
I mean that if you analyze the source code for the RouterOS\Util::edit() method, you'll see that it ultimately does the same thing as the first piece of code - it creates a RouterOS\Request object for the "set" command at the menu, fills up the "numbers" and other arguments, and sends the request via the RouterOS\Client object.

In other words, whether you do the first or second piece of code, the same things will end up going to the router, and the same things will be returned by the router.
Is there a way I can run a script in mikrotik core router box to change hotspot password?

Please i need urgent help.
If your router has enough RAM, create a MetaRouter guest, or if your router is an x86 PC - create a KVM guest. Install any OS onto it (OpenWrt will do), install Apache and PHP, configure Apache so that PHP can run on it, and place the files within the MetaRouter/KVM. Connect to the "real" machine through the internal IP configured between RouterOS and the guest.

That's the general process, but I've never fully completed it myself to give you a detailed step-by-step guide.

If you don't have enough RAM to spare for a MetaRouter/KVM, you're out of luck - you need to get a separate device and connect it to the router in some way, be it VPN or normally.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Tue May 08, 2018 11:14 am

Thanks for your response. I will give it a trial and actually get back to you on my result.

Details of my mikrotik router
Product code CCR1009-7G-1C-1S+PC
Architecture TILE
CPU TLR4-00980CH-10CE-A3b
CPU core count 9
CPU nominal frequency 1 GHz
Dimensions 272x190x47mm
License level 6
Operating System RouterOS
Size of RAM 2 GB
Storage size 128 MB
Storage type NAND
Tested ambient temperature -20C .. +60C



Will this RAM size (2 GB) be enough?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Tue May 08, 2018 9:38 pm

The router model would've been sufficient (unless it was an x86 PC) :D

How much RAM you need depends on which OS you're going to install, and i don't know of a TILE compatible one you can use. In general, if you can spare at least 256MiB for the guest, that would most probably work.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Wed May 09, 2018 1:08 pm

Thanks so much for your response. If any information is out there regarding metarouter on tile architecture, kindly inform me.
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Thu Jun 14, 2018 11:12 pm

please I need urgent help. I have installed Ubuntu, Apache, PHP, MySQL, phpmyadmin tested and running. static IP enabled.

I have mikrotik routerboard on tile architecture

I want to achieve user self change of hotspot password and also to send mikrotik syslog to external webserver

1. can I run the above php script to enable change of hotspot password by self.

2. do I need to load users credentials on webserver before it can work

3. or do I use external login php script to do authentication, where will be users credentials hosted.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Fri Jun 15, 2018 9:17 am

The hotspot user credentials remain hosted on the router.

The only thing you need to give to the script are credentials for a RouterOS user. From then on, the idea is similar to logging in from a terminal, and doing the commands on the router... Except that you're letting PHP do them automatically when users submit the form, instead of you manually doing them when users phone you or whatever.

The whole flow is that users go to that web page, they submit the new password they want, then PHP connects to the given router with the given RouterOS credentials, and performs a "set" command for the password of the currently logged in hotspot user.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Sat Jun 16, 2018 12:23 am

Thanks alot, I have done that. I tested phpinfo on the url to know if the php is working properly. it displayed php information installed same thing with Apache. however when I run above script on browser url bar, the page displayed is blank and white.

what could be the problem or error?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Sun Jun 17, 2018 12:08 am

There are several possible reasons. To narrow it down, you'll need to see some error messages from PHP.

Open up your php.ini, and find the lines "display_errors", "error_reporting", "error_log", and set them to
display_errors = Off
log_erros = On
error_reporting = E_ALL | E_STRICT
error_log = "php_errors.log"
You may open phpinfo() again to confirm the settings are in effect. Then start the file again, and check for a php_errors.log in the same folder. Open it up, and see what it says.


The most frequent cause people encounter is that they need to allow PHP and/or Apache to make outgoing connections. If PHP is running as an Apache module, whitelist Apache, or if you're running PHP as FCGI, whitelist "php-cgi".
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Mon Jun 18, 2018 3:22 pm

Thanks a lot. I have two php.ini files namely which i edited the two
/var/www$ locate php.ini
/etc/php/7.0/apache2/php.ini
/etc/php/7.2/apache2/php.ini



The top information displayed by phpinfo is shown below that am running php as apache module and how do I allow outgoing connection by whitelist apache?


System Linux nuc-ubuntu 4.4.0-128-generic #154-Ubuntu SMP Fri May 25 14:14:58 UTC 2018 i686
Build Date May 2 2018 12:43:14
Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php/7.0/apache2
Loaded Configuration File /etc/php/7.0/apache2/php.ini
Scan this dir for additional .ini files /etc/php/7.0/apache2/conf.d

Below is the output of sudo tail -f /var/log/apache2/error.log


[Mon Jun 18 14:32:57.619324 2018] [:error] [pid 17550] [client 192.168.8.118:52272] PHP Warning: require_once(PEAR2/Autoload.php): failed to open stream: No such file or directory in /var/www/html/changepass.php on line 5
[Mon Jun 18 14:32:57.619413 2018] [:error] [pid 17550] [client 192.168.8.118:52272] PHP Fatal error: require_once(): Failed opening required 'PEAR2/Autoload.php' (include_path='.:/usr/share/php') in /var/www/html/changepass.php on line 5
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Tue Jun 19, 2018 5:46 pm

Hi every one,

I need urgent help. How do I install Pyrus and Pear2 and PEAR2/Autoload.php.
Please help with step by step guidelines. I have installed and tested ok the following: Ubuntu16.04, Apache2, php7.0 and php7.2. Pear.

Following many guides online did not succeed, always having issues or errors with installing Pyrus and Pear2 and PEAR2/Autoload.php.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Tue Jun 19, 2018 8:32 pm

It will be quickest if you download the .phar file, and include it instead of trying to install PEAR or Pyrus.

Or alternatively, install composer, call "composer require pear2/net_routeros:@beta", and include "vendor/autoload.php".

The latest version of the API client is not available from PEAR and Pyrus, because the repo on GitHub hasn't been synchronized with the live pear2.php.net site (and unfortunately, it's not in my power to trigger such a sync).
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Wed Jun 20, 2018 2:33 pm

Hi boen_robot, this is error log after installing composer, what do I do next.

PHP Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/html/changepass.php on line 5

Secondly, when I issue this command
sudo composer require pear2/net_routeros:*@beta

I get this below:

./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- pear2/net_routeros 1.0.0b6 requires pear2/net_transmitter >=1.0.0b1 -> satisfiable by pear2/net_transmitter[1.0.0b1, 1.0.0b2, dev-master] but these conflict with your requirements or minimum-stability.
- pear2/net_routeros 1.0.0b5 requires pear2/net_transmitter >=1.0.0a5 -> satisfiable by pear2/net_transmitter[1.0.0a5, 1.0.0b1, 1.0.0b2, dev-master] but these conflict with your requirements or minimum-stability.
- pear2/net_routeros 1.0.0b4 requires pear2/net_transmitter >=1.0.0a4 -> satisfiable by pear2/net_transmitter[1.0.0a4, 1.0.0a5, 1.0.0b1, 1.0.0b2, dev-master] but these conflict with your requirements or minimum-stability.
- Installation request for pear2/net_routeros *@beta -> satisfiable by pear2/net_routeros[1.0.0b4, 1.0.0b5, 1.0.0b6].

Installation failed, deleting ./composer.json.




I am at a loss, not really making headway. This needs to be sorted out as soon as possible. Please I need urgent help
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Wed Jun 20, 2018 5:45 pm

Run
composer config minimum-stability beta
and run
composer require pear2/net_routeros:@beta
again afterwards.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Thu Jun 21, 2018 5:42 pm

[Thu Jun 21 15:03:45.435480 2018] [:error] [pid 17527] [client 192.168.0.2:33912] PHP Fatal error: Uncaught Error: Class 'PEAR2\\Net\\RouterOS\\Client' not found in /var/www/html/changepass.php:12\nStack trace:\n#0 {main}\n thrown in /var/www/html/changepass.php on line 12
[Thu Jun 21 15:03:48.983596 2018] [:error] [pid 17528] [client 192.168.0.2:33914] PHP Fatal error: Uncaught Error: Class 'PEAR2\\Net\\RouterOS\\Client' not found in /var/www/html/changepass.php:12\nStack trace:\n#0 {main}\n thrown in /var/www/html/changepass.php on line 12
[Thu Jun 21 15:04:03.567555 2018] [:error] [pid 17524] [client 192.168.0.2:33916] script '/var/www/html/slugify/changepass.php' not found or unable to stat
[Thu Jun 21 15:04:15.048245 2018] [:error] [pid 17525] [client 192.168.0.2:33918] PHP Fatal error: Uncaught Error: Class 'PEAR2\\Net\\RouterOS\\Client' not found in /var/www/html/changepass.php:12\nStack trace:\n#0 {main}\n thrown in /var/www/html/changepass.php on line 12


Below is the line 12 referred to in the /var/www/html/changepass.php

$client = new RouterOS\Client('192.168.8.118', 'admin', 'password');
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Thu Jun 21, 2018 7:05 pm

Strange... Did the two composer commands succeed with no errors?

Maybe try calling "composer update" to double check everything is installed, and regenerate the autoloader.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Fri Jun 22, 2018 1:26 pm

Hi,

After calling composer update I got the below

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files


Secondly I issue sudo composer diagnose and I got the below

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.6.5
PHP version: 7.2.6-1+ubuntu16.04.1+deb.sury.org+1
PHP binary path: /usr/bin/php7.2


Thirdly, I issue sudo composer self-update and I got the below

You are already using composer version 1.6.5 (stable channel).
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Fri Jun 22, 2018 5:34 pm

Maybe retry the whole installation from the beginning.

Remove the whole vendor dir, as well as composer.json and composer.lock.

Then run
composer init
enter whatever details you want, but make sure "minimum-stability" says "beta". When asked to define dependencies, search for "pear2/net_routeros", and then enter "@beta" as the version you want. Press Enter with an empty line to stop adding dependencies.

Once you're out of the init command, and back to the prompt, run
composer install
to actually install the package and make the autoloader.

And maybe also double check that you're indeed including "vendor/autoload.php"... Use require_once to terminate with a different error message if the path to it is the problem, i.e.
require_once 'vendor/autoload.php';
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Wed Jul 04, 2018 7:44 pm

Hi boen_robot,

Thanks so much. I followed your advice above and the above script worked including others scripts. I am indeed grateful. All errors resolved accordingly thanks so much.
Last edited by faogundele on Thu Jul 05, 2018 1:16 pm, edited 3 times in total.
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Fri Jul 06, 2018 4:13 pm

Hi boen_robot,

I encountered a problem while testing the script above. When I connect my laptop to mikrotik box directly I could change my password on web browser but when I connect to access point ( access point--->switch--->mikrotik) the script page either not reacheable (i.e taking too long to respond) or won't load on web browser.

What could be responsible for this?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Fri Jul 06, 2018 10:29 pm

It's generally not a good idea to have a web server running over Wi-Fi, precisely because of issues like this.

The AP probably has "client isolation" enabled, meaning that Wi-Fi clients can't access either other. This is good for security, but bad if your goal IS for all Wi-Fi clients to see a particular Wi-Fi client.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
faogundele
just joined
Topic Author
Posts: 18
Joined: Wed May 02, 2018 5:01 pm

Re: Change of Password for hotspot users

Sun Jul 08, 2018 10:05 pm

Hi,

The webserver is directly connected with cat6 cable to mikrotik Ethernet port while APs are connected via switch to the same mikrotik but another ethernet port. What do I do now?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2382
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Change of Password for hotspot users

Mon Jul 09, 2018 5:31 pm

With that setup, it should work, as long as
1) Both of the ethernet ports on the MikroTik are on the same bridge.
2) You have excluded your web server from hotspot via a "bypassed" IP binding that also sets it to a fixed IP.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)

Who is online

Users browsing this forum: No registered users and 4 guests