Browse Source
Merge pull request #40 from EvilFreelancer/development
Merge pull request #40 from EvilFreelancer/development
Update to version 1.3tags/1.3.0 1.3.0
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 1036 additions and 643 deletions
-
2.gitignore
-
2.travis.yml
-
165README.md
-
15composer.json
-
44configs/routeros-api.php
-
2examples/bridge_hosts.php
-
6examples/different_queries.php
-
30examples/export.php
-
2examples/interface_print.php
-
2examples/ip_address_print.php
-
2examples/ip_filrewall_address-list_print.php
-
2examples/queue_simple_print.php
-
2examples/queue_simple_print_v2.php
-
4examples/queue_simple_write.php
-
14examples/remove_security_profile.php
-
2examples/system_package_print.php
-
6examples/vlans_bridge.php
-
6examples/vlans_bridge_v2.php
-
6examples/vlans_bridge_v3.php
-
14phpunit.xml
-
2preconf.tcl
-
15src/APIConnector.php
-
8src/APILengthCoDec.php
-
174src/Client.php
-
106src/Config.php
-
14src/Helpers/ArrayHelper.php
-
81src/Interfaces/ClientInterface.php
-
34src/Interfaces/ConfigInterface.php
-
2src/Interfaces/QueryInterface.php
-
2src/Interfaces/StreamInterface.php
-
24src/Laravel/ClientWrapper.php
-
6src/Laravel/Facade.php
-
4src/Laravel/ServiceProvider.php
-
63src/Laravel/Wrapper.php
-
10src/Query.php
-
27src/ResponseIterator.php
-
87src/ShortsTrait.php
-
37src/SocketTrait.php
-
27src/Streams/ResourceStream.php
-
24src/Streams/StringStream.php
-
8tests/APIConnectorTest.php
-
25tests/APILengthCoDecTest.php
-
230tests/ClientTest.php
-
55tests/ConfigTest.php
-
4tests/Helpers/ArrayHelperTest.php
-
5tests/Helpers/BinaryStringHelperTest.php
-
2tests/Helpers/TypeHelperTest.php
-
62tests/Laravel/ServiceProviderTests.php
-
35tests/Laravel/TestCase.php
-
30tests/QueryTest.php
-
39tests/ResponseIteratorTest.php
-
66tests/Streams/ResourceStreamTest.php
-
43tests/Streams/StringStreamTest.php
@ -1,13 +1,39 @@ |
|||
<?php |
|||
|
|||
return [ |
|||
// 'host' => null,
|
|||
// 'user' => null,
|
|||
// 'pass' => null,
|
|||
// 'port' => null,
|
|||
'ssl' => false, |
|||
'legacy' => false, |
|||
'timeout' => 10, |
|||
'attempts' => 10, |
|||
'delay' => 1, |
|||
|
|||
/* |
|||
|-------------------------------------------------------------------------- |
|||
| Connection details |
|||
|-------------------------------------------------------------------------- |
|||
| |
|||
| Here you may specify different information about your router, like |
|||
| hostname (or ip-address), username, password, port and ssl mode. |
|||
| |
|||
| SSH port should be set if you want to use "/export" command. |
|||
| |
|||
*/ |
|||
|
|||
'host' => '192.168.88.1', // Address of Mikrotik RouterOS
|
|||
'user' => 'admin', // Username
|
|||
'pass' => null, // Password
|
|||
'port' => 8728, // RouterOS API port number for access (if not set use default or default with SSL if SSL enabled)
|
|||
'ssl' => false, // Enable ssl support (if port is not set this parameter must change default port to ssl port)
|
|||
'ssh_port' => 22, // Number of SSH port
|
|||
|
|||
/* |
|||
|-------------------------------------------------------------------------- |
|||
| Optional connection settings of client |
|||
|-------------------------------------------------------------------------- |
|||
| |
|||
| Settings bellow need to advanced tune of your connection, for example |
|||
| you may enable legacy mode by default, or change timeout of connection. |
|||
| |
|||
*/ |
|||
|
|||
'legacy' => false, // Support of legacy login scheme (true - pre 6.43, false - post 6.43)
|
|||
'timeout' => 10, // Max timeout for answer from RouterOS
|
|||
'attempts' => 10, // Count of attempts to establish TCP session
|
|||
'delay' => 1, // Delay between attempts in seconds
|
|||
|
|||
]; |
|||
@ -0,0 +1,14 @@ |
|||
<?php |
|||
require_once __DIR__ . '/../vendor/autoload.php'; |
|||
|
|||
error_reporting(E_ALL); |
|||
|
|||
// Create query which should remove security profile
|
|||
$query = new \RouterOS\Query('/interface/wireless/security-profiles/remove'); |
|||
|
|||
// Here, instead of `->where()` need to use `->equal()`, it will generate queries,
|
|||
// which stared from "=" symbol:
|
|||
$query->where('.id', '*1'); |
|||
|
|||
$client = new \RouterOS\Client(['host' => '192.168.88.1', 'user' => 'admin', 'pass' => 'password']); |
|||
$response = $client->query($query)->read(); |
|||
@ -1,24 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace RouterOS\Laravel; |
|||
|
|||
use RouterOS\Client; |
|||
|
|||
class ClientWrapper |
|||
{ |
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \RouterOS\Client |
|||
* @throws \RouterOS\Exceptions\ClientException |
|||
* @throws \RouterOS\Exceptions\ConfigException |
|||
* @throws \RouterOS\Exceptions\QueryException |
|||
*/ |
|||
public function getClient(array $params = []): Client |
|||
{ |
|||
$configs = config('routeros-api'); |
|||
$configs = array_merge($configs, $params); |
|||
|
|||
return new Client($configs); |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
<?php |
|||
|
|||
namespace RouterOS\Laravel; |
|||
|
|||
use RouterOS\Client; |
|||
use RouterOS\Config; |
|||
use RouterOS\Interfaces\ClientInterface; |
|||
use RouterOS\Interfaces\ConfigInterface; |
|||
|
|||
class Wrapper |
|||
{ |
|||
/** |
|||
* Alias for \RouterOS::client() method |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \RouterOS\Client |
|||
* @throws \RouterOS\Exceptions\ClientException |
|||
* @throws \RouterOS\Exceptions\ConfigException |
|||
* @throws \RouterOS\Exceptions\QueryException |
|||
* @deprecated |
|||
* @codeCoverageIgnore |
|||
*/ |
|||
public function getClient(array $params = []): ClientInterface |
|||
{ |
|||
return $this->client($params); |
|||
} |
|||
|
|||
/** |
|||
* Get configs of library |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \RouterOS\Interfaces\ConfigInterface |
|||
* @throws \RouterOS\Exceptions\ConfigException |
|||
*/ |
|||
public function config(array $params = []): ConfigInterface |
|||
{ |
|||
$config = config('routeros-api'); |
|||
$config = array_merge($config, $params); |
|||
$config = new Config($config); |
|||
|
|||
return $config; |
|||
} |
|||
|
|||
/** |
|||
* Instantiate client object |
|||
* |
|||
* @param array $params |
|||
* @param bool $autoConnect |
|||
* |
|||
* @return \RouterOS\Interfaces\ClientInterface |
|||
* @throws \RouterOS\Exceptions\ClientException |
|||
* @throws \RouterOS\Exceptions\ConfigException |
|||
* @throws \RouterOS\Exceptions\QueryException |
|||
*/ |
|||
public function client(array $params = [], bool $autoConnect = true): ClientInterface |
|||
{ |
|||
$config = $this->config($params); |
|||
|
|||
return new Client($config, $autoConnect); |
|||
} |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
<?php |
|||
|
|||
namespace RouterOS\Tests\Laravel; |
|||
|
|||
use RouterOS\Config; |
|||
use RouterOS\Laravel\Wrapper; |
|||
|
|||
class ServiceProviderTests extends TestCase |
|||
{ |
|||
private $client = [ |
|||
"__construct", |
|||
"query", |
|||
"read", |
|||
"readAsIterator", |
|||
"parseResponse", |
|||
"connect", |
|||
"export", |
|||
"getSocket", |
|||
"q", |
|||
"r", |
|||
"ri", |
|||
"qr", |
|||
"qri", |
|||
]; |
|||
|
|||
public function testAbstractsAreLoaded(): void |
|||
{ |
|||
$manager = app(Wrapper::class); |
|||
$this->assertInstanceOf(Wrapper::class, $manager); |
|||
} |
|||
|
|||
public function testConfig(): void |
|||
{ |
|||
$config = \RouterOS::config([ |
|||
'host' => '192.168.1.3', |
|||
'user' => 'admin', |
|||
'pass' => 'admin' |
|||
]); |
|||
$this->assertInstanceOf(Config::class, $config); |
|||
|
|||
$params = $config->getParameters(); |
|||
$this->assertArrayHasKey('host', $params); |
|||
$this->assertArrayHasKey('user', $params); |
|||
$this->assertArrayHasKey('pass', $params); |
|||
$this->assertArrayHasKey('ssl', $params); |
|||
$this->assertArrayHasKey('legacy', $params); |
|||
$this->assertArrayHasKey('timeout', $params); |
|||
$this->assertArrayHasKey('attempts', $params); |
|||
$this->assertArrayHasKey('delay', $params); |
|||
} |
|||
|
|||
public function testClient(): void |
|||
{ |
|||
$client = \RouterOS::client([ |
|||
'host' => '192.168.1.3', |
|||
'user' => 'admin', |
|||
'pass' => 'admin' |
|||
], false); |
|||
|
|||
$this->assertEquals(get_class_methods($client), $this->client); |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
namespace RouterOS\Tests\Laravel; |
|||
|
|||
use RouterOS\Laravel\Facade; |
|||
use RouterOS\Laravel\ServiceProvider; |
|||
use Orchestra\Testbench\TestCase as Orchestra; |
|||
|
|||
/** |
|||
* Class TestCase |
|||
* |
|||
* @package Tests |
|||
*/ |
|||
abstract class TestCase extends Orchestra |
|||
{ |
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
protected function getPackageProviders($app): array |
|||
{ |
|||
return [ |
|||
ServiceProvider::class, |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
protected function getPackageAliases($app): array |
|||
{ |
|||
return [ |
|||
'RouterOS' => Facade::class, |
|||
]; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue