<?php

namespace app\models\mikrotik\ip\socks;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use yii\base\Model;
use Yii;
use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Connections extends Model {

    public $src_address;
    public $dst_address;
    public $rx;
    public $tx;

    public function rules() {
        return [
            ['src_address', 'string'],
            ['dst_address', 'string'],
            ['rx', 'string'],
            ['tx', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/ip/socks/connections/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Socks();
                $c->src_address = $response->getProperty('src-address');
                $c->dst_address = $response->getProperty('dst-address');
                $c->rx = $response->getProperty('rx');
                $c->tx = $response->getProperty('tx');
                $return[] = $c;
            }
        }
        return $return;
    }

}
