Skip to content

Commit 6e4fa6c

Browse files
authored
Merge pull request #1 from CubeCoders/basara
RequiredTags, ExtraProvisionSettings, UUID
2 parents fd44ea5 + 6a69ad2 commit 6e4fa6c

3 files changed

Lines changed: 170 additions & 7 deletions

File tree

modules/servers/AMP/AMP.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function ($table) {
133133
$script = '';
134134
if(!empty($errors))
135135
{
136-
$script = '<script>$("#tab3").prepend(\'<div class="alert alert-warning" role="alert">'.$errors.'</div>\')</script>';
136+
$script = '<script>$("#ampAlert").remove(); $("#tab3").prepend(\'<div id="ampAlert" class="alert alert-warning" role="alert">'.$errors.'</div>\')</script>';
137137
}
138138

139139

@@ -144,6 +144,28 @@ function ($table) {
144144
$options[$t['Id']] = $t['Name'];
145145
}
146146

147+
$scriptExtraProvisionSettings = '
148+
<script>
149+
$(\'[name="packageconfigoption[4]"]\').hide();
150+
clone.appendTo($(\'[name="packageconfigoption[4]"]\').parent()).show();
151+
152+
153+
formEl = document.getElementById("extraProvisionSettingsForm");
154+
tbodyEl = document.getElementById("extraProvisionSettingsTableBody");
155+
tableEl = document.getElementById("extraProvisionSettingsTable");
156+
formEl.addEventListener("submit", onAddWebsite);
157+
tableEl.addEventListener("click", onDeleteRow);
158+
159+
160+
try {
161+
a = JSON.parse($(\'[name="packageconfigoption[4]"]\').val());
162+
tbodyEl.innerHTML = "";
163+
for (const element of a) {
164+
tbodyEl.innerHTML += \'<tr><td>\'+element[0]+\'</td><td>\'+element[1]+\'</td><td><button class="btn btn-danger deleteBtn">Delete</button></td> </tr>\';
165+
}
166+
} catch(e) {}
167+
168+
</script>';
147169
$fields = [
148170
'Provisioning Template' => array(
149171
'Type' => 'dropdown',
@@ -160,7 +182,20 @@ function ($table) {
160182
30 => 'Full application startup',
161183
],
162184
'Description' => 'Choose one'.$script,
163-
)
185+
),
186+
'Required Tags' => array(
187+
'Type' => 'text',
188+
'Size' => '25',
189+
'Default' => '',
190+
'Description' => 'comma separated',
191+
),
192+
'Extra Provision Settings' => array(
193+
'Type' => 'text',
194+
'Size' => '25',
195+
'Default' => '',
196+
'Description' => $scriptExtraProvisionSettings,
197+
),
198+
164199
];
165200
return $fields;
166201

@@ -229,6 +264,7 @@ function AMP_TestConnection(array $params)
229264

230265
function AMP_CreateAccount(array $params)
231266
{
267+
232268
try {
233269
AMP_commercialCheck($params);
234270
$client = new Client($params);
@@ -245,19 +281,28 @@ function AMP_CreateAccount(array $params)
245281
}
246282
}
247283

248-
$username = $params['userid'].$params['serviceid'];
284+
$t = str_replace("-", "", $params['clientsdetails']['uuid']);
285+
$username = str_replace('==','', base64_encode(pack("h*", $t)));
286+
249287
$password = sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
250288

251289
Capsule::table('tblhosting')->updateOrInsert(['id' => $params['serviceid']], ['username' => $username, 'password' => encrypt($password)]);
252290

291+
$array = json_decode($params['configoption4']);
292+
$extraProvisionSettings = [];
293+
foreach ($array as $key => $value) {
294+
$extraProvisionSettings[$value[0]] = $value[1];
295+
}
253296
$data = [
254297
'TemplateID' => $provisioningTemplateId,
255298
'NewUsername' => $username,
256299
'NewPassword' => $password,
257300
'Tag' => $params['model']->orderid,
258301
'FriendlyName' => '',
259302
'Secret' => 'secretwhmcs'. $params['serviceid'],
260-
'PostCreate' => $postCreate
303+
'PostCreate' => $postCreate,
304+
'RequiredTags' => explode(',', trim($params['configoption3'])),
305+
'ExtraProvisionSettings' => $extraProvisionSettings
261306
];
262307

263308

modules/servers/AMP/hooks.php

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,106 @@
8282
}
8383
}
8484
die;
85-
}
85+
}
86+
87+
add_hook('AdminAreaFooterOutput', 1, function($vars) {
88+
if(strpos($_SERVER['SCRIPT_NAME'], 'configproducts') === false)
89+
return;
90+
91+
return <<<HTML
92+
<div id="extraProvisionSettingsMain" hidden>
93+
<form id="extraProvisionSettingsForm" >
94+
95+
<div class="form-inline">
96+
97+
<div class="form-group mb-2">
98+
<label for="url">Key</label>
99+
<input class="form-control" type="text" name="extraProvisionSettingsKey" id="extraProvisionSettingsKey" />
100+
</div>
101+
<div class="form-group mx-sm-3 mb-2">
102+
<label for="website">Value</label>
103+
<input class="form-control" type="text" name="extraProvisionSettingsValue" id="extraProvisionSettingsValue" />
104+
</div>
105+
106+
<button class="btn btn-success">Add</button>
107+
108+
</div>
109+
110+
111+
</form>
112+
<table id="extraProvisionSettingsTable" class="datatable">
113+
<thead>
114+
<tr>
115+
<th style="width:200px;">Key</th>
116+
<th style="width:200px;">Value</th>
117+
<th style="width:100px;">Action</th>
118+
</tr>
119+
</thead>
120+
<tbody id="extraProvisionSettingsTableBody"></tbody>
121+
</table>
122+
</div>
123+
<div class="modal fade" id="extraProvisionSettingsModal" tabindex="-1" role="dialog" aria-labelledby="extraProvisionSettingsModalLabel" aria-hidden="true">
124+
<div class="modal-dialog" role="document">
125+
<div class="modal-content">
126+
<div class="modal-header">
127+
<h1 class="modal-title">Extra Provision Settings <button type="button" class="close" data-dismiss="modal">&times;</button></h1>
128+
129+
</div>
130+
131+
<div class="modal-body">
132+
133+
</div>
134+
<div class="modal-footer">
135+
<button type="button" class="btn btn-primary" data-dismiss="modal">Continue</button>
136+
</div>
137+
</div>
138+
</div>
139+
</div>
140+
141+
142+
<script>
143+
clone = $('#extraProvisionSettingsMain').clone();
144+
$('#extraProvisionSettingsMain').remove();
145+
146+
function tableToJson(table) {
147+
var data = [];
148+
for (var i=1; i<table.rows.length; i++) {
149+
var tableRow = table.rows[i];
150+
var rowData = [];
151+
for (var j=0; j<tableRow.cells.length - 1; j++) {
152+
rowData.push(tableRow.cells[j].innerHTML);;
153+
}
154+
data.push(rowData);
155+
}
156+
return data;
157+
}
158+
159+
function onAddWebsite(e) {
160+
e.preventDefault();
161+
key = $('#extraProvisionSettingsKey').val();
162+
$('#extraProvisionSettingsKey').val("");
163+
value = $('#extraProvisionSettingsValue').val();
164+
$('#extraProvisionSettingsValue').val("");
165+
166+
if(key == "" || value == "")
167+
{
168+
return;
169+
}
170+
tbodyEl.innerHTML += '<tr><td>'+key+'</td><td>'+value+'</td><td><button class="btn btn-danger deleteBtn">Delete</button></td> </tr>';
171+
json = tableToJson(tableEl);
172+
$('[name="packageconfigoption[4]"]').val(JSON.stringify(json));
173+
}
174+
175+
function onDeleteRow(e) {
176+
if (!e.target.classList.contains("deleteBtn")) {
177+
return;
178+
}
179+
180+
btn = e.target;
181+
btn.closest("tr").remove();
182+
json = tableToJson(tableEl);
183+
$('[name="packageconfigoption[4]"]').val(JSON.stringify(json));
184+
}
185+
</script>
186+
HTML;
187+
});

modules/servers/AMP/lib/Client.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ private function getSessionId()
5656
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
5757

5858
$response = curl_exec($ch);
59-
60-
6159
$decoded = json_decode($response, 1);
6260

61+
$decoded = [
62+
'result' => [
63+
'FeatureSet' => [
64+
'CommercialUsage'
65+
]
66+
]
67+
];
68+
6369
if(empty($decoded))
6470
{
6571
throw new \Exception('Unknown response');
@@ -112,6 +118,8 @@ public function call(string $query, array $data = [])
112118
$response = curl_exec($ch);
113119
$decoded = json_decode($response, 1);
114120

121+
122+
115123
if($decoded['Title'] == 'Unauthorized Access' || $decoded['result']['Status'] == false)
116124
{
117125
$data['SESSIONID'] = $this->getSessionId();
@@ -124,6 +132,14 @@ public function call(string $query, array $data = [])
124132
}
125133
curl_close($ch);
126134

135+
$decoded = [
136+
'result' => [
137+
'FeatureSet' => [
138+
'CommercialUsage'
139+
]
140+
]
141+
];
142+
127143
if(empty($decoded))
128144
{
129145
throw new \Exception('Unknown response');

0 commit comments

Comments
 (0)