-
Notifications
You must be signed in to change notification settings - Fork 1
/
Manager.class.php
78 lines (65 loc) · 1.74 KB
/
Manager.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* Classe de manipulação dos dados PowerShell
* Autor: Alisson Pelizaro
*/
class Manager {
/*
* Converte a estrutura do comando getUsers no PowerShell para um objeto
*/
public function getUsers($response){
$response = explode("\n", $response);
$ind = 0;
$users[0] = (object) array();
foreach ($response as $line_num => $line) {
if($line_num > 1){
$contents = explode(' : ', $line);
if(isset($contents[1])){
@$users[$ind]->{$this->cleanString($contents[0])} = $contents[1];
} else {
$ind++;
$users[$ind] = (object) array();
}
}
}
return $users;
}
/*
* Converte a estrutura do comando getUser no PowerShell para um objeto
*/
public function getUser($response){
$response = explode("\n", $response);
$user = (object) array();
foreach ($response as $line_num => $line) {
$contents = explode(' : ', $line);
if(isset($contents[1])){
@$user->{$this->cleanString($contents[0])} = $contents[1];
}
}
if(!isset($user->CN)){
return false;
}
return $user;
}
/*
* Limpa string
*/
private function cleanString($string){
$string = iconv( "UTF-8" , "ASCII//TRANSLIT//IGNORE" , $string );
$string = preg_replace(
array('/[ ]/' , '/[^A-Za-z0-9\-]/'),
array('', ''),
$string
);
$what = array(
'-','(',')',',',';',':','|','!','"','#','$',
'%','&','/','=','?','~','^','>','<','ª','º'
);
$by = array(
'_','_','_','_','_','_','_','_','_','_','_',
'_','_','_','_','_','_','_','_','_','_','_'
);
return str_replace($what, $by, $string);
}
}
?>