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:
Code: Select all
<?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>';}
?>