-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphyre.php
More file actions
263 lines (218 loc) · 11 KB
/
phyre.php
File metadata and controls
263 lines (218 loc) · 11 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
include_once __DIR__ . '/src/PhyreApi.php';
//include __DIR__ . '/hooks.php';
include __DIR__ . '/../../../lang/english.php';
if (!isset($_LANG['Phyre'])) {
$phyreLangContent = file_get_contents(__DIR__ . '/lang/english.php');
$phyreLangContent = str_replace('<?php', '', $phyreLangContent);
$oldLangFileContent = file_get_contents(__DIR__ . '/../../../lang/english.php');
$newLangFileContent = $oldLangFileContent . "\n\n" . $phyreLangContent;
// backup original lang file
file_put_contents(__DIR__ . '/../../../lang/english.php.bak', $oldLangFileContent);
file_put_contents(__DIR__ . '/../../../lang/english.php', $newLangFileContent);
}
function phyre_MetaData()
{
return array("DisplayName" => "Phyre", "APIVersion" => "1.1", "ListAccountsUniqueIdentifierDisplayName" => "Domain", "ListAccountsUniqueIdentifierField" => "domain", "ListAccountsProductField" => "configoption1");
}
function phyre_TestConnection($params)
{
$phyreApi = new PhyreApi($params['serverip']);
$phyreApi->setCredentials($params["serverusername"], $params["serverpassword"]);
$getHostingPlans = $phyreApi->request('hosting-plans');
if (isset($getHostingPlans['data']['hostingPlans'])) {
return array("success" => true);
}
return array("error" => true);
}
function phyre_ListAccounts(array $params)
{
$accounts = array();
return array("success" => true, "accounts" => $accounts);
}
function phyre_CreateAccount($params)
{
$phyreApi = new PhyreApi($params['serverip']);
$phyreApi->setCredentials($params["serverusername"], $params["serverpassword"]);
$phyreCustomerId = null;
// Find Phyre customer by email
$phyreCustomers = $phyreApi->request('customers');
if (isset($phyreCustomers['data']['customers'])) {
foreach ($phyreCustomers['data']['customers'] as $phyreCustomer) {
if ($phyreCustomer['email'] == $params['clientsdetails']['email']) {
$phyreCustomerId = $phyreCustomer['id'];
}
}
}
// Create Phyre customer if not found
if (!$phyreCustomerId) {
$createCustomer = $phyreApi->request('customers', [
'name' => $params['clientsdetails']['firstname'] . ' ' . $params['clientsdetails']['lastname'],
'email' => $params['clientsdetails']['email'],
], 'POST');
if (isset($createCustomer['data']['customer'])) {
$phyreCustomerId = $createCustomer['data']['customer']['id'];
}
}
$hostingPlanId = 0;
if (isset($params['configoption1'])) {
$hostingPlanId = $params['configoption1'];
}
$hostingSubscriptionRequestData = [
'customer_id' => $phyreCustomerId,
'hosting_plan_id' => $hostingPlanId,
'domain' => $params['domain'],
'system_username' => $params['username'],
'system_password' => $params['password'],
];
$createHostingSubscription = $phyreApi->request('hosting-subscriptions', $hostingSubscriptionRequestData, 'POST');
if (isset($createHostingSubscription['status']) && $createHostingSubscription['status'] == 'ok') {
return "success";
}
if (isset($createHostingSubscription['status']) && $createHostingSubscription['status'] == 'error') {
return $createHostingSubscription['message'];
}
return "error";
}
function phyre_TerminateAccount($params)
{
try {
$phyreApi = new PhyreApi($params['serverip']);
$phyreApi->setCredentials($params["serverusername"], $params["serverpassword"]);
$hostingSubscriptionId = null;
$getHostingSubscriptions = $phyreApi->request('hosting-subscriptions',[]);
if (isset($getHostingSubscriptions['data']['hostingSubscriptions'])) {
foreach ($getHostingSubscriptions['data']['hostingSubscriptions'] as $hostingSubscription) {
if ($hostingSubscription['domain'] == $params['domain']) {
$hostingSubscriptionId = $hostingSubscription['id'];
}
}
}
if (!$hostingSubscriptionId) {
return "Hosting subscription not found";
}
$deleteHostingSubscriptions = $phyreApi->request('hosting-subscriptions/'.$hostingSubscriptionId,[], 'DELETE');
if ($deleteHostingSubscriptions) {
return "success";
}
} catch (\Exception $e) {
return $e->getMessage();
}
return "error";
}
function phyre_ChangePassword($params)
{
return "error";
}
function phyre_SuspendAccount($params)
{
try {
$phyreApi = new PhyreApi($params['serverip']);
$phyreApi->setCredentials($params["serverusername"], $params["serverpassword"]);
$hostingSubscriptionId = null;
$getHostingSubscriptions = $phyreApi->request('hosting-subscriptions',[]);
if (isset($getHostingSubscriptions['data']['hostingSubscriptions'])) {
foreach ($getHostingSubscriptions['data']['hostingSubscriptions'] as $hostingSubscription) {
if ($hostingSubscription['domain'] == $params['domain']) {
$hostingSubscriptionId = $hostingSubscription['id'];
}
}
}
if (!$hostingSubscriptionId) {
return "Hosting subscription not found";
}
$deleteHostingSubscriptions = $phyreApi->request('hosting-subscriptions/'.$hostingSubscriptionId.'/suspend',[], 'POST');
if ($deleteHostingSubscriptions) {
return "success";
}
} catch (\Exception $e) {
return $e->getMessage();
}
return "error";
}
function phyre_UnsuspendAccount($params)
{
try {
$phyreApi = new PhyreApi($params['serverip']);
$phyreApi->setCredentials($params["serverusername"], $params["serverpassword"]);
$hostingSubscriptionId = null;
$getHostingSubscriptions = $phyreApi->request('hosting-subscriptions',[]);
if (isset($getHostingSubscriptions['data']['hostingSubscriptions'])) {
foreach ($getHostingSubscriptions['data']['hostingSubscriptions'] as $hostingSubscription) {
if ($hostingSubscription['domain'] == $params['domain']) {
$hostingSubscriptionId = $hostingSubscription['id'];
}
}
}
if (!$hostingSubscriptionId) {
return "Hosting subscription not found";
}
$deleteHostingSubscriptions = $phyreApi->request('hosting-subscriptions/'.$hostingSubscriptionId.'/unsuspend',[], 'POST');
if ($deleteHostingSubscriptions) {
return "success";
}
} catch (\Exception $e) {
return $e->getMessage();
}
return "error";
}
function phyre_ChangePackage($params)
{
return "success";
}
function phyre_GetUserCount(array $params)
{
$totalCount = 111;
$ownedAccounts = array();
return array("success" => true, "totalAccounts" => $totalCount, "ownedAccounts" => $ownedAccounts);
}
function phyre_ConfigOptions(array $params)
{
$resellerSimpleMode = $params["producttype"] == "reselleraccount";
return array("Phyre Hosting Plan" => array("Type" => "text", "Size" => "25", "Loader" => "phyre_ListHostingPlans", "SimpleMode" => true), "Max FTP Accounts" => array("Type" => "text", "Size" => "5"), "Web Space Quota" => array("Type" => "text", "Size" => "5", "Description" => "MB"), "Max Email Accounts" => array("Type" => "text", "Size" => "5"), "Bandwidth Limit" => array("Type" => "text", "Size" => "5", "Description" => "MB"), "Dedicated IP" => array("Type" => "yesno"), "Shell Access" => array("Type" => "yesno", "Description" => "Tick to grant access"), "Max SQL Databases" => array("Type" => "text", "Size" => "5"), "CGI Access" => array("Type" => "yesno", "Description" => "Tick to grant access"), "Max Subdomains" => array("Type" => "text", "Size" => "5"), "Frontpage Extensions" => array("Type" => "yesno", "Description" => "Tick to grant access"), "Max Parked Domains" => array("Type" => "text", "Size" => "5"), "Phyre Theme" => array("Type" => "text", "Size" => "15"), "Max Addon Domains" => array("Type" => "text", "Size" => "5"), "Limit Reseller by Number" => array("Type" => "text", "Size" => "5", "Description" => "Enter max number of allowed accounts"), "Limit Reseller by Usage" => array("Type" => "yesno", "Description" => "Tick to limit by resource usage"), "Reseller Disk Space" => array("Type" => "text", "Size" => "7", "Description" => "MB", "SimpleMode" => $resellerSimpleMode), "Reseller Bandwidth" => array("Type" => "text", "Size" => "7", "Description" => "MB", "SimpleMode" => $resellerSimpleMode), "Allow DS Overselling" => array("Type" => "yesno", "Description" => "MB"), "Allow BW Overselling" => array("Type" => "yesno", "Description" => "MB"), "Reseller ACL List" => array("Type" => "text", "Size" => "20", "SimpleMode" => $resellerSimpleMode), "Add Prefix to Package" => array("Type" => "yesno", "Description" => "Add username_ to package name"), "Configure Nameservers" => array("Type" => "yesno", "Description" => "Setup Custom ns1/ns2 Nameservers"), "Reseller Ownership" => array("Type" => "yesno", "Description" => "Set the reseller to own their own account"));
}
function phyre_ListHostingPlans(array $params, $removeUsername = true)
{
$phyreApi = new PhyreApi($params['serverip']);
$phyreApi->setCredentials($params["serverusername"], $params["serverpassword"]);
$getHostingPlans = $phyreApi->request('hosting-plans');
if (isset($getHostingPlans['data']['hostingPlans'])) {
$hostingPlans = [];
foreach ($getHostingPlans['data']['hostingPlans'] as $hostingPlan) {
$hostingPlans[$hostingPlan['id']] = $hostingPlan['name'];
}
return $hostingPlans;
}
return [];
}
function phyre_ClientArea($params)
{
return array("overrideDisplayTitle" => ucfirst($params["domain"]), "tabOverviewReplacementTemplate" => "overview.tpl", "tabOverviewModuleOutputTemplate" => "loginbuttons.tpl");
}
function phyre_ServiceSingleSignOn(array $params) {
$phyreApi = new PhyreApi($params['serverip']);
$phyreApi->setCredentials($params["serverusername"], $params["serverpassword"]);
$customerId = null;
$hostingSubscriptionId = null;
$getHostingSubscriptions = $phyreApi->request('hosting-subscriptions',[]);
if (isset($getHostingSubscriptions['data']['hostingSubscriptions'])) {
foreach ($getHostingSubscriptions['data']['hostingSubscriptions'] as $hostingSubscription) {
if ($hostingSubscription['domain'] == $params['domain']) {
$hostingSubscriptionId = $hostingSubscription['id'];
$customerId = $hostingSubscription['customer_id'];
}
}
}
if (!$customerId) {
return "Customer not found";
}
if (!$hostingSubscriptionId) {
return "Hosting subscription not found";
}
$hostingSubscriptionId = null;
$generateLoginTokenRequest = $phyreApi->request('customers/'.$customerId.'/generate-login-token',[]);
if (isset($generateLoginTokenRequest['data']['token'])) {
header('Location: http://' . $params['serverip'].':8443/customers/'.$customerId.'/login-with-token?token='.$generateLoginTokenRequest['data']['token']);
return;
}
}