Community discussions

 
BimoSora
just joined
Topic Author
Posts: 2
Joined: Tue Mar 27, 2018 11:45 am

Script Api PHP set

Sun Aug 18, 2019 10:10 am

How about the Mikrotik PHP API script to change the settings in it, my script set cannot change the settings in the Mikrotik PHP API?
<?php 
    session_start();
    if($_SESSION['group_name'] <> 'Administrator'){
        echo '<meta http-equiv="Refresh" Content="0; URL=../../id/error">';
        exit;
    }
?>

<?php

if (isset($_POST['submit'])) {

    $vpn_id = $_POST['vpn_id'];
    $vpn_title = $_POST['vpn_title'];
    $vpn_harga = $_POST['vpn_harga'];
    $vpn_kuota = $_POST['vpn_kuota'];
    $vpn_local = $_POST['vpn_local'];
    $vpn_remote = $_POST['vpn_remote'];
    $vpn_dns = $_POST['vpn_dns'];
    $vpn_pool = $_POST['vpn_pool'];
    $vpn_masaaktif = $_POST['vpn_masaaktif'];
    $vpn_koneksi = $_POST['vpn_koneksi'];
    $vpn_server = $_POST['vpn_server'];

    require_once("../../connection.php");
    require_once('../../routeros_api.class.php');

    $tw_status_vpn = $db->prepare("SELECT * FROM tw_status_vpn ORDER BY status_vpn_id");
	$tw_status_vpn->execute();
	while($d = $tw_status_vpn->fetch(PDO::FETCH_ASSOC)){

		$API = new RouterosAPI();

		$API->debug = true;

		if ($API->connect($d['status_ip'], $d['status_login'], $d['status_password']

	)) {	

            $API->comm("/ip/pool/set", array( 
                ".id" => "$vpn_title",
                "name" => "$vpn_title",
                "ranges" => "$vpn_pool",
                "comment" => "$vpn_title",
            	));

		$API->comm("/ppp/profile/set", array(
                ".id" => "$vpn_title",
		"name" => "$vpn_title",
                "dns-server" => "$vpn_dns",
                "change-tcp-mss" => "yes",
                "use-mpls" => "default",
                "use-compression" => "default",
                "use-encryption" => "yes",
                "only-one" => "yes",
                "comment" => "$vpn_title",
            	));
            
            $API->comm("/ip/firewall/address-list/set", array(
                ".id" => "$vpn_title",
		"list" => "$vpn_title",
                "address" => "$vpn_pool",
                "comment" => "$vpn_title",
            	));
    
            $API->comm("/ip/firewall/nat/set", array(
                ".id" => "$vpn_title",
                "chain" => "srcnat",
                "src-address-list" => "$vpn_title",
                "action" => "masquerade",
                "log" => "yes",
                "comment" => "$vpn_title",
		));
	}
}

        $tw_vpn = $db->prepare("UPDATE tw_vpn SET vpn_title = :vpn_title, vpn_harga = :vpn_harga, vpn_kuota = :vpn_kuota, vpn_local = :vpn_local, vpn_remote = :vpn_remote, vpn_dns = :vpn_dns, vpn_pool = :vpn_pool, vpn_masaaktif = :vpn_masaaktif, vpn_koneksi = :vpn_koneksi, vpn_server = :vpn_server WHERE vpn_id = :vpn_id");
        $tw_vpn->BindParam(':vpn_id',$vpn_id);
        $tw_vpn->BindParam(':vpn_title',$vpn_title);
        $tw_vpn->BindParam(':vpn_harga',$vpn_harga);
        $tw_vpn->BindParam(':vpn_kuota',$vpn_kuota);
        $tw_vpn->BindParam(':vpn_local',$vpn_local);
        $tw_vpn->BindParam(':vpn_remote',$vpn_remote);
        $tw_vpn->BindParam(':vpn_dns',$vpn_dns);
        $tw_vpn->BindParam(':vpn_pool',$vpn_pool);
        $tw_vpn->BindParam(':vpn_masaaktif',$vpn_masaaktif);
        $tw_vpn->BindParam(':vpn_koneksi',$vpn_koneksi);
        $tw_vpn->BindParam(':vpn_server',$vpn_server);   
        $tw_vpn->execute();

        } else {
	    echo "!!!";
    }

?>

