Community discussions

MikroTik App
 
OliverST
just joined
Topic Author
Posts: 13
Joined: Sun Aug 16, 2015 9:14 pm

Need help by php api

Sat Oct 17, 2020 5:42 pm

Hi, i try to make a small app to list all ssid and make it possible to swicht on or off.
Is here someone how know to help just with the list and edit state ( swicht on off ) script?

On the original api site i see nothing.


Big thx
 
Sob
Forum Guru
Forum Guru
Posts: 6111
Joined: Mon Apr 20, 2009 9:11 pm

Re: Need help by php api

Sat Oct 17, 2020 8:38 pm

I can show you piece of code for listing firewall rules and disabling/enabling them, that should be enough to get you going.
$api = new routeros_api();
$api->debug = false;
$api->attempts = 2;
if($api->connect('192.168.88.1', 'username', 'password')) {
  $api->write('/ip/firewall/filter/print', false);
  $api->write('?chain=outgoing');
  $tmp = $api->read(false);
  $response = $api->parse_response($tmp);
  foreach($response as $rule) {
    echo 'id = '.$rule['.id'].'; comment = '.$rule['comment'].'; disabled = '.$rule['disabled'].PHP_EOL;
  }
  $api->disconnect();
} else {
  echo 'error';
}
And when you want to change something:
$api->write('/ip/firewall/filter/set', false);
$api->write('=.id='.$id, false);
$api->write('=disabled='.$val);
$tmp = $api->read(false);
$response = $api->parse_response($tmp);
People who quote full posts should be spanked with ethernet cable. Some exceptions for multi-topic threads may apply. Not intended as incentive for masochists.
 
OliverST
just joined
Topic Author
Posts: 13
Joined: Sun Aug 16, 2015 9:14 pm

Re: Need help by php api

Sat Oct 17, 2020 9:09 pm

Thank you , i will try
 
OliverST
just joined
Topic Author
Posts: 13
Joined: Sun Aug 16, 2015 9:14 pm

Re: Need help by php api

Sun Oct 18, 2020 1:43 pm

do u know maybe the command for list the interfaces under the capsman? ssid and state.

thx
 
Sob
Forum Guru
Forum Guru
Posts: 6111
Joined: Mon Apr 20, 2009 9:11 pm

Re: Need help by php api

Sun Oct 18, 2020 7:38 pm

No, but it should use the same structure as config export.
People who quote full posts should be spanked with ethernet cable. Some exceptions for multi-topic threads may apply. Not intended as incentive for masochists.
 
OliverST
just joined
Topic Author
Posts: 13
Joined: Sun Aug 16, 2015 9:14 pm

Re: Need help by php api

Sun Oct 18, 2020 7:54 pm

so i figured out and now i need to make it editable :-) switch on off if i klick on the name....
maybe someone for this part? here is the code

<?php



$API = new RouterosAPI();

$API->debug = false;




if ($API->connect('192.168.1.1', 'admin', 'admin')) {
$ARRAY = $API->comm("/caps-man/interface/print");
echo "<table width=100% border=1>";

echo "<tr><td size=2>name</td><td size=1>mac-address</td><td>Disabled?</td><td>ssid</td><td>hide ssid</td></tr>";

echo "<tr><td align=left>";

for ($i=0; $i<10; $i++)

{
$regtable = $ARRAY[$i];

echo "<font color=#04B404 size=2>" . $regtable['name'] . "</font><br>";
}

echo "</td><td>";

for ($i=0; $i<10; $i++)

{
$regtable = $ARRAY[$i];

echo "<font color=#04B404 size=2>" . $regtable['mac-address'] . "</font><br>";

}

echo "</td><td>";




for ($i=0; $i<10; $i++)

{
$regtable = $ARRAY[$i];

echo "<font color=#04B404 size=2>" . $regtable['disabled'] . "</font><br>";
}

echo "</td><td>";

for ($i=0; $i<10; $i++)

{
$regtable = $ARRAY[$i];

echo "<font color=#003300 size=2>" . $regtable['configuration.ssid'] . "</font><br>";
}

echo "</td><td>";


for ($i=0; $i<10; $i++)

{
$regtable = $ARRAY[$i];
if ($regtable['hide-ssid']=="true")
{
echo "<font color=#04B404 size=2>" . $regtable['configuration.hide-ssid'] . "</font><br>";
}else{
echo "<font color=#FF0000 size=2>". $regtable['configuration.hide-ssid'] ."</font><br>";
}
}

echo "</td><td>";





echo "</table>";
echo "<br />Debug:";
echo "<br />";
print_r($ARRAY);

$API->disconnect();

}

?>
 
OliverST
just joined
Topic Author
Posts: 13
Joined: Sun Aug 16, 2015 9:14 pm

Re: Need help by php api

Wed Oct 21, 2020 9:00 pm

I am trying to set one CAP to enable ---disable but no reaction


$id = "*B";
$val = "false";

$api->write('/ip/firewall/filter/set', false);
$api->write('=.id='.$id, false);
$api->write('=disabled='.$val);

Who is online

Users browsing this forum: No registered users and 19 guests