WIP 2025-07-31 Citycom OAN Api WIP
This commit is contained in:
@@ -14,7 +14,7 @@ class mfRouteros {
|
||||
private $password;
|
||||
private $ros = false;
|
||||
|
||||
public function __construct($hostname, $username, $password, $port = 8729, $use_ssl = true) {
|
||||
public function __construct($hostname, $username, $password, $port = 8729, $use_ssl = "auto") {
|
||||
$this->hostname = $hostname;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
@@ -25,7 +25,9 @@ class mfRouteros {
|
||||
|
||||
private function _connect() {
|
||||
$crypto = NetworkStream::CRYPTO_OFF;
|
||||
if($this->use_ssl) {
|
||||
if($this->use_ssl === true) {
|
||||
$crypto = NetworkStream::CRYPTO_TLS;
|
||||
} elseif($this->use_ssl == "auto" && $this->port == 8729) {
|
||||
$crypto = NetworkStream::CRYPTO_TLS;
|
||||
}
|
||||
|
||||
@@ -104,6 +106,60 @@ class mfRouteros {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function add($table, $set = []) {
|
||||
if(!$this->ros) $this->_connect();
|
||||
|
||||
if(substr($table, 0, 1) != '/') {
|
||||
$table = "/".$table;
|
||||
}
|
||||
|
||||
$req = new RouterOS\Request("$table add");
|
||||
|
||||
if(count($set)) {
|
||||
foreach($set as $name => $value) {
|
||||
$req->setArgument($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$resp = $this->ros->sendSync($req);
|
||||
|
||||
if($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function remove($table, $filter = []) {
|
||||
if(!$filter) {
|
||||
// no filter would remove every entry in table -> disallowed
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->ros) $this->_connect();
|
||||
$util = new RouterOS\Util($this->ros);
|
||||
|
||||
if(substr($table, 0, 1) != '/') {
|
||||
$table = "/".$table;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$query = false;
|
||||
if(count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
if(!$query) {
|
||||
$query = RouterOS\Query::where($name, $value);
|
||||
} else {
|
||||
$query->andWhere($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$util->setMenu($table);
|
||||
$util->remove($query);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* accessors */
|
||||
public function hostname($hostname=false) {
|
||||
|
||||
Reference in New Issue
Block a user