-
Notifications
You must be signed in to change notification settings - Fork 0
/
whm.php
74 lines (54 loc) · 2.11 KB
/
whm.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
<?php
class WHM
{
public function getDomainData($domainName)
{
$argument = "domain=" . $domainName;
$domainuserdata = $this->call("domainuserdata", $argument);
return $domainuserdata;
}
public function getCsrData($csrInputData)
{
$argument = ' domains=' . urlencode($csrInputData->domainName)
. ' emailAddress=' . urlencode($csrInputData->emailAdd)
. ' countryName=' . urlencode($csrInputData->country)
. ' stateOrProvinceName=' . urlencode($csrInputData->state)
. ' localityName=' . urlencode($csrInputData->locality)
. ' organizationName=' . urlencode($csrInputData->org)
. ' unitName=' . urlencode($csrInputData->unit)
. ' keysize=' . 2048
. ' skip_certificate=' . 1;
$csrData = $this->call("generatessl", $argument);
return $csrData;
}
public function sslInstall($domain, $key, $certificate)
{
$argument = 'domain=' . urlencode($domain)
. ' crt=' . urlencode($certificate->cert)
. ' key=' . urlencode($key)
. ' cab=' . urlencode($certificate->caCert);
$sslInstall = $this->call("installssl", $argument);
echo "\nSSL Certificate Installed Successfully\n";
return $sslInstall;
}
function call($whmCommand, $whmParams)
{
$shellExecStr = "whmapi1 " . $whmCommand . " " . $whmParams
. " --output=json";
$output = shell_exec($shellExecStr);
$jsonoutput = json_decode($output);
$this->isValidApiCall($jsonoutput->metadata);
return $jsonoutput;
}
function isValidAPiCall($resultMetadata)
{
if ($resultMetadata->result == 0) {
echo "\nWHMAPI Call Failed\n";
echo "\t" . $resultMetadata->reason . "\n";
die("\nWHMAPI Failure\n");
}
if ($resultMetadata->result == 1) {
return true;
}
}
}