Community discussions

MikroTik App
 
butteryak
newbie
Topic Author
Posts: 40
Joined: Fri Sep 12, 2008 1:16 am

Can't change transfer-limit after upgrade to 6 to 4, via API

Fri Nov 21, 2014 4:05 am

Hi,
I've got a client that I've not been to in a number of years. I did an update from 4 to the latest 6.22. they have a PHP page which accesses the API so that they can change transfer-limits on users without having to log into Usermanager. After the upgrade it is no longer working. I'm guessing that its probably due to changes made with the Usermanager and not the API,but I'm not sure... I keep getting the result "invalid user please try again" Here is my code:
<?php

#PHP- connect to mikrotik router to update user's transfer limit as stated in add.html.
# uses the router_api class to connect to the mikrotik router API.

require('routeros_api.class.php');

$API = new routeros_api();

$X = $_POST['admin'];
$Y = $_POST['pass'];
$U = $_POST['user'];

# connect to mikrotik

if ($API->connect('192.168.1.1', $X, $Y)) {

   # pull transfer limit for user from usermanager
   $API->write('/tool/user-manager/user/getall', false);
   $API->write('=.proplist=transfer-limit', false);
   $API->write('?name='.$U);
 
   
   $A = $API->read(false);
   
   # extract transfer-limit from returned Array
   extract($A);
   $A=$A[1];
   $B =  substr($A,16);
   
  #check for valid user, if transfer-limit comes back blank, assume it is an invalid user
  if ($B == null) {print '<center>';
                   print "Invalid user"; 
                   print '<br><br>';
                   print '<a href="add.html">Try Again</a>';
                   print '</center>';}

   else {

   #calculate new transferlimit...
    $C = $_POST['amount'];
    $G = (($C / 5) * 524288000);
    $D = $G + $B;

   #write new transfer-limit to Usermanager
   $API->write('/tool/user-manager/user/set', false);
   $API->write('=.id='.$U, false);
   $API->write('=transfer-limit='.$D);

  $F = $API->read(false);
  
  #print results
  echo '<head>';
  echo '<style type="text/css">';
  echo 'body td, th {color:#999999; font-family: Veranda,Arial,Helvetica, sans-serif; font-size: 14px;}';
  echo 'body {background-color: #07223c;}';
  echo '</style>';
  echo '</head>';
  echo '<body>';
  echo '<br><br>';
  echo '<center>';
  echo '<table cols="2" border="1" cellpadding="10" cellspacing="0" align="center" width="400" bordercolor="#666666" bgcolor="#051833">';
  echo '<tr>';
  echo '<td width="224" bgcolor="#051833" valign="top">';
  echo '<center>';

   print "This is what user had --- "; echo round($B / 1048576, 0); print " MB";
   print "<br />";

  echo '</center>';
  echo '</td>';echo '</tr>';echo '<tr>';
  echo '<td width="224" bgcolor="#051833" valign="top">';
  echo '<center>';
   
   print "Amount to be added to user ";echo ($U);print " --- ";echo($G / 1048576); print " MB";
   print "<br />";

  echo '</center>';
  echo '</td>';echo '</tr>';echo '<tr>';
  echo '<td width="224" bgcolor="#051833" valign="top">';
  echo '<center>';

   print "This is appended amount ---   "; echo round($D / 1048576, 0); print " MB";
   print "<br />";

  echo '</center>';
  echo '</td>';echo '</tr>';echo '<tr>';
  echo '<td width="224" bgcolor="#051833" valign="top">';
  echo '<center>'; 
   
   print "operation success!!";
   print "</br>";

 echo '</center>'; 
 echo '</td>'; echo '</tr>';
 
 echo '</table>';
 echo '<br><br>';
 echo '<a href="add.html">Add more</a>';
 echo '<br>';
 echo '<a href="http://192.168.1.17">Main Menu</a>';
 echo '<br><br>';
 

 

 echo '</center>'; echo '</body>';}

   $API->disconnect();

} else { 
echo '<center>';
print "Login failed!";
echo '<br><br>';
echo  '<a href="add.html">Try Again</a>';
echo  '</center>';}

?>
Thanks so much for any help anyone could provide, or point in the right direction.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Can't change transfer-limit after upgrade to 6 to 4, via

Fri Nov 21, 2014 2:39 pm

Those are now in the "session" submenu. Each session has the limits, split into "upload" and "download", along with the times and user the limits apply to.
 
butteryak
newbie
Topic Author
Posts: 40
Joined: Fri Sep 12, 2008 1:16 am

Re: Can't change transfer-limit after upgrade to 6 to 4, via

Thu Dec 04, 2014 11:48 pm

I don't see any submenu under sessions in the usermanager. When I click on sessions, it shows me a list of user sessions that have taken place. I'm unclear if your answer is referring to the API. It's all a bit confusing with the changes in the usermanager from 4 to 6. Looks like things have changed alot, and it seems alot of things that were very simple are now difficult. It's also been challenging to find any updated information and documentation. It would seem that all the documentation I find is outdated pertaining to both the API and Usermanager.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Can't change transfer-limit after upgrade to 6 to 4, via

Fri Dec 05, 2014 12:22 am

Don't let the web interface fool you. Check what's visible from terminal.

In it, you have the "/tool user-manager session" menu.
 
butteryak
newbie
Topic Author
Posts: 40
Joined: Fri Sep 12, 2008 1:16 am

Re: Can't change transfer-limit after upgrade to 6 to 4, via

Fri Dec 05, 2014 1:16 am

Yes, but that does not really give me the information or access to what is needed. That only tells me what sessions are happening or have happened. This does not really give me access to the transfer-limit that I used to be able to apply to each specific user, within their profile, and then change that transfer-limit via the API if I so desired. Unless I'm completely missing something.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Can't change transfer-limit after upgrade to 6 to 4, via

Fri Dec 05, 2014 1:35 am

This menu has an "add" command, which you must apply to a particular user. The "session" will start at the specified time, and last for the specified duration, meaning that in that time interval, if that user logs in, they will have those limits.