Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('/srv/lb/mtik_api/mtikapi.class.php');
- $API = new routeros_api();
- $args=count($argv)-1;
- $API->debug = false;
- if ($API->connect('somehost', 'someusr', 'somepw')) {
- switch ($argv[1]) {
- case "add":
- $API->write('/ip/firewall/address-list/add',false);
- for ($i = 2; $i <= $args; $i++) {
- //echo "=".$argv[$i]."\n";
- if ($i == $args) {
- $API->write("=".$argv[$i]);
- } else {
- $API->write("=".$argv[$i],false);
- }
- }
- // getting some answers...
- $API->read(false);
- break;
- case "del":
- $API->write('/ip/firewall/address-list/print',false);
- for ($i = 2; $i <= $args; $i++) {
- //echo "=".$argv[$i]."\n";
- if ($i == $args) {
- $API->write("?".$argv[$i]);
- } else {
- $API->write("?".$argv[$i],false);
- }
- }
- // getting some answers...
- $READ = $API->read(false);
- $ARRAY = $API->parse_response($READ);
- $secid="".$ARRAY[0][".id"];
- // removing selected address from list
- if ($secid !== "") {
- $API->write("/ip/firewall/address-list/remove",false);
- $API->write("=.id=$secid");
- $API->read(false);
- }
- break;
- case "disable":
- $API->write('/ip/firewall/address-list/print',false);
- for ($i = 2; $i <= $args; $i++) {
- //echo "=".$argv[$i]."\n";
- if ($i == $args) {
- $API->write("?".$argv[$i]);
- } else {
- $API->write("?".$argv[$i],false);
- }
- }
- // getting some answers...
- $READ = $API->read(false);
- $ARRAY = $API->parse_response($READ);
- $secid="".$ARRAY[0][".id"];
- // disabling selected address from list
- if ($secid !== "") {
- $API->write("/ip/firewall/address-list/set",false);
- $API->write("=.id=$secid",false);
- $API->write("=disabled=yes");
- $API->read(false);
- }
- break;
- case "enable":
- $API->write('/ip/firewall/address-list/print',false);
- for ($i = 2; $i <= $args; $i++) {
- //echo "=".$argv[$i]."\n";
- if ($i == $args) {
- $API->write("?".$argv[$i]);
- } else {
- $API->write("?".$argv[$i],false);
- }
- }
- // getting some answers...
- $READ = $API->read(false);
- $ARRAY = $API->parse_response($READ);
- $secid="".$ARRAY[0][".id"];
- // enabling selected address
- if ($secid !== "") {
- $API->write("/ip/firewall/address-list/set",false);
- $API->write("=.id=$secid",false);
- $API->write("=disabled=no");
- $API->read(false);
- }
- break;
- case "get":
- $API->write('/ip/firewall/address-list/print');
- $READ = $API->read(false);
- $ARRAY = $API->parse_response($READ);
- $disabled="";
- foreach ($ARRAY as $item) {
- if ($item["disabled"] == "false") {
- $disabled="no";
- } else {
- $disabled="yes";
- }
- if ((strpos($item["list"],"class_client") !== false) || (strpos($item["list"],"_unknown_class") !== false)) {
- print("\"address=".$item["address"]."\" \"comment=".$item["comment"]."\" \"disabled=".$disabled."\" \"list=".$item["list"]."\"");
- echo "\n";
- }
- }
- break;
- }
- $API->disconnect();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement