Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
locales/po/*.mo
\!templates/**
.omc/
2 changes: 2 additions & 0 deletions RouterOS/examples/example1.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require('../routeros_api.class.php');

$API = new RouterosAPI();
Expand Down
2 changes: 2 additions & 0 deletions RouterOS/examples/example2.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require('../routeros_api.class.php');

$API = new RouterosAPI();
Expand Down
6 changes: 4 additions & 2 deletions RouterOS/examples/example3.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/* Example for adding a VPN user */

require('../routeros_api.class.php');
Expand All @@ -10,13 +12,13 @@

if ($API->connect('111.111.111.111', 'LOGIN', 'PASSWORD')) {

$API->comm('/ppp/secret/add', array(
$API->comm('/ppp/secret/add', [
'name' => 'user',
'password' => 'pass',
'remote-address' => '172.16.1.10',
'comment' => '{new VPN user}',
'service' => 'pptp',
));
]);

$API->disconnect();

Expand Down
6 changes: 4 additions & 2 deletions RouterOS/examples/example4.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/* Example of finding registration-table ID for specified MAC */

require('../routeros_api.class.php');
Expand All @@ -10,10 +12,10 @@

if ($API->connect('111.111.111.111', 'LOGIN', 'PASSWORD')) {

$ARRAY = $API->comm("/interface/wireless/registration-table/print", array(
$ARRAY = $API->comm("/interface/wireless/registration-table/print", [
".proplist"=> ".id",
"?mac-address" => "00:0E:BB:DD:FF:FF",
));
]);

print_r($ARRAY);

Expand Down
6 changes: 4 additions & 2 deletions RouterOS/examples/example5.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/* Example of counting leases from a specific IP Pool (using regexp) */

require('../routeros_api.class.php');
Expand All @@ -10,10 +12,10 @@

if ($API->connect('111.111.111.111', 'LOGIN', 'PASSWORD')) {

$ARRAY = $API->comm("/ip/dhcp-server/lease/print", array(
$ARRAY = $API->comm("/ip/dhcp-server/lease/print", [
"count-only"=> "",
"~active-address" => "1.1.",
));
]);

print_r($ARRAY);

Expand Down
6 changes: 4 additions & 2 deletions RouterOS/examples/example6.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/* 3 step action
1) fetch all static dns hosts
2) remove all static dns hosts
Expand All @@ -21,11 +23,11 @@
}

#add some new
$API->comm('/ip/dns/static/add', array(
$API->comm('/ip/dns/static/add', [
'name' => 'jefkeklak',
'address' => '1.2.3.4',
'ttl' => '1m'
));
]);

#show me what you got
$API->write('/ip/dns/static/print');
Expand Down
2 changes: 2 additions & 0 deletions RouterOS/examples/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<?php

declare(strict_types=1);
header('Location:../index.php');
2 changes: 2 additions & 0 deletions RouterOS/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<?php

declare(strict_types=1);
header('Location:../index.php');
24 changes: 13 additions & 11 deletions RouterOS/routeros_api.class.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/*****************************
*
* RouterOS PHP API class v1.6
Expand Down Expand Up @@ -109,7 +111,7 @@ public function connect($ip, $login, $password) {
$this->write('/login');
$RESPONSE = $this->read(false);
if (isset($RESPONSE[0]) && $RESPONSE[0] == '!done') {
$MATCHES = array();
$MATCHES = [];
if (preg_match_all('/[^=]+/i', $RESPONSE[1], $MATCHES)) {
if ($MATCHES[0][0] == 'ret' && strlen($MATCHES[0][1]) == 32) {
$this->write('/login', false);
Expand Down Expand Up @@ -159,18 +161,18 @@ public function disconnect() {
*/
public function parseResponse($response) {
if (is_array($response)) {
$PARSED = array();
$PARSED = [];
$CURRENT = null;
$singlevalue = null;
foreach ($response as $x) {
if (in_array($x, array('!fatal','!re','!trap'))) {
if (in_array($x, ['!fatal','!re','!trap'])) {
if ($x == '!re') {
$CURRENT =& $PARSED[];
} else {
$CURRENT =& $PARSED[$x][];
}
} elseif ($x != '!done') {
$MATCHES = array();
$MATCHES = [];
if (preg_match_all('/[^=]+/i', $x, $MATCHES)) {
if ($MATCHES[0][0] == 'ret') {
$singlevalue = $MATCHES[0][1];
Expand All @@ -186,7 +188,7 @@ public function parseResponse($response) {

return $PARSED;
} else {
return array();
return [];
}
}

Expand All @@ -199,18 +201,18 @@ public function parseResponse($response) {
*/
public function parseResponse4Smarty($response) {
if (is_array($response)) {
$PARSED = array();
$PARSED = [];
$CURRENT = null;
Comment on lines 202 to 205
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseResponse4Smarty() uses is_[$response], which is invalid PHP syntax and will prevent the file from parsing. Replace with a valid check (e.g., is_array($response)).

Copilot uses AI. Check for mistakes.
$singlevalue = null;
foreach ($response as $x) {
if (in_array($x, array('!fatal','!re','!trap'))) {
if (in_array($x, ['!fatal','!re','!trap'])) {
if ($x == '!re') {
$CURRENT =& $PARSED[];
} else {
$CURRENT =& $PARSED[$x][];
}
} elseif ($x != '!done') {
$MATCHES = array();
$MATCHES = [];
if (preg_match_all('/[^=]+/i', $x, $MATCHES)) {
if ($MATCHES[0][0] == 'ret') {
$singlevalue = $MATCHES[0][1];
Expand All @@ -227,7 +229,7 @@ public function parseResponse4Smarty($response) {
$PARSED = $singlevalue;
}
} else {
return array();
return [];
}
}

Expand Down Expand Up @@ -263,7 +265,7 @@ public function arrayChangeKeyName(&$array) {
* @return array Array with parsed or unparsed data
*/
public function read($parse = true) {
$RESPONSE = array();
$RESPONSE = [];
$receiveddone = false;
while (true) {
// Read the first byte of input which gives us some or all of the length
Expand Down Expand Up @@ -377,7 +379,7 @@ public function write($command, $param2 = true) {
*
* @return array Array with parsed
*/
public function comm($com, $arr = array()) {
public function comm($com, $arr = []) {
$count = count($arr);
$this->write($com, !$arr);
$i = 0;
Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<?php

declare(strict_types=1);
header('Location:../index.php');
2 changes: 2 additions & 0 deletions locales/LC_MESSAGES/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<?php

declare(strict_types=1);
header('Location:../index.php');
2 changes: 2 additions & 0 deletions locales/index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

declare(strict_types=1);
header('Location:../index.php');

Loading