Community discussions

MikroTik App
 
jalokim
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 76
Joined: Thu Dec 07, 2006 1:39 pm
Location: PL, Tychy
Contact:

[PHP] When API will work ?

Tue Feb 16, 2010 9:26 pm

Since begening I have problems with API.

In log I have:
Image
and:
Image

So API user is not logged off.

My PHP code is:
function blokada_www($typ,$ip,$lista)
{
	include_once('mt/ros_api.php');

	$API = new routeros_api();

	$API->debug = false;

	if ($API->connect('host', 'user', 'pass'))
	{
		if($typ == "usun")
		{
			$API->write('/ip/firewall/address-list/getall');

			$READ = $API->read();
		   $array = $API->parse_response($READ);

			for($x=0;$x<count($array);$x++)
			{
				if(array_search($ip, $array[$x]))
				{
					if($array[$x]["list"] == $lista)
					{
						$API->write('/ip/firewall/address-list/remove',false);
						$API->write('=.id='.$array[$x][".id"],true);
						$odp = $API->read();
						if($odp[0] == "!done") return TRUE;
					}
				}
			}
			$API->disconnect();
		}		
		elseif($typ == "dodaj")
		{
			$API->write('/ip/firewall/address-list/getall');

			$READ = $API->read();
		   $array = $API->parse_response($READ);
			
			for($x=0;$x<count($array);$x++)
			{
				//echo $x."-".$array[$x]["list"]."-".$lista." | ".$array[$x]["address"]."-".$ip."<br>";
			
				if($array[$x]["list"] == $lista && $array[$x]["address"] == $ip)
				{
					//echo "Adres ".$array[$x]["address"]." jest juş na li�cie ".$lista;
					$count++;
					return TRUE;
				}
			}
			
			if($count == 0)
			{
				$API->write('/ip/firewall/address-list/add',false);
				$API->write('=list='.$lista,false);
				$API->write('=address='.$ip);
				$odp = $API->read();
				if($odp[0] == "!done") return TRUE;
			}
			$API->disconnect();
			
		}		
	}
}
My question is:
Why sometimes this works, and somethimes not?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [PHP] When API will work ?

Wed Feb 17, 2010 12:30 am

So API user is not logged off.
what version of ROS do you use?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: [PHP] When API will work ?

Wed Feb 17, 2010 11:07 am

API log off is equal to closing connection, if you do not do that proper way, USER will stay logged in if logged through API

also /quit exists
 
jalokim
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 76
Joined: Thu Dec 07, 2006 1:39 pm
Location: PL, Tychy
Contact:

Re: [PHP] When API will work ?

Wed Feb 17, 2010 1:21 pm

what version of ROS do you use?
3.30
 
jalokim
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 76
Joined: Thu Dec 07, 2006 1:39 pm
Location: PL, Tychy
Contact:

Re: [PHP] When API will work ?

Wed Feb 17, 2010 1:22 pm

API log off is equal to closing connection, if you do not do that proper way, USER will stay logged in if logged through API

also /quit exists
On every
if
there is
$API->disconnect();
so what else shoud i do?

Who is online

Users browsing this forum: No registered users and 43 guests