1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: nicolas |
5
|
|
|
* Date: 05/02/17 |
6
|
|
|
* Time: 14:32 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Devgiants\Command; |
10
|
|
|
|
11
|
|
|
use Buzz\Message\Request; |
12
|
|
|
use Devgiants\Configuration\ConfigurationManager; |
13
|
|
|
use Devgiants\Configuration\ApplicationConfiguration as AppConf; |
14
|
|
|
use Devgiants\Model\ApplicationCommand; |
15
|
|
|
use Pimple\Container; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
class WifiStatusCommand extends ApplicationCommand { |
21
|
|
|
|
22
|
|
|
const STATUS = 'status'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* WifiStatusCommand constructor. |
26
|
|
|
* |
27
|
|
|
* @param null|string $name |
28
|
|
|
* @param Container $container |
29
|
|
|
*/ |
30
|
|
|
public function __construct( $name, Container $container ) { |
31
|
|
|
parent::__construct( $name, $container ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
|
|
protected function configure() { |
38
|
|
|
$this |
39
|
|
|
->setName( 'wifi:status' ) |
40
|
|
|
->setDescription( 'Get wifi status (1 = ON, 0 = OFF)' ) |
41
|
|
|
->setHelp( "This command allows you to get wifi status" ); |
42
|
|
|
|
43
|
|
|
parent::configure(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
|
|
protected function execute( InputInterface $input, OutputInterface $output ) { |
50
|
|
|
|
51
|
|
|
$ymlFile = $this->getConfigurationFile( $input ); |
52
|
|
|
|
53
|
|
|
if ( $ymlFile !== NULL && is_file( $ymlFile ) ) { |
54
|
|
|
|
55
|
|
|
// Structures check and configuration loading |
56
|
|
|
$configurationManager = new ConfigurationManager( $ymlFile ); |
57
|
|
|
$configuration = $configurationManager->load(); |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
// Authentication |
61
|
|
|
$this->tools->authenticate( |
62
|
|
|
$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ], |
63
|
|
|
$configuration[ AppConf::USER[ AppConf::NODE_NAME ] ], |
64
|
|
|
$configuration[ AppConf::PASSWORD ] |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$response = $this->tools->createRequest( |
68
|
|
|
Request::METHOD_POST, |
69
|
|
|
"{$configuration[ AppConf::HOST[ AppConf::NODE_NAME ] ]}/ws", |
70
|
|
|
[ |
71
|
|
|
"service" => "NMC.Wifi", |
72
|
|
|
"method" => "get", |
73
|
|
|
"parameters" => [], |
74
|
|
|
] |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$json = json_decode( $response->getContent() ); |
78
|
|
|
|
79
|
|
|
if ( isset( $json->result->status ) ) { |
80
|
|
|
$output->write( $json->result->status->Status ? 1 : 0 ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// Handle post command stuff |
84
|
|
|
parent::execute( $input, $output ); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|