<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PEAR2\Net\RouterOS;
use Exception;

class RouterController extends Controller
{
    //
    public function connect()
    {
        try {
            $client = new RouterOS\Client('','','');
            echo "connected successfully";
        }catch (Exception $e)
        {
            throw $e;
        }



    }
    //get devices
    public function getDevices()
    {
        try {
            $client = new RouterOS\Client('','','');
            echo "connected successfully";

            $devices = $client->sendSync(new RouterOS\Request('/ip/arp/print'));
            foreach ($devices as $device){
               // dd($device);

                if($device->getType() === RouterOS\Response::TYPE_DATA){

                    //mac address
                    dd($device->getProperty('mac-address'));
                }
            }
        }catch (Exception $e)
        {
            throw $e;
        }

    }
    public function getProfile()
    {
        $host = env('MIKROTIK_HOST');
        $user = env('MIKROTIK_USERNAME');
        $pass = env('MIKROTIK_PASSWORD');


        try {
            $client = new RouterOS\Client($host,$user,$pass);
            $profile = $client->sendSync(new RouterOS\Request('/tool/user-manager/user/print'));
            dd($profile);
        }catch (Exception $e)
        {
            throw $e;
        }
    }
    public function index() {


        $host = "us-1.hostddns.us:15476";
        $user = 'admin';
        $pass = "";


        $client = new RouterOS\Client($host,$user,$pass);
        dd($client);
        $get_users = new RouterOS\Request('/tool user-manager user print');
        $users = $client->sendSync($get_users);

        dd($users);

    }


}



