· 6 years ago · Jan 01, 2020, 04:42 PM
1<?php
2/**
3*
4* @ This file is created by http://DeZender.Net
5* @ deZender (PHP7 Decoder for ionCube Encoder)
6*
7* @ Version : 4.0.9.0
8* @ Author : DeZender
9* @ Release on : 08.08.2019
10* @ Official site : http://DeZender.Net
11*
12*/
13
14class HetznerCloudHelper
15{
16 static public function getLang()
17 {
18 $languageDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR;
19 $config = $GLOBALS['CONFIG'];
20 $language = (isset($_SESSION['Language']) ? $_SESSION['Language'] : $config['Language']);
21 $languageFile = (file_exists($languageDir . $language . '.php') ? $language : 'english');
22
23 if (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'english.php')) {
24 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'english.php';
25 }
26
27 require $languageDir . $languageFile . '.php';
28 return isset($_LANG) ? $_LANG : [];
29 }
30}
31
32function HetznerCloud_MetaData()
33{
34 return ['DisplayName' => 'Hetzner Cloud Automation', 'APIVersion' => '2019.5', 'ServiceSingleSignOnLabel' => 'Login to Panel as User', 'RequiresServer' => true];
35}
36
37function HetznerCloud_TestConnection($params)
38{
39 try {
40 $ServerID = $params['serveraccesshash'];
41 $ProJectID = $params['serverusername'];
42 $Api = Illuminate\Database\Capsule\Manager::table('mod_hcloud_project')->select('projectapikey')->where(['id' => $ProJectID])->get();
43 $HetznerCloud = new HetznerCloud($Api[0]->projectapikey);
44 $single = $HetznerCloud->serverGet($ServerID);
45
46 if ($single['server']['id'] == $ServerID) {
47 $success = true;
48 }
49 else {
50 $errorMsg = 'Server ID: ' . $ServerID . ' Not Found';
51 }
52 }
53 catch (Exception $e) {
54 logModuleCall('HetznerCloud', __FUNCTION__, $params, $e->getMessage(), $e->getTraceAsString());
55 $success = false;
56 $errorMsg = $e->getMessage();
57 }
58
59 return ['success' => $success, 'error' => $errorMsg];
60}
61
62function HetznerCloud_ConfigOptions()
63{
64 $ProjectID = Illuminate\Database\Capsule\Manager::table('mod_hcloud_project')->get();
65 $_LANG = HetznerCloudHelper::getLang();
66 $ProjectIDS = [];
67
68 foreach ($ProjectID as $HCloudProject) {
69 $ProjectIDS[$HCloudProject->id] = $HCloudProject->projectname;
70 }
71
72 $Api = Illuminate\Database\Capsule\Manager::table('mod_hcloud_project')->select('projectapikey')->where(['id' => $ProjectID[0]->id])->get();
73 $HetznerCloud = new HetznerCloud($Api[0]->projectapikey);
74 $ServerTypeGetAll = $HetznerCloud->ServerTypeGetAll();
75 $ServerType = [];
76
77 foreach ($ServerTypeGetAll['server_types'] as $ServerTypeAll) {
78 $ServerType[$ServerTypeAll['name']] = $ServerTypeAll['description'] . '( ' . $ServerTypeAll['cores'] . ' vCPU, ' . $ServerTypeAll['memory'] . ' GB RAM, ' . $ServerTypeAll['disk'] . ' GB HDD)';
79 }
80
81 $LocationGetAll = $HetznerCloud->LocationGetAll();
82 $Location = [];
83
84 foreach ($LocationGetAll['locations'] as $LocationAll) {
85 $Location[$LocationAll['name']] = $LocationAll['city'] . ' (' . $HetznerCloud->codeToCountryName($LocationAll['country']) . ')';
86 }
87
88 $LocationCustom = $HetznerCloud->LocationGetAll();
89 $LocationArray = [];
90
91 foreach ($LocationCustom['locations'] as $LocationCustomAll) {
92 array_push($LocationArray, $LocationCustomAll['name'] . '|' . $LocationCustomAll['city'] . ' (' . $HetznerCloud->codeToCountryName($LocationCustomAll['country']) . ')');
93 }
94
95 $ImagesGetAll = $HetznerCloud->ImagesGetTypes('system');
96 $OSImages = [];
97
98 foreach ($ImagesGetAll['images'] as $Images) {
99 array_push($OSImages, $Images['name'] . '|' . $Images['description']);
100 }
101
102 $LocCustomField = Illuminate\Database\Capsule\Manager::table('tblcustomfields')->select('relid')->where('fieldname', 'location|Location')->where('relid', $_REQUEST['id'])->get();
103 $LocCustomFieldID = $LocCustomField[0]->relid;
104
105 if (empty($LocCustomFieldID)) {
106 $HetznerCloud->HCloud_Insert('tblcustomfields', ['type' => 'product', 'relid' => $_REQUEST['id'], 'fieldname' => 'location|Location', 'fieldtype' => 'dropdown', 'description' => 'Select your Server Location', 'fieldoptions' => implode(',', $LocationArray), 'adminonly' => '', 'required' => 'on', 'showorder' => 'on']);
107 }
108
109 $CustomField = Illuminate\Database\Capsule\Manager::table('tblcustomfields')->select('relid')->where('fieldname', 'os|Operating System')->where('relid', $_REQUEST['id'])->get();
110 $CustomFieldID = $CustomField[0]->relid;
111
112 if (empty($CustomFieldID)) {
113 $HetznerCloud->HCloud_Insert('tblcustomfields', ['type' => 'product', 'relid' => $_REQUEST['id'], 'fieldname' => 'os|Operating System', 'fieldtype' => 'dropdown', 'description' => 'Select your Cloud VM Image', 'fieldoptions' => implode(',', $OSImages), 'adminonly' => '', 'required' => 'on', 'showorder' => 'on']);
114 }
115
116 $CustomFieldSSH = Illuminate\Database\Capsule\Manager::table('tblcustomfields')->select('relid')->where('fieldname', 'ssh_key|SSH Public Key')->where('relid', $_REQUEST['id'])->get();
117 $CustomFieldSSHID = $CustomFieldSSH[0]->relid;
118
119 if (empty($CustomFieldSSHID)) {
120 $HetznerCloud->HCloud_Insert('tblcustomfields', ['type' => 'product', 'relid' => $_REQUEST['id'], 'fieldname' => 'ssh_key|SSH Public Key', 'fieldtype' => 'textarea', 'description' => 'If you want to login into the Cloud VM without password, then you need to enter your public key generated from OpenSSH or ssh-keygen (e.g: ssh-rsa)', 'adminonly' => '', 'required' => '', 'showorder' => 'on']);
121 }
122
123 $CustomFieldUD = Illuminate\Database\Capsule\Manager::table('tblcustomfields')->select('relid')->where('fieldname', 'user_data|Custom Script')->where('relid', $_REQUEST['id'])->get();
124 $CustomFieldUDID = $CustomFieldUD[0]->relid;
125
126 if (empty($CustomFieldUDID)) {
127 $HetznerCloud->HCloud_Insert('tblcustomfields', ['type' => 'product', 'relid' => $_REQUEST['id'], 'fieldname' => 'user_data|Custom Script', 'fieldtype' => 'textarea', 'description' => 'Cloud-Init user data to use during server creation. This field is limited to 32KiB.', 'adminonly' => '', 'required' => '', 'showorder' => 'on']);
128 }
129
130 return [
131 'Project ID' => ['Type' => 'dropdown', 'Options' => $ProjectIDS, 'Description' => $_LANG['ConfigOptions']['ProjectID']],
132 'Plan Name' => ['Type' => 'dropdown', 'Options' => $ServerType, 'Description' => $_LANG['ConfigOptions']['Plan']],
133 'Server Location' => ['Type' => 'dropdown', 'Options' => $Location, 'Description' => $_LANG['ConfigOptions']['Location']],
134 'OS Installation' => ['Type' => 'yesno', 'Description' => $_LANG['ConfigOptions']['OS']],
135 'Rescue Mode' => ['Type' => 'yesno', 'Description' => $_LANG['ConfigOptions']['Rescue']],
136 'Protection' => ['Type' => 'yesno', 'Description' => $_LANG['ConfigOptions']['Protection']],
137 'Password Change' => ['Type' => 'yesno', 'Description' => $_LANG['ConfigOptions']['Password']],
138 'Console Access' => ['Type' => 'yesno', 'Description' => $_LANG['ConfigOptions']['noVNC']],
139 'ISO Images' => ['Type' => 'yesno', 'Description' => $_LANG['ConfigOptions']['ISO']]
140 ];
141}
142
143function HetznerCloud_CreateAccount($params)
144{
145 if (($params['status'] != 'Pending') && ($params['status'] != 'Terminated')) {
146 return 'Cannot create service.';
147 }
148
149 try {
150 $HCloudLicense = new HetznerCloudLicense();
151
152 if ($HCloudLicense->HetznerCloud_LicenseCheck() == 'Active') {
153 $_LANG = HetznerCloudHelper::getLang();
154
155 if ($params['serveraccesshash']) {
156 $result = $_LANG['Server_Exist'];
157 }
158 else {
159 $ProJectID = $params['configoption1'];
160 $name = $params['domain'];
161 $servertype = $params['configoption2'];
162...............................................................................
163.................................................
164........................