8
8
9
9
# RouterOS API Client
10
10
11
- composer require evilfreelancer/routeros-api-php
11
+ ``` shell
12
+ composer require evilfreelancer/routeros-api-php
13
+ ```
12
14
13
15
This library is partly based on [ this old project] ( https://github.com/BenMenking/routeros-api ) , but unlike it has many
14
- innovations to ease development. In addition, the project is designed
15
- to work with PHP7 in accordance with the PSR standards.
16
+ innovations to ease development. In addition, the project designed
17
+ to work with PHP7/8 in accordance with the PSR standards.
16
18
17
19
You can use this library with pre-6.43 and post-6.43 versions of
18
20
RouterOS firmware, it will be detected automatically on connection stage.
19
21
20
22
## Minimum requirements
21
23
22
- * ` php ` >= 7.2
24
+ * ` php ` >= 7.2|8.0
23
25
* ` ext-sockets `
24
26
25
27
## Laravel framework support
@@ -37,7 +39,7 @@ $config = new \RouterOS\Config([
37
39
$client = new \RouterOS\Client($config);
38
40
```
39
41
40
- Call facade and pass array of parameters to ` client ` method:
42
+ Use the facade and pass array of parameters to ` client ` method:
41
43
42
44
``` php
43
45
$client = \RouterOS::client([
@@ -66,8 +68,8 @@ $client = \RouterOS::client($config);
66
68
### Laravel installation
67
69
68
70
By default, the package will automatically register its service provider, but
69
- if you are a happy owner of Laravel version less than 5.5, then in a project, which is using your package
70
- (after composer require is done, of course), add into` providers ` block of your ` config/app.php ` :
71
+ if you are a happy owner of Laravel version less than 5.5, then in a project, which is using the package
72
+ (after ` composer require ` is done, of course), add into` providers ` block of your ` config/app.php ` :
71
73
72
74
``` php
73
75
'providers' => [
@@ -78,7 +80,9 @@ if you are a happy owner of Laravel version less than 5.5, then in a project, wh
78
80
79
81
Optionally, publish the configuration file if you want to change any defaults:
80
82
81
- php artisan vendor:publish --provider="RouterOS\\Laravel\\ServiceProvider"
83
+ ``` shell
84
+ php artisan vendor:publish --provider=" RouterOS\\ Laravel\\ ServiceProvider"
85
+ ```
82
86
83
87
## How to use
84
88
@@ -92,7 +96,8 @@ use \RouterOS\Query;
92
96
$client = new Client([
93
97
'host' => '192.168.1.3',
94
98
'user' => 'admin',
95
- 'pass' => 'admin'
99
+ 'pass' => 'admin',
100
+ 'port' => 8728,
96
101
]);
97
102
98
103
// Create "where" Query object for RouterOS
@@ -139,10 +144,11 @@ use \RouterOS\Client;
139
144
140
145
// Initiate client with config object
141
146
$client = new Client([
142
- 'host' => '192.168.1.3',
143
- 'user' => 'admin',
144
- 'pass' => 'admin',
145
- 'ssh_port' => 22222,
147
+ 'host' => '192.168.1.3',
148
+ 'user' => 'admin',
149
+ 'pass' => 'admin',
150
+ 'ssh_port' => 22222,
151
+ 'ssh_timeout' => 60, // if not set then 30 seconds by default
146
152
]);
147
153
148
154
// Execute export command via ssh
@@ -270,17 +276,21 @@ $client = new Client($config);
270
276
271
277
### List of available configuration parameters
272
278
273
- | Parameter | Type | Default | Description |
274
- | -----------| --------| ---------| -------------|
275
- | host | string | | (required) Address of Mikrotik RouterOS |
276
- | user | string | | (required) Username |
277
- | pass | string | | (required) Password |
278
- | port | int | | RouterOS API port number for access (if not set use 8728 or 8729 if SSL enabled) |
279
- | ssl | bool | false | Enable ssl support (if port is not set this parameter must change default port to ssl port) |
280
- | legacy | bool | false | Support of legacy login scheme (true - pre 6.43, false - post 6.43) |
281
- | timeout | int | 10 | Max timeout for answer from RouterOS |
282
- | attempts | int | 10 | Count of attempts to establish TCP session |
283
- | delay | int | 1 | Delay between attempts in seconds |
279
+ | Parameter | Type | Default | Description |
280
+ | ----------------| --------| ---------| -------------|
281
+ | host | string | | (required) Address of Mikrotik RouterOS |
282
+ | user | string | | (required) Username |
283
+ | pass | string | | (required) Password |
284
+ | port | int | | RouterOS API port number for access (if not set use 8728 or 8729 if SSL enabled) |
285
+ | ssl | bool | false | Enable ssl support (if port is not set this parameter must change default port to ssl port) |
286
+ | ssl_options | array | [ details] ( https://github.com/EvilFreelancer/routeros-api-php/blob/master/src/Config.php#L46 ) | See https://www.php.net/manual/en/context.ssl.php |
287
+ | legacy | bool | false | Support of legacy login scheme (true - pre 6.43, false - post 6.43) |
288
+ | timeout | int | 10 | Max timeout for connecting to RouterOS (in seconds) |
289
+ | socket_timeout | int | 30 | Max read timeout from RouterOS (in seconds) |
290
+ | attempts | int | 10 | Count of attempts to establish TCP session |
291
+ | delay | int | 1 | Delay between attempts in seconds |
292
+ | ssh_port | int | 22 | Number of SSH port for exporting configuration |
293
+ | ssh_timeout | int | 30 | Max timeout from router via SSH (in seconds) |
284
294
285
295
### How to enable support of legacy login schema (RouterOS pre-6.43)
286
296
@@ -421,14 +431,14 @@ $query->equal('disabled', 'no');
421
431
$query->equal('.id', 'ether1');
422
432
$query->tag(4);
423
433
424
- // Or
434
+ // Or, RAW mode
425
435
426
436
$query = new Query('/interface/set');
427
437
$query->add('=disabled=no');
428
438
$query->add('=.id=ether1');
429
439
$query->add('.tag=4');
430
440
431
- // Or
441
+ // Or, RAW mode in format of array
432
442
433
443
$query = new Query('/interface/set', [
434
444
'=disabled=no',
0 commit comments