1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Sanchescom\WiFi\System\Windows; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use pastuhov\Command\Command; |
9
|
|
|
use Sanchescom\WiFi\System\AbstractNetwork; |
10
|
|
|
use Sanchescom\WiFi\System\Windows\Profile\Service; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Network. |
14
|
|
|
*/ |
15
|
|
|
class Network extends AbstractNetwork |
16
|
|
|
{ |
17
|
|
|
use UtilityTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string $password |
21
|
|
|
* @param string $device |
22
|
|
|
* |
23
|
|
|
* @throws Exception |
24
|
|
|
*/ |
25
|
|
|
public function connect(string $password, string $device): void |
26
|
|
|
{ |
27
|
|
|
$this->getProfileService()->create($password); |
28
|
|
|
|
29
|
|
|
Command::exec( |
30
|
|
|
implode(' && ', [ |
31
|
|
|
sprintf( |
32
|
|
|
($this->getUtility().' add profile filename="%s"'), |
33
|
|
|
$this->getProfileService()->getTmpProfileFileName() |
34
|
|
|
), |
35
|
|
|
sprintf( |
36
|
|
|
($this->getUtility().' connect interface="%s" ssid="%s" name="%s"'), |
37
|
|
|
$device, |
38
|
|
|
$this->ssid, |
39
|
|
|
$this->ssid |
40
|
|
|
), |
41
|
|
|
]) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$this->getProfileService()->delete(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $device |
49
|
|
|
* |
50
|
|
|
* @throws Exception |
51
|
|
|
*/ |
52
|
|
|
public function disconnect(string $device): void |
53
|
|
|
{ |
54
|
|
|
Command::exec( |
55
|
|
|
sprintf($this->getUtility().' disconnect interface="%s"', $device) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $network |
61
|
|
|
* |
62
|
|
|
* @return Network |
63
|
|
|
*/ |
64
|
|
|
public static function createFromArray(array $network): AbstractNetwork |
65
|
|
|
{ |
66
|
|
|
$instance = new self(); |
67
|
|
|
$instance->ssid = $network[0]; |
68
|
|
|
$instance->bssid = $network[4]; |
69
|
|
|
$instance->channel = $network[7]; |
70
|
|
|
$instance->security = $network[2]; |
71
|
|
|
$instance->securityFlags = $network[3]; |
72
|
|
|
$instance->quality = (int) $network[5]; |
73
|
|
|
$instance->frequency = $instance->getFrequency(); |
74
|
|
|
$instance->dbm = $instance->qualityToDBm(); |
75
|
|
|
$instance->connected = isset($network[10]); |
76
|
|
|
|
77
|
|
|
return $instance; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function getProfileService() |
81
|
|
|
{ |
82
|
|
|
return new Service($this); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|