Output
Connection attempt #1 to 117.53.46.249:65529... <<< [6] /login <<< [11] =name=gonit <<< [18] =password=b0bc1b62 >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [15] /ip/pool/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [12] /ip/pool/set <<< [5] =.id= <<< [10] =name=tria <<< [19] =ranges=192.168.0.2 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [19] /ppp/profile/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [16] /ppp/profile/set <<< [5] =.id= <<< [10] =name=tria <<< [23] =dns-server=192.168.0.1 <<< [19] =change-tcp-mss=yes <<< [17] =use-mpls=default <<< [24] =use-compression=default <<< [19] =use-encryption=yes <<< [13] =only-one=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [32] /ip/firewall/address-list/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [29] /ip/firewall/address-list/set <<< [5] =.id= <<< [10] =list=tria <<< [20] =address=192.168.0.2 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [23] /ip/firewall/nat/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [20] /ip/firewall/nat/set <<< [5] =.id= <<< [13] =chain=srcnat <<< [22] =src-address-list=tria <<< [18] =action=masquerade <<< [8] =log=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done Disconnected... Connection attempt #1 to 66.42.36.148:65529... <<< [6] /login <<< [11] =name=gonit <<< [18] =password=b0bc1b62 >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [15] /ip/pool/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [12] /ip/pool/set <<< [5] =.id= <<< [10] =name=tria <<< [19] =ranges=192.168.0.2 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [19] /ppp/profile/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [16] /ppp/profile/set <<< [5] =.id= <<< [10] =name=tria <<< [23] =dns-server=192.168.0.1 <<< [19] =change-tcp-mss=yes <<< [17] =use-mpls=default <<< [24] =use-compression=default <<< [19] =use-encryption=yes <<< [13] =only-one=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [32] /ip/firewall/address-list/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [29] /ip/firewall/address-list/set <<< [5] =.id= <<< [10] =list=tria <<< [20] =address=192.168.0.2 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [23] /ip/firewall/nat/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [20] /ip/firewall/nat/set <<< [5] =.id= <<< [13] =chain=srcnat <<< [22] =src-address-list=tria <<< [18] =action=masquerade <<< [8] =log=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done Disconnected...

print_r ($arrID);
var_dump($arrID);
Connection attempt #1 to 117.53.46.249:65529... <<< [6] /login <<< [11] =name=gonit <<< [18] =password=b0bc1b62 >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [15] /ip/pool/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [12] /ip/pool/set <<< [5] =.id= <<< [10] =name=tria <<< [19] =ranges=192.168.0.3 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [19] /ppp/profile/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [16] /ppp/profile/set <<< [5] =.id= <<< [10] =name=tria <<< [23] =dns-server=192.168.0.2 <<< [19] =change-tcp-mss=yes <<< [17] =use-mpls=default <<< [24] =use-compression=default <<< [19] =use-encryption=yes <<< [13] =only-one=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [32] /ip/firewall/address-list/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [29] /ip/firewall/address-list/set <<< [5] =.id= <<< [10] =list=tria <<< [20] =address=192.168.0.3 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [23] /ip/firewall/nat/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [20] /ip/firewall/nat/set <<< [5] =.id= <<< [13] =chain=srcnat <<< [22] =src-address-list=tria <<< [18] =action=masquerade <<< [8] =log=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done Disconnected... Connection attempt #1 to 66.42.36.148:65529... <<< [6] /login <<< [11] =name=gonit <<< [18] =password=b0bc1b62 >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [15] /ip/pool/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [12] /ip/pool/set <<< [5] =.id= <<< [10] =name=tria <<< [19] =ranges=192.168.0.3 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [19] /ppp/profile/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [16] /ppp/profile/set <<< [5] =.id= <<< [10] =name=tria <<< [23] =dns-server=192.168.0.2 <<< [19] =change-tcp-mss=yes <<< [17] =use-mpls=default <<< [24] =use-compression=default <<< [19] =use-encryption=yes <<< [13] =only-one=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [32] /ip/firewall/address-list/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [29] /ip/firewall/address-list/set <<< [5] =.id= <<< [10] =list=tria <<< [20] =address=192.168.0.3 <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [23] /ip/firewall/nat/getall <<< [14] =.proplist=.id <<< [13] ?comment=tria >>> [5/5] bytes read. >>> [5, 1]!done <<< [20] /ip/firewall/nat/set <<< [5] =.id= <<< [13] =chain=srcnat <<< [22] =src-address-list=tria <<< [18] =action=masquerade <<< [8] =log=yes <<< [13] =comment=tria >>> [5/5] bytes read. >>> [5, 1]!done Array ( ) array(0) { } Disconnected...

Info
ppp profile and ppp secrets cannot manage local-addresses and remote-addresses

Who is online

Users browsing this forum: Bing [Bot] and 7 guests