/
hostnamechanger.class.php
165 lines (165 loc) · 4.57 KB
/
hostnamechanger.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* Sends the client with the hostname and domain
* information needed to perform the client actions.
*
* PHP version 5
*
* @category HostnameChanger
* @package FOGProject
* @author Tom Elliott <tommygunsster@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
/**
* Sends the client with the hostname and domain
* information needed to perform the client actions.
*
* @category HostnameChanger
* @package FOGProject
* @author Tom Elliott <tommygunsster@gmail.com>
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link https://fogproject.org
*/
class HostnameChanger extends FOGClient implements FOGClientSend
{
/**
* Module associated shortname
*
* @var string
*/
public $shortName = 'hostnamechanger';
/**
* Function returns data that will be translated to json
*
* @return array
*/
public function json()
{
$password = self::$Host->get('ADPass');
$passwordtest = self::aesdecrypt($password);
if ($test_base64 = base64_decode($passwordtest)) {
if (mb_detect_encoding($test_base64, 'utf-8', true)) {
$password = $test_base64;
} elseif (mb_detect_encoding($passwordtest, 'utf-8', true)) {
$password = $passwordtest;
}
}
$productKey = self::$Host->get('productKey');
$productKeytest = self::aesdecrypt($productKey);
if ($test_base64 = base64_decode($productKeytest)) {
if (mb_detect_encoding($test_base64, 'utf-8', true)) {
$productKey = $test_base64;
}
}
if (mb_detect_encoding($productKeytest, 'utf-8', true)) {
$productKey = $productKeytest;
}
$username = trim(
self::$Host->get('ADUser')
);
if (strpos($username, chr(92))
|| strpos($username, chr(64))
) {
$adUser = $username;
} elseif ($username) {
$adUser = sprintf(
'%s\%s',
self::$Host->get('ADDomain'),
$username
);
} else {
$adUser = '';
}
$AD = (bool)self::$Host->get('useAD');
$enforce = (bool)self::$Host->get('enforce');
$hostname = self::$Host->get('name');
$ADDom = '';
$ADOU = '';
$ADUser = '';
$ADPass = '';
if ($AD === true) {
$ADDom = self::$Host->get('ADDomain');
$ADOU = str_replace(
';',
'',
self::$Host->get('ADOU')
);
$ADUser = $adUser;
$ADPass = $password;
}
self::$Host->setAD();
$val = array(
'enforce' => (bool)$enforce,
'hostname' => $hostname,
'AD' => (bool)$AD,
'ADDom' => $ADDom,
'ADOU' => $ADOU,
'ADUser' => $ADUser,
'ADPass' => $ADPass
);
if ($productKey) {
$val['Key'] = $productKey;
}
return $val;
}
/**
* Creates the send string and stores to send variable
*
* @return void
*/
public function send()
{
ob_start();
echo '#!ok';
$password = self::$Host->get('ADPassLegacy');
printf(
"=%s\n",
self::$Host->get('name')
);
self::$Host->setAD();
$username = trim(
self::$Host->get('ADUser')
);
if (strpos($username, chr(92))
|| strpos($username, chr(64))
) {
$adUser = $username;
} elseif ($username) {
$adUser = sprintf(
'%s\%s',
self::$Host->get('ADDomain'),
$username
);
} else {
$adUser = '';
}
$AD = (bool)self::$Host->get('useAD');
$hostname = self::$Host->get('name');
$ADDom = '';
$ADOU = '';
$ADUser = '';
$ADPass = '';
if ($AD === true) {
$AD = 1;
$ADDom = self::$Host->get('ADDomain');
$ADOU = str_replace(
';',
'',
self::$Host->get('ADOU')
);
$ADUser = $adUser;
$ADPass = $password;
}
self::$Host->setAD();
printf(
"#AD=%s\n#ADDom=%s\n#ADOU=%s\n#ADUser=%s\n#ADPass=%s",
$AD,
$ADDom,
$ADOU,
$ADUser,
$ADPass
);
$this->send = ob_get_clean();
}
}