├── Gateways ├── LitePay │ ├── index.php │ ├── litepay.php │ └── routes.php ├── Mollie │ ├── README.md │ ├── index.php │ └── routes.php ├── PayPal │ ├── index.php │ └── routes.php ├── PayPal_IPN │ ├── README.md │ ├── index.php │ └── routes.php ├── PayU │ ├── README.md │ ├── index.php │ └── routes.php ├── Stripe │ ├── index.php │ └── routes.php ├── StripeSofort │ ├── index.php │ ├── readme.md │ └── routes.php └── Xendit │ ├── index.php │ └── routes.php ├── LICENSE ├── README.md └── Servers ├── CyberPanel └── index.php ├── DirectAdmin ├── httpsocket.php └── index.php ├── ISPConfig ├── ISPConfigWS.php └── index.php ├── Plesk └── index.php ├── Proxmox ├── index.php ├── routes.php └── views │ ├── control.blade.php │ ├── settings.blade.php │ ├── stats.blade.php │ └── vnc.blade.php ├── Pterodactyl └── index.php ├── VirtFusion ├── index.php └── views │ └── control.blade.php └── Virtualizor ├── index.php └── sdk.php /Gateways/LitePay/index.php: -------------------------------------------------------------------------------- 1 | 'secret', 11 | 'friendlyName' => 'Secret', 12 | 'type' => 'text', 13 | 'required' => true, 14 | ], 15 | [ 16 | 'name' => 'merchant_id', 17 | 'friendlyName' => 'VENDOR ID', 18 | 'type' => 'text', 19 | 'required' => true, 20 | ], 21 | ]; 22 | } 23 | 24 | function LitePay_pay($total, $products, $invoiceId) 25 | { 26 | include_once __DIR__ . '/litepay.php'; 27 | 28 | $litepay = new litepay('merchant'); 29 | $req = $litepay->__call('pay', [[ 30 | 'vendor' => ExtensionHelper::getConfig('LitePay', 'merchant_id'), 31 | 'secret' => ExtensionHelper::getConfig('LitePay', 'secret'), 32 | 'invoice' => $invoiceId, 33 | 'price' => $total, 34 | 'currency' => ExtensionHelper::getCurrency(), 35 | 'callbackUrl' => url('/extensions/litepay/webhook') . '?invoiceId=' . $invoiceId . '&secret=' . ExtensionHelper::getConfig('LitePay', 'secret'), 36 | 'returnUrl' => route('clients.invoice.show', $invoiceId), 37 | ]]); 38 | 39 | return $req->url; 40 | } 41 | 42 | function LitePay_webhook(Request $request) 43 | { 44 | $input = $request->all(); 45 | $invoiceId = $input['invoiceId']; 46 | $secret = $input['secret']; 47 | if (!isset($invoiceId) || !isset($secret)) 48 | return; 49 | if ($secret !== ExtensionHelper::getConfig('LitePay', 'secret')) 50 | return; 51 | ExtensionHelper::paymentDone($invoiceId); 52 | 53 | // Return *ok* 54 | return response('*ok*'); 55 | } 56 | -------------------------------------------------------------------------------- /Gateways/LitePay/litepay.php: -------------------------------------------------------------------------------- 1 | type = $type; 19 | } 20 | 21 | public function __call($name, array $args) 22 | { // method_missing for PHP 23 | 24 | $response = ""; 25 | 26 | if (empty($args)) { 27 | $args = array(); 28 | } else { 29 | $args = $args[0]; 30 | } 31 | 32 | if ($this->type == 'merchant') { 33 | $response = $this->_request('p/', $args, 'POST'); 34 | } elseif ($this->type == 'api') { 35 | $response = $this->_request('api/' . $name, $args, 'GET'); 36 | } else { 37 | $response = $this->_request($name, $args); 38 | } 39 | 40 | return $response; 41 | } 42 | 43 | /** 44 | * cURL GET request driver 45 | */ 46 | private function _request($path, $args = array(), $method = 'GET') 47 | { 48 | // Generate cURL URL 49 | $url = 'https://litepay.ch/' . $path; 50 | $addedData = http_build_query($args); 51 | 52 | // Initiate cURL and set headers/options 53 | $ch = curl_init(); 54 | 55 | // If we run windows, make sure the needed pem file is used 56 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 57 | $pemfile = dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . 'cacert.pem'; 58 | if (!file_exists($pemfile)) { 59 | throw new Exception("Needed .pem file not found. Please download the .pem file at http://curl.haxx.se/ca/cacert.pem and save it as " . $pemfile); 60 | } 61 | curl_setopt($ch, CURLOPT_CAINFO, $pemfile); 62 | } 63 | 64 | // it's a GET method 65 | if ($method == 'GET') { 66 | $url .= '?' . $addedData; 67 | } 68 | 69 | curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1'); // enforce use of TLSv1 70 | curl_setopt($ch, CURLOPT_URL, $url); 71 | 72 | if ($method == 'POST') { // this is a POST method 73 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 74 | curl_setopt($ch, CURLOPT_POST, 1); 75 | curl_setopt($ch, CURLOPT_POSTFIELDS, $addedData); 76 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 77 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 78 | curl_setopt($ch, CURLOPT_TIMEOUT, 100); 79 | } 80 | 81 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 82 | 83 | // Execute the cURL request 84 | $result = curl_exec($ch); 85 | curl_close($ch); 86 | 87 | $json_result = json_decode($result); 88 | 89 | if ($json_result->status != 'success') { 90 | throw new Exception('Failed: ' . $json_result->message); 91 | } 92 | 93 | // Spit back the response object or fail 94 | return $result ? $json_result : false; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Gateways/LitePay/routes.php: -------------------------------------------------------------------------------- 1 | name . ' x' . $product->quantity . ', '; 13 | } 14 | $response = Http::withHeaders([ 15 | 'Content-Type' => 'application/json', 16 | 'Authorization' => 'Bearer ' . $client_id, 17 | ])->post($url, [ 18 | 'amount' => [ 19 | 'currency' => ExtensionHelper::getCurrency(), 20 | 'value' => number_format($total, 2, '.', ''), 21 | ], 22 | 'description' => $description, 23 | 'redirectUrl' => route('clients.invoice.show', $orderId), 24 | 'webhookUrl' => url('/extensions/mollie/webhook'), 25 | 'metadata' => [ 26 | 'order_id' => $orderId, 27 | ], 28 | ]); 29 | 30 | return $response->json()['_links']['checkout']['href']; 31 | } 32 | 33 | function Mollie_webhook($request) 34 | { 35 | $url = 'https://api.mollie.com/v2/payments/' . $request->id; 36 | $client_id = ExtensionHelper::getConfig('Mollie', 'api_key'); 37 | $response = Http::withHeaders([ 38 | 'Content-Type' => 'application/json', 39 | 'Authorization' => 'Bearer ' . $client_id, 40 | ])->get($url); 41 | if ($response->json()['status'] == 'paid') { 42 | $orderId = $response->json()['metadata']['order_id']; 43 | ExtensionHelper::paymentDone($orderId); 44 | } 45 | 46 | return $response->json(); 47 | } 48 | 49 | function Mollie_getConfig() 50 | { 51 | return [ 52 | [ 53 | 'name' => 'api_key', 54 | 'friendlyName' => 'API Key', 55 | 'type' => 'text', 56 | 'required' => true, 57 | ], 58 | ]; 59 | } 60 | -------------------------------------------------------------------------------- /Gateways/Mollie/routes.php: -------------------------------------------------------------------------------- 1 | 'application/x-www-form-urlencoded', 19 | 'Authorization' => 'Basic ' . base64_encode($client_id . ':' . $client_secret), 20 | ])->asForm()->post($url . '/v1/oauth2/token', [ 21 | 'grant_type' => 'client_credentials', 22 | ]); 23 | 24 | $token = $response->json()['access_token']; 25 | $response = Http::withHeaders([ 26 | 'Content-Type' => 'application/json', 27 | 'Authorization' => 'Bearer ' . $token, 28 | ])->post($url . '/v2/checkout/orders', [ 29 | 'intent' => 'CAPTURE', 30 | 'purchase_units' => [ 31 | [ 32 | 'reference_id' => $orderId, 33 | 'amount' => [ 34 | 'currency_code' => ExtensionHelper::getCurrency(), 35 | 'value' => round($total, 2) 36 | ], 37 | ], 38 | ], 39 | 'application_context' => [ 40 | 'cancel_url' => route('clients.invoice.show', $orderId), 41 | 'return_url' => route('clients.invoice.show', $orderId), 42 | 'brand_name' => config('app.name', 'Paymenter'), 43 | 'shipping_preference' => 'NO_SHIPPING', 44 | ], 45 | ]); 46 | 47 | if($response->failed()) { 48 | ExtensionHelper::error('PayPal', $response->json()); 49 | } 50 | 51 | return $response->json()['links'][1]['href']; 52 | } 53 | 54 | function PayPal_webhook($request) 55 | { 56 | $body = $request->getContent(); 57 | $sigString = $request->header('PAYPAL-TRANSMISSION-ID') . '|' . $request->header('PAYPAL-TRANSMISSION-TIME') . '|' . ExtensionHelper::getConfig('PayPal', 'webhookId') . '|' . crc32($body); 58 | $pubKey = openssl_pkey_get_public(file_get_contents($request->header('PAYPAL-CERT-URL'))); 59 | $details = openssl_pkey_get_details($pubKey); 60 | $verifyResult = openssl_verify( 61 | $sigString, 62 | base64_decode( 63 | $request->header('PAYPAL-TRANSMISSION-SIG') 64 | ), 65 | $details['key'], 66 | 'sha256WithRSAEncryption' 67 | ); 68 | if ($verifyResult === 1) { 69 | $data = json_decode($body, true); 70 | if ($data['event_type'] == 'CHECKOUT.ORDER.APPROVED') { 71 | $orderId = $data['resource']['purchase_units'][0]['reference_id']; 72 | ExtensionHelper::paymentDone($orderId); 73 | } 74 | } 75 | } 76 | 77 | function PayPal_getConfig() 78 | { 79 | return [ 80 | [ 81 | 'name' => 'client_id', 82 | 'type' => 'text', 83 | 'friendlyName' => 'Client ID', 84 | 'required' => true, 85 | ], 86 | [ 87 | 'name' => 'client_secret', 88 | 'type' => 'text', 89 | 'friendlyName' => 'Client Secret', 90 | 'required' => true, 91 | ], 92 | [ 93 | 'name' => 'live', 94 | 'type' => 'boolean', 95 | 'friendlyName' => 'Live mode', 96 | 'required' => false, 97 | ], 98 | [ 99 | 'name' => 'webhookId', 100 | 'type' => 'text', 101 | 'friendlyName' => 'Webhook ID', 102 | 'required' => true, 103 | ], 104 | ]; 105 | } 106 | -------------------------------------------------------------------------------- /Gateways/PayPal/routes.php: -------------------------------------------------------------------------------- 1 | Payment Gateways` and click on the `PayPal_IPN` gateway. Enter your email address and press `Save`. 10 | 11 | ## Usage 12 | When a user selects the `PayPal_IPN` gateway, they will be redirected to the PayPal payment page. After the payment is completed, the user will be redirected back to the site. 13 | -------------------------------------------------------------------------------- /Gateways/PayPal_IPN/index.php: -------------------------------------------------------------------------------- 1 | [ 41 | 'type' => 'text', 42 | 'name' => 'paypal_email', 43 | 'friendlyName' => 'PayPal Email', 44 | 'description' => 'Your PayPal email address', 45 | 'required' => true, 46 | ], 47 | 'live' => [ 48 | 'type' => 'boolean', 49 | 'name' => 'live', 50 | 'friendlyName' => 'Live', 51 | 'description' => 'Check this box if you want to use the live PayPal API', 52 | 'required' => false, 53 | ], 54 | ]; 55 | } 56 | 57 | function PayPal_IPN_webhook($request) 58 | { 59 | $raw_post_data = file_get_contents('php://input'); 60 | $raw_post_array = explode('&', $raw_post_data); 61 | $myPost = []; 62 | foreach ($raw_post_array as $keyval) { 63 | $keyval = explode('=', $keyval); 64 | if (count($keyval) == 2) { 65 | $myPost[$keyval[0]] = urldecode($keyval[1]); 66 | } 67 | } 68 | $req = 'cmd=_notify-validate'; 69 | foreach ($myPost as $key => $value) { 70 | $value = urlencode($value); 71 | 72 | $req .= "&$key=$value"; 73 | } 74 | 75 | if (ExtensionHelper::getConfig('PayPal_IPN', 'live')) { 76 | $ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr'); 77 | } else { 78 | $ch = curl_init('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'); 79 | } 80 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 81 | curl_setopt($ch, CURLOPT_POST, 1); 82 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 83 | curl_setopt($ch, CURLOPT_POSTFIELDS, $req); 84 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 85 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 86 | curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); 87 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']); 88 | if (!($res = curl_exec($ch))) { 89 | error_log('Got ' . curl_error($ch) . ' when processing IPN data'); 90 | curl_close($ch); 91 | exit; 92 | } 93 | curl_close($ch); 94 | if ($res == 'VERIFIED') { 95 | error_log($myPost['custom']); 96 | ExtensionHelper::paymentDone($myPost['custom']); 97 | } 98 | header('HTTP/1.1 200 OK'); 99 | } 100 | -------------------------------------------------------------------------------- /Gateways/PayPal_IPN/routes.php: -------------------------------------------------------------------------------- 1 | name('paypal_ipn.webhook'); 10 | -------------------------------------------------------------------------------- /Gateways/PayU/README.md: -------------------------------------------------------------------------------- 1 | # PayU Documents 2 | 3 | ## Written by GreenArrow99 4 | 5 | ### Follow these step by step to make sure you don't mess up 6 | 7 | **Step: 1** 8 | - Obtain a PayU account 9 | - website: https://payu.in 10 | 11 | **Step: 2** 12 | - Click on "Payment Gateway" Under `Collect Payment` 13 | 14 | ![image](https://github.com/Paymenter/Extensions/assets/88144943/5fb70829-f965-4d85-a5a0-de2125fb4f41) 15 | 16 | 17 | **Step: 3** 18 | - Scroll down till you find "Key Salt Details" 19 | - Copy your `Merchant Key` & `Merchant Salt v2` 20 | 21 | ![image](https://github.com/Paymenter/Extensions/assets/88144943/167ba5f9-23cc-498d-9dc6-e18d91eac298) 22 | 23 | 24 | **Step: 4** 25 | - Go over to Extensions on your Paymenter Admin Site 26 | - Download PayU 27 | 28 | Location Preview: 29 | ![image](https://github.com/Paymenter/Extensions/assets/88144943/a25bbae9-ca4b-4611-b947-2f036f75da94) 30 | 31 | - Click Edit 32 | 33 | Location Preview: 34 | ![image](https://github.com/Paymenter/Extensions/assets/88144943/7892a4d9-2788-4bb9-afa1-16e945114bcf) 35 | 36 | **Step: 5** 37 | - Toggle "Enabled" to `True` 38 | - Paste your `Merchant Key` & `Merchant Salt v2` 39 | - Click Update & you're done! 40 | -------------------------------------------------------------------------------- /Gateways/PayU/index.php: -------------------------------------------------------------------------------- 1 | 'merchant_key', 12 | 'friendlyName' => 'Merchant Key', 13 | 'type' => 'text', 14 | 'required' => true, 15 | ], 16 | [ 17 | 'name' => 'merchant_salt', 18 | 'friendlyName' => 'Merchant Salt V1', 19 | 'type' => 'text', 20 | 'required' => true, 21 | ], 22 | [ 23 | 'name' => 'test_mode', 24 | 'friendlyName' => 'Test Mode', 25 | 'type' => 'boolean', 26 | 'required' => false, 27 | ], 28 | [ 29 | 'name' => 'test_merchant_key', 30 | 'friendlyName' => 'Test Merchant Key', 31 | 'type' => 'text', 32 | 'required' => false, 33 | ], 34 | [ 35 | 'name' => 'test_merchant_salt', 36 | 'friendlyName' => 'Test Merchant Salt V1', 37 | 'type' => 'text', 38 | 'required' => false, 39 | ], 40 | ]; 41 | } 42 | 43 | function PayU_pay($total, $products, $invoiceId) 44 | { 45 | $apiKey = ExtensionHelper::getConfig('PayU', 'test_mode') ? ExtensionHelper::getConfig('PayU', 'test_merchant_key') : ExtensionHelper::getConfig('PayU', 'merchant_key'); 46 | $salt = ExtensionHelper::getConfig('PayU', 'test_mode') ? ExtensionHelper::getConfig('PayU', 'test_merchant_salt') : ExtensionHelper::getConfig('PayU', 'merchant_salt'); 47 | $txnId = $invoiceId; 48 | $amount = $total; 49 | $productInfo = $products[0]->name; 50 | $firstName = auth()->user()->name; 51 | $email = auth()->user()->email; 52 | $phone = auth()->user()->phone; 53 | $surl = route('payu.success'); 54 | $furl = route('payu.cancel'); 55 | $hashString = "$apiKey|$txnId|$amount|$productInfo|$firstName|$email|||||||||||$salt"; 56 | $hash = hash('sha512', $hashString); 57 | 58 | $data = array( 59 | 'key' => $apiKey, 60 | 'txnid' => $txnId, 61 | 'amount' => $amount, 62 | 'productinfo' => $productInfo, 63 | 'firstname' => $firstName, 64 | 'email' => $email, 65 | 'phone' => $phone, 66 | 'surl' => $surl, 67 | 'furl' => $furl, 68 | 'hash' => $hash, 69 | ); 70 | if (ExtensionHelper::getConfig('PayU', 'test_mode')) { 71 | $url = "https://test.payu.in/_payment"; 72 | } else { 73 | $url = "https://secure.payu.in/_payment"; 74 | } 75 | 76 | echo "
"; 77 | foreach ($data as $key => $value) { 78 | echo ""; 79 | } 80 | echo "
"; 81 | echo ""; 82 | exit; 83 | } 84 | 85 | 86 | 87 | function PayU_success(Request $request) 88 | { 89 | $posted = $request->all(); 90 | $orderId = $posted['txnid']; 91 | $apiKey = ExtensionHelper::getConfig('PayU', 'test_mode') ? ExtensionHelper::getConfig('PayU', 'test_merchant_key') : ExtensionHelper::getConfig('PayU', 'merchant_key'); 92 | $salt = ExtensionHelper::getConfig('PayU', 'test_mode') ? ExtensionHelper::getConfig('PayU', 'test_merchant_salt') : ExtensionHelper::getConfig('PayU', 'merchant_salt'); 93 | $hashString = "$apiKey|verify_payment|$orderId|$salt"; 94 | $hash = hash('sha512', $hashString); 95 | 96 | $data = array( 97 | 'key' => $apiKey, 98 | 'command' => 'verify_payment', 99 | 'var1' => $orderId, 100 | 'hash' => $hash, 101 | ); 102 | 103 | if (ExtensionHelper::getConfig('PayU', 'test_mode')) { 104 | $url = "https://test.payu.in/merchant/postservice?form=2"; 105 | } else { 106 | $url = "https://info.payu.in/merchant/postservice?form=2"; 107 | } 108 | 109 | $response = Http::withHeaders([ 110 | 'Content-Type' => 'application/x-www-form-urlencoded', 111 | ])->asForm()->post($url, $data); 112 | 113 | $response = $response->json(); 114 | 115 | if ($response['transaction_details'][$orderId]['status'] == 'success') { 116 | ExtensionHelper::paymentDone($orderId); 117 | return redirect()->route('clients.invoice.show', $orderId)->with('success', 'Payment Successful'); 118 | } else { 119 | return redirect()->route('clients.invoice.show', $orderId)->with('error', 'Payment Failed'); 120 | } 121 | } 122 | 123 | function PayU_cancel(Request $request) 124 | { 125 | $posted = $request->all(); 126 | return redirect()->route('clients.invoice.show', $posted['txnid'])->with('error', 'Payment Cancelled'); 127 | } 128 | -------------------------------------------------------------------------------- /Gateways/PayU/routes.php: -------------------------------------------------------------------------------- 1 | name('payu.cancel'); 10 | 11 | Route::post('/payu/success', function () { 12 | return PayU_success(request()); 13 | })->name('payu.success'); 14 | -------------------------------------------------------------------------------- /Gateways/Stripe/index.php: -------------------------------------------------------------------------------- 1 | [ 14 | 'currency' => ExtensionHelper::getCurrency(), 15 | 'product_data' => [ 16 | 'name' => $product->name, 17 | ], 18 | 'unit_amount' => $product->price * 100, 19 | ], 20 | 'quantity' => $product->quantity, 21 | ]; 22 | } 23 | $order = $client->checkout->sessions->create([ 24 | 'line_items' => $items, 25 | 'mode' => 'payment', 26 | 'success_url' => route('clients.invoice.show', $orderId), 27 | 'cancel_url' => route('clients.invoice.show', $orderId), 28 | 'customer_email' => auth()->user()->email, 29 | 'metadata' => [ 30 | 'user_id' => auth()->user()->id, 31 | 'order_id' => $orderId, 32 | ], 33 | ]); 34 | 35 | return $order; 36 | } 37 | 38 | function Stripe_webhook($request) 39 | { 40 | $payload = $request->getContent(); 41 | $sig_header = $request->header('stripe-signature'); 42 | $endpoint_secret = ExtensionHelper::getConfig('Stripe', 'stripe_webhook_secret'); 43 | $event = null; 44 | 45 | try { 46 | $event = \Stripe\Webhook::constructEvent( 47 | $payload, 48 | $sig_header, 49 | $endpoint_secret 50 | ); 51 | } catch (\UnexpectedValueException $e) { 52 | // Invalid payload 53 | http_response_code(400); 54 | exit; 55 | } catch (\Stripe\Exception\SignatureVerificationException $e) { 56 | // Invalid signature 57 | http_response_code(400); 58 | exit; 59 | } 60 | if ($event->type == 'checkout.session.completed') { 61 | $order = $event->data->object; 62 | $order_id = $order->metadata->order_id; 63 | ExtensionHelper::paymentDone($order_id); 64 | } 65 | } 66 | 67 | function stripeClient() 68 | { 69 | if (!ExtensionHelper::getConfig('Stripe', 'stripe_test_mode')) { 70 | $stripe = new StripeClient( 71 | ExtensionHelper::getConfig('Stripe', 'stripe_secret_key') 72 | ); 73 | } else { 74 | $stripe = new StripeClient( 75 | ExtensionHelper::getConfig('Stripe', 'stripe_test_key') 76 | ); 77 | } 78 | 79 | return $stripe; 80 | } 81 | 82 | function Stripe_pay($total, $products, $orderId) 83 | { 84 | $stripe = stripeClient(); 85 | $order = Stripe_getUrl($total, $products, $orderId); 86 | 87 | return $stripe->checkout->sessions->retrieve($order->id, [])->url; 88 | } 89 | 90 | function Stripe_getConfig() 91 | { 92 | return [ 93 | [ 94 | 'name' => 'stripe_secret_key', 95 | 'friendlyName' => 'Stripe Secret Key', 96 | 'type' => 'text', 97 | 'description' => 'Stripe secret key', 98 | 'required' => true, 99 | ], 100 | [ 101 | 'name' => 'stripe_webhook_secret', 102 | 'friendlyName' => 'Stripe webhook secret', 103 | 'type' => 'text', 104 | 'description' => 'Stripe webhook secret', 105 | 'required' => true, 106 | ], 107 | [ 108 | 'name' => 'stripe_test_mode', 109 | 'friendlyName' => 'Stripe test mode', 110 | 'type' => 'boolean', 111 | 'description' => 'Stripe test mode', 112 | 'required' => false, 113 | ], 114 | [ 115 | 'name' => 'stripe_test_key', 116 | 'friendlyName' => 'Stripe test key', 117 | 'type' => 'text', 118 | 'description' => 'Stripe test key', 119 | 'required' => false, 120 | ], 121 | ]; 122 | } 123 | -------------------------------------------------------------------------------- /Gateways/Stripe/routes.php: -------------------------------------------------------------------------------- 1 | paymentIntents->create([ 10 | 'confirm' => true, 11 | 'amount' => $total * 100, 12 | 'currency' => ExtensionHelper::getCurrency(), 13 | 'payment_method_types' => ['sofort'], 14 | 'payment_method_data' => ['type' => 'sofort', 'sofort' => ['country' => ExtensionHelper::getConfig('StripeSofort', 'country')]], 15 | 'return_url' => route('clients.invoice.show', $orderId), 16 | 'metadata' => [ 17 | 'user_id' => auth()->user()->id, 18 | 'order_id' => $orderId, 19 | ], 20 | ]); 21 | 22 | return $order; 23 | } 24 | 25 | function StripeSofort_webhook($request) 26 | { 27 | $payload = $request->getContent(); 28 | $sig_header = $request->header('stripe-signature'); 29 | $endpoint_secret = ExtensionHelper::getConfig('Stripe', 'stripe_webhook_secret'); 30 | $event = null; 31 | 32 | try { 33 | $event = \Stripe\Webhook::constructEvent( 34 | $payload, 35 | $sig_header, 36 | $endpoint_secret 37 | ); 38 | } catch (\UnexpectedValueException $e) { 39 | // Invalid payload 40 | http_response_code(400); 41 | exit; 42 | } catch (\Stripe\Exception\SignatureVerificationException $e) { 43 | // Invalid signature 44 | http_response_code(400); 45 | exit; 46 | } 47 | if ($event->type == 'checkout.session.completed') { 48 | $order = $event->data->object; 49 | $order_id = $order->metadata->order_id; 50 | ExtensionHelper::paymentDone($order_id); 51 | } 52 | } 53 | 54 | function StripeSofortClient() 55 | { 56 | if (!ExtensionHelper::getConfig('Stripe', 'stripe_test_mode')) { 57 | $stripe = new StripeClient( 58 | ExtensionHelper::getConfig('Stripe', 'stripe_secret_key') 59 | ); 60 | } else { 61 | $stripe = new StripeClient( 62 | ExtensionHelper::getConfig('Stripe', 'stripe_test_key') 63 | ); 64 | } 65 | 66 | return $stripe; 67 | } 68 | 69 | function StripeSofort_pay($total, $products, $orderId) 70 | { 71 | $order = StripeSofort_getUrl($total, $products, $orderId); 72 | if ($order->status == 'requires_action' && $order->next_action->type == 'redirect_to_url') { 73 | $url = $order->next_action->redirect_to_url->url; 74 | return $url; 75 | } 76 | dd($order); 77 | } 78 | 79 | function StripeSofort_getConfig() 80 | { 81 | return [ 82 | [ 83 | 'name' => 'country', 84 | 'friendlyName' => 'Country short code', 85 | 'type' => 'text', 86 | 'description' => 'The country code for sofort. For example: DE, NL', 87 | 'required' => true, 88 | ], 89 | ]; 90 | } 91 | -------------------------------------------------------------------------------- /Gateways/StripeSofort/readme.md: -------------------------------------------------------------------------------- 1 | # Sofort Direct Payment Gateway for Stripe 2 | 3 | ## Installation 4 | Download the code and place it in the `app/Extensions/Gateways/StripeSofort` directory. 5 | 6 | ## Configuration 7 | In the admin panel, go to `Settings > Payment Gateways` and click on the `Stripe Sofort` gateway. Enter your your wanted country then press `Save`. 8 | 9 | ## IMPORTANT 10 | You need to set the apikeys in the Stripe gateway settings. The Stripe Sofort gateway will use the same apikeys as the Stripe gateway. 11 | 12 | ## Usage 13 | When a user selects the `Stripe Sofort` gateway, they will be redirected to the Stripe Sofort payment page. After the payment is completed, the user will be redirected back to the site. 14 | -------------------------------------------------------------------------------- /Gateways/StripeSofort/routes.php: -------------------------------------------------------------------------------- 1 | name . ' x' . $product->quantity . ', '; 15 | } 16 | $response = Http::withHeaders([ 17 | 'Content-Type' => 'application/json', 18 | 'Authorization' => 'Basic ' . $apiKey, 19 | ])->post($url, [ 20 | 'amount' => number_format($total, 2, '.', ''), 21 | 'description' => $description, 22 | 'success_redirect_url' => route('clients.invoice.show', $orderId), 23 | 'failure_redirect_url' => route('clients.invoice.show', $orderId), 24 | 'external_id' => (string) $orderId, 25 | ]); 26 | 27 | return $response->json()['invoice_url']; 28 | } 29 | 30 | function Xendit_webhook($request) 31 | { 32 | if ($request->header('x-callback-token') != ExtensionHelper::getConfig('Xendit', 'callback')) { 33 | return response()->json(['message' => 'Invalid callback token'], 403); 34 | } 35 | $json = $request->getContent(); 36 | $json = json_decode($json, true); 37 | ExtensionHelper::paymentDone($json['external_id']); 38 | response()->json(['message' => 'Webhook received'], 200); 39 | } 40 | 41 | function Xendit_getConfig() 42 | { 43 | return [ 44 | [ 45 | 'name' => 'api_key', 46 | 'friendlyName' => 'API Key', 47 | 'type' => 'text', 48 | 'required' => true, 49 | ], 50 | [ 51 | 'name' => 'callback', 52 | 'friendlyName' => 'Callback verification token', 53 | 'type' => 'text', 54 | 'required' => true, 55 | ], 56 | ]; 57 | } 58 | -------------------------------------------------------------------------------- /Gateways/Xendit/routes.php: -------------------------------------------------------------------------------- 1 | name('xendit.webhook'); 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Paymenter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > [!WARNING] 2 | > This repository has been deprecated in favor of the extensions being default included in: https://github.com/Paymenter/Paymenter/tree/master/extensions 3 | 4 | # Extensions 5 | All public extensions for Paymenter 6 | 7 | Download this repository as a zip file and extract it to your paymenter app/extensions folder. 8 | Go to the paymenter admin panel and enable the extension you want to use. 9 | 10 | 11 | - Some must-have extensions are standard included in the paymenter installation (Mollie, Xendit, PayPal, Stripe) (Pterodactyl, Virtualizor, VirtFusion, DirectAdmin) 12 | 13 | | Extension | Description | Link | 14 | | --- | --- | --- | 15 | | Mollie | [Mollie](https://mollie.com) payment gateway | [Link](https://github.com/Paymenter/Extensions/tree/main/Gateways/Mollie) 16 | | Xendit | [Xendit](https://xendit.com) payment gateway | [Link](https://github.com/Paymenter/Extensions/tree/main/Gateways/Xendit) 17 | | PayPal | [PayPal](https://developer.paypal.com) payment gateway | [Link](https://github.com/Paymenter/Extensions/tree/main/Gateways/PayPal) 18 | | PayPal IPN | [PayPal](https://developer.paypal.com) IPN payment gateway | [Link](https://github.com/Paymenter/Extensions/tree/main/Gateways/PayPal_IPN) 19 | | Stripe | [Stripe](https://stripe.com) payment gateway | [Link](https://github.com/Paymenter/Extensions/tree/main/Gateways/Stipe) 20 | | Stripe Sofort | Direct sofort payment gateway | [Link](https://github.com/Paymenter/Extensions/tree/main/Gateways/StripeSofort) 21 | | PayU.in | [PayU](https://payu.in) | [Link](https://github.com/Paymenter/Extensions/tree/main/Gateways/PayU) 22 | | **Servers** | | | | 23 | | Pterodactyl | [Pterodactyl](https://pterodactyl.io) panel | [Link](https://github.com/Paymenter/Extensions/tree/main/Servers/Pterodactyl) 24 | | Virtualizor | [Virtualizor](https://virtualizor.com) VPS management panel | [Link](https://github.com/Paymenter/Extensions/tree/main/Servers/Virtualizor) 25 | | VirtFusion | [VirtFusion](https://virtfusion.com) VPS management panel | [Link](https://github.com/Paymenter/Extensions/tree/main/Servers/VirtFusion) 26 | | DirectAdmin | [DirectAdmin](https://directadmin.com) VPS management panel | [Link](https://github.com/Paymenter/Extensions/tree/main/Servers/DirectAdmin) 27 | | ISPConfig | [ISPConfig](https://www.ispconfig.org) webhosting panel | [Link](https://github.com/Paymenter/Extensions/tree/main/Servers/ISPConfig) 28 | -------------------------------------------------------------------------------- /Servers/CyberPanel/index.php: -------------------------------------------------------------------------------- 1 | 'host', 11 | 'friendlyName' => 'Url to CyberPanel server (with port)', 12 | 'type' => 'text', 13 | 'required' => true, 14 | ], 15 | [ 16 | 'name' => 'username', 17 | 'friendlyName' => 'Username', 18 | 'type' => 'text', 19 | 'required' => true, 20 | ], 21 | [ 22 | 'name' => 'password', 23 | 'friendlyName' => 'Password', 24 | 'type' => 'text', 25 | 'required' => true, 26 | ] 27 | ]; 28 | } 29 | 30 | function CyberPanel_getProductConfig() 31 | { 32 | return [ 33 | [ 34 | 'name' => 'packageName', 35 | 'friendlyName' => 'Package Name', 36 | 'type' => 'text', 37 | 'required' => true, 38 | 'description' => 'Package Name for the CyberPanel server', 39 | ], 40 | ]; 41 | } 42 | 43 | function CyberPanel_getUserConfig() 44 | { 45 | return [ 46 | [ 47 | 'name' => 'domain', 48 | 'friendlyName' => 'Domain', 49 | 'type' => 'text', 50 | 'required' => true, 51 | 'description' => 'Domain for the webhost', 52 | ], 53 | [ 54 | 'name' => 'username', 55 | 'friendlyName' => 'Username', 56 | 'type' => 'text', 57 | 'required' => true, 58 | 'description' => 'Username to login to the website', 59 | ], 60 | [ 61 | 'name' => 'password', 62 | 'friendlyName' => 'Password', 63 | 'type' => 'text', 64 | 'required' => true, 65 | 'description' => 'Password to login to the website', 66 | ] 67 | ]; 68 | } 69 | 70 | function CyberPanel_createServer($user, $params, $order, $product) 71 | { 72 | $response = Http::post(ExtensionHelper::getConfig('CyberPanel', 'host') . '/api/createWebsite', [ 73 | 'adminUser' => ExtensionHelper::getConfig('CyberPanel', 'username'), 74 | 'adminPass' => ExtensionHelper::getConfig('CyberPanel', 'password'), 75 | 'domainName' => $params['config']['domain'], 76 | 'packageName' => $params['packageName'], 77 | 'ownerEmail' => $user->email, 78 | 'websiteOwner' => $params['config']['username'], 79 | 'ownerPassword' => $params['config']['password'], 80 | ]); 81 | if(!$response->successful()){ 82 | ExtensionHelper::error('CyberPanel', 'Failed to create server: ' . $response->body()); 83 | } 84 | } 85 | 86 | function CyberPanel_suspendServer($user, $params, $order, $product) 87 | { 88 | $response = Http::post(ExtensionHelper::getConfig('CyberPanel', 'host') . '/api/suspendWebsite', [ 89 | 'adminUser' => ExtensionHelper::getConfig('CyberPanel', 'username'), 90 | 'adminPass' => ExtensionHelper::getConfig('CyberPanel', 'password'), 91 | 'domainName' => $params['config']['domain'], 92 | 'state' => 'Suspend', 93 | ]); 94 | if(!$response->successful()){ 95 | ExtensionHelper::error('CyberPanel', 'Failed to suspend server: ' . $response->body()); 96 | } 97 | } 98 | 99 | function CyberPanel_unsuspendServer($user, $params, $order, $product) 100 | { 101 | $response = Http::post(ExtensionHelper::getConfig('CyberPanel', 'host') . '/api/suspendWebsite', [ 102 | 'adminUser' => ExtensionHelper::getConfig('CyberPanel', 'username'), 103 | 'adminPass' => ExtensionHelper::getConfig('CyberPanel', 'password'), 104 | 'domainName' => $params['config']['domain'], 105 | 'state' => 'Active', 106 | ]); 107 | if(!$response->successful()){ 108 | ExtensionHelper::error('CyberPanel', 'Failed to unsuspend server: ' . $response->body()); 109 | } 110 | } 111 | 112 | function CyberPanel_terminateServer($user, $params, $order, $product) 113 | { 114 | $response = Http::post(ExtensionHelper::getConfig('CyberPanel', 'host') . '/api/deleteWebsite', [ 115 | 'adminUser' => ExtensionHelper::getConfig('CyberPanel', 'username'), 116 | 'adminPass' => ExtensionHelper::getConfig('CyberPanel', 'password'), 117 | 'domainName' => $params['config']['domain'], 118 | ]); 119 | if(!$response->successful()){ 120 | ExtensionHelper::error('CyberPanel', 'Failed to terminate server: ' . $response->body()); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /Servers/DirectAdmin/httpsocket.php: -------------------------------------------------------------------------------- 1 | get('http://user:pass@somesite.com/somedir/some.file?query=string&this=that'); 11 | * 12 | * @author Phi1 'l0rdphi1' Stier 13 | * 14 | * @version 3.0.4 15 | * 16 | * 3.0.4 17 | * store first proxy headers for return, in event of redirect 18 | * 19 | * 3.0.3 20 | * curl Cookie for SESSION_ID+SESSION_KEY changed to setopt with 21 | * 22 | * 3.0.2 23 | * added longer curl timeouts 24 | * 25 | * 3.0.1 26 | * support for tcp:// conversion to http:// 27 | * 28 | * 3.0.0 29 | * swapped to use curl to address ssl certificate issues with php 5.6 30 | * 31 | * 2.7.2 32 | * added x-use-https header check 33 | * added max number of location redirects 34 | * added custom settable message if x-use-https is found, so users can be told where to set their scripts 35 | * if a redirect host is https, add ssl:// to remote_host 36 | * 37 | * 2.7.1 38 | * added isset to headers['location'], line 306 39 | */ 40 | class DAHTTPSocket 41 | { 42 | public $version = '3.0.4'; 43 | 44 | /* all vars are private except $error, $query_cache, and $doFollowLocationHeader */ 45 | 46 | public $method = 'GET'; 47 | 48 | public $remote_host; 49 | public $remote_port; 50 | public $remote_uname; 51 | public $remote_passwd; 52 | 53 | public $result; 54 | public $result_header; 55 | public $result_body; 56 | public $result_status_code; 57 | 58 | public $lastTransferSpeed; 59 | 60 | public $bind_host; 61 | 62 | public $error = []; 63 | public $warn = []; 64 | public $query_cache = []; 65 | 66 | public $doFollowLocationHeader = true; 67 | public $redirectURL; 68 | public $max_redirects = 5; 69 | public $ssl_setting_message = 'DirectAdmin appears to be using SSL. Change your script to connect to ssl://'; 70 | 71 | public $extra_headers = []; 72 | 73 | public $proxy = false; 74 | public $proxy_headers = []; 75 | 76 | /** 77 | * Create server "connection". 78 | */ 79 | public function connect($host, $port = '') 80 | { 81 | if (!is_numeric($port)) { 82 | $port = 80; 83 | } 84 | 85 | $this->remote_host = $host; 86 | $this->remote_port = $port; 87 | } 88 | 89 | public function bind($ip = '') 90 | { 91 | if ($ip == '') { 92 | $ip = $_SERVER['SERVER_ADDR']; 93 | } 94 | 95 | $this->bind_host = $ip; 96 | } 97 | 98 | /** 99 | * Change the method being used to communicate. 100 | * 101 | * @param string|null request method. supports GET, POST, and HEAD. default is GET 102 | */ 103 | public function set_method($method = 'GET') 104 | { 105 | $this->method = strtoupper($method); 106 | } 107 | 108 | /** 109 | * Specify a username and password. 110 | * 111 | * @param string|null username. defualt is null 112 | * @param string|null password. defualt is null 113 | */ 114 | public function set_login($uname = '', $passwd = '') 115 | { 116 | if (strlen($uname) > 0) { 117 | $this->remote_uname = $uname; 118 | } 119 | 120 | if (strlen($passwd) > 0) { 121 | $this->remote_passwd = $passwd; 122 | } 123 | } 124 | 125 | /** 126 | * For pass through, this function writes the data in chunks. 127 | */ 128 | private function stream_chunk($ch, $data) 129 | { 130 | echo $data; 131 | 132 | return strlen($data); 133 | } 134 | 135 | private function stream_header($ch, $data) 136 | { 137 | if (!preg_match('/^HTTP/i', $data)) { 138 | header($data); 139 | } 140 | 141 | return strlen($data); 142 | } 143 | 144 | /** 145 | * Query the server. 146 | * 147 | * @param string containing properly formatted server API. See DA API docs and examples. Http:// URLs O.K. too. 148 | * @param string|array query to pass to url 149 | * @param int if connection KB/s drops below value here, will drop connection 150 | */ 151 | public function query($request, $content = '', $doSpeedCheck = 0) 152 | { 153 | $this->error = $this->warn = []; 154 | $this->result_status_code = null; 155 | 156 | $is_ssl = false; 157 | 158 | // is our request a http:// ... ? 159 | if (preg_match('!^http://!i', $request) || preg_match('!^https://!i', $request)) { 160 | $location = parse_url($request); 161 | if (preg_match('!^https://!i', $request)) { 162 | $this->connect('https://' . $location['host'], $location['port']); 163 | } else { 164 | $this->connect('http://' . $location['host'], $location['port']); 165 | } 166 | 167 | $this->set_login($location['user'], $location['pass']); 168 | 169 | $request = $location['path']; 170 | $content = $location['query']; 171 | 172 | if (strlen($request) < 1) { 173 | $request = '/'; 174 | } 175 | } 176 | 177 | if (preg_match('!^ssl://!i', $this->remote_host)) { 178 | $this->remote_host = 'https://' . substr($this->remote_host, 6); 179 | } 180 | 181 | if (preg_match('!^tcp://!i', $this->remote_host)) { 182 | $this->remote_host = 'http://' . substr($this->remote_host, 6); 183 | } 184 | 185 | if (preg_match('!^https://!i', $this->remote_host)) { 186 | $is_ssl = true; 187 | } 188 | 189 | $array_headers = [ 190 | 'Host' => ($this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port"), 191 | 'Accept' => '*/*', 192 | 'Connection' => 'Close']; 193 | 194 | foreach ($this->extra_headers as $key => $value) { 195 | $array_headers[$key] = $value; 196 | } 197 | 198 | $this->result = $this->result_header = $this->result_body = ''; 199 | 200 | // was content sent as an array? if so, turn it into a string 201 | if (is_array($content)) { 202 | $pairs = []; 203 | 204 | foreach ($content as $key => $value) { 205 | $pairs[] = "$key=" . urlencode($value); 206 | } 207 | 208 | $content = implode('&', $pairs); 209 | unset($pairs); 210 | } 211 | 212 | $OK = true; 213 | 214 | if ($this->method == 'GET' && isset($content) && $content != '') { 215 | $request .= '?' . $content; 216 | } 217 | 218 | $ch = curl_init($this->remote_host . ':' . $this->remote_port . $request); 219 | 220 | if ($is_ssl) { 221 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 1 222 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 2 223 | // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); 224 | } 225 | 226 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 227 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 228 | curl_setopt($ch, CURLOPT_USERAGENT, "HTTPSocket/$this->version"); 229 | curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); 230 | curl_setopt($ch, CURLOPT_TIMEOUT, 100); 231 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 232 | curl_setopt($ch, CURLOPT_HEADER, 1); 233 | 234 | if ($this->proxy) { 235 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); 236 | curl_setopt($ch, CURLOPT_HEADER, false); 237 | curl_setopt($ch, CURLINFO_HEADER_OUT, false); 238 | curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192); // 8192 239 | curl_setopt($ch, CURLOPT_WRITEFUNCTION, [$this, 'stream_chunk']); 240 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, [$this, 'stream_header']); 241 | } 242 | 243 | curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 512); 244 | curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 120); 245 | 246 | // instance connection 247 | if ($this->bind_host) { 248 | curl_setopt($ch, CURLOPT_INTERFACE, $this->bind_host); 249 | } 250 | 251 | // if we have a username and password, add the header 252 | if (isset($this->remote_uname) && isset($this->remote_passwd)) { 253 | curl_setopt($ch, CURLOPT_USERPWD, $this->remote_uname . ':' . $this->remote_passwd); 254 | } 255 | 256 | // for DA skins: if $this->remote_passwd is NULL, try to use the login key system 257 | if (isset($this->remote_uname) && $this->remote_passwd == null) { 258 | curl_setopt($ch, CURLOPT_COOKIE, "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}"); 259 | } 260 | 261 | // if method is POST, add content length & type headers 262 | if ($this->method == 'POST') { 263 | curl_setopt($ch, CURLOPT_POST, 1); 264 | curl_setopt($ch, CURLOPT_POSTFIELDS, $content); 265 | 266 | // $array_headers['Content-type'] = 'application/x-www-form-urlencoded'; 267 | $array_headers['Content-length'] = strlen($content); 268 | } 269 | 270 | curl_setopt($ch, CURLOPT_HTTPHEADER, $array_headers); 271 | 272 | if (!($this->result = curl_exec($ch))) { 273 | $this->error[] .= curl_error($ch); 274 | $OK = false; 275 | } 276 | 277 | $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 278 | $this->result_header = substr($this->result, 0, $header_size); 279 | $this->result_body = substr($this->result, $header_size); 280 | $this->result_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 281 | 282 | $this->lastTransferSpeed = curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD) / 1024; 283 | 284 | curl_close($ch); 285 | 286 | $this->query_cache[] = $this->remote_host . ':' . $this->remote_port . $request; 287 | 288 | $headers = $this->fetch_header(); 289 | 290 | // did we get the full file? 291 | if (!empty($headers['content-length']) && $headers['content-length'] != strlen($this->result_body)) { 292 | $this->result_status_code = 206; 293 | } 294 | 295 | // now, if we're being passed a location header, should we follow it? 296 | if ($this->doFollowLocationHeader) { 297 | // dont bother if we didn't even setup the script correctly 298 | if (isset($headers['x-use-https']) && $headers['x-use-https'] == 'yes') { 299 | exit($this->ssl_setting_message); 300 | } 301 | 302 | if (isset($headers['location'])) { 303 | if ($this->max_redirects <= 0) { 304 | exit('Too many redirects on: ' . $headers['location']); 305 | } 306 | 307 | --$this->max_redirects; 308 | $this->redirectURL = $headers['location']; 309 | $this->query($headers['location']); 310 | } 311 | } 312 | } 313 | 314 | public function getTransferSpeed() 315 | { 316 | return $this->lastTransferSpeed; 317 | } 318 | 319 | /** 320 | * The quick way to get a URL's content :). 321 | * 322 | * @param string URL 323 | * @param bool return as array? (like PHP's file() command) 324 | * 325 | * @return string result body 326 | */ 327 | public function get($location, $asArray = false) 328 | { 329 | $this->query($location); 330 | 331 | if ($this->get_status_code() == 200) { 332 | if ($asArray) { 333 | return preg_split("/\n/", $this->fetch_body()); 334 | } 335 | 336 | return $this->fetch_body(); 337 | } 338 | 339 | return false; 340 | } 341 | 342 | /** 343 | * Returns the last status code. 344 | * 200 = OK; 345 | * 403 = FORBIDDEN; 346 | * etc. 347 | * 348 | * @return int status code 349 | */ 350 | public function get_status_code() 351 | { 352 | return $this->result_status_code; 353 | } 354 | 355 | /** 356 | * Adds a header, sent with the next query. 357 | * 358 | * @param string header name 359 | * @param string header value 360 | */ 361 | public function add_header($key, $value) 362 | { 363 | $this->extra_headers[$key] = $value; 364 | } 365 | 366 | /** 367 | * Clears any extra headers. 368 | */ 369 | public function clear_headers() 370 | { 371 | $this->extra_headers = []; 372 | } 373 | 374 | /** 375 | * Return the result of a query. 376 | * 377 | * @return string result 378 | */ 379 | public function fetch_result() 380 | { 381 | return $this->result; 382 | } 383 | 384 | /** 385 | * Return the header of result (stuff before body). 386 | * 387 | * @param string (optional) header to return 388 | * 389 | * @return array result header 390 | */ 391 | public function fetch_header($header = '') 392 | { 393 | if ($this->proxy) { 394 | return $this->proxy_headers; 395 | } 396 | 397 | $array_headers = preg_split("/\r\n/", $this->result_header); 398 | 399 | $array_return = [0 => $array_headers[0]]; 400 | unset($array_headers[0]); 401 | 402 | foreach ($array_headers as $pair) { 403 | if ($pair == '' || $pair == "\r\n") { 404 | continue; 405 | } 406 | list($key, $value) = preg_split('/: /', $pair, 2); 407 | $array_return[strtolower($key)] = $value; 408 | } 409 | 410 | if ($header != '') { 411 | return $array_return[strtolower($header)]; 412 | } 413 | 414 | return $array_return; 415 | } 416 | 417 | /** 418 | * Return the body of result (stuff after header). 419 | * 420 | * @return string result body 421 | */ 422 | public function fetch_body() 423 | { 424 | return $this->result_body; 425 | } 426 | 427 | /** 428 | * Return parsed body in array format. 429 | * 430 | * @return array result parsed 431 | */ 432 | public function fetch_parsed_body() 433 | { 434 | parse_str($this->result_body, $x); 435 | 436 | return $x; 437 | } 438 | 439 | /** 440 | * Set a specifc message on how to change the SSL setting, in the event that it's not set correctly. 441 | */ 442 | public function set_ssl_setting_message($str) 443 | { 444 | $this->ssl_setting_message = $str; 445 | } 446 | } 447 | -------------------------------------------------------------------------------- /Servers/DirectAdmin/index.php: -------------------------------------------------------------------------------- 1 | connect('ssl://' . $host, '2222'); 14 | } else { 15 | $sock->connect($host, '2222'); 16 | } 17 | $server_login = ExtensionHelper::getConfig('DirectAdmin', 'username'); 18 | $server_pass = ExtensionHelper::getConfig('DirectAdmin', 'password'); 19 | $sock->set_login($server_login, $server_pass); 20 | // Generate random username with 8 characters 21 | $username = substr(str_shuffle(str_repeat($x = 'abcdefghijklmnopqrstuvwxyz', ceil(8 / strlen($x)))), 1, 8); 22 | if (isset($params['ip'])) { 23 | $ip = $params['ip']; 24 | } else { 25 | $sock->query('/CMD_API_SHOW_RESELLER_IPS'); 26 | $result = $sock->fetch_parsed_body(); 27 | $ip = $result['list'][0]; 28 | } 29 | $response = $sock->query( 30 | '/CMD_API_ACCOUNT_USER', 31 | [ 32 | 'action' => 'create', 33 | 'add' => 'Submit', 34 | 'username' => $username, 35 | 'email' => $user->email, 36 | 'passwd' => 'Random', 37 | 'passwd2' => 'Random', 38 | 'domain' => $params['config']['domain'], 39 | 'package' => 'test', 40 | 'ip' => $ip, 41 | 'notify' => 'yes', 42 | ] 43 | ); 44 | $result = $sock->fetch_parsed_body(); 45 | if ($result['error'] != '0') { 46 | ExtensionHelper::error('DirectAdmin', $result); 47 | 48 | return; 49 | } else { 50 | ExtensionHelper::setOrderProductConfig('username', $username, $params['config_id']); 51 | } 52 | 53 | return $response; 54 | } 55 | 56 | function DirectAdmin_suspendServer($user, $params, $order) 57 | { 58 | $host = ExtensionHelper::getConfig('DirectAdmin', 'host'); 59 | $sock = new DAHTTPSocket(); 60 | if (ExtensionHelper::getConfig('DirectAdmin', 'ssl')) { 61 | $sock->connect('ssl://' . $host, '2222'); 62 | } else { 63 | $sock->connect($host, '2222'); 64 | } 65 | $server_login = ExtensionHelper::getConfig('DirectAdmin', 'username'); 66 | $server_pass = ExtensionHelper::getConfig('DirectAdmin', 'password'); 67 | $sock->set_login($server_login, $server_pass); 68 | $username = $params['config']['username']; 69 | $response = $sock->query( 70 | '/CMD_API_SELECT_USERS', 71 | [ 72 | 'location' => 'CMD_SELECT_USERS', 73 | 'suspend' => 'suspend', 74 | 'select0' => $username, 75 | ] 76 | ); 77 | $result = $sock->fetch_parsed_body(); 78 | if ($result['error'] != '0') { 79 | ExtensionHelper::error('DirectAdmin', $result); 80 | 81 | return; 82 | } 83 | } 84 | 85 | function DirectAdmin_unsuspendServer($user, $params, $order) 86 | { 87 | $host = ExtensionHelper::getConfig('DirectAdmin', 'host'); 88 | $sock = new DAHTTPSocket(); 89 | if (ExtensionHelper::getConfig('DirectAdmin', 'ssl')) { 90 | $sock->connect('ssl://' . $host, '2222'); 91 | } else { 92 | $sock->connect($host, '2222'); 93 | } 94 | $server_login = ExtensionHelper::getConfig('DirectAdmin', 'username'); 95 | $server_pass = ExtensionHelper::getConfig('DirectAdmin', 'password'); 96 | $sock->set_login($server_login, $server_pass); 97 | $username = $params['config']['username']; 98 | $response = $sock->query( 99 | '/CMD_API_SELECT_USERS', 100 | [ 101 | 'location' => 'CMD_SELECT_USERS', 102 | 'suspend' => 'unsuspend', 103 | 'select0' => $username, 104 | ] 105 | ); 106 | $result = $sock->fetch_parsed_body(); 107 | if ($result['error'] != '0') { 108 | ExtensionHelper::error('DirectAdmin', $result, true); 109 | 110 | return; 111 | } 112 | 113 | return $response; 114 | } 115 | 116 | function DirectAdmin_terminateServer($user, $params, $order) 117 | { 118 | $host = ExtensionHelper::getConfig('DirectAdmin', 'host'); 119 | $sock = new DAHTTPSocket(); 120 | if (ExtensionHelper::getConfig('DirectAdmin', 'ssl')) { 121 | $sock->connect('ssl://' . $host, '2222'); 122 | } else { 123 | $sock->connect($host, '2222'); 124 | } 125 | $server_login = ExtensionHelper::getConfig('DirectAdmin', 'username'); 126 | $server_pass = ExtensionHelper::getConfig('DirectAdmin', 'password'); 127 | $sock->set_login($server_login, $server_pass); 128 | $username = $params['config']['username']; 129 | $response = $sock->query( 130 | '/CMD_API_SELECT_USERS', 131 | [ 132 | 'confirmed' => 'Confirm', 133 | 'delete' => 'yes', 134 | 'select0' => $username, 135 | ] 136 | ); 137 | $result = $sock->fetch_parsed_body(); 138 | if ($result['error'] != '0') { 139 | error_log(print_r($result, true)); 140 | 141 | return; 142 | // TODO: Handle error 143 | } 144 | 145 | return $response; 146 | } 147 | 148 | function DirectAdmin_getConfig() 149 | { 150 | return [ 151 | [ 152 | 'name' => 'host', 153 | 'friendlyName' => 'Host', 154 | 'type' => 'text', 155 | 'required' => true, 156 | 'description' => 'The IP address or domain name of the DirectAdmin server', 157 | ], 158 | [ 159 | 'name' => 'username', 160 | 'friendlyName' => 'Username', 161 | 'type' => 'text', 162 | 'required' => true, 163 | 'description' => 'The username of the DirectAdmin server', 164 | ], 165 | [ 166 | 'name' => 'password', 167 | 'friendlyName' => 'Password', 168 | 'type' => 'text', 169 | 'required' => true, 170 | 'description' => 'The password of the DirectAdmin server', 171 | ], 172 | [ 173 | 'name' => 'ssl', 174 | 'friendlyName' => 'SSL', 175 | 'type' => 'boolean', 176 | 'required' => true, 177 | 'description' => 'Whether to use SSL to connect to the DirectAdmin server', 178 | ], 179 | ]; 180 | } 181 | 182 | function DirectAdmin_getUserConfig(Product $product) 183 | { 184 | return [ 185 | [ 186 | 'name' => 'domain', 187 | 'type' => 'text', 188 | 'friendlyName' => 'Domain', 189 | 'required' => true, 190 | ], 191 | ]; 192 | } 193 | 194 | function DirectAdmin_getProductConfig() 195 | { 196 | return [ 197 | [ 198 | 'name' => 'package', 199 | 'type' => 'text', 200 | 'friendlyName' => 'Package', 201 | 'required' => true, 202 | ], 203 | [ 204 | 'name' => 'ip', 205 | 'type' => 'text', 206 | 'friendlyName' => 'IP', 207 | 'required' => false, 208 | ], 209 | ]; 210 | } 211 | -------------------------------------------------------------------------------- /Servers/ISPConfig/ISPConfigWS.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://opensource.org/licenses/mit-license.php The MIT License 12 | */ 13 | class ISPConfigWS 14 | { 15 | /** 16 | * Holds the SOAPclient object. 17 | * 18 | * access protected; 19 | * 20 | * @var \SOAPclient|null 21 | */ 22 | protected ?SOAPclient $client = null; 23 | 24 | /** 25 | * Holds the SOAP session ID. 26 | * 27 | * access protected; 28 | * 29 | * @var string 30 | */ 31 | protected string $sessionId; 32 | /** 33 | * Holds the ISPConfig login details. 34 | * 35 | * access private; 36 | * 37 | * @var array 38 | */ 39 | private array $config; 40 | 41 | /** 42 | * Holds the SOAP response. 43 | * 44 | * access private; 45 | * 46 | * @var mixed 47 | */ 48 | private $wsResponse; 49 | 50 | /** 51 | * Holds the parameters used for SOAP requests. 52 | * 53 | * access private; 54 | * 55 | * @var array 56 | */ 57 | private array $params; 58 | 59 | /** 60 | * @throws \SoapFault 61 | */ 62 | public function __construct(array $config = array()) 63 | { 64 | if (count($config) !== 0) { 65 | $this->init($config); 66 | } 67 | } 68 | 69 | /** 70 | * @param array $config 71 | * 72 | * @throws \SoapFault 73 | */ 74 | public function init(array $config = array()) 75 | { 76 | if (count($config) !== 0) { 77 | $this->config = $config; 78 | } 79 | 80 | $this->client = new SoapClient( 81 | null, 82 | array( 83 | 'location' => $this->config['host'] . '/remote/index.php', 84 | 'uri' => $this->config['host'] . '/remote/', 85 | 'trace' => 1, 86 | 'allow_self_siged' => 1, 87 | 'exceptions' => 0, 88 | 'login' => $this->config['user'], 89 | 'password' => $this->config['pass'], 90 | "stream_context" => stream_context_create( 91 | array( 92 | 'ssl' => array( 93 | 'verify_peer' => false, 94 | 'verify_peer_name' => false, 95 | ) 96 | ) 97 | ) 98 | ) 99 | ); 100 | $this->sessionId = $this->client->login($this->config['user'], $this->config['pass']); 101 | } 102 | 103 | /** 104 | * Holds the SOAPclient, creating it if needed. 105 | * 106 | * @return void 107 | * @throws \SoapFault 108 | */ 109 | private function ws(): SOAPclient 110 | { 111 | if ($this->client instanceof SoapClient) { 112 | return $this->client; 113 | } 114 | 115 | $this->init(); 116 | } 117 | 118 | /** 119 | * Alias for getResponse. 120 | * 121 | * @return string 122 | */ 123 | public function response(): string 124 | { 125 | return $this->getResponse(); 126 | } 127 | 128 | /** 129 | * Get the API ID. 130 | * 131 | * @return string Returns "self" 132 | */ 133 | public function getResponse(): string 134 | { 135 | if (is_soap_fault($this->wsResponse)) { 136 | return json_encode( 137 | array('error' => array( 138 | 'code' => $this->wsResponse->faultcode, 139 | 'message' => $this->wsResponse->faultstring, 140 | )), 141 | JSON_FORCE_OBJECT 142 | ); 143 | } 144 | 145 | if (!is_array($this->wsResponse)) { 146 | return json_encode(array('result' => $this->wsResponse), JSON_FORCE_OBJECT); 147 | } 148 | 149 | return json_encode($this->wsResponse, JSON_FORCE_OBJECT); 150 | } 151 | 152 | /** 153 | * Alias for setParams. 154 | * 155 | * @param $params 156 | * 157 | * @return $this 158 | */ 159 | public function with($params): ISPConfigWS 160 | { 161 | $this->setParams($params); 162 | 163 | return $this; 164 | } 165 | 166 | /** 167 | * Set the parameters used for SOAP calls. 168 | * 169 | * @param array $params 170 | * 171 | * @internal param mixed $params 172 | */ 173 | public function setParams(array $params) 174 | { 175 | $this->params = $params; 176 | } 177 | 178 | /** 179 | * @return $this 180 | * @throws \SoapFault 181 | * @throws \SoapFault 182 | */ 183 | public function addClient(): ISPConfigWS 184 | { 185 | $reseller_id = $this->extractParameter('reseller_id'); 186 | $this->wsResponse = $this->ws()->client_add($this->sessionId, $reseller_id, $this->params); 187 | 188 | return $this; 189 | } 190 | 191 | /** 192 | * Extracts a parameter from $params and remove it from $params array. 193 | * 194 | * @param $param 195 | * 196 | * @return mixed 197 | */ 198 | private function extractParameter($param) 199 | { 200 | $parameter = array_key_exists($param, $this->params) ? $this->params[$param] : false; 201 | unset($this->params[$param]); 202 | 203 | return $parameter; 204 | } 205 | 206 | /** 207 | * @return $this 208 | * @throws \SoapFault 209 | * @throws \SoapFault 210 | */ 211 | public function getClientByCustomerNo(): ISPConfigWS 212 | { 213 | $customer_no = $this->extractParameter('customer_no'); 214 | $this->wsResponse = $this->ws()->client_get_by_customer_no($this->sessionId, $customer_no); 215 | 216 | return $this; 217 | } 218 | 219 | /** 220 | * @return $this 221 | * @throws \SoapFault 222 | * @throws \SoapFault 223 | */ 224 | public function addWebDomain(): ISPConfigWS 225 | { 226 | $client_id = $this->extractParameter('client_id'); 227 | $this->wsResponse = $this->ws()->sites_web_domain_add($this->sessionId, $client_id, $this->params); 228 | 229 | return $this; 230 | } 231 | 232 | /** 233 | * @return $this 234 | * @throws \SoapFault 235 | * @throws \SoapFault 236 | */ 237 | public function deleteWebDomain(): ISPConfigWS 238 | { 239 | $primary_id = $this->extractParameter('domain_id'); 240 | $this->wsResponse = $this->ws()->sites_web_domain_delete($this->sessionId, $primary_id); 241 | 242 | return $this; 243 | } 244 | 245 | /** 246 | * @return $this 247 | * @throws \SoapFault 248 | * @throws \SoapFault 249 | */ 250 | public function updateWebDomain(): ISPConfigWS 251 | { 252 | $client_id = $this->extractParameter('client_id'); 253 | $primary_id = $this->extractParameter('domain_id'); 254 | $this->wsResponse = $this->ws()->sites_web_domain_update($this->sessionId, $client_id, $primary_id, $this->params); 255 | 256 | return $this; 257 | } 258 | 259 | /** 260 | * 261 | */ 262 | public function logout() 263 | { 264 | $this->ws()->logout($this->sessionId); 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /Servers/ISPConfig/index.php: -------------------------------------------------------------------------------- 1 | 'host', 16 | 'friendlyName' => 'ISPConfig panel url', 17 | 'type' => 'text', 18 | 'required' => true, 19 | 'description' => 'Example: https://panel.example.com:8080/remote/json.php', 20 | ], 21 | [ 22 | 'name' => 'username', 23 | 'friendlyName' => 'Username', 24 | 'type' => 'text', 25 | 'required' => true, 26 | ], 27 | [ 28 | 'name' => 'password', 29 | 'friendlyName' => 'Password', 30 | 'type' => 'text', 31 | 'required' => true, 32 | ] 33 | ]; 34 | } 35 | 36 | function ISPConfig_getProductConfig() 37 | { 38 | return [ 39 | [ 40 | 'name' => 'hd_quota', 41 | 'friendlyName' => 'Disk space MB', 42 | 'type' => 'text', 43 | 'required' => true, 44 | 'description' => 'Disk space in MB', 45 | ], 46 | [ 47 | 'name' => 'traffic_quota', 48 | 'friendlyName' => 'Traffic MB', 49 | 'type' => 'text', 50 | 'required' => true, 51 | 'description' => 'Traffic in MB', 52 | ], 53 | [ 54 | 'name' => 'pm_max_requests', 55 | 'friendlyName' => 'Max requests', 56 | 'type' => 'text', 57 | 'required' => true, 58 | 'description' => 'Max requests of the customer website', 59 | ], 60 | ]; 61 | } 62 | 63 | function ISPConfig_createServer($user, $params, $order, OrderProduct $product) 64 | { 65 | $webService = new ISPConfigWS\ISPConfigWS( 66 | array( 67 | 'host' => ExtensionHelper::getConfig('ISPConfig', 'host'), 68 | 'user' => ExtensionHelper::getConfig('ISPConfig', 'username'), 69 | 'pass' => ExtensionHelper::getConfig('ISPConfig', 'password'), 70 | ), 71 | ); 72 | 73 | $client_id = ISPConfig_getClient($user, $webService); 74 | if (!$client_id) { 75 | return false; 76 | } 77 | $result = $webService 78 | ->with(array( 79 | 'client_id' => $client_id, 80 | 'domain' => $params['config']['domain'], 81 | 'type' => 'vhost', 82 | 'vhost_type' => 'name', 83 | 'ip_address' => '*', 84 | 'active' => 'y', 85 | 'hd_quota' => -1, 86 | 'traffic_quota' => -1, 87 | 'client_group_id' => $client_id + 1, 88 | 'server_id' => 1, 89 | 'http_port' => 80, 90 | 'https_port' => 443, 91 | 'allow_override' => 'All', 92 | 'php' => 'suphp', 93 | 'pm_max_requests' => 500, 94 | 'pm_process_idle_timeout' => 10, 95 | 'added_date' => date('Y-m-d'), 96 | )) 97 | ->addWebDomain() 98 | ->response(); 99 | 100 | $result = json_decode($result, true); 101 | if (isset($result['error'])) { 102 | return false; 103 | } 104 | if (empty($result)) { 105 | return false; 106 | } 107 | if (isset($result['result'])){ 108 | ExtensionHelper::setOrderProductConfig('domain_id', $result['result'], $product->id); 109 | } 110 | return true; 111 | } 112 | 113 | function ISPConfig_getUserConfig(Product $product) 114 | { 115 | return [ 116 | [ 117 | 'name' => 'domain', 118 | 'friendlyName' => 'Domain', 119 | 'type' => 'text', 120 | 'required' => true, 121 | 'description' => 'Domain for the webhosting', 122 | ], 123 | ]; 124 | } 125 | 126 | function ISPConfig_getClient($user, $webService) 127 | { 128 | $reseller_id = 1; 129 | $result = $webService 130 | ->with(array('customer_no' => $user->id)) 131 | ->getClientByCustomerNo() 132 | ->response(); 133 | $result = json_decode($result, true); 134 | $user->name = str_replace(' ', '', $user->name); 135 | if (empty($result) || isset($result['error'])) { 136 | $result = $webService 137 | ->with(array( 138 | 'reseller_id' => $reseller_id, 139 | 'email' => $user->email, 140 | 'username' => $user->name, 141 | 'password' => $user->password, 142 | 'ssh_chroot' => 'no', 143 | 'contact_name' => $user->name, 144 | 'web_php_options' => 'no', 145 | 'customer_no' => $user->id, 146 | )) 147 | ->addClient() 148 | ->response(); 149 | $result = json_decode($result, true); 150 | if (empty($result)) { 151 | return false; 152 | } else { 153 | $result = $webService 154 | ->with(array('customer_no' => $user->id)) 155 | ->getClientByCustomerNo() 156 | ->response(); 157 | } 158 | } 159 | 160 | if (isset($result['error'])) { 161 | return false; 162 | } 163 | return $result['client_id']; 164 | } 165 | 166 | function ISPConfig_suspendServer(User $user, $params, Orders $order, OrderProducts $product) 167 | { 168 | // deactivate the domain 169 | $webService = new ISPConfigWS\ISPConfigWS( 170 | array( 171 | 'host' => ExtensionHelper::getConfig('ISPConfig', 'host'), 172 | 'user' => ExtensionHelper::getConfig('ISPConfig', 'username'), 173 | 'pass' => ExtensionHelper::getConfig('ISPConfig', 'password'), 174 | ), 175 | ); 176 | 177 | $result = $webService 178 | ->with(array('customer_no' => $user->id)) 179 | ->getClientByCustomerNo() 180 | ->response(); 181 | $result = json_decode($result, true); 182 | if (isset($result['error'])) { 183 | return false; 184 | } 185 | if (empty($result)) { 186 | return false; 187 | } 188 | if (!isset($params['config']['domain_id'])){ 189 | return false; 190 | } 191 | // Get website by domain 192 | $result = $webService 193 | ->with(array('domain_id' => $params['config']['domain_id'], 'client_id' => $result['client_id'], 'active' => 'n')) 194 | ->updateWebDomain() 195 | ->response(); 196 | $result = json_decode($result, true); 197 | } 198 | 199 | function ISPConfig_unsuspendServer(User $user, $params, Order $order, OrderProduct $product) 200 | { 201 | // deactivate the domain 202 | $webService = new ISPConfigWS\ISPConfigWS( 203 | array( 204 | 'host' => ExtensionHelper::getConfig('ISPConfig', 'host'), 205 | 'user' => ExtensionHelper::getConfig('ISPConfig', 'username'), 206 | 'pass' => ExtensionHelper::getConfig('ISPConfig', 'password'), 207 | ), 208 | ); 209 | 210 | $result = ISPConfig_getClient($user, $webService); 211 | if (!isset($params['config']['domain_id'])){ 212 | return false; 213 | } 214 | // Get website by domain 215 | $result = $webService 216 | ->with(array('domain_id' => $params['config']['domain_id'], 'client_id' => $result, 'active' => 'y')) 217 | ->updateWebDomain() 218 | ->response(); 219 | $result = json_decode($result, true); 220 | } 221 | 222 | function ISPConfig_terminateServer($user, $params, $order) { 223 | 224 | $webService = new ISPConfigWS\ISPConfigWS( 225 | array( 226 | 'host' => ExtensionHelper::getConfig('ISPConfig', 'host'), 227 | 'user' => ExtensionHelper::getConfig('ISPConfig', 'username'), 228 | 'pass' => ExtensionHelper::getConfig('ISPConfig', 'password'), 229 | ), 230 | ); 231 | 232 | $result = ISPConfig_getClient($user, $webService); 233 | if (empty($result)) { 234 | return false; 235 | } 236 | if (!isset($params['config']['domain_id'])){ 237 | return false; 238 | } 239 | // Get website by domain 240 | $result = $webService 241 | ->with(array('domain_id' => $params['config']['domain_id'], 'client_id' => $result['client_id'])) 242 | ->deleteWebDomain() 243 | ->response(); 244 | $result = json_decode($result, true); 245 | } -------------------------------------------------------------------------------- /Servers/Plesk/index.php: -------------------------------------------------------------------------------- 1 | withoutVerifying()->post($host . '/api/v2/auth/keys'); 14 | $response = json_decode($response->body(), true); 15 | return $response['key']; 16 | } 17 | 18 | function Plesk_getConfig() 19 | { 20 | return [ 21 | [ 22 | 'name' => 'host', 23 | 'friendlyName' => 'Host', 24 | 'type' => 'text', 25 | 'required' => true, 26 | 'description' => 'The IP address or domain name of the Plesk server (with http:// or https://)', 27 | ], 28 | [ 29 | 'name' => 'username', 30 | 'friendlyName' => 'Username', 31 | 'type' => 'text', 32 | 'required' => true, 33 | 'description' => 'The username of the Plesk server', 34 | ], 35 | [ 36 | 'name' => 'password', 37 | 'friendlyName' => 'Password', 38 | 'type' => 'text', 39 | 'required' => true, 40 | 'description' => 'The password of the Plesk server', 41 | ] 42 | ]; 43 | } 44 | 45 | function Plesk_getProductConfig() 46 | { 47 | 48 | return [ 49 | [ 50 | 'name' => 'plan', 51 | 'type' => 'text', 52 | 'friendlyName' => 'Plan', 53 | 'required' => true, 54 | 'description' => 'The plan name of the wanted service plan', 55 | ] 56 | ]; 57 | } 58 | 59 | function Plesk_getUserConfig() 60 | { 61 | return [ 62 | [ 63 | 'name' => 'domain', 64 | 'type' => 'text', 65 | 'friendlyName' => 'Domain', 66 | 'required' => true, 67 | ], 68 | ]; 69 | } 70 | 71 | function Plesk_createServer($user, $params, $order) 72 | { 73 | $apiKey = Plesk_getApiKey(); 74 | $host = ExtensionHelper::getConfig('Plesk', 'host'); 75 | // Check if client already has a server 76 | $clientCheck = Http::withHeaders([ 77 | 'Content-Type' => 'application/json', 78 | 'Accept' => 'application/json', 79 | 'X-API-Key' => $apiKey 80 | ])->withoutVerifying()->get($host . '/api/v2/clients/' . $user->id); 81 | $clientCheck = json_decode($clientCheck->body(), true); 82 | // Remove spaces and special characters from username 83 | $username = preg_replace('/[^A-Za-z0-9\-]/', '', $user->name); 84 | $uuid; 85 | if (isset($clientCheck['code'])) { 86 | $newClient = Http::withHeaders([ 87 | 'Content-Type' => 'application/json', 88 | 'Accept' => 'application/json', 89 | 'X-API-Key' => $apiKey 90 | ])->withoutVerifying()->post($host . '/api/v2/clients', [ 91 | 'username' => $username, 92 | 'email' => $user->email, 93 | 'password' => $params['password'] ?? $user->password, 94 | 'name' => $user->name, 95 | 'login' => $username, 96 | 'type' => 'customer', 97 | 'external_id' => $user->id, 98 | ]); 99 | $newClient = json_decode($newClient->body(), true); 100 | $uuid = $newClient['guid']; 101 | } else { 102 | $uuid = $clientCheck['guid']; 103 | } 104 | // Lowercase username 105 | $username = strtolower($username); 106 | $domain = Http::withHeaders([ 107 | 'Content-Type' => 'application/json', 108 | 'Accept' => 'application/json', 109 | 'X-API-Key' => $apiKey 110 | ])->withoutVerifying()->post($host . '/api/v2/domains', [ 111 | 'name' => $params['config']['domain'], 112 | 'external_id' => $order->id, 113 | 'client' => $uuid, 114 | 'hosting_type' => 'virtual', 115 | 'hosting_settings' => [ 116 | 'ftp_login' => $username, 117 | 'ftp_password' => $params['password'] ?? $user->password, 118 | ], 119 | 'plan' => [ 120 | 'name' => $params['plan'], 121 | ] 122 | ]); 123 | $domain = json_decode($domain->body(), true); 124 | return $domain; 125 | } 126 | 127 | function Plesk_suspendServer($user, $params) 128 | { 129 | $apiKey = Plesk_getApiKey(); 130 | $host = ExtensionHelper::getConfig('Plesk', 'host'); 131 | $domain = Http::withHeaders([ 132 | 'Content-Type' => 'application/json', 133 | 'Accept' => 'application/json', 134 | 'X-API-Key' => $apiKey 135 | ])->withoutVerifying()->put($host . '/api/v2/domains/' . Plesk_getDomainID($params['config']['domain']) . '/status', [ 136 | 'status' => 'suspended' 137 | ]); 138 | $domain = json_decode($domain->body(), true); 139 | return $domain; 140 | } 141 | 142 | function Plesk_getDomainID($domain) 143 | { 144 | $apiKey = Plesk_getApiKey(); 145 | $host = ExtensionHelper::getConfig('Plesk', 'host'); 146 | $domain = Http::withHeaders([ 147 | 'Content-Type' => 'application/json', 148 | 'Accept' => 'application/json', 149 | 'X-API-Key' => $apiKey 150 | ])->withoutVerifying()->get($host . '/api/v2/domains?name=' . $domain); 151 | $domain = json_decode($domain->body(), true); 152 | return $domain[0]['id']; 153 | } 154 | 155 | function Plesk_unsuspendServer($user, $params) 156 | { 157 | $apiKey = Plesk_getApiKey(); 158 | $host = ExtensionHelper::getConfig('Plesk', 'host'); 159 | $domain = Http::withHeaders([ 160 | 'Content-Type' => 'application/json', 161 | 'Accept' => 'application/json', 162 | 'X-API-Key' => $apiKey 163 | ])->withoutVerifying()->put($host . '/api/v2/domains/' . Plesk_getDomainID($params['config']['domain']) . '/status', [ 164 | 'status' => 'active' 165 | ]); 166 | $domain = json_decode($domain->body(), true); 167 | return $domain; 168 | } 169 | 170 | function Plesk_terminateServer($user, $params) 171 | { 172 | $apiKey = Plesk_getApiKey(); 173 | $host = ExtensionHelper::getConfig('Plesk', 'host'); 174 | $domain = Http::withHeaders([ 175 | 'Content-Type' => 'application/json', 176 | 'Accept' => 'application/json', 177 | 'X-API-Key' => $apiKey 178 | ])->withoutVerifying()->delete($host . '/api/v2/domains/' . Plesk_getDomainID($params['config']['domain'])); 179 | $domain = json_decode($domain->body(), true); 180 | return $domain; 181 | } 182 | 183 | function Plesk_getLink($user, $params){ 184 | $host = ExtensionHelper::getConfig('Plesk', 'host'); 185 | return $host . '/smb/web/overview/id/' . Plesk_getDomainID($params['config']['domain']) . '/type/domain'; 186 | } 187 | -------------------------------------------------------------------------------- /Servers/Proxmox/index.php: -------------------------------------------------------------------------------- 1 | 'host', 15 | 'friendlyName' => 'Host', 16 | 'type' => 'text', 17 | 'required' => true, 18 | 'description' => 'The IP address or domain name of the Proxmox server (with http:// or https://)', 19 | ], 20 | [ 21 | 'name' => 'port', 22 | 'friendlyName' => 'Port', 23 | 'type' => 'text', 24 | 'required' => true, 25 | 'description' => 'The port of the Proxmox server', 26 | ], 27 | [ 28 | 'name' => 'username', 29 | 'friendlyName' => 'Username', 30 | 'type' => 'text', 31 | 'required' => true, 32 | 'description' => 'The api username of the Proxmox server', 33 | ], 34 | [ 35 | 'name' => 'password', 36 | 'friendlyName' => 'API Token', 37 | 'type' => 'text', 38 | 'required' => true, 39 | 'description' => 'The API Token of the Proxmox server', 40 | ] 41 | ]; 42 | } 43 | 44 | function Proxmox_getProductConfig($options) 45 | { 46 | $nodes = Proxmox_getRequest('/nodes'); 47 | if (!$nodes->json()) throw new Exception('Unable to get nodes'); 48 | foreach ($nodes->json()['data'] as $node) { 49 | $nodeList[] = [ 50 | 'name' => $node['node'], 51 | 'value' => $node['node'] 52 | ]; 53 | } 54 | 55 | $currentNode = isset($options['node']) ? $options['node'] : null; 56 | $storageName = isset($options['storage']) ? $options['storage'] : null; 57 | if ($currentNode == null) { 58 | $currentNode = $nodeList[0]['value']; 59 | } 60 | $storage = Proxmox_getRequest('/nodes/' . $currentNode . '/storage'); 61 | $storageList = []; 62 | if (!$storage->json()) throw new Exception('Unable to get storage'); 63 | foreach ($storage->json()['data'] as $storage) { 64 | $storageList[] = [ 65 | 'name' => $storage['storage'], 66 | 'value' => $storage['storage'] 67 | ]; 68 | } 69 | 70 | $resourcePool = Proxmox_getRequest('/pools'); 71 | $poolList = [ 72 | [ 73 | 'name' => 'None', 74 | 'value' => '' 75 | ] 76 | ]; 77 | 78 | if (!$resourcePool->json()) throw new Exception('Unable to get resource pool'); 79 | foreach ($resourcePool->json()['data'] as $pool) { 80 | $poolList[] = [ 81 | 'name' => $pool['poolid'], 82 | 'value' => $pool['poolid'] 83 | ]; 84 | } 85 | 86 | // Only list contentVztmpl 87 | $templateList = []; 88 | $isoList = []; 89 | foreach ($nodeList as $node) { 90 | // Get all storage 91 | $storage = Proxmox_getRequest('/nodes/' . $node['value'] . '/storage'); 92 | if (!$storage->json()) throw new Exception('Unable to get storage'); 93 | foreach ($storage->json()['data'] as $storage) { 94 | $storageName = $storage['storage']; 95 | $template = Proxmox_getRequest('/nodes/' . $node['value'] . '/storage/' . $storageName . '/content'); 96 | if (!$template->json()) throw new Exception('Unable to get template'); 97 | foreach ($template->json()['data'] as $template) { 98 | if ($template['content'] == 'vztmpl') { 99 | $templateList[] = [ 100 | 'name' => $template['volid'], 101 | 'value' => $template['volid'] 102 | ]; 103 | } else if ($template['content'] == 'iso') { 104 | $isoList[] = [ 105 | 'name' => $template['volid'], 106 | 'value' => $template['volid'] 107 | ]; 108 | } 109 | } 110 | } 111 | } 112 | 113 | 114 | 115 | $bridgeList = []; 116 | $bridge = Proxmox_getRequest('/nodes/' . $currentNode . '/network'); 117 | if (!$bridge->json()) throw new Exception('Unable to get bridge'); 118 | foreach ($bridge->json()['data'] as $bridge) { 119 | if (!isset($bridge['active'])) continue; 120 | if (!$bridge['active']) continue; 121 | $bridgeList[] = [ 122 | 'name' => $bridge['iface'], 123 | 'value' => $bridge['iface'] 124 | ]; 125 | } 126 | 127 | $cpuList = [ 128 | [ 129 | 'name' => 'Default', 130 | 'value' => '' 131 | ] 132 | ]; 133 | $cpu = Proxmox_getRequest('/nodes/' . $currentNode . '/capabilities/qemu/cpu'); 134 | if (!$cpu->json()) throw new Exception('Unable to get cpu'); 135 | foreach ($cpu->json()['data'] as $cpu) { 136 | $cpuList[] = [ 137 | 'name' => $cpu['name'] . ' (' . $cpu['vendor'] . ')', 138 | 'value' => $cpu['name'] 139 | ]; 140 | } 141 | 142 | 143 | 144 | return [ 145 | [ 146 | 'type' => 'title', 147 | 'friendlyName' => 'General', 148 | 'description' => 'General options', 149 | ], 150 | [ 151 | 'name' => 'node', 152 | 'type' => 'dropdown', 153 | 'friendlyName' => 'Node', 154 | 'required' => true, 155 | 'description' => 'The node name of the wanted node (submit to update the storage list)', 156 | 'options' => $nodeList 157 | ], 158 | [ 159 | 'name' => 'storage', 160 | 'type' => 'dropdown', 161 | 'friendlyName' => 'Storage', 162 | 'description' => 'The storage name of the wanted storage', 163 | 'options' => $storageList 164 | ], 165 | [ 166 | 'name' => 'pool', 167 | 'type' => 'dropdown', 168 | 'friendlyName' => 'Resource Pool', 169 | 'description' => 'Resource Pool places VMs in a group', 170 | 'options' => $poolList 171 | ], 172 | [ 173 | 'name' => 'type', 174 | 'type' => 'dropdown', 175 | 'friendlyName' => 'Type', 176 | 'required' => true, 177 | 'description' => 'The type of the wanted VM', 178 | 'options' => [ 179 | [ 180 | 'name' => 'qemu', 181 | 'value' => 'qemu' 182 | ], 183 | [ 184 | 'name' => 'lxc', 185 | 'value' => 'lxc' 186 | ] 187 | ] 188 | ], 189 | [ 190 | 'name' => 'cores', 191 | 'type' => 'text', 192 | 'friendlyName' => 'Cores', 193 | 'required' => true, 194 | 'description' => 'The number of cores of the wanted VM', 195 | ], 196 | [ 197 | 'name' => 'memory', 198 | 'type' => 'text', 199 | 'friendlyName' => 'Memory (MB)', 200 | 'required' => true, 201 | 'description' => 'The amount of memory of the wanted VM', 202 | ], 203 | [ 204 | 'name' => 'disk', 205 | 'type' => 'text', 206 | 'friendlyName' => 'Disk (GB)', 207 | 'required' => true, 208 | 'description' => 'The amount of disk of the wanted VM', 209 | ], 210 | [ 211 | 'name' => 'network_limit', 212 | 'type' => 'text', 213 | 'friendlyName' => 'Network Limit (MB)', 214 | 'description' => 'The network limit of the wanted VM', 215 | ], 216 | 217 | 218 | [ 219 | 'name' => 'lxc', 220 | 'type' => 'title', 221 | 'friendlyName' => 'LXC', 222 | 'description' => 'All LXC options', 223 | ], 224 | [ 225 | 'name' => 'template', 226 | 'type' => 'dropdown', 227 | 'friendlyName' => 'Template', 228 | 'description' => 'The template name of the wanted VM', 229 | 'options' => $templateList 230 | ], 231 | [ 232 | 'name' => 'unprivileged', 233 | 'type' => 'boolean', 234 | 'friendlyName' => 'Unprivileged Container', 235 | 'description' => 'Enable/disable unprivileged container', 236 | ], 237 | [ 238 | 'name' => 'nesting', 239 | 'type' => 'boolean', 240 | 'friendlyName' => 'Nesting', 241 | 'description' => 'Enable/disable nesting', 242 | ], 243 | [ 244 | 'name' => 'ostypelxc', 245 | 'type' => 'dropdown', 246 | 'friendlyName' => 'OS Type', 247 | 'description' => 'The OS type of the wanted VM', 248 | 'options' => [ 249 | [ 250 | 'name' => 'debian', 251 | 'value' => 'debian' 252 | ], 253 | [ 254 | 'name' => 'devuan', 255 | 'value' => 'devuan' 256 | ], 257 | [ 258 | 'name' => 'ubuntu', 259 | 'value' => 'ubuntu' 260 | ], 261 | [ 262 | 'name' => 'centos', 263 | 'value' => 'centos' 264 | ], 265 | [ 266 | 'name' => 'fedora', 267 | 'value' => 'fedora' 268 | ], 269 | [ 270 | 'name' => 'opensuse', 271 | 'value' => 'opensuse' 272 | ], 273 | [ 274 | 'name' => 'archlinux', 275 | 'value' => 'archlinux' 276 | ], 277 | [ 278 | 'name' => 'alpine', 279 | 'value' => 'alpine' 280 | ], 281 | [ 282 | 'name' => 'gentoo', 283 | 'value' => 'gentoo' 284 | ], 285 | [ 286 | 'name' => 'nixos', 287 | 'value' => 'nixos' 288 | ], 289 | [ 290 | 'name' => 'unmanaged', 291 | 'value' => 'unmanaged' 292 | ] 293 | ] 294 | ], 295 | [ 296 | 'type' => 'text', 297 | 'name' => 'swap', 298 | 'friendlyName' => 'Swap (MB)', 299 | 'description' => 'The amount of swap of the wanted VM', 300 | ], 301 | 302 | [ 303 | 'type' => 'title', 304 | 'friendlyName' => 'QEMU', 305 | 'description' => 'All QEMU options', 306 | ], 307 | [ 308 | 'name' => 'nonetwork', 309 | 'type' => 'boolean', 310 | 'friendlyName' => 'No Network', 311 | 'description' => 'Enable/disable network', 312 | ], 313 | [ 314 | 'name' => 'bridge', 315 | 'type' => 'dropdown', 316 | 'friendlyName' => 'Bridge', 317 | 'options' => $bridgeList 318 | ], 319 | [ 320 | 'name' => 'model', 321 | 'type' => 'dropdown', 322 | 'friendlyName' => 'Model', 323 | 'options' => [ 324 | [ 325 | 'name' => 'VirtIO', 326 | 'value' => 'virtio' 327 | ], 328 | [ 329 | 'name' => 'Intel E1000', 330 | 'value' => 'e1000' 331 | ], 332 | [ 333 | 'name' => 'Realtek RTL8139', 334 | 'value' => 'rtl8139' 335 | ], 336 | [ 337 | 'name' => 'VMWare VMXNET3', 338 | 'value' => 'vmxnet3' 339 | ] 340 | ] 341 | ], 342 | [ 343 | 'name' => 'vlantag', 344 | 'type' => 'text', 345 | 'friendlyName' => 'VLAN Tag', 346 | 'description' => 'Optional VLAN tag', 347 | ], 348 | [ 349 | 'name' => 'firewall', 350 | 'type' => 'boolean', 351 | 'friendlyName' => 'Firewall', 352 | 'description' => 'Enable/disable firewall', 353 | ], 354 | [ 355 | 'name' => 'os', 356 | 'type' => 'dropdown', 357 | 'friendlyName' => 'OS', 358 | 'required' => true, 359 | 'options' => [ 360 | [ 361 | 'name' => 'ISO', 362 | 'value' => 'iso' 363 | ], 364 | [ 365 | 'name' => 'Pysical CD/DVD drive', 366 | 'value' => 'cdrom' 367 | ], 368 | [ 369 | 'name' => 'None', 370 | 'value' => 'none' 371 | ] 372 | ] 373 | ], 374 | [ 375 | 'name' => 'iso', 376 | 'type' => 'dropdown', 377 | 'friendlyName' => 'ISO', 378 | 'description' => 'The ISO name of the wanted VM', 379 | 'options' => $isoList 380 | ], 381 | [ 382 | 'name' => 'cloudinit', 383 | 'type' => 'boolean', 384 | 'friendlyName' => 'Cloudinit', 385 | 'description' => 'Enable/disable cloudinit', 386 | ], 387 | [ 388 | 'name' => 'storageType', 389 | 'type' => 'dropdown', 390 | 'friendlyName' => 'Bus/Device', 391 | 'description' => 'The bus/device of the VM', 392 | 'options' => 393 | [ 394 | [ 395 | 'name' => 'IDE', 396 | 'value' => 'ide' 397 | ], 398 | [ 399 | 'name' => 'SATA', 400 | 'value' => 'sata' 401 | ], 402 | [ 403 | 'name' => 'SCSI', 404 | 'value' => 'scsi' 405 | ], 406 | [ 407 | 'name' => 'VirtIO block', 408 | 'value' => 'virtio' 409 | ] 410 | ] 411 | ], 412 | [ 413 | 'name' => 'storageFormat', 414 | 'type' => 'dropdown', 415 | 'friendlyName' => 'Storage Format', 416 | 'description' => 'The storage format of the VM', 417 | 'options' => [ 418 | [ 419 | 'name' => 'Raw', 420 | 'value' => 'raw' 421 | ], 422 | [ 423 | 'name' => 'Qcow2', 424 | 'value' => 'qcow2' 425 | ], 426 | [ 427 | 'name' => 'VMDK', 428 | 'value' => 'vmdk' 429 | ], 430 | ] 431 | ], 432 | [ 433 | 'name' => 'cache', 434 | 'type' => 'dropdown', 435 | 'friendlyName' => 'Cache', 436 | 'description' => 'The cache of the VM', 437 | 'options' => [ 438 | [ 439 | 'name' => 'Default (no cache)', 440 | 'value' => 'default' 441 | ], 442 | [ 443 | 'name' => 'Direct Sync', 444 | 'value' => 'directsync' 445 | ], 446 | [ 447 | 'name' => 'Write Through', 448 | 'value' => 'writethrough' 449 | ], 450 | [ 451 | 'name' => 'Write Back', 452 | 'value' => 'write back' 453 | ], 454 | [ 455 | 'name' => 'Write Back (unsafe)', 456 | 'value' => 'unsafe' 457 | ], 458 | [ 459 | 'name' => 'No Cache', 460 | 'value' => 'none' 461 | ], 462 | ] 463 | ], 464 | [ 465 | 'name' => 'ostype', 466 | 'type' => 'dropdown', 467 | 'friendlyName' => 'Guest OS type', 468 | 'description' => 'The OS type of the VM', 469 | 'options' => [ 470 | [ 471 | 'name' => 'other', 472 | 'value' => 'other' 473 | ], 474 | [ 475 | 'name' => 'Windows XP', 476 | 'value' => 'wxp' 477 | ], 478 | [ 479 | 'name' => 'Windows 2000', 480 | 'value' => 'w2k' 481 | ], 482 | [ 483 | 'name' => 'Windows 2003', 484 | 'value' => 'w2k3' 485 | ], 486 | [ 487 | 'name' => 'Windows 2008', 488 | 'value' => 'w2k8' 489 | ], 490 | [ 491 | 'name' => 'Windows Vista', 492 | 'value' => 'wvista' 493 | ], 494 | [ 495 | 'name' => 'Windows 7', 496 | 'value' => 'win7' 497 | ], 498 | [ 499 | 'name' => 'Windows 8', 500 | 'value' => 'win8' 501 | ], 502 | [ 503 | 'name' => 'Windows 10', 504 | 'value' => 'win10' 505 | ], 506 | [ 507 | 'name' => 'Windows 11', 508 | 'value' => 'win11' 509 | ], 510 | [ 511 | 'name' => 'Linux 2.4 Kernel', 512 | 'value' => 'l24' 513 | ], 514 | [ 515 | 'name' => 'Linux 6.x - 2.6 Kernel', 516 | 'value' => 'l26' 517 | ], 518 | [ 519 | 'name' => 'solaris', 520 | 'value' => 'solaris' 521 | ] 522 | ] 523 | ], 524 | [ 525 | 'name' => 'cputype', 526 | 'type' => 'dropdown', 527 | 'friendlyName' => 'CPU type', 528 | 'description' => 'The CPU type of the VM', 529 | 'options' => $cpuList 530 | ], 531 | [ 532 | 'name' => 'vcpu', 533 | 'type' => 'number', 534 | 'friendlyName' => 'vCPU cores', 535 | 'description' => 'The number of vCPU cores of the VM', 536 | ], 537 | [ 538 | 'name' => 'sockets', 539 | 'type' => 'number', 540 | 'friendlyName' => 'Sockets', 541 | 'description' => 'The number of sockets of the VM', 542 | ], 543 | 544 | [ 545 | 'type' => 'title', 546 | 'friendlyName' => 'Clone options', 547 | 'description' => 'Options for cloning a VM' 548 | ], 549 | [ 550 | 'name' => 'clone', 551 | 'type' => 'boolean', 552 | 'friendlyName' => 'Clone', 553 | 'description' => 'Enable/disable cloning', 554 | ], 555 | [ 556 | 'name' => 'vmId', 557 | 'type' => 'number', 558 | 'friendlyName' => 'VM ID', 559 | 'description' => 'The ID of the VM to clone', 560 | ], 561 | ]; 562 | } 563 | 564 | function Proxmox_getRequest($url) 565 | { 566 | $response = Http::withHeaders([ 567 | 'Authorization' => 'PVEAPIToken=' . ExtensionHelper::getConfig('Proxmox', 'username') . '=' . ExtensionHelper::getConfig('Proxmox', 'password'), 568 | 'Accept' => 'application/json', 569 | 'Content-Type' => 'application/json' 570 | ])->withoutVerifying()->get(ExtensionHelper::getConfig('Proxmox', 'host') . ':' . ExtensionHelper::getConfig('Proxmox', 'port') . '/api2/json' . $url); 571 | 572 | return $response; 573 | } 574 | 575 | function Proxmox_postRequest($url, $data = []) 576 | { 577 | $response = Http::withHeaders([ 578 | 'Authorization' => 'PVEAPIToken=' . ExtensionHelper::getConfig('Proxmox', 'username') . '=' . ExtensionHelper::getConfig('Proxmox', 'password'), 579 | 'Accept' => 'application/json', 580 | 'Content-Type' => 'application/json' 581 | ])->withoutVerifying()->post(ExtensionHelper::getConfig('Proxmox', 'host') . ':' . ExtensionHelper::getConfig('Proxmox', 'port') . '/api2/json' . $url, $data); 582 | 583 | return $response; 584 | } 585 | 586 | function Proxmox_deleteRequest($url) 587 | { 588 | $response = Http::withHeaders([ 589 | 'Authorization' => 'PVEAPIToken=' . ExtensionHelper::getConfig('Proxmox', 'username') . '=' . ExtensionHelper::getConfig('Proxmox', 'password'), 590 | 'Accept' => 'application/json', 591 | 'Content-Type' => 'application/json' 592 | ])->withoutVerifying()->delete(ExtensionHelper::getConfig('Proxmox', 'host') . ':' . ExtensionHelper::getConfig('Proxmox', 'port') . '/api2/json' . $url); 593 | 594 | return $response; 595 | } 596 | 597 | function Proxmox_putRequest($url, $data = []) 598 | { 599 | $response = Http::withHeaders([ 600 | 'Authorization' => 'PVEAPIToken=' . ExtensionHelper::getConfig('Proxmox', 'username') . '=' . ExtensionHelper::getConfig('Proxmox', 'password'), 601 | 'Accept' => 'application/json', 602 | 'Content-Type' => 'application/json' 603 | ])->withoutVerifying()->put(ExtensionHelper::getConfig('Proxmox', 'host') . ':' . ExtensionHelper::getConfig('Proxmox', 'port') . '/api2/json' . $url, $data); 604 | 605 | return $response; 606 | } 607 | 608 | function Proxmox_test() 609 | { 610 | $response = Proxmox_getRequest('/nodes'); 611 | if (!$response->json()) throw new Exception('Unable to get nodes'); 612 | return true; 613 | } 614 | 615 | function Proxmox_getUserConfig(Product $product) 616 | { 617 | $currentConfig = $product->settings; 618 | if ($currentConfig->where('name', 'type')->first()->value == 'lxc') { 619 | return [ 620 | [ 621 | 'name' => 'hostname', 622 | 'type' => 'text', 623 | 'friendlyName' => 'Hostname', 624 | 'description' => 'The hostname of the VM', 625 | ], 626 | [ 627 | 'name' => 'password', 628 | 'type' => 'password', 629 | 'friendlyName' => 'Password', 630 | 'description' => 'The password of the VM', 631 | 'required' => true, 632 | ], 633 | ]; 634 | } 635 | 636 | return [ 637 | [ 638 | 'name' => 'hostname', 639 | 'type' => 'text', 640 | 'friendlyName' => 'Hostname', 641 | 'description' => 'The hostname of the VM', 642 | ], 643 | [ 644 | 'name' => 'password', 645 | 'type' => 'password', 646 | 'friendlyName' => 'Password', 647 | 'description' => 'The password of the VM', 648 | 'required' => true, 649 | ], 650 | ]; 651 | } 652 | 653 | function Proxmox_createServer($user, $parmas, $order, $product, $configurableOptions) 654 | { 655 | $node = isset($configurableOptions['node']) ? $configurableOptions['node'] : $parmas['node']; 656 | $storage = isset($configurableOptions['storage']) ? $configurableOptions['storage'] : $parmas['storage']; 657 | $pool = isset($configurableOptions['pool']) ? $configurableOptions['pool'] : $parmas['pool']; 658 | $cores = isset($configurableOptions['cores']) ? $configurableOptions['cores'] : $parmas['cores']; 659 | $memory = isset($configurableOptions['memory']) ? $configurableOptions['memory'] : $parmas['memory']; 660 | $disk = isset($configurableOptions['disk']) ? $configurableOptions['disk'] : $parmas['disk']; 661 | $swap = isset($configurableOptions['swap']) ? $configurableOptions['swap'] : $parmas['swap']; 662 | $network_limit = isset($configurableOptions['network_limit']) ? $configurableOptions['network_limit'] : ($parmas['network_limit'] ?? null); 663 | $cpu = isset($configurableOptions['cpu']) ? $configurableOptions['cpu'] : ($parmas['cpu'] ?? null); 664 | 665 | $vmid = Proxmox_getRequest('/cluster/nextid')->json()['data']; 666 | 667 | // Assign it to the orderProduct for further use 668 | ExtensionHelper::setOrderProductConfig('vmid', $vmid, $order->id); 669 | $postData = []; 670 | 671 | $currentConfig = $product->product->settings; 672 | $postData = []; 673 | $vmType = $currentConfig->where('name', 'type')->first()->value; 674 | if ($currentConfig->where('name', 'clone')->first()->value == '1') { 675 | $postData = [ 676 | 'newid' => $vmid, 677 | 'name' => $parmas['config']['hostname'], 678 | 'target' => $node, 679 | 'storage' => $storage, 680 | 'full' => 1, 681 | ]; 682 | isset($parmas['pool']) && $postData['pool'] = $parmas['pool']; 683 | $response = Proxmox_postRequest('/nodes/' . $node . '/' . $vmType . '/' . $parmas['vmId'] . '/clone', $postData); 684 | } else if ($vmType == 'lxc') { 685 | $postData = [ 686 | 'vmid' => $vmid, 687 | 'node' => $node, 688 | 'storage' => $storage, 689 | 'cores' => $cores, 690 | 'memory' => $memory, 691 | 'onboot' => 1, 692 | 'ostemplate' => $parmas['template'], 693 | 'ostype' => $parmas['ostypelxc'], 694 | 'description' => $parmas['config']['hostname'], 695 | 'hostname' => $parmas['config']['hostname'], 696 | 'password' => $parmas['config']['password'], 697 | 'swap' => $swap ?? 512, 698 | 'net0' => 'name=test' . ',bridge=' . $parmas['bridge'] . ',' . (isset($parmas['firewall']) ? 'firewall=1' : 'firewall=0') . (isset($network_limit) ? ',rate=' . $network_limit : ''), 699 | ]; 700 | isset($pool) ? $postData['pool'] = $pool : null; 701 | $response = Proxmox_postRequest('/nodes/' . $node . '/lxc', $postData); 702 | } else { 703 | $socket = isset($configurableOptions['sockets']) ? $configurableOptions['sockets'] : ($parmas['sockets'] ?? null); 704 | $vcpu = isset($configurableOptions['vcpu']) ? $configurableOptions['vcpu'] : ($parmas['vcpu'] ?? null); 705 | $postData = [ 706 | 'vmid' => $vmid, 707 | 'node' => $node, 708 | 'storage' => $storage, 709 | 'cores' => $cores, 710 | 'memory' => $memory, 711 | 'onboot' => 1, 712 | 'sockets' => $socket ?? 1, 713 | 'agent' => 1, 714 | 'ostype' => $parmas['ostype'], 715 | 'name' => $parmas['config']['hostname'], 716 | 'description' => $parmas['config']['hostname'], 717 | $parmas['storageType'] . '0' => $parmas['storage'] . ':' . $disk . ',format=' . $parmas['storageFormat'], 718 | 'net0' => $parmas['model'] . ',bridge=' . $parmas['bridge'] . ',' . (isset($parmas['firewall']) ? 'firewall=1' : 'firewall=0'), 719 | ]; 720 | isset($pool) ? $postData['pool'] = $pool : null; 721 | isset($parmas['cloudinit']) ? $postData[$parmas['storageType'] . '0'] = $parmas['storage'] . ':cloudinit' . ',format=' . $parmas['storageFormat'] : null; 722 | isset($cpu) ? $postData['cpu'] = $cpu : null; 723 | isset($vcpu) ? $postData['vcpus'] = $vcpu : null; 724 | if (isset($parmas['os']) && $parmas['os'] == 'iso') { 725 | $postData['ide2'] = $parmas['iso'] . ',media=cdrom'; 726 | } 727 | $response = Proxmox_postRequest('/nodes/' . $node . '/qemu', $postData); 728 | } 729 | if (!$response->json()) throw new Exception('Unable to create server' . $response->body()); 730 | return true; 731 | } 732 | 733 | function Proxmox_suspendServer($user, $parmas, $order, $product, $configurableOptions) 734 | { 735 | throw new Exception('Not implemented'); 736 | } 737 | 738 | function Proxmox_unsuspendServer($user, $parmas, $order, $product, $configurableOptions) 739 | { 740 | throw new Exception('Not implemented'); 741 | } 742 | 743 | function Proxmox_terminateServer($user, $parmas, $order, $product, $configurableOptions) 744 | { 745 | $vmType = $parmas['type']; 746 | $vmid = $parmas['config']['vmid']; 747 | // Stop the VM first 748 | $response = Proxmox_postRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/status/stop'); 749 | // Delete the VM 750 | $postData = [ 751 | 'purge' => 1, 752 | 'destroy-unreferenced-disks' => 1, 753 | ]; 754 | $response = Proxmox_deleteRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid, $postData); 755 | if (!$response->json()) throw new Exception('Unable to terminate server'); 756 | return true; 757 | } 758 | 759 | 760 | function Proxmox_getCustomPages($user, $parmas, $order, $product, $configurableOptions) 761 | { 762 | $vmType = $parmas['type']; 763 | $vmid = $parmas['config']['vmid']; 764 | $status = Proxmox_getRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/status/current'); 765 | if (!$status->json()) throw new Exception('Unable to get server status'); 766 | $status = $status->json()['data']; 767 | 768 | $stats = Proxmox_getRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/rrddata?timeframe=hour'); 769 | if (!$stats->json()) throw new Exception('Unable to get server stats'); 770 | $stats = $stats->json()['data']; 771 | 772 | // $vnc; 773 | // if ($vmType == 'lxc') $vnc = Proxmox_postRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/vncproxy', ['websocket' => 1]); 774 | // else $vnc = Proxmox_postRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/vncproxy', ['websocket' => 1, 'generate-password' => 1]); 775 | // if (!$vnc->json()) throw new Exception('Unable to get server vnc'); 776 | // $vnc = $vnc->json()['data']; 777 | // $websocket = ExtensionHelper::getConfig('Proxmox', 'host') . ':' . ExtensionHelper::getConfig('Proxmox', 'port') . '/?console=kvm&novnc=1&node=' . $parmas['node'] . '&resize=1&vmid=' . $vmid . '&path=api2/json/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/vncwebsocket/port/' . $vnc['port'] . '/"vncticket"/' . $vnc['ticket']; 778 | 779 | $users = Proxmox_getRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/agent/get-users'); 780 | if (!$users->json()) throw new Exception('Unable to get server users'); 781 | $users = $users->json()['data']; 782 | 783 | $config = Proxmox_getRequest('/nodes/' . $parmas['node'] . '/' . $vmType . '/' . $vmid . '/config'); 784 | if (!$config->json()) throw new Exception('Unable to get server config'); 785 | $config = $config->json()['data']; 786 | 787 | 788 | // Make url for iframe 789 | 790 | 791 | return [ 792 | 'name' => 'Proxmox', 793 | 'template' => 'proxmox::control', 794 | 'data' => [ 795 | 'status' => $status, 796 | 'node' => $parmas['node'], 797 | 'vmid' => $vmid, 798 | 'stats' => $stats, 799 | // 'vnc' => $vnc, 800 | // 'websocket' => $websocket, 801 | 'users' => $users, 802 | 'config' => (object) $config, 803 | ], 804 | 'pages' => [ 805 | [ 806 | 'template' => 'proxmox::stats', 807 | 'name' => 'Statistics', 808 | 'url' => 'stats', 809 | ], 810 | // [ 811 | // 'template' => 'proxmox::vnc', 812 | // 'name' => 'VNC', 813 | // 'url' => 'vnc', 814 | // ], 815 | [ 816 | 'template' => 'proxmox::settings', 817 | 'name' => 'Settings', 818 | 'url' => 'settings', 819 | ] 820 | ] 821 | ]; 822 | } 823 | 824 | function Proxmox_status(Request $request, OrderProduct $product) 825 | { 826 | if (!ExtensionHelper::hasAccess($product, $request->user())) throw new Exception('You do not have access to this server'); 827 | $request->validate([ 828 | 'status' => ['required', 'string', 'in:stop,start,reboot,shutdown'], 829 | ]); 830 | $data = ExtensionHelper::getParameters($product); 831 | $params = $data->config; 832 | $vmid = $params['config']['vmid']; 833 | $vmType = $params['type']; 834 | $postData = [ 835 | 'node' => $params['node'], 836 | 'vmid' => $vmid, 837 | ]; 838 | // Change status 839 | $status = Proxmox_postRequest('/nodes/' . $params['node'] . '/' . $vmType . '/' . $vmid . '/status/' . $request->status, $postData); 840 | if (!$status->json()) throw new Exception('Unable to ' . $request->status . ' server'); 841 | 842 | // Return json response 843 | return response()->json([ 844 | 'status' => 'success', 845 | 'message' => 'Server has been ' . $request->status . 'ed successfully' 846 | ]); 847 | } 848 | 849 | function Proxmox_configure(Request $request, OrderProduct $product) 850 | { 851 | if (!ExtensionHelper::hasAccess($product, $request->user())) throw new Exception('You do not have access to this server'); 852 | $request->validate([ 853 | 'hostname' => ['required', 'string', 'max:255'], 854 | ]); 855 | $data = ExtensionHelper::getParameters($product); 856 | 857 | $params = $data->config; 858 | $vmid = $params['config']['vmid']; 859 | $vmType = $params['type']; 860 | 861 | $postData = [ 862 | 'hostname' => $request->hostname, 863 | ]; 864 | $config = Proxmox_putRequest('/nodes/' . $params['node'] . '/' . $vmType . '/' . $vmid . '/config', $postData); 865 | 866 | if (!$config->json()) throw new Exception('Unable to configure server'); 867 | return redirect()->back()->with('success', 'Server has been configured successfully'); 868 | } 869 | -------------------------------------------------------------------------------- /Servers/Proxmox/routes.php: -------------------------------------------------------------------------------- 1 | name('extensions.proxmox.status'); 12 | 13 | Route::post('/proxmox/configure/{id}', function (Request $request, OrderProduct $id) { 14 | return Proxmox_configure($request, $id); 15 | })->name('extensions.proxmox.configure'); -------------------------------------------------------------------------------- /Servers/Proxmox/views/control.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | The server is currently {{ ucfirst($status['status']) }}. 4 |
5 |
6 |
7 | 11 | 12 | 16 | 17 | 21 |
22 |
23 | 24 |
25 |
26 |
27 | CPU Usage: 28 |
29 |
30 | Memory Usage: 32 |
33 |
34 | Disk Usage: 35 |
36 |
37 |
38 |
39 | {{--

Name: {{ $status['hostname'] }}

--}} 40 |
41 |
42 |
43 | 66 | @include('proxmox::stats') -------------------------------------------------------------------------------- /Servers/Proxmox/views/settings.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @csrf 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Servers/Proxmox/views/stats.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 100 | -------------------------------------------------------------------------------- /Servers/Proxmox/views/vnc.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | -------------------------------------------------------------------------------- /Servers/Pterodactyl/index.php: -------------------------------------------------------------------------------- 1 | 'host', 21 | 'friendlyName' => 'Pterodactyl panel url', 22 | 'type' => 'text', 23 | 'required' => true, 24 | ], 25 | [ 26 | 'name' => 'apiKey', 27 | 'friendlyName' => 'API Key', 28 | 'type' => 'text', 29 | 'required' => true, 30 | ], 31 | ]; 32 | } 33 | 34 | function Pterodactyl_getProductConfig() 35 | { 36 | $nodes = Pterodactyl_getRequest(pteroConfig('host') . '/api/application/nodes'); 37 | $nodeList = [ 38 | [ 39 | 'name' => 'None', 40 | 'value' => '', 41 | ], 42 | ]; 43 | foreach ($nodes->json()['data'] as $node) { 44 | $nodeList[] = [ 45 | 'name' => $node['attributes']['name'], 46 | 'value' => $node['attributes']['id'], 47 | ]; 48 | } 49 | 50 | $location = Pterodactyl_getRequest(pteroConfig('host') . '/api/application/locations'); 51 | $locationList = []; 52 | foreach ($location->json()['data'] as $location) { 53 | $locationList[] = [ 54 | 'name' => $location['attributes']['short'], 55 | 'value' => $location['attributes']['id'], 56 | ]; 57 | } 58 | 59 | $nests = Pterodactyl_getRequest(pteroConfig('host') . '/api/application/nests'); 60 | $nestList = []; 61 | foreach ($nests->json()['data'] as $nest) { 62 | $nestList[] = [ 63 | 'name' => $nest['attributes']['name'], 64 | 'value' => $nest['attributes']['id'], 65 | ]; 66 | } 67 | 68 | 69 | 70 | return [ 71 | [ 72 | 'name' => 'node', 73 | 'friendlyName' => 'Pterodactyl Node (leave empty for node assigned to location)', 74 | 'type' => 'dropdown', 75 | 'options' => $nodeList, 76 | ], 77 | [ 78 | 'name' => 'location', 79 | 'friendlyName' => 'Pterodactyl Location', 80 | 'type' => 'dropdown', 81 | 'options' => $locationList, 82 | 'required' => true, 83 | ], 84 | [ 85 | 'name' => 'egg', 86 | 'friendlyName' => 'Pterodactyl Egg ID', 87 | 'type' => 'text', 88 | 'required' => true, 89 | ], 90 | [ 91 | 'name' => 'nest', 92 | 'friendlyName' => 'Pterodactyl Nest', 93 | 'type' => 'dropdown', 94 | 'options' => $nestList, 95 | 'required' => true, 96 | ], 97 | [ 98 | 'name' => 'memory', 99 | 'friendlyName' => 'Pterodactyl Memory', 100 | 'type' => 'text', 101 | 'required' => true, 102 | ], 103 | [ 104 | 'name' => 'swap', 105 | 'friendlyName' => 'Pterodactyl Swap', 106 | 'type' => 'text', 107 | 'required' => true, 108 | ], 109 | [ 110 | 'name' => 'disk', 111 | 'friendlyName' => 'Pterodactyl Disk', 112 | 'type' => 'text', 113 | 'required' => true, 114 | ], 115 | [ 116 | 'name' => 'io', 117 | 'friendlyName' => 'Pterodactyl IO', 118 | 'type' => 'text', 119 | 'required' => true, 120 | 'description' => 'IO is a number between 10 and 1000. 500 is the default value.', 121 | ], 122 | [ 123 | 'name' => 'cpu', 124 | 'friendlyName' => 'CPU limit', 125 | 'type' => 'text', 126 | 'required' => true, 127 | ], 128 | [ 129 | 'name' => 'databases', 130 | 'friendlyName' => 'Pterodactyl Database', 131 | 'type' => 'text', 132 | 'required' => true, 133 | ], 134 | [ 135 | 'name' => 'backups', 136 | 'friendlyName' => 'Pterodactyl Backups', 137 | 'type' => 'text', 138 | 'required' => true, 139 | ], 140 | [ 141 | 'name' => 'allocation', 142 | 'friendlyName' => 'Pterodactyl Allocation', 143 | 'type' => 'text', 144 | 'required' => true, 145 | 'description' => 'How many ports the user can allocate. Must be at least one.', 146 | ], 147 | [ 148 | 'name' => 'port_range', 149 | 'friendlyName' => 'Port Range', 150 | 'type' => 'text', 151 | 'required' => false, 152 | "Size" => 25, 153 | 'description' => 'Port ranges seperated by comma to assign to the server (Example: 25565-25570,25580-25590) (optional)', 154 | ], 155 | ]; 156 | } 157 | 158 | function Pterodactyl_postRequest($url, $data) 159 | { 160 | $response = Http::withHeaders([ 161 | 'Authorization' => 'Bearer ' . pteroConfig('apiKey'), 162 | 'Accept' => 'Application/vnd.Pterodactyl.v1+json', 163 | 'Content-Type' => 'application/json', 164 | ])->post($url, $data); 165 | 166 | return $response; 167 | } 168 | 169 | function Pterodactyl_getRequest($url) 170 | { 171 | $response = Http::withHeaders([ 172 | 'Authorization' => 'Bearer ' . pteroConfig('apiKey'), 173 | 'Accept' => 'Application/vnd.Pterodactyl.v1+json', 174 | 'Content-Type' => 'application/json', 175 | ])->get($url); 176 | 177 | return $response; 178 | } 179 | 180 | function Pterodactyl_deleteRequest($url) 181 | { 182 | $response = Http::withHeaders([ 183 | 'Authorization' => 'Bearer ' . pteroConfig('apiKey'), 184 | 'Accept' => 'Application/vnd.Pterodactyl.v1+json', 185 | 'Content-Type' => 'application/json', 186 | ])->delete($url); 187 | 188 | return $response; 189 | } 190 | 191 | function Pterodactyl_createServer($user, $parmas, $order, $product, $configurableOptions) 192 | { 193 | if (Pterodactyl_serverExists($product->id)) { 194 | ExtensionHelper::error('Pterodactyl', 'Server already exists for order ' . $product->id); 195 | 196 | return; 197 | } 198 | $url = pteroConfig('host') . '/api/application/servers'; 199 | $nest_id = isset($configurableOptions['nest_id']) ? $configurableOptions['nest_id'] : $parmas['nest']; 200 | $egg_id = isset($configurableOptions['egg']) ? $configurableOptions['egg'] : $parmas['egg']; 201 | $eggData = Pterodactyl_getRequest(pteroConfig('host') . '/api/application/nests/' . $nest_id . '/eggs/' . $egg_id . '?include=variables')->json(); 202 | if (!isset($eggData['attributes'])) { 203 | ExtensionHelper::error('Pterodactyl', 'No egg data found for ' . $parmas['egg']); 204 | 205 | return; 206 | } 207 | $environment = []; 208 | foreach ($eggData['attributes']['relationships']['variables']['data'] as $key => $val) { 209 | $attr = $val['attributes']; 210 | $var = $attr['env_variable']; 211 | $default = $attr['default_value']; 212 | // If the variable is configurable, get the value from the configurable options 213 | if (isset($configurableOptions[$var])) { 214 | $default = $configurableOptions[$var]; 215 | } 216 | $environment[$var] = $default; 217 | } 218 | $cpu = isset($configurableOptions['cpu']) ? $configurableOptions['cpu'] : $parmas['cpu']; 219 | $io = isset($configurableOptions['io']) ? $configurableOptions['io'] : $parmas['io']; 220 | $disk = isset($configurableOptions['disk']) ? $configurableOptions['disk'] : $parmas['disk']; 221 | $swap = isset($configurableOptions['swap']) ? $configurableOptions['swap'] : $parmas['swap']; 222 | $memory = isset($configurableOptions['memory']) ? $configurableOptions['memory'] : $parmas['memory']; 223 | $allocations = isset($configurableOptions['allocation']) ? $configurableOptions['allocation'] : $parmas['allocation']; 224 | $location = isset($configurableOptions['location']) ? $configurableOptions['location'] : $parmas['location']; 225 | $databases = isset($configurableOptions['databases']) ? $configurableOptions['databases'] : $parmas['databases']; 226 | $backups = isset($configurableOptions['backups']) ? $configurableOptions['backups'] : $parmas['backups']; 227 | $startup = isset($configurableOptions['startup']) ? $configurableOptions['startup'] : $eggData['attributes']['startup']; 228 | $node = isset($configurableOptions['node']) ? $configurableOptions['node'] : $parmas['node']; 229 | $port_range = isset($configurableOptions['port_range']) ? $configurableOptions['port_range'] : $parmas['port_range'] ??[]; 230 | 231 | 232 | if ($node) { 233 | $allocation = Pterodactyl_getRequest(pteroConfig('host') . '/api/application/nodes/' . $parmas['node'] . '/allocations'); 234 | $allocation = $allocation->json(); 235 | foreach ($allocation['data'] as $key => $val) { 236 | if ($val['attributes']['assigned'] == false) { 237 | $allocation = $val['attributes']['id']; 238 | break; 239 | } 240 | } 241 | $json = [ 242 | 'name' => Pterodactyl_random_string(8) . '-' . $product->id, 243 | 'user' => (int) Pterodactyl_getUser($user), 244 | 'egg' => (int) $egg_id, 245 | 'docker_image' => $eggData['attributes']['docker_image'], 246 | 'startup' => $startup, 247 | 'limits' => [ 248 | 'memory' => (int) $memory, 249 | 'swap' => (int) $swap, 250 | 'disk' => (int) $disk, 251 | 'io' => (int) $io, 252 | 'cpu' => (int) $cpu, 253 | ], 254 | 'feature_limits' => [ 255 | 'databases' => $databases ? (int) $databases : null, 256 | 'allocations' => $allocations, 257 | 'backups' => $backups, 258 | ], 259 | 'allocation' => [ 260 | 'default' => (int) $allocation, 261 | ], 262 | 'environment' => $environment, 263 | 'external_id' => (string) $product->id, 264 | ]; 265 | } else { 266 | $json = [ 267 | 'name' => Pterodactyl_random_string(8) . '-' . $product->id, 268 | 'user' => (int) Pterodactyl_getUser($user), 269 | 'egg' => (int) $egg_id, 270 | 'docker_image' => $eggData['attributes']['docker_image'], 271 | 'startup' => $startup, 272 | 'limits' => [ 273 | 'memory' => (int) $memory, 274 | 'swap' => (int) $swap, 275 | 'disk' => (int) $disk, 276 | 'io' => (int) $io, 277 | 'cpu' => (int) $cpu, 278 | ], 279 | 'feature_limits' => [ 280 | 'databases' => $databases ? (int) $databases : null, 281 | 'allocations' => $allocations, 282 | 'backups' => $backups, 283 | ], 284 | 'deploy' => [ 285 | 'locations' => [(int) $location], 286 | 'dedicated_ip' => false, 287 | 'port_range' => [$port_range], 288 | ], 289 | 'environment' => $environment, 290 | 'external_id' => (string) $product->id, 291 | ]; 292 | } 293 | $response = Pterodactyl_postRequest($url, $json); 294 | 295 | if (!$response->successful()) { 296 | ExtensionHelper::error('Pterodactyl', 'Failed to create server for order ' . $product->id . ' with error ' . $response->body()); 297 | 298 | return; 299 | } 300 | 301 | return true; 302 | } 303 | 304 | function Pterodactyl_random_string($length = 10) 305 | { 306 | $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 307 | $charactersLength = strlen($characters); 308 | $randomString = ''; 309 | for ($i = 0; $i < $length; ++$i) { 310 | $randomString .= $characters[mt_rand(0, $charactersLength - 1)]; 311 | } 312 | 313 | return $randomString; 314 | } 315 | 316 | function Pterodactyl_getUser($user) 317 | { 318 | $url = pteroConfig('host') . '/api/application/users?filter%5Bemail%5D=' . $user->email; 319 | $response = Pterodactyl_getRequest($url); 320 | $users = $response->json(); 321 | if (count($users['data']) > 0) { 322 | return $users['data'][0]['attributes']['id']; 323 | } else { 324 | $url = pteroConfig('host') . '/api/application/users'; 325 | $json = [ 326 | 'username' => Pterodactyl_random_string(8), 327 | 'email' => $user->email, 328 | 'first_name' => $user->name, 329 | 'last_name' => 'User', 330 | 'language' => 'en', 331 | 'root_admin' => false, 332 | ]; 333 | $response = Pterodactyl_postRequest($url, $json); 334 | if(!$response->successful()) { 335 | ExtensionHelper::error('Pterodactyl', 'Failed to create user for order ' . $product->id . ' with error ' . $response->body()); 336 | } 337 | $user = $response->json(); 338 | 339 | return $user['attributes']['id']; 340 | } 341 | } 342 | 343 | function Pterodactyl_serverExists($order) 344 | { 345 | $url = pteroConfig('host') . '/api/application/servers/external/' . $order; 346 | $response = Pterodactyl_getRequest($url); 347 | $code = $response->status(); 348 | if ($code == 200) { 349 | return $response->json()['attributes']['id']; 350 | } 351 | 352 | return false; 353 | } 354 | 355 | function Pterodactyl_suspendServer($user, $params, $order, $product) 356 | { 357 | $server = Pterodactyl_serverExists($product->id); 358 | if ($server) { 359 | $url = pteroConfig('host') . '/api/application/servers/' . $server . '/suspend'; 360 | Pterodactyl_postRequest($url, []); 361 | 362 | return true; 363 | } 364 | 365 | return false; 366 | } 367 | 368 | function Pterodactyl_unsuspendServer($user, $params, $order, $product) 369 | { 370 | $server = Pterodactyl_serverExists($product->id); 371 | if ($server) { 372 | $url = pteroConfig('host') . '/api/application/servers/' . $server . '/unsuspend'; 373 | Pterodactyl_postRequest($url, []); 374 | 375 | return true; 376 | } 377 | 378 | return false; 379 | } 380 | 381 | function Pterodactyl_terminateServer($user, $params,$order, $product) 382 | { 383 | $server = Pterodactyl_serverExists($product->id); 384 | if ($server) { 385 | $url = pteroConfig('host') . '/api/application/servers/' . $server; 386 | Pterodactyl_deleteRequest($url); 387 | 388 | return true; 389 | } 390 | 391 | return false; 392 | } 393 | 394 | function Pterodactyl_getLink($user, $params, $order, $product) 395 | { 396 | $server = Pterodactyl_serverExists($product->id); 397 | if ($server) { 398 | $url = pteroConfig('host') . '/api/application/servers/' . $server; 399 | $response = Pterodactyl_getRequest($url); 400 | $server = $response->json(); 401 | 402 | return pteroConfig('host') . '/server/' . $server['attributes']['identifier']; 403 | } 404 | 405 | return false; 406 | } 407 | -------------------------------------------------------------------------------- /Servers/VirtFusion/index.php: -------------------------------------------------------------------------------- 1 | 'host', 13 | 'type' => 'text', 14 | 'friendlyName' => 'Hostname', 15 | 'required' => true, 16 | ], 17 | [ 18 | 'name' => 'apikey', 19 | 'type' => 'text', 20 | 'friendlyName' => 'API key', 21 | 'required' => true, 22 | ], 23 | ]; 24 | } 25 | 26 | function VirtFusion_getProductConfig() 27 | { 28 | $packages = VirtFusion_getRequest('/api/v1/packages'); 29 | $package = []; 30 | foreach ($packages->json()['data'] as $p) { 31 | $package[] = [ 32 | 'name' => $p['name'], 33 | 'value' => $p['id'], 34 | ]; 35 | } 36 | return [ 37 | [ 38 | 'name' => 'package', 39 | 'type' => 'dropdown', 40 | 'friendlyName' => 'Package', 41 | 'required' => true, 42 | 'options' => $package, 43 | ], 44 | [ 45 | 'name' => 'hypervisor', 46 | 'type' => 'text', 47 | 'friendlyName' => 'Hypervisor Group ID', 48 | 'required' => true, 49 | ], 50 | [ 51 | 'name' => 'ips', 52 | 'type' => 'text', 53 | 'friendlyName' => 'Number IPs', 54 | 'required' => true, 55 | ], 56 | ]; 57 | } 58 | 59 | function VirtFusion_createServer($user, $params, $order, $product, $configurableOptions) 60 | { 61 | $package = $params['package']; 62 | 63 | $user = VirtFusion_getUser($user); 64 | $response = VirtFusion_postRequest( 65 | '/api/v1/servers', 66 | [ 67 | 'packageId' => $package, 68 | 'userId' => $user, 69 | 'hypervisorId' => $params['hypervisor'], 70 | 'ipv4' => $params['ips'], 71 | ] 72 | ); 73 | if (isset($response->json()['errors'])) { 74 | // Array to string conversion 75 | $error = implode(" ", $response->json()['errors']); 76 | ExtensionHelper::error('VirtFusion', 'Failed to create server' . $error); 77 | return; 78 | } 79 | ExtensionHelper::setOrderProductConfig('server_id', $response->json()['data']['id'], $product->id); 80 | 81 | return true; 82 | } 83 | 84 | function VirtFusion_getRequest($url) 85 | { 86 | $apikey = ExtensionHelper::getConfig('VirtFusion', 'apikey'); 87 | $host = ExtensionHelper::getConfig('VirtFusion', 'host'); 88 | 89 | $response = Http::withHeaders([ 90 | 'Authorization' => 'Bearer ' . $apikey, 91 | 'Accept' => 'Application/json', 92 | 'Content-Type' => 'application/json', 93 | ])->get( 94 | $host . $url 95 | ); 96 | return $response; 97 | } 98 | 99 | function VirtFusion_postRequest($url, $data) 100 | { 101 | $apikey = ExtensionHelper::getConfig('VirtFusion', 'apikey'); 102 | $host = ExtensionHelper::getConfig('VirtFusion', 'host'); 103 | 104 | $response = Http::withHeaders([ 105 | 'Authorization' => 'Bearer ' . $apikey, 106 | 'Accept' => 'Application/json', 107 | 'Content-Type' => 'application/json', 108 | ])->post( 109 | $host . $url, 110 | $data 111 | ); 112 | return $response; 113 | } 114 | 115 | function VirtFusion_getUser($user) 116 | { 117 | $response = VirtFusion_getRequest('/api/v1/users/' . $user->id . '/byExtRelation'); 118 | 119 | if (isset($response->json()['data'])) { 120 | return $response->json()['data']['id']; 121 | } else { 122 | // Create user 123 | $response = VirtFusion_postRequest( 124 | '/api/v1/users', 125 | [ 126 | 'name' => $user->name, 127 | 'email' => $user->email, 128 | 'extRelationId' => $user->id, 129 | ] 130 | ); 131 | 132 | if ($response->status() == 200) { 133 | return $response->json()['data']['id']; 134 | } else { 135 | ExtensionHelper::error('VirtFusion', 'Failed to create user ', (string) $response->json() . ' ' . $response->status()); 136 | 137 | return; 138 | } 139 | } 140 | } 141 | 142 | function VirtFusion_suspendServer($user, $params, $order) 143 | { 144 | $apikey = ExtensionHelper::getConfig('VirtFusion', 'apikey'); 145 | $host = ExtensionHelper::getConfig('VirtFusion', 'host'); 146 | if (!isset($params['config']['server_id'])) { 147 | return; 148 | } 149 | $server = $params['config']['server_id']; 150 | 151 | $response = Http::withHeaders([ 152 | 'Authorization' => 'Bearer ' . $apikey, 153 | 'Accept' => 'Application/json', 154 | 'Content-Type' => 'application/json', 155 | ])->post( 156 | $host . '/api/v1/servers/' . $server . '/suspend' 157 | ); 158 | if ($response->status() == 204) { 159 | return true; 160 | } else { 161 | ExtensionHelper::error('VirtFusion', 'Failed to suspend server'); 162 | 163 | return; 164 | } 165 | 166 | return true; 167 | } 168 | 169 | function VirtFusion_unsuspendServer($user, $params, $order) 170 | { 171 | $apikey = ExtensionHelper::getConfig('VirtFusion', 'apikey'); 172 | $host = ExtensionHelper::getConfig('VirtFusion', 'host'); 173 | if (!isset($params['config']['server_id'])) { 174 | return; 175 | } 176 | $server = $params['config']['server_id']; 177 | 178 | $response = Http::withHeaders([ 179 | 'Authorization' => 'Bearer ' . $apikey, 180 | 'Accept' => 'Application/json', 181 | 'Content-Type' => 'application/json', 182 | ])->post( 183 | $host . '/api/v1/servers/' . $server . '/unsuspend' 184 | ); 185 | if ($response->status() == 204) { 186 | return true; 187 | } else { 188 | ExtensionHelper::error('VirtFusion', 'Failed to unsuspend server'); 189 | 190 | return; 191 | } 192 | 193 | return true; 194 | } 195 | 196 | function VirtFusion_terminateServer($user, $params, $order) 197 | { 198 | $apikey = ExtensionHelper::getConfig('VirtFusion', 'apikey'); 199 | $host = ExtensionHelper::getConfig('VirtFusion', 'host'); 200 | if (!isset($params['config']['server_id'])) { 201 | return; 202 | } 203 | $server = $params['config']['server_id']; 204 | 205 | $response = Http::withHeaders([ 206 | 'Authorization' => 'Bearer ' . $apikey, 207 | 'Accept' => 'Application/json', 208 | 'Content-Type' => 'application/json', 209 | ])->delete( 210 | $host . '/api/v1/servers/' . $server . '?delay=5' 211 | ); 212 | if ($response->status() == 204) { 213 | return true; 214 | } else { 215 | ExtensionHelper::error('VirtFusion', 'Failed to terminate server'); 216 | 217 | return; 218 | } 219 | 220 | return true; 221 | } 222 | 223 | function VirtFusion_getCustomPages($user, $params, $order, $product, $configurableOptions) 224 | { 225 | $apikey = ExtensionHelper::getConfig('VirtFusion', 'apikey'); 226 | $host = ExtensionHelper::getConfig('VirtFusion', 'host'); 227 | if (!isset($params['config']['server_id'])) { 228 | return; 229 | } 230 | $server = $params['config']['server_id']; 231 | 232 | $response = Http::withHeaders([ 233 | 'Authorization' => 'Bearer ' . $apikey, 234 | 'Accept' => 'Application/json', 235 | 'Content-Type' => 'application/json', 236 | ])->get( 237 | $host . '/api/v1/servers/' . $server 238 | ); 239 | 240 | if ($response->successful()) { 241 | ExtensionHelper::error('VirtFusion', 'Failed to get custom pages'); 242 | 243 | return; 244 | } 245 | 246 | return [ 247 | 'name' => 'VirtFusion', 248 | 'template' => 'virtfusion::control', 249 | 'data' => [ 250 | 'details' => (object) $response->json()['data'], 251 | ], 252 | ]; 253 | } 254 | 255 | function VirtFusion_getLink($user, $params, $order, $product, $configurableOptions) 256 | { 257 | $apikey = ExtensionHelper::getConfig('VirtFusion', 'apikey'); 258 | $host = ExtensionHelper::getConfig('VirtFusion', 'host'); 259 | if (!isset($params['config']['server_id'])) { 260 | return; 261 | } 262 | $server = $params['config']['server_id']; 263 | 264 | $response = Http::withHeaders([ 265 | 'Authorization' => 'Bearer ' . $apikey, 266 | 'Accept' => 'Application/json', 267 | 'Content-Type' => 'application/json', 268 | ])->get( 269 | $host . '/api/v1/servers/' . $server 270 | ); 271 | return $host . '/server/' . $response->json()['data']['uuid']; 272 | } 273 | 274 | 275 | function VirtFusion_login(OrderProduct $id, Request $request) 276 | { 277 | 278 | if (!ExtensionHelper::hasAccess($id, auth()->user())) { 279 | return response()->json(['error' => 'You do not have access to this server'], 403); 280 | } 281 | $params = ExtensionHelper::getParameters($id)->config; 282 | 283 | $loginLink = VirtFusion_postRequest( 284 | '/api/v1/users/' . auth()->user()->id . '/serverAuthenticationTokens/' . $params['config']['server_id'], 285 | [] 286 | ); 287 | 288 | $loginLink = $loginLink->json()['data']['authentication']['endpoint_complete']; 289 | 290 | return redirect(ExtensionHelper::getConfig('VirtFusion', 'host') . $loginLink); 291 | } 292 | -------------------------------------------------------------------------------- /Servers/VirtFusion/views/control.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
Name:
5 |
Hostname:
6 |
Ram:
7 |
CPU:
8 |
9 |
10 |
{{ $details->name ?? 'N/A'}}
11 |
{{ $details->hostname ?? 'N/A'}}
12 |
{{ $details->settings['resources']['memory'] ?? 'N/A'}} MB
13 |
{{ $details->settings['resources']['cpuCores'] ?? 'N/A' }} @if($details->settings['resources']['cpuCores'] > 1)cores @else core @endif
14 |
15 |
16 |
17 |
18 |
IPv4:
19 |
IPv6:
20 |
Storage:
21 |
Traffic:
22 |
23 |
24 |
{{ $details->network['interfaces'][0]['ipv4'][0]['address'] ?? 'N/A' }}
25 |
{{ $details->network['interfaces'][0]['ipv6'][0]['address'] ?? 'N/A' }}
26 |
{{ $details->settings['resources']['storage'] ?? 'N/A' }} MB
27 |
{{ $details->settings['resources']['traffic'] ?? 'N/A'}} MB
28 |
29 |
30 |
31 | -------------------------------------------------------------------------------- /Servers/Virtualizor/index.php: -------------------------------------------------------------------------------- 1 | 'key', 13 | 'type' => 'text', 14 | 'friendlyName' => 'API Key', 15 | 'required' => true, 16 | ], 17 | [ 18 | 'name' => 'pass', 19 | 'type' => 'text', 20 | 'friendlyName' => 'API Password', 21 | 'required' => true, 22 | ], 23 | [ 24 | 'name' => 'ip', 25 | 'type' => 'text', 26 | 'friendlyName' => 'IP Address', 27 | 'required' => true, 28 | ], 29 | [ 30 | 'name' => 'port', 31 | 'type' => 'text', 32 | 'friendlyName' => 'Port', 33 | 'required' => true, 34 | ], 35 | ]; 36 | } 37 | 38 | function Virtualizor_getUserConfig(Product $product) 39 | { 40 | $key = ExtensionHelper::getConfig('virtualizor', 'key'); 41 | $pass = ExtensionHelper::getConfig('virtualizor', 'pass'); 42 | $ip = ExtensionHelper::getConfig('virtualizor', 'ip'); 43 | $port = ExtensionHelper::getConfig('virtualizor', 'port'); 44 | $admin = new Virtualizor_Admin_API(); 45 | $admin->Virtualizor_Admin_API($ip, $key, $pass, $port); 46 | // Get os list 47 | $os = $admin->ostemplates(); 48 | $allos = []; 49 | foreach ($os['oslist'][$product->settings()->get()->where('name', 'virt')->first()->value] as $osid => $osname) { 50 | foreach ($osname as $osid => $osname) { 51 | $allos[] = [ 52 | 'name' => $osname['name'], 53 | 'value' => $osid, 54 | ]; 55 | } 56 | } 57 | 58 | return [ 59 | [ 60 | 'name' => 'hostname', 61 | 'type' => 'text', 62 | 'friendlyName' => 'Hostname', 63 | 'required' => true, 64 | ], 65 | [ 66 | 'name' => 'password', 67 | 'type' => 'text', 68 | 'friendlyName' => 'Password', 69 | 'required' => true, 70 | ], 71 | [ 72 | 'name' => 'os', 73 | 'type' => 'dropdown', 74 | 'friendlyName' => 'Operating System', 75 | 'required' => true, 76 | 'options' => $allos, 77 | ], 78 | ]; 79 | } 80 | 81 | function Virtualizor_getProductConfig() 82 | { 83 | $key = ExtensionHelper::getConfig('virtualizor', 'key'); 84 | $pass = ExtensionHelper::getConfig('virtualizor', 'pass'); 85 | $ip = ExtensionHelper::getConfig('virtualizor', 'ip'); 86 | $port = ExtensionHelper::getConfig('virtualizor', 'port'); 87 | $admin = new Virtualizor_Admin_API(); 88 | $admin->Virtualizor_Admin_API($ip, $key, $pass, $port); 89 | 90 | // Get Plan list 91 | $plans = $admin->plans(); 92 | $allplans = []; 93 | foreach ($plans['plans'] as $plan) { 94 | $allplans[] = [ 95 | 'name' => $plan['plan_name'], 96 | 'value' => $plan['plan_name'], 97 | ]; 98 | } 99 | 100 | return [ 101 | [ 102 | 'name' => 'virt', 103 | 'friendlyName' => 'Virtualizon Type', 104 | 'type' => 'dropdown', 105 | 'required' => true, 106 | 'options' => [ 107 | [ 108 | 'name' => 'OpenVZ', 109 | 'value' => 'openvz', 110 | ], 111 | [ 112 | 'name' => 'Xen', 113 | 'value' => 'xen', 114 | ], 115 | [ 116 | 'name' => 'KVM', 117 | 'value' => 'kvm', 118 | ], 119 | ], 120 | ], 121 | [ 122 | 'name' => 'planname', 123 | 'friendlyName' => 'Plan Name', 124 | 'type' => 'dropdown', 125 | 'required' => true, 126 | 'options' => $allplans, 127 | ], 128 | ]; 129 | } 130 | 131 | function Virtualizor_createServer($user, $params, $order, $product, $configurableOptions) 132 | { 133 | $config = $params['config']; 134 | $key = ExtensionHelper::getConfig('virtualizor', 'key'); 135 | $pass = ExtensionHelper::getConfig('virtualizor', 'pass'); 136 | $ip = ExtensionHelper::getConfig('virtualizor', 'ip'); 137 | $port = ExtensionHelper::getConfig('virtualizor', 'port'); 138 | $admin = new Virtualizor_Admin_API(); 139 | $admin->Virtualizor_Admin_API($ip, $key, $pass, $port); 140 | // Get plan ID 141 | $page = 1; 142 | $reslen = 1; 143 | $post = []; 144 | $post['planname'] = $params['planname']; 145 | $post['ptype'] = $params['virt']; 146 | $plans = $admin->plans($page, $reslen, $post); 147 | if (!key($plans['plans'])) { 148 | ExtensionHelper::error('Virtualizor', 'Plan not found'); 149 | return; 150 | } 151 | $plan = $plans['plans'][key($plans['plans'])]; 152 | // Create server 153 | $post = []; 154 | $post['virt'] = $params['virt']; 155 | $post['user_email'] = $user->email; 156 | $post['user_pass'] = $config['password']; 157 | $post['fname'] = $user->name; 158 | $post['lname'] = $user->name; 159 | $post['osid'] = 909; 160 | $post['server_group'] = 0; 161 | $post['hostname'] = $config['hostname']; 162 | $post['rootpass'] = $config['password']; 163 | $post['num_ips6'] = isset($configurableOptions['ips6']) ? $configurableOptions['ips6'] : $plan['ips6']; 164 | $post['num_ips6_subnet'] = isset($configurableOptions['ips6_subnet']) ? $configurableOptions['ips6_subnet'] : $plan['ips6_subnet']; 165 | $post['num_ips'] = isset($configurableOptions['ips']) ? $configurableOptions['ips'] : $plan['ips']; 166 | $post['ram'] = isset($configurableOptions['ram']) ? $configurableOptions['ram'] : $plan['ram']; 167 | $post['swapram'] = isset($configurableOptions['swap']) ? $configurableOptions['swap'] : $plan['swap']; 168 | $post['bandwidth'] = isset($configurableOptions['bandwidth']) ? $configurableOptions['bandwidth'] : $plan['bandwidth']; 169 | $post['network_speed'] = isset($configurableOptions['network_speed']) ? $configurableOptions['network_speed'] : $plan['network_speed']; 170 | $post['cpu'] = isset($configurableOptions['cpu']) ? $configurableOptions['cpu'] : $plan['cpu']; 171 | $post['cores'] = isset($configurableOptions['cores']) ? $configurableOptions['cores'] : $plan['cores']; 172 | $post['cpu_percent'] = isset($configurableOptions['cpu_percent']) ? $configurableOptions['cpu_percent'] : $plan['cpu_percent']; 173 | $post['vnc'] = isset($configurableOptions['vnc']) ? $configurableOptions['vnc'] : $plan['vnc']; 174 | $post['vncpass'] = $config['password']; 175 | $post['kvm_cache'] = $plan['kvm_cache']; 176 | $post['io_mode'] = $plan['io_mode']; 177 | $post['vnc_keymap'] = $plan['vnc_keymap']; 178 | $post['nic_type'] = $plan['nic_type']; 179 | $post['osreinstall_limit'] = isset($configurableOptions['osreinstall_limit']) ? $configurableOptions['osreinstall_limit'] : $plan['osreinstall_limit']; 180 | $post['space'] = isset($configurableOptions['space']) ? $configurableOptions['space'] : $plan['space']; 181 | 182 | $output = $admin->addvs_v2($post); 183 | 184 | if (isset($output['error'])) { 185 | ExtensionHelper::error('Virtualizor', $output['error']); 186 | return; 187 | } 188 | // Set server ID 189 | $server = $output['vs_info']['vpsid']; 190 | ExtensionHelper::setOrderProductConfig('external_id', $server, $params['config_id']); 191 | 192 | return true; 193 | } 194 | 195 | function Virtualizor_suspendServer($user, $params, $order) 196 | { 197 | $key = ExtensionHelper::getConfig('virtualizor', 'key'); 198 | $pass = ExtensionHelper::getConfig('virtualizor', 'pass'); 199 | $ip = ExtensionHelper::getConfig('virtualizor', 'ip'); 200 | $port = ExtensionHelper::getConfig('virtualizor', 'port'); 201 | $admin = new Virtualizor_Admin_API(); 202 | $admin->Virtualizor_Admin_API($ip, $key, $pass, $port); 203 | if (!isset($params['config']['external_id'])) { 204 | ExtensionHelper::error('Virtualizor', 'Server not found for order #' . $order->id . '.'); 205 | return; 206 | } 207 | $admin->suspend($params['config']['external_id']); 208 | 209 | return true; 210 | } 211 | 212 | function Virtualizor_unsuspendServer($user, $params, $order) 213 | { 214 | $key = ExtensionHelper::getConfig('virtualizor', 'key'); 215 | $pass = ExtensionHelper::getConfig('virtualizor', 'pass'); 216 | $ip = ExtensionHelper::getConfig('virtualizor', 'ip'); 217 | $port = ExtensionHelper::getConfig('virtualizor', 'port'); 218 | $admin = new Virtualizor_Admin_API(); 219 | $admin->Virtualizor_Admin_API($ip, $key, $pass, $port); 220 | if (!isset($params['config']['external_id'])) { 221 | ExtensionHelper::error('Virtualizor', 'Server not found for order #' . $order->id . '.'); 222 | return; 223 | } 224 | $admin->unsuspend($params['config']['external_id']); 225 | 226 | return true; 227 | } 228 | 229 | function Virtualizor_terminateServer($user, $params, $order) 230 | { 231 | $key = ExtensionHelper::getConfig('virtualizor', 'key'); 232 | $pass = ExtensionHelper::getConfig('virtualizor', 'pass'); 233 | $ip = ExtensionHelper::getConfig('virtualizor', 'ip'); 234 | $port = ExtensionHelper::getConfig('virtualizor', 'port'); 235 | $admin = new Virtualizor_Admin_API(); 236 | $admin->Virtualizor_Admin_API($ip, $key, $pass, $port); 237 | if (!isset($params['config']['external_id'])) { 238 | ExtensionHelper::error('Virtualizor', 'Server not found for order #' . $order->id . '.'); 239 | return; 240 | } 241 | $admin->delete_vs($params['config']['external_id']); 242 | 243 | return true; 244 | } 245 | -------------------------------------------------------------------------------- /Servers/Virtualizor/sdk.php: -------------------------------------------------------------------------------- 1 | key = $key; 27 | $this->pass = $pass; 28 | $this->ip = $ip; 29 | $this->port = $port; 30 | if ($port != 4085) { 31 | $this->protocol = 'http'; 32 | } 33 | } 34 | 35 | /** 36 | * Dumps a variable. 37 | * 38 | * @author Pulkit Gupta 39 | * 40 | * @param array $re the Array or any other variable 41 | * 42 | * @return null 43 | */ 44 | public function r($re) 45 | { 46 | echo '
';
  47 |         print_r($re);
  48 |         echo '
'; 49 | } 50 | 51 | /** 52 | * Unserializes a string. 53 | * 54 | * @author Pulkit Gupta 55 | * 56 | * @param string $str The serialized string 57 | * 58 | * @return array The unserialized array on success OR false on failure 59 | */ 60 | public function _unserialize($str) 61 | { 62 | $var = @unserialize($str); 63 | 64 | if (empty($var)) { 65 | preg_match_all('!s:(\d+):"(.*?)";!s', $str, $matches); 66 | foreach ($matches[2] as $mk => $mv) { 67 | $tmp_str = 's:' . strlen($mv) . ':"' . $mv . '";'; 68 | $str = str_replace($matches[0][$mk], $tmp_str, $str); 69 | } 70 | $var = @unserialize($str); 71 | } 72 | 73 | // If it is still empty false 74 | if (empty($var)) { 75 | return false; 76 | } else { 77 | return $var; 78 | } 79 | } 80 | 81 | /** 82 | * Make an API Key. 83 | * 84 | * @author Pulkit Gupta 85 | * 86 | * @param string $key An 8 bit random string 87 | * @param string $pass The API Password of your NODE 88 | * 89 | * @return string The new APIKEY which will be used to query 90 | */ 91 | public function make_apikey($key, $pass) 92 | { 93 | return $key . md5($pass . $key); 94 | } 95 | 96 | /** 97 | * Generates a random string for the given length. 98 | * 99 | * @author Pulkit Gupta 100 | * 101 | * @param int $length The length of the random string to be generated 102 | * 103 | * @return string The generated random string 104 | */ 105 | public function generateRandStr($length) 106 | { 107 | $randstr = ''; 108 | for ($i = 0; $i < $length; ++$i) { 109 | $randnum = mt_rand(0, 61); 110 | if ($randnum < 10) { 111 | $randstr .= chr($randnum + 48); 112 | } elseif ($randnum < 36) { 113 | $randstr .= chr($randnum + 55); 114 | } else { 115 | $randstr .= chr($randnum + 61); 116 | } 117 | } 118 | 119 | return strtolower($randstr); 120 | } 121 | 122 | /** 123 | * Makes an API request to the server to do a particular task. 124 | * 125 | * @author Pulkit Gupta 126 | * 127 | * @param string $path The action you want to do 128 | * @param array $post An array of DATA that should be posted 129 | * @param array $cookies An array FOR SENDING COOKIES 130 | * 131 | * @return array The unserialized array on success OR false on failure 132 | */ 133 | public function call($path, $data = [], $post = [], $cookies = []) 134 | { 135 | $key = $this->generateRandStr(8); 136 | $apikey = $this->make_apikey($key, $this->pass); 137 | 138 | $url = $this->protocol . '://' . $this->ip . ':' . $this->port . '/' . $path; 139 | $url .= (strstr($url, '?') ? '' : '?'); 140 | $url .= '&api=serialize&apikey=' . rawurlencode($apikey); 141 | 142 | // Pass some data if there 143 | if (!empty($data)) { 144 | $url .= '&apidata=' . rawurlencode(base64_encode(serialize($data))); 145 | } 146 | // Set the curl parameters. 147 | $ch = curl_init(); 148 | curl_setopt($ch, CURLOPT_URL, $url); 149 | 150 | // Time OUT 151 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 152 | 153 | // Turn off the server and peer verification (TrustManager Concept). 154 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 155 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 156 | 157 | // UserAgent 158 | curl_setopt($ch, CURLOPT_USERAGENT, 'Corwinus'); 159 | 160 | // Cookies 161 | if (!empty($cookies)) { 162 | curl_setopt($ch, CURLOPT_COOKIESESSION, true); 163 | curl_setopt($ch, CURLOPT_COOKIE, http_build_query($cookies, '', '; ')); 164 | } 165 | 166 | if (!empty($post)) { 167 | curl_setopt($ch, CURLOPT_POST, 1); 168 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); 169 | } 170 | 171 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 172 | 173 | // Get response from the server. 174 | $resp = curl_exec($ch); 175 | 176 | // The following line is a method to test 177 | // if(preg_match('/sync/is', $url)) echo $resp; 178 | 179 | if (empty($resp)) { 180 | return false; 181 | } 182 | 183 | $r = @unserialize($resp); 184 | 185 | if (empty($r)) { 186 | return false; 187 | } 188 | curl_close($ch); 189 | 190 | return $r; 191 | } 192 | 193 | /** 194 | * Create a VPS. 195 | * 196 | * @author Pulkit Gupta 197 | * 198 | * @param string $path The action you want to do 199 | * @param array $post An array of DATA that should be posted 200 | * @param array $cookies An array FOR SENDING COOKIES 201 | * 202 | * @return array The unserialized array on success OR false on failure 203 | */ 204 | public function addippool($post) 205 | { 206 | $post['addippool'] = 1; 207 | $path = 'index.php?act=addippool'; 208 | $ret = $this->call($path, [], $post); 209 | 210 | return $ret; 211 | } 212 | 213 | public function addips($post) 214 | { 215 | $post['submitip'] = 1; 216 | $path = 'index.php?act=addips'; 217 | $ret = $this->call($path, [], $post); 218 | 219 | return $ret; 220 | } 221 | 222 | public function addiso($post) 223 | { 224 | $path = 'index.php?act=addiso'; 225 | $ret = $this->call($path, [], $post); 226 | 227 | return $ret; 228 | } 229 | 230 | public function deleteiso($post) 231 | { 232 | $path = 'index.php?act=iso'; 233 | $ret = $this->call($path, [], $post); 234 | 235 | return $ret; 236 | } 237 | 238 | public function addplan($post) 239 | { 240 | $post['addplan'] = 1; 241 | $path = 'index.php?act=addplan'; 242 | $ret = $this->call($path, [], $post); 243 | 244 | return $ret; 245 | } 246 | 247 | public function mediagroups($page = 1, $reslen = 50, $post = []) 248 | { 249 | if (empty($post)) { 250 | $path = 'index.php?act=mediagroups'; 251 | $ret = $this->call($path, [], $post); 252 | } else { 253 | $path = 'index.php?act=mediagroups&mgid=' . $post['mgid'] . '&mg_name=' . $post['mg_name'] . '&page=' . $page . '&reslen=' . $reslen; 254 | $ret = $this->call($path, [], $post); 255 | } 256 | 257 | return $ret; 258 | } 259 | 260 | public function addserver($post) 261 | { 262 | $post['addserver'] = 1; 263 | $path = 'index.php?act=addserver'; 264 | $ret = $this->call($path, [], $post); 265 | 266 | return $ret; 267 | } 268 | 269 | public function servergroups($post = 0) 270 | { 271 | $path = 'index.php?act=servergroups'; 272 | $ret = $this->call($path, [], $post); 273 | 274 | return $ret; 275 | } 276 | 277 | public function addtemplate($post) 278 | { 279 | $post['addtemplate'] = 1; 280 | $path = 'index.php?act=addtemplate'; 281 | $ret = $this->call($path, [], $post); 282 | 283 | return $ret; 284 | } 285 | 286 | public function adduser($post = 0) 287 | { 288 | $path = 'index.php?act=adduser'; 289 | $ret = $this->call($path, [], $post); 290 | 291 | return $ret; 292 | } 293 | 294 | /** 295 | * Create a VPS. 296 | * 297 | * @author Pulkit Gupta 298 | * 299 | * @param array $post An array of DATA that should be posted 300 | * @param array $cookies An array FOR SENDING COOKIES 301 | * 302 | * @return array The unserialized array on success OR false on failure 303 | */ 304 | public function addvs($post, $cookies = '') 305 | { 306 | $path = 'index.php?act=addvs'; 307 | $post = $this->clean_post($post); 308 | $ret = $this->call($path, '', $post, $cookies); 309 | 310 | return [ 311 | 'title' => $ret['title'], 312 | 'error' => @empty($ret['error']) ? [] : $ret['error'], 313 | 'vs_info' => $ret['newvs'], 314 | 'globals' => $ret['globals'], 315 | ]; 316 | } 317 | 318 | /** 319 | * Create a VPS (V2 Method). 320 | * 321 | * @author Pulkit Gupta 322 | * 323 | * @param array $post An array of DATA that should be posted 324 | * @param array $cookies An array FOR SENDING COOKIES 325 | * 326 | * @return array The unserialized array on success OR false on failure 327 | */ 328 | public function addvs_v2($post, $cookies = '') 329 | { 330 | $path = 'index.php?act=addvs'; 331 | $post['addvps'] = 1; 332 | $post['node_select'] = 1; 333 | $ret = $this->call($path, '', $post, $cookies); 334 | 335 | return [ 336 | 'title' => $ret['title'], 337 | 'error' => @empty($ret['error']) ? [] : $ret['error'], 338 | 'vs_info' => $ret['newvs'], 339 | 'globals' => $ret['globals'], 340 | 'done' => $ret['done'] ?? 0, 341 | ]; 342 | } 343 | 344 | public function addiprange($post) 345 | { 346 | $path = 'index.php?act=addiprange'; 347 | $ret = $this->call($path, [], $post); 348 | 349 | return $ret; 350 | } 351 | 352 | public function editiprange($post) 353 | { 354 | $path = 'index.php?act=editiprange&ipid=' . $post['ipid']; 355 | $ret = $this->call($path, [], $post); 356 | 357 | return $ret; 358 | } 359 | 360 | public function iprange($page, $reslen, $post) 361 | { 362 | if (empty($post)) { 363 | $path = 'index.php?act=ipranges&page=' . $page . '&reslen=' . $reslen; 364 | $ret = $this->call($path, [], $post); 365 | } elseif (isset($post['delete'])) { 366 | $path = 'index.php?act=ipranges'; 367 | $ret = $this->call($path, [], $post); 368 | } else { 369 | $path = 'index.php?act=ipranges&ipsearch=' . $post['ipsearch'] . '&ippoolsearch=' . $post['ippoolsearch'] . '&lockedsearch=' . $post['lockedsearch'] . '&page=' . $page . '&reslen=' . $reslen; 370 | $ret = $this->call($path, [], $post); 371 | } 372 | 373 | return $ret; 374 | } 375 | 376 | public function addsg($post) 377 | { 378 | $post['addsg'] = 1; 379 | $path = 'index.php?act=addsg'; 380 | $ret = $this->call($path, [], $post); 381 | 382 | return $ret; 383 | } 384 | 385 | public function editsg($post) 386 | { 387 | $post['editsg'] = 1; 388 | $path = 'index.php?act=editsg&sgid=' . $post['sgid']; 389 | $ret = $this->call($path, [], $post); 390 | 391 | return $ret; 392 | } 393 | 394 | public function deletesg($post) 395 | { 396 | $path = 'index.php?act=servergroups'; 397 | $ret = $this->call($path, [], $post); 398 | 399 | return $ret; 400 | } 401 | 402 | public function listbackupplans($page = 1, $reslen = 50, $post = []) 403 | { 404 | $path = 'index.php?act=backup_plans&page=' . $page . '&reslen=' . $reslen; 405 | $ret = $this->call($path, [], $post); 406 | 407 | return $ret; 408 | } 409 | 410 | public function addbackupplan($post = []) 411 | { 412 | $post['addbackup_plan'] = 1; 413 | $path = 'index.php?act=addbackup_plan'; 414 | $ret = $this->call($path, [], $post); 415 | 416 | return $ret; 417 | } 418 | 419 | public function editbackupplan($post = []) 420 | { 421 | $post['editbackup_plan'] = 1; 422 | $path = 'index.php?act=editbackup_plan'; 423 | $ret = $this->call($path, [], $post); 424 | 425 | return $ret; 426 | } 427 | 428 | public function deletebackupplan($post) 429 | { 430 | $path = 'index.php?act=backup_plans'; 431 | $ret = $this->call($path, [], $post); 432 | unset($ret['backup_plans']); 433 | 434 | return $ret; 435 | } 436 | 437 | public function backupservers($page = 1, $reslen = 50, $post = []) 438 | { 439 | $path = 'index.php?act=backupservers&page=' . $page . '&reslen=' . $reslen; 440 | $ret = $this->call($path, [], $post); 441 | 442 | return $ret; 443 | } 444 | 445 | public function deletebackupservers($post) 446 | { 447 | $path = 'index.php?act=backupservers'; 448 | $ret = $this->call($path, [], $post); 449 | 450 | return $ret; 451 | } 452 | 453 | public function testbackupservers($post) 454 | { 455 | $path = 'index.php?act=backupservers'; 456 | $ret = $this->call($path, [], $post); 457 | 458 | return $ret; 459 | } 460 | 461 | public function addbackupserver($post) 462 | { 463 | $post['addbackupserver'] = 1; 464 | $path = 'index.php?act=addbackupserver'; 465 | $ret = $this->call($path, [], $post); 466 | 467 | return $ret; 468 | } 469 | 470 | public function editbackupserver($post) 471 | { 472 | $post['editbackupserver'] = 1; 473 | $path = 'index.php?act=editbackupserver&id=' . $post['id']; 474 | $ret = $this->call($path, [], $post); 475 | 476 | return $ret; 477 | } 478 | 479 | public function addstorage($post) 480 | { 481 | $post['addstorage'] = 1; 482 | $path = 'index.php?act=addstorage'; 483 | $ret = $this->call($path, [], $post); 484 | 485 | return $ret; 486 | } 487 | 488 | public function storages($post = [], $page = 1, $reslen = 50) 489 | { 490 | $path = 'index.php?act=storage&page=' . $page . '&reslen=' . $reslen; 491 | $ret = $this->call($path, [], $post); 492 | 493 | return $ret; 494 | } 495 | 496 | public function editstorage($post) 497 | { 498 | $post['editstorage'] = 1; 499 | $path = 'index.php?act=editstorage&stid=' . $post['stid']; 500 | $ret = $this->call($path, [], $post); 501 | 502 | return $ret; 503 | } 504 | 505 | public function orhpaneddisks($post = []) 506 | { 507 | $path = 'index.php?act=orphaneddisks'; 508 | $ret = $this->call($path, [], $post); 509 | 510 | return $ret; 511 | } 512 | 513 | public function adddnsplan($post) 514 | { 515 | $post['adddnsplan'] = 1; 516 | $path = 'index.php?act=adddnsplan'; 517 | $ret = $this->call($path, [], $post); 518 | 519 | return $ret; 520 | } 521 | 522 | public function listdnsplans($page = 1, $reslen = 50, $post = []) 523 | { 524 | if (!isset($post['planname'])) { 525 | $path = 'index.php?act=dnsplans'; 526 | $ret = $this->call($path, [], $post); 527 | } else { 528 | $path = 'index.php?act=dnsplans&planname=' . $post['planname'] . '&page=' . $page . '&reslen=' . $reslen; 529 | $ret = $this->call($path, [], $post); 530 | } 531 | 532 | return $ret; 533 | } 534 | 535 | public function edit_dnsplans($post = []) 536 | { 537 | $post['editdnsplan'] = 1; 538 | $path = 'index.php?act=editdnsplan&dnsplid=' . $post['dnsplid']; 539 | $ret = $this->call($path, [], $post); 540 | 541 | return $ret; 542 | } 543 | 544 | public function delete_dnsplans($post) 545 | { 546 | $path = 'index.php?act=dnsplans'; 547 | $ret = $this->call($path, [], $post); 548 | 549 | return $ret; 550 | } 551 | 552 | public function add_admin_acl($post) 553 | { 554 | $path = 'index.php?act=add_admin_acl'; 555 | $ret = $this->call($path, [], $post); 556 | 557 | return $ret; 558 | } 559 | 560 | public function admin_acl($post = []) 561 | { 562 | if (empty($post)) { 563 | $path = 'index.php?act=admin_acl'; 564 | $ret = $this->call($path); 565 | } else { 566 | $path = 'index.php?act=admin_acl'; 567 | $ret = $this->call($path, [], $post); 568 | } 569 | 570 | return $ret; 571 | } 572 | 573 | public function edit_admin_acl($post = []) 574 | { 575 | $path = 'index.php?act=edit_admin_acl&aclid=' . $post['aclid']; 576 | $ret = $this->call($path, [], $post); 577 | 578 | return $ret; 579 | } 580 | 581 | public function addmg($post) 582 | { 583 | $post['addmg'] = 1; 584 | $path = 'index.php?act=addmg'; 585 | $ret = $this->call($path, [], $post); 586 | 587 | return $ret; 588 | } 589 | 590 | public function editmg($post) 591 | { 592 | $post['editmg'] = 1; 593 | $path = 'index.php?act=editmg&mgid=' . $post['mgid']; 594 | $ret = $this->call($path, [], $post); 595 | 596 | return $ret; 597 | } 598 | 599 | public function delete_mg($post) 600 | { 601 | $path = 'index.php?act=mediagroups&delete=' . $post['delete']; 602 | $ret = $this->call($path); 603 | 604 | return $ret; 605 | } 606 | 607 | public function add_distro($post) 608 | { 609 | $post['add_distro'] = 1; 610 | $path = 'index.php?act=add_distro'; 611 | $ret = $this->call($path, [], $post); 612 | 613 | return $ret; 614 | } 615 | 616 | public function edit_distro($post) 617 | { 618 | $post['add_distro'] = 1; 619 | $path = 'index.php?act=add_distro&edit=' . $post['edit']; 620 | $ret = $this->call($path, [], $post); 621 | 622 | return $ret; 623 | } 624 | 625 | public function list_distros($post = 0) 626 | { 627 | if (empty($post)) { 628 | $path = 'index.php?act=list_distros'; 629 | $ret = $this->call($path, [], $post); 630 | } else { 631 | $path = 'index.php?act=list_distros&delete=' . $post['delete']; 632 | $ret = $this->call($path); 633 | } 634 | 635 | return $ret; 636 | } 637 | 638 | public function list_euiso($page = 1, $reslen = 50, $post = []) 639 | { 640 | $path = 'index.php?act=euiso&page=' . $page . '&reslen=' . $reslen; 641 | $ret = $this->call($path, [], $post); 642 | 643 | return $ret; 644 | } 645 | 646 | public function delete_euiso($post) 647 | { 648 | $path = 'index.php?act=euiso'; 649 | $ret = $this->call($path, [], $post); 650 | 651 | return $ret; 652 | } 653 | 654 | public function list_recipes($page = 1, $reslen = 50, $post = []) 655 | { 656 | if (!isset($post['rid'])) { 657 | $path = 'index.php?act=recipes&page=' . $page . '&reslen=' . $reslen; 658 | $ret = $this->call($path, [], $post); 659 | } else { 660 | $path = 'index.php?act=recipes&rid=' . $post['rid'] . '&rname=' . $post['rname'] . '&page=' . $page . '&reslen=' . $reslen; 661 | $ret = $this->call($path, [], $post); 662 | } 663 | 664 | return $ret; 665 | } 666 | 667 | public function add_recipes($post) 668 | { 669 | $post['addrecipe'] = 1; 670 | $path = 'index.php?act=addrecipe'; 671 | $ret = $this->call($path, [], $post); 672 | 673 | return $ret; 674 | } 675 | 676 | public function editrecipe($post) 677 | { 678 | $post['editrecipe'] = 1; 679 | $path = 'index.php?act=editrecipe&rid=' . $post['rid']; 680 | $ret = $this->call($path, [], $post); 681 | 682 | return $ret; 683 | } 684 | 685 | // The recipe function deletes activates and deactivates a recipes 686 | public function recipes($post) 687 | { 688 | $path = 'index.php?act=recipes'; 689 | $ret = $this->call($path, [], $post); 690 | 691 | return $ret; 692 | } 693 | 694 | public function tasks($page = 1, $reslen = 50, $post = []) 695 | { 696 | if (empty($post)) { 697 | $path = 'index.php?act=tasks'; 698 | // $ret = $this->call($path); 699 | } elseif (isset($post['showlogs'])) { 700 | $path = 'index.php?act=tasks'; 701 | } else { 702 | $path = 'index.php?act=tasks&actid=' . $post['actid'] . '&vpsid=' . $post['vpsid'] . '&username=' . $post['username'] . '&action=' . $post['action'] . '&status=' . $post['status'] . '&order=' . $post['order'] . '&page=' . $page . '&reslen=' . $reslen; 703 | } 704 | $ret = $this->call($path, [], $post); 705 | 706 | return $ret; 707 | } 708 | 709 | public function addpdns($post) 710 | { 711 | $post['addpdns'] = 1; 712 | $path = 'index.php?act=addpdns'; 713 | $ret = $this->call($path, [], $post); 714 | 715 | return $ret; 716 | } 717 | 718 | public function adminindex() 719 | { 720 | $path = 'index.php?act=adminindex'; 721 | $res = $this->call($path); 722 | 723 | return $res; 724 | } 725 | 726 | public function apidoings() 727 | { 728 | } 729 | 730 | public function backup($post) 731 | { 732 | $path = 'index.php?act=backup'; 733 | $ret = $this->call($path, [], $post); 734 | 735 | return $ret; 736 | } 737 | 738 | public function bandwidth($post = []) 739 | { 740 | if (empty($post)) { 741 | $path = 'index.php?act=bandwidth'; 742 | $ret = $this->call($path); 743 | } else { 744 | $path = 'index.php?act=bandwidth&show=' . $post['show']; 745 | $ret = $this->call($path, [], $post); 746 | } 747 | 748 | return $ret; 749 | } 750 | 751 | /** 752 | * Cleaning the POST variables. 753 | * 754 | * @author Pulkit Gupta 755 | * 756 | * @param array $post An array of DATA that should be posted 757 | * @param array $cookies An array FOR SENDING COOKIES 758 | * 759 | * @return array The unserialized array on success OR false on failure 760 | */ 761 | public function clean_post(&$post, $edit = 0) 762 | { 763 | $post['serid'] = !isset($post['serid']) ? 0 : (int) $post['serid']; 764 | $post['uid'] = !isset($post['uid']) ? 0 : (int) $post['uid']; 765 | $post['plid'] = !isset($post['plid']) ? 0 : (int) $post['plid']; 766 | $post['osid'] = !isset($post['osid']) ? 0 : (int) $post['osid']; 767 | $post['iso'] = !isset($post['iso']) ? 0 : (int) $post['iso']; 768 | $post['space'] = !isset($post['space']) ? 10 : $post['space']; 769 | $post['ram'] = !isset($post['ram']) ? 512 : (int) $post['ram']; 770 | $post['swapram'] = !isset($post['swapram']) ? 1024 : (int) $post['swapram']; 771 | $post['bandwidth'] = !isset($post['bandwidth']) ? 0 : (int) $post['bandwidth']; 772 | $post['network_speed'] = !isset($post['network_speed']) ? 0 : (int) $post['network_speed']; 773 | $post['cpu'] = !isset($post['cpu']) ? 1000 : (int) $post['cpu']; 774 | $post['cores'] = !isset($post['cores']) ? 4 : (int) $post['cores']; 775 | $post['cpu_percent'] = !isset($post['cpu_percent']) ? 100 : (int) $post['cpu_percent']; 776 | $post['vnc'] = !isset($post['vnc']) ? 1 : (int) $post['vnc']; 777 | $post['vncpass'] = !isset($post['vncpass']) ? 'test' : $post['vncpass']; 778 | $post['sec_iso'] = !isset($post['sec_iso']) ? 0 : $post['sec_iso']; 779 | $post['kvm_cache'] = !isset($post['kvm_cache']) ? 0 : $post['kvm_cache']; 780 | $post['io_mode'] = !isset($post['io_mode']) ? 0 : $post['io_mode']; 781 | $post['vnc_keymap'] = !isset($post['vnc_keymap']) ? 'en-us' : $post['vnc_keymap']; 782 | $post['nic_type'] = !isset($post['nic_type']) ? 'default' : $post['nic_type']; 783 | $post['osreinstall_limit'] = !isset($post['osreinstall_limit']) ? 0 : (int) $post['osreinstall_limit']; 784 | $post['mgs'] = !isset($post['mgs']) ? 0 : $post['mgs']; 785 | $post['tuntap'] = !isset($post['tuntap']) ? 0 : $post['tuntap']; 786 | $post['virtio'] = !isset($post['virtio']) ? 0 : $post['virtio']; 787 | if (isset($post['hvm'])) { 788 | $post['hvm'] = $post['hvm']; 789 | } 790 | $post['noemail'] = !isset($post['noemail']) ? 0 : $post['noemail']; 791 | $post['boot'] = !isset($post['boot']) ? 'dca' : $post['boot']; 792 | $post['band_suspend'] = !isset($post['band_suspend']) ? 0 : $post['band_suspend']; 793 | $post['vif_type'] = !isset($post['vif_type']) ? 'netfront' : $post['vif_type']; 794 | if ($edit == 0) { 795 | $post['addvps'] = !isset($post['addvps']) ? 1 : (int) $post['addvps']; 796 | } else { 797 | $post['editvps'] = !isset($post['editvps']) ? 1 : $post['editvps']; 798 | $post['acpi'] = !isset($post['acpi']) ? 1 : $post['acpi']; 799 | $post['apic'] = !isset($post['apic']) ? 1 : $post['apic']; 800 | $post['pae'] = !isset($post['pae']) ? 1 : $post['pae']; 801 | $post['dns'] = !isset($post['dns']) ? ['4.2.2.1', '4.2.2.2'] : $post['dns']; 802 | $post['editvps'] = !isset($post['editvps']) ? 1 : (int) $post['editvps']; 803 | } 804 | 805 | return $post; 806 | } 807 | 808 | public function cluster() 809 | { 810 | } 811 | 812 | public function config($post = []) 813 | { 814 | $path = 'index.php?act=config'; 815 | $ret = $this->call($path, [], $post); 816 | 817 | return $ret; 818 | } 819 | 820 | public function config_slave($post = []) 821 | { 822 | $path = 'index.php?act=config_slave'; 823 | $ret = $this->call($path, [], $post); 824 | 825 | return $ret; 826 | } 827 | 828 | /** 829 | * Get CPU usage details. 830 | * 831 | * @author Pulkit Gupta 832 | * 833 | * @return array The unserialised array is returned on success or 834 | * empty array is returned on failure 835 | */ 836 | public function cpu($serverid = 0) 837 | { 838 | $path = 'index.php?act=manageserver&changeserid=' . $serverid; 839 | $ret = $this->call($path); 840 | 841 | return $ret['usage']['cpu']; 842 | } 843 | 844 | public function serverloads($post = []) 845 | { 846 | $path = 'index.php?act=serverloads'; 847 | $ret = $this->call($path, [], $post); 848 | 849 | return $ret; 850 | } 851 | 852 | public function createssl($post) 853 | { 854 | $path = 'index.php?act=createssl'; 855 | $ret = $this->call($path, [], $post); 856 | 857 | return $ret; 858 | } 859 | 860 | public function letsencrypt($post) 861 | { 862 | $path = 'index.php?act=letsencrypt'; 863 | $ret = $this->call($path, [], $post); 864 | 865 | return $ret; 866 | } 867 | 868 | public function createtemplate($post) 869 | { 870 | $path = 'index.php?act=createtemplate'; 871 | $post['createtemp'] = 1; 872 | $ret = $this->call($path, [], $post); 873 | 874 | return $ret; 875 | } 876 | 877 | public function server_stats($post) 878 | { 879 | $path = 'index.php?act=server_stats' . (!empty($post['serid']) ? '&changeserid=' . (int) $post['serid'] : ''); 880 | $ret = $this->call($path, [], $post); 881 | 882 | return $ret; 883 | } 884 | 885 | public function vps_stats($post) 886 | { 887 | $path = 'index.php?act=vps_stats' . (!empty($post['serid']) ? '&changeserid=' . (int) $post['serid'] : ''); 888 | $ret = $this->call($path, [], $post); 889 | 890 | return $ret; 891 | } 892 | 893 | public function databackup($post) 894 | { 895 | $path = 'index.php?act=databackup'; 896 | $ret = $this->call($path, [], $post); 897 | 898 | return $ret; 899 | } 900 | 901 | public function listdbbackfiles() 902 | { 903 | $path = 'index.php?act=databackup'; 904 | $ret = $this->call($path); 905 | 906 | return $ret; 907 | } 908 | 909 | public function createvpsbackup($post) 910 | { 911 | $path = 'index.php?act=editbackup_plan'; 912 | $ret = $this->call($path, [], $post); 913 | 914 | return $ret; 915 | } 916 | 917 | public function vps_backup_list($post) 918 | { 919 | $path = 'index.php?act=vpsrestore&op=get_vps&vpsid=' . $post['vpsid']; 920 | $res = $this->call($path, [], $post); 921 | 922 | return $res; 923 | } 924 | 925 | public function vpsrestore($post) 926 | { 927 | $post['restore'] = 1; 928 | $path = 'index.php?act=vpsrestore'; 929 | $ret = $this->call($path, [], $post); 930 | 931 | return $ret; 932 | } 933 | 934 | public function deletevpsbackup($post) 935 | { 936 | $path = 'index.php?act=vpsrestore'; 937 | $ret = $this->call($path, [], $post); 938 | 939 | return $ret; 940 | } 941 | 942 | public function pdns($page, $reslen, $post = []) 943 | { 944 | if (empty($post)) { 945 | $path = 'index.php?act=pdns&page=' . $page . '&reslen=' . $reslen; 946 | $ret = $this->call($path, [], $post); 947 | } elseif (isset($post['test'])) { 948 | $path = 'index.php?act=pdns&test=' . $post['test']; 949 | $ret = $this->call($path); 950 | } elseif (isset($post['delete'])) { 951 | $path = 'index.php?act=pdns'; 952 | $ret = $this->call($path, [], $post); 953 | } else { 954 | $path = 'index.php?act=pdns&pdns_name=' . $post['pdns_name'] . '&pdns_ipaddress=' . $post['pdns_ipaddress'] . '&page=' . $page . '&reslen=' . $reslen; 955 | $ret = $this->call($path, [], $post); 956 | } 957 | 958 | return $ret; 959 | } 960 | 961 | public function rdns($post = []) 962 | { 963 | $path = 'index.php?act=rdns'; 964 | $ret = $this->call($path, [], $post); 965 | 966 | return $ret; 967 | } 968 | 969 | public function domains($page = 1, $reslen = 50, $post = []) 970 | { 971 | if (!isset($post['del'])) { 972 | $path = 'index.php?act=domains&pdnsid=' . $post['pdnsid'] . '&page=' . $page . '&reslen=' . $reslen; 973 | $ret = $this->call($path); 974 | } else { 975 | $path = 'index.php?act=domains&pdnsid=' . $post['pdnsid'] . '&page=' . $page . '&reslen=' . $reslen; 976 | $ret = $this->call($path, [], $post); 977 | } 978 | 979 | return $ret; 980 | } 981 | 982 | public function delete_dnsrecords($post = []) 983 | { 984 | $path = 'index.php?act=dnsrecords&pdnsid=' . $post['pdnsid']; 985 | $ret = $this->call($path, [], $post); 986 | 987 | return $ret; 988 | } 989 | 990 | public function dnsrecords($page = 1, $reslen = 50, $post = []) 991 | { 992 | if (!isset($post['del'])) { 993 | $path = 'index.php?act=dnsrecords&pdnsid=' . $post['pdnsid'] . '&domain_id=' . $post['domain_id'] . '&page=' . $page . '&reslen=' . $reslen; 994 | $ret = $this->call($path); 995 | } else { 996 | $path = 'index.php?act=dnsrecords&pdnsid=' . $post['pdnsid'] . '&domain_id=' . $post['domain_id']; 997 | $ret = $this->call($path, [], $post); 998 | } 999 | 1000 | return $ret; 1001 | } 1002 | 1003 | public function search_dnsrecords($page = 1, $reslen = 50, $post = []) 1004 | { 1005 | $path = 'index.php?act=dnsrecords&pdnsid=' . $post['pdnsid'] . '&domain_id=' . $post['domain_id'] . '&dns_name=' . $post['dns_name'] . '&dns_domain=' . $post['dns_domain'] . '&record_type=' . $post['record_type'] . '&page=' . $page . '&reslen=' . $reslen; 1006 | $ret = $this->call($path, [], $post); 1007 | 1008 | return $ret; 1009 | } 1010 | 1011 | public function add_dnsrecord($post = []) 1012 | { 1013 | $post['add_dnsrecord'] = 1; 1014 | $path = 'index.php?act=add_dnsrecord&pdnsid=' . $post['pdnsid']; 1015 | $ret = $this->call($path, [], $post); 1016 | 1017 | return $ret; 1018 | } 1019 | 1020 | public function edit_dnsrecord($post = []) 1021 | { 1022 | $post['add_dnsrecord'] = 1; 1023 | $path = 'index.php?act=add_dnsrecord&pdnsid=' . $post['pdnsid'] . '&edit=' . $post['edit']; 1024 | $ret = $this->call($path, [], $post); 1025 | 1026 | return $ret; 1027 | } 1028 | 1029 | public function editpdns($post = []) 1030 | { 1031 | $post['editpdns'] = 1; 1032 | $path = 'index.php?act=editpdns&pdnsid=' . $post['pdnsid']; 1033 | $ret = $this->call($path, [], $post); 1034 | 1035 | return $ret; 1036 | } 1037 | 1038 | public function defaultvsconf($post) 1039 | { 1040 | $path = 'index.php?act=defaultvsconf'; 1041 | $ret = $this->call($path, [], $post); 1042 | 1043 | return $ret; 1044 | } 1045 | 1046 | /** 1047 | * Delete a VPS. 1048 | * 1049 | * @author Pulkit Gupta 1050 | * 1051 | * @param array $post An array of DATA that should be posted 1052 | * 1053 | * @return bool 1 on success OR 0 on failure 1054 | */ 1055 | public function delete_vs($vid) 1056 | { 1057 | $path = 'index.php?act=vs&delete=' . (int) $vid; 1058 | $res = $this->call($path); 1059 | 1060 | return $res; 1061 | } 1062 | 1063 | /** 1064 | * Get Disk usage details. 1065 | * 1066 | * @author Pulkit Gupta 1067 | * 1068 | * @return array The unserialised array is returned on success or 1069 | * empty array is returned on failure 1070 | */ 1071 | public function disk($serverid = 0) 1072 | { 1073 | $path = 'index.php?act=manageserver&changeserid=' . $serverid; 1074 | $ret = $this->call($path); 1075 | 1076 | return $ret['usage']['disk']; 1077 | } 1078 | 1079 | public function webuzo($post = []) 1080 | { 1081 | $post['webuzo'] = 1; 1082 | $path = 'index.php?act=webuzo'; 1083 | $ret = $this->call($path, [], $post); 1084 | 1085 | return $ret; 1086 | } 1087 | 1088 | public function webuzo_scripts() 1089 | { 1090 | $path = 'index.php?act=webuzo'; 1091 | $ret = $this->call($path); 1092 | 1093 | return $ret; 1094 | } 1095 | 1096 | public function editemailtemp($post) 1097 | { 1098 | $path = 'index.php?act=editemailtemp&temp=' . $post['temp']; 1099 | $ret = $this->call($path, [], $post); 1100 | 1101 | return $ret; 1102 | } 1103 | 1104 | public function resetemailtemp($post) 1105 | { 1106 | $path = 'index.php?act=editemailtemp&temp=' . $post['temp'] . '&reset=' . $post['reset']; 1107 | $ret = $this->call($path); 1108 | 1109 | return $ret; 1110 | } 1111 | 1112 | public function billingsettings($post = []) 1113 | { 1114 | $post['editsettings'] = 1; 1115 | $path = 'index.php?act=billing'; 1116 | $ret = $this->call($path, [], $post); 1117 | 1118 | return $ret; 1119 | } 1120 | 1121 | public function resourcepricing($post = []) 1122 | { 1123 | $post['editsettings'] = 1; 1124 | $path = 'index.php?act=resource_pricing'; 1125 | $ret = $this->call($path, [], $post); 1126 | 1127 | return $ret; 1128 | } 1129 | 1130 | public function addinvoice($post = []) 1131 | { 1132 | $post['addinvoice'] = 1; 1133 | $path = 'index.php?act=addinvoice'; 1134 | $ret = $this->call($path, [], $post); 1135 | 1136 | return $ret; 1137 | } 1138 | 1139 | public function editinvoice($post = []) 1140 | { 1141 | $post['editinvoice'] = 1; 1142 | $path = 'index.php?act=editinvoice&invoid=' . $post['invoid']; 1143 | $ret = $this->call($path, [], $post); 1144 | 1145 | return $ret; 1146 | } 1147 | 1148 | public function listinvoice($page = 1, $reslen = 50, $post = []) 1149 | { 1150 | $path = 'index.php?act=invoices&page=' . $page . '&reslen=' . $reslen; 1151 | $ret = $this->call($path, [], $post); 1152 | 1153 | return $ret; 1154 | } 1155 | 1156 | public function deleteinvoice($post = []) 1157 | { 1158 | $path = 'index.php?act=invoices'; 1159 | $ret = $this->call($path, [], $post); 1160 | 1161 | return $ret; 1162 | } 1163 | 1164 | public function addtransaction($post = []) 1165 | { 1166 | $post['addtransaction'] = 1; 1167 | $path = 'index.php?act=addtransaction'; 1168 | $ret = $this->call($path, [], $post); 1169 | 1170 | return $ret; 1171 | } 1172 | 1173 | public function edittransaction($post = []) 1174 | { 1175 | $post['edittransaction'] = 1; 1176 | $path = 'index.php?act=edittransaction&trid=' . $post['trid']; 1177 | $ret = $this->call($path, [], $post); 1178 | 1179 | return $ret; 1180 | } 1181 | 1182 | public function listtransaction($page = 1, $reslen = 50, $post = []) 1183 | { 1184 | $path = 'index.php?act=transactions&page=' . $page . '&reslen=' . $reslen; 1185 | $ret = $this->call($path, [], $post); 1186 | 1187 | return $ret; 1188 | } 1189 | 1190 | public function deletetransactions($post = []) 1191 | { 1192 | $path = 'index.php?act=transactions'; 1193 | $ret = $this->call($path, [], $post); 1194 | 1195 | return $ret; 1196 | } 1197 | 1198 | public function editippool($post) 1199 | { 1200 | $post['editippool'] = 1; 1201 | $path = 'index.php?act=editippool&ippid=' . $post['ippid']; 1202 | $res = $this->call($path, [], $post); 1203 | 1204 | return $res; 1205 | } 1206 | 1207 | public function deleteippool($ippid) 1208 | { 1209 | $path = 'index.php?act=ippool'; 1210 | $ret = $this->call($path, [], $ippid); 1211 | 1212 | return $ret; 1213 | } 1214 | 1215 | public function editips($post) 1216 | { 1217 | $path = 'index.php?act=editips'; 1218 | $res = $this->call($path, [], $post); 1219 | 1220 | return $res; 1221 | } 1222 | 1223 | public function delete_ips($post) 1224 | { 1225 | $path = 'index.php?act=ips'; 1226 | $res = $this->call($path, [], $post); 1227 | 1228 | return $res; 1229 | } 1230 | 1231 | public function editplan($post) 1232 | { 1233 | $post['editplan'] = 1; 1234 | $path = 'index.php?act=editplan&plid=' . $post['plid']; 1235 | $res = $this->call($path, [], $post); 1236 | 1237 | return $res; 1238 | } 1239 | 1240 | public function editserver($post) 1241 | { 1242 | $post['editserver'] = 1; 1243 | $path = 'index.php?act=editserver&serid=' . $post['serid']; 1244 | $res = $this->call($path, [], $post); 1245 | 1246 | return $res; 1247 | } 1248 | 1249 | public function edittemplate($post) 1250 | { 1251 | $path = 'index.php?act=edittemplate'; 1252 | $res = $this->call($path, [], $post); 1253 | 1254 | return $res; 1255 | } 1256 | 1257 | public function edituser($post) 1258 | { 1259 | $path = 'index.php?act=edituser&uid=' . $post['uid']; 1260 | $res = $this->call($path, [], $post); 1261 | 1262 | return $res; 1263 | } 1264 | 1265 | /** 1266 | * Create a VPS. 1267 | * 1268 | * @author Pulkit Gupta 1269 | * 1270 | * @param array $post An array of DATA that should be posted 1271 | * 1272 | * @return array The unserialized array on success OR false on failure 1273 | */ 1274 | public function editvs($post, $cookies = []) 1275 | { 1276 | $path = 'index.php?act=editvs&vpsid=' . $post['vpsid']; 1277 | // $post = $this->clean_post($post, 1); 1278 | $ret = $this->call($path, '', $post, $cookies); 1279 | 1280 | return [ 1281 | 'title' => $ret['title'], 1282 | 'done' => $ret['done'], 1283 | 'error' => @empty($ret['error']) ? [] : $ret['error'], 1284 | 'vs_info' => $ret['vps'], 1285 | ]; 1286 | } 1287 | 1288 | public function managevps($post) 1289 | { 1290 | $post['theme_edit'] = 1; 1291 | $post['editvps'] = 1; 1292 | $path = 'index.php?act=managevps&vpsid=' . $post['vpsid']; 1293 | $ret = $this->call($path, [], $post); 1294 | 1295 | return [ 1296 | 'title' => $ret['title'], 1297 | 'done' => $ret['done'], 1298 | 'error' => @empty($ret['error']) ? [] : $ret['error'], 1299 | 'vs_info' => $ret['vps'], 1300 | ]; 1301 | } 1302 | 1303 | public function emailconfig($post) 1304 | { 1305 | $path = 'index.php?act=emailconfig'; 1306 | $res = $this->call($path, [], $post); 1307 | 1308 | return $res; 1309 | } 1310 | 1311 | public function emailtemp($post = []) 1312 | { 1313 | $path = 'index.php?act=emailtemp'; 1314 | $res = $this->call($path, [], $post); 1315 | 1316 | return $res; 1317 | } 1318 | 1319 | public function filemanager($post) 1320 | { 1321 | $path = 'index.php?act=filemanager'; 1322 | $res = $this->call($path, '', $post); 1323 | 1324 | return $res; 1325 | } 1326 | 1327 | public function firewall($post) 1328 | { 1329 | $path = 'index.php?act=firewall'; 1330 | $res = $this->call($path, [], $post); 1331 | 1332 | return $res; 1333 | } 1334 | 1335 | public function giveos() 1336 | { 1337 | } 1338 | 1339 | public function health() 1340 | { 1341 | } 1342 | 1343 | public function hostname($post) 1344 | { 1345 | $path = 'index.php?act=hostname'; 1346 | $res = $this->call($path, '', $post); 1347 | 1348 | return $res; 1349 | } 1350 | 1351 | public function import($page, $reslen, $post) 1352 | { 1353 | $path = 'index.php?act=import'; 1354 | $res = $this->call($path, [], $post); 1355 | 1356 | return $res; 1357 | } 1358 | 1359 | public function ippool($page = 1, $reslen = 50, $post = []) 1360 | { 1361 | if (empty($post)) { 1362 | $path = 'index.php?act=ippool&page=' . $page . '&reslen=' . $reslen; 1363 | $res = $this->call($path); 1364 | } else { 1365 | $path = 'index.php?act=ippool&poolname=' . $post['poolname'] . '&poolgateway=' . $post['poolgateway'] . '&netmask=' . $post['netmask'] . '&nameserver=' . $post['nameserver'] . '&page=' . $page . '&reslen=' . $reslen; 1366 | $res = $this->call($path); 1367 | } 1368 | 1369 | return $res; 1370 | } 1371 | 1372 | /** 1373 | * Get list of IPs. 1374 | * 1375 | * @author Pulkit Gupta 1376 | * 1377 | * @return array the unserialised array on success 1378 | */ 1379 | public function ips($page, $reslen, $post) 1380 | { 1381 | if (empty($post)) { 1382 | $path = 'index.php?act=ips&page=' . $page . '&reslen=' . $reslen; 1383 | $ret = $this->call($path); 1384 | } else { 1385 | $path = 'index.php?act=ips&ipsearch=' . $post['ipsearch'] . '&ippoolsearch=' . $post['ippoolsearch'] . '&macsearch=' . $post['macsearch'] . '&vps_search=' . $post['vps_search'] . '&servers_search=' . $post['servers_search'] . '&lockedsearch=' . $post['lockedsearch'] . '&page=' . $page . '&reslen=' . $reslen; 1386 | $ret = $this->call($path); 1387 | } 1388 | 1389 | return $ret; 1390 | } 1391 | 1392 | public function iso() 1393 | { 1394 | $path = 'index.php?act=iso'; 1395 | $ret = $this->call($path); 1396 | 1397 | return $ret; 1398 | } 1399 | 1400 | public function kernelconf($post = 0) 1401 | { 1402 | $path = 'index.php?act=kernelconf'; 1403 | $ret = $this->call($path, [], $post); 1404 | 1405 | return $ret; 1406 | } 1407 | 1408 | public function license() 1409 | { 1410 | $path = 'index.php?act=license'; 1411 | $ret = $this->call($path); 1412 | 1413 | return $ret; 1414 | } 1415 | 1416 | /** 1417 | * List VPS. 1418 | * 1419 | * @author Pulkit Gupta 1420 | * 1421 | * @param int page number, if not specified then only 50 records are returned 1422 | * 1423 | * @return array The unserialized array on success OR false on failure 1424 | */ 1425 | public function listvs($page = 1, $reslen = 50, $search = []) 1426 | { 1427 | if (empty($search)) { 1428 | $path = 'index.php?act=vs&page=' . $page . '&reslen=' . $reslen; 1429 | } else { 1430 | $path = 'index.php?act=vs&vpsid=' . $search['vpsid'] . '&vpsname=' . $search['vpsname'] . '&vpsip=' . $search['vpsip'] . '&vpshostname=' . $search['vpshostname'] . '&vsstatus=' . $search['vsstatus'] . '&vstype=' . $search['vstype'] . '&user=' . $search['user'] . '&serid=' . $search['serid'] . '&search=' . $search['search']; 1431 | } 1432 | 1433 | $result = $this->call($path); 1434 | $ret = $result['vs']; 1435 | 1436 | return $ret; 1437 | } 1438 | 1439 | public function login() 1440 | { 1441 | } 1442 | 1443 | public function loginlogs($page = 1, $reslen = 50, $post = []) 1444 | { 1445 | if (empty($post)) { 1446 | $path = 'index.php?act=loginlogs&page=' . $page . '&reslen=' . $reslen; 1447 | $ret = $this->call($path); 1448 | } else { 1449 | $path = 'index.php?act=loginlogs&username=' . $post['username'] . '&ip=' . $post['ip'] . '&page=' . $page . '&reslen=' . $reslen; 1450 | $ret = $this->call($path, [], $post); 1451 | } 1452 | error_log('loginlogs: ' . print_r($ret, true)); 1453 | 1454 | return $ret; 1455 | } 1456 | 1457 | public function logs($page = 1, $reslen = 50, $post = []) 1458 | { 1459 | if (empty($post)) { 1460 | $path = 'index.php?act=logs&page=' . $page . '&reslen=' . $reslen; 1461 | $ret = $this->call($path); 1462 | } else { 1463 | $path = 'index.php?act=logs&id=' . $post['id'] . '&email=' . $post['email'] . '&page=' . $page . '&reslen=' . $reslen; 1464 | $ret = $this->call($path, [], $post); 1465 | } 1466 | 1467 | return $ret; 1468 | } 1469 | 1470 | public function maintenance($post) 1471 | { 1472 | $path = 'index.php?act=maintenance'; 1473 | $ret = $this->call($path, [], $post); 1474 | 1475 | return $ret; 1476 | } 1477 | 1478 | public function makeslave() 1479 | { 1480 | } 1481 | 1482 | public function os($post = []) 1483 | { 1484 | if (empty($post)) { 1485 | $path = 'index.php?act=os'; 1486 | } else { 1487 | $path = 'index.php?act=os&getos=' . $post['osids'][0]; 1488 | } 1489 | $result = $this->call($path, [], $post); 1490 | 1491 | return $result; 1492 | } 1493 | 1494 | public function ostemplates($page = 1, $reslen = 50) 1495 | { 1496 | $path = 'index.php?act=ostemplates&page=' . $page . '&reslen=' . $reslen; 1497 | $result = $this->call($path); 1498 | // $ret['title'] = $result['title']; 1499 | // $ret['ostemplates'] = $result['ostemplates']; 1500 | return $result; 1501 | } 1502 | 1503 | public function delostemplates($post = []) 1504 | { 1505 | $path = 'index.php?act=ostemplates&delete=' . $post['delete']; 1506 | $result = $this->call($path); 1507 | $ret['title'] = $result['title']; 1508 | $ret['done'] = $result['done']; 1509 | $ret['ostemplates'] = $result['ostemplates']; 1510 | 1511 | return $ret; 1512 | } 1513 | 1514 | public function performance() 1515 | { 1516 | $path = 'index.php?act=performance'; 1517 | $result = $this->call($path); 1518 | 1519 | return $result; 1520 | } 1521 | 1522 | public function phpmyadmin() 1523 | { 1524 | } 1525 | 1526 | public function plans($page = 1, $reslen = 50, $search = []) 1527 | { 1528 | if (empty($search)) { 1529 | $path = 'index.php?act=plans&page=' . $page . '&reslen=' . $reslen; 1530 | $ret = $this->call($path); 1531 | } else { 1532 | $path = 'index.php?act=plans&planname=' . $search['planname'] . '&ptype=' . $search['ptype'] . '&page=' . $page . '&reslen=' . $reslen; 1533 | $ret = $this->call($path); 1534 | } 1535 | 1536 | return $ret; 1537 | } 1538 | 1539 | public function sort_plans($page = 1, $reslen = 50, $sort = []) 1540 | { 1541 | $path = 'index.php?act=plans&sortcolumn=' . $sort['sortcolumn'] . '&sortby=' . $sort['sortby'] . '&page=' . $page . '&reslen=' . $reslen; 1542 | $ret = $this->call($path); 1543 | 1544 | return $ret; 1545 | } 1546 | 1547 | public function delete_plans($post) 1548 | { 1549 | $path = 'index.php?act=plans&delete=' . $post['delete']; 1550 | $ret = $this->call($path); 1551 | 1552 | return $ret; 1553 | } 1554 | 1555 | public function list_user_plans($post = [], $page = 1, $reslen = 50) 1556 | { 1557 | $path = 'index.php?act=user_plans&page=' . $page . '&reslen=' . $reslen; 1558 | $ret = $this->call($path, [], $post); 1559 | 1560 | return $ret; 1561 | } 1562 | 1563 | public function add_user_plans($post = []) 1564 | { 1565 | $post['adduser_plans'] = 1; 1566 | $path = 'index.php?act=adduser_plans'; 1567 | $ret = $this->call($path, [], $post); 1568 | 1569 | return $ret; 1570 | } 1571 | 1572 | public function edit_user_plans($post) 1573 | { 1574 | $post['edituser_plans'] = 1; 1575 | $path = 'index.php?act=edituser_plans&uplid=' . $post['uplid']; 1576 | $ret = $this->call($path, [], $post); 1577 | 1578 | return $ret; 1579 | } 1580 | 1581 | public function delete_user_plans($post = []) 1582 | { 1583 | $path = 'index.php?act=user_plans'; 1584 | $ret = $this->call($path, [], $post); 1585 | 1586 | return $ret; 1587 | } 1588 | 1589 | /** 1590 | * POWER OFF a Virtual Server. 1591 | * 1592 | * @author Pulkit Gupta 1593 | * 1594 | * @param int $vid The VMs ID 1595 | * 1596 | * @return bool TRUE on success or FALSE on failure 1597 | */ 1598 | public function poweroff($vid) 1599 | { 1600 | // Make the Request 1601 | $res = $this->call('index.php?act=vs&action=poweroff&serid=0&vpsid=' . (int) $vid); 1602 | 1603 | return $res; 1604 | } 1605 | 1606 | public function processes($post = []) 1607 | { 1608 | $path = 'index.php?act=processes'; 1609 | $ret = $this->call($path, [], $post); 1610 | 1611 | return $ret; 1612 | } 1613 | 1614 | /** 1615 | * Get RAM details. 1616 | * 1617 | * @author Pulkit Gupta 1618 | * 1619 | * @return array The unserialised array is returned on success or 1620 | * empty array is returned on failure 1621 | */ 1622 | public function ram($serverid = 0) 1623 | { 1624 | $path = 'index.php?act=manageserver&changeserid=' . $serverid; 1625 | $ret = $this->call($path); 1626 | 1627 | return $ret['usage']['ram']; 1628 | } 1629 | 1630 | /** 1631 | * Rebuild a VPS. 1632 | * 1633 | * @author Pulkit Gupta 1634 | * 1635 | * @param array $post An array of DATA that should be posted 1636 | * 1637 | * @return array The unserialized array on success OR false on failure 1638 | */ 1639 | public function rebuild($post) 1640 | { 1641 | $post['reos'] = 1; 1642 | $path = 'index.php?act=rebuild' . (!empty($post['serid']) ? '&changeserid=' . (int) $post['serid'] : ''); 1643 | 1644 | return $this->call($path, '', $post); 1645 | } 1646 | 1647 | /** 1648 | * RESTART a Virtual Server. 1649 | * 1650 | * @author Pulkit Gupta 1651 | * 1652 | * @param int $vid The VMs ID 1653 | * 1654 | * @return bool TRUE on success or FALSE on failure 1655 | */ 1656 | public function restart($vid) 1657 | { 1658 | // Make the Request 1659 | $res = $this->call('index.php?act=vs&action=restart&serid=0&vpsid=' . (int) $vid); 1660 | 1661 | return $res; 1662 | } 1663 | 1664 | public function restartservices($post) 1665 | { 1666 | $post['do'] = 1; 1667 | $path = 'index.php?act=restartservices&service=' . $post['service'] . '&do=' . $post['do']; 1668 | $res = $this->call($path, [], $post); 1669 | 1670 | return $res; 1671 | } 1672 | 1673 | /** 1674 | * Current server information. 1675 | * 1676 | * @author Pulkit Gupta 1677 | * 1678 | * @return array The unserialized array on success OR false on failure 1679 | */ 1680 | public function serverinfo() 1681 | { 1682 | $path = 'index.php?act=serverinfo'; 1683 | $result = $this->call($path); 1684 | 1685 | $ret = []; 1686 | $ret['title'] = $result['title']; 1687 | $ret['info']['path'] = $result['info']['path']; 1688 | $ret['info']['key'] = $result['info']['key']; 1689 | $ret['info']['pass'] = $result['info']['pass']; 1690 | $ret['info']['kernel'] = $result['info']['kernel']; 1691 | $ret['info']['num_vs'] = $result['info']['num_vs']; 1692 | $ret['info']['version'] = $result['info']['version']; 1693 | $ret['info']['patch'] = $result['info']['patch']; 1694 | 1695 | return $ret; 1696 | } 1697 | 1698 | /** 1699 | * List Servers. 1700 | * 1701 | * @author Pulkit Gupta 1702 | * 1703 | * @return array The unserialized array on success OR false on failure 1704 | */ 1705 | public function servers($del_serid = 0) 1706 | { 1707 | if ($del_serid == 0) { 1708 | $path = 'index.php?act=servers'; 1709 | } else { 1710 | $path = 'index.php?act=servers&delete=' . $del_serid; 1711 | } 1712 | 1713 | return $this->call($path); 1714 | } 1715 | 1716 | public function server_force_delete($del_serid = 0) 1717 | { 1718 | if ($del_serid == 0) { 1719 | $path = 'index.php?act=servers'; 1720 | } else { 1721 | $path = 'index.php?act=servers&force=' . $del_serid; 1722 | } 1723 | 1724 | return $this->call($path); 1725 | } 1726 | 1727 | public function listservers() 1728 | { 1729 | $path = 'index.php?act=servers'; 1730 | 1731 | return $this->call($path); 1732 | } 1733 | 1734 | public function services($post = []) 1735 | { 1736 | $path = 'index.php?act=services'; 1737 | $res = $this->call($path, [], $post); 1738 | 1739 | return $res; 1740 | } 1741 | 1742 | public function ssh() 1743 | { 1744 | /* $path = 'index.php?act=ssh'; 1745 | $res = $this->call($path); 1746 | return $res;*/ 1747 | } 1748 | 1749 | public function ssl($post = 0) 1750 | { 1751 | $path = 'index.php?act=ssl'; 1752 | $res = $this->call($path, [], $post); 1753 | 1754 | return $res; 1755 | } 1756 | 1757 | public function sslcert() 1758 | { 1759 | /* $path = 'index.php?act=sslcert'; 1760 | $res = $this->call($path); 1761 | return $res;*/ 1762 | } 1763 | 1764 | /** 1765 | * START a Virtual Server. 1766 | * 1767 | * @author Pulkit Gupta 1768 | * 1769 | * @param int $vid The VMs ID 1770 | * 1771 | * @return bool TRUE on success or FALSE on failure 1772 | */ 1773 | public function start($vid) 1774 | { 1775 | $res = $this->call('index.php?act=vs&action=start&serid=0&vpsid=' . (int) $vid); 1776 | 1777 | return $res; 1778 | } 1779 | 1780 | /** 1781 | * STOP a Virtual Server. 1782 | * 1783 | * @author Pulkit Gupta 1784 | * 1785 | * @param int $vid The VMs ID 1786 | * 1787 | * @return bool TRUE on success or FALSE on failure 1788 | */ 1789 | public function stop($vid) 1790 | { 1791 | // Make the Request 1792 | $res = $this->call('index.php?act=vs&action=stop&serid=0&vpsid=' . (int) $vid); 1793 | 1794 | return $res; 1795 | } 1796 | 1797 | /** 1798 | * Gives status of a Virtual Server. 1799 | * 1800 | * @author Pulkit Gupta 1801 | * 1802 | * @param array $vids array of IDs of VMs 1803 | * 1804 | * @return array Contains the status info of the VMs 1805 | */ 1806 | public function status($vids) 1807 | { 1808 | // Make the Request 1809 | $res = $this->call('index.php?act=vs&vs_status=' . implode(',', $vids)); 1810 | 1811 | return $res['status']; 1812 | } 1813 | 1814 | /** 1815 | * Suspends a VM of a Virtual Server. 1816 | * 1817 | * @author Pulkit Gupta 1818 | * 1819 | * @param int $vid The VMs ID 1820 | * 1821 | * @return int 1 if the VM is ON, 0 if its OFF 1822 | */ 1823 | public function suspend($vid) 1824 | { 1825 | $path = 'index.php?act=vs&suspend=' . (int) $vid; 1826 | $res = $this->call($path); 1827 | 1828 | return $res; 1829 | } 1830 | 1831 | /** 1832 | * Unsuspends a VM of a Virtual Server. 1833 | * 1834 | * @author Pulkit Gupta 1835 | * 1836 | * @param int $vid The VMs ID 1837 | * 1838 | * @return int 1 if the VM is ON, 0 if its OFF 1839 | */ 1840 | public function unsuspend($vid) 1841 | { 1842 | $path = 'index.php?act=vs&unsuspend=' . (int) $vid; 1843 | $res = $this->call($path); 1844 | 1845 | return $res; 1846 | } 1847 | 1848 | public function suspend_net($vid) 1849 | { 1850 | $path = 'index.php?act=vs&suspend_net=' . $vid; 1851 | $res = $this->call($path); 1852 | 1853 | return $res; 1854 | } 1855 | 1856 | public function unsuspend_net($vid) 1857 | { 1858 | $path = 'index.php?act=vs&unsuspend_net=' . $vid; 1859 | $res = $this->call($path); 1860 | 1861 | return $res; 1862 | } 1863 | 1864 | public function tools() 1865 | { 1866 | } 1867 | 1868 | public function ubc($post) 1869 | { 1870 | $path = 'index.php?act=ubc'; 1871 | $res = $this->call($path, [], $post); 1872 | 1873 | return $res; 1874 | } 1875 | 1876 | public function updates($post) 1877 | { 1878 | $path = 'index.php?act=updates'; 1879 | $res = $this->call($path, [], $post); 1880 | 1881 | return $res; 1882 | } 1883 | 1884 | public function userlogs($page = 1, $reslen = 50, $post = []) 1885 | { 1886 | if (empty($post)) { 1887 | $path = 'index.php?act=userlogs&page=' . $page . '&reslen=' . $reslen; 1888 | $res = $this->call($path); 1889 | } else { 1890 | $path = 'index.php?act=userlogs&vpsid=' . $post['vpsid'] . '&email=' . $post['email'] . '&page=' . $page . '&reslen=' . $reslen; 1891 | $res = $this->call($path, [], $post); 1892 | } 1893 | 1894 | return $res; 1895 | } 1896 | 1897 | public function iplogs($page = 1, $reslen = 50, $post = []) 1898 | { 1899 | if (empty($post)) { 1900 | $path = 'index.php?act=iplogs&page=' . $page . '&reslen=' . $reslen; 1901 | $res = $this->call($path); 1902 | } else { 1903 | $path = 'index.php?act=iplogs&vpsid=' . $post['vpsid'] . '&ip=' . $post['ip'] . '&page=' . $page . '&reslen=' . $reslen; 1904 | $res = $this->call($path, [], $post); 1905 | } 1906 | 1907 | return $res; 1908 | } 1909 | 1910 | public function deleteiplogs($post) 1911 | { 1912 | if (!empty($post)) { 1913 | $path = 'index.php?act=iplogs'; 1914 | $res = $this->call($path, [], $post); 1915 | } 1916 | 1917 | return $res; 1918 | } 1919 | 1920 | public function users($page = 1, $reslen = 50, $post = []) 1921 | { 1922 | if (empty($post)) { 1923 | $path = 'index.php?act=users&page=' . $page . '&reslen=' . $reslen; 1924 | $res = $this->call($path, [], $post); 1925 | } else { 1926 | $path = 'index.php?act=users&uid=' . $post['uid'] . '&email=' . $post['email'] . '&type=' . $post['type'] . '&page=' . $page . '&reslen=' . $reslen; 1927 | $res = $this->call($path, [], $post); 1928 | } 1929 | 1930 | return $res; 1931 | } 1932 | 1933 | public function delete_users($del_userid) 1934 | { 1935 | $path = 'index.php?act=users'; 1936 | $res = $this->call($path, [], $del_userid); 1937 | 1938 | return $res; 1939 | } 1940 | 1941 | public function vnc($post) 1942 | { 1943 | $path = 'index.php?act=vnc&novnc=' . $post['novnc']; 1944 | $res = $this->call($path, [], $post); 1945 | 1946 | return $res; 1947 | } 1948 | 1949 | public function vs($page = 1, $reslen = 50) 1950 | { 1951 | $path = 'index.php?act=vs&page=' . $page . '&reslen=' . $reslen; 1952 | $res = $this->call($path); 1953 | 1954 | return $res; 1955 | } 1956 | 1957 | public function vsbandwidth() 1958 | { 1959 | $path = 'index.php?act=vsbandwidth'; 1960 | $res = $this->call($path); 1961 | 1962 | return $res; 1963 | } 1964 | 1965 | public function vscpu() 1966 | { 1967 | $path = 'index.php?act=vscpu'; 1968 | $res = $this->call($path); 1969 | 1970 | return $res; 1971 | } 1972 | 1973 | public function vsram() 1974 | { 1975 | $path = 'index.php?act=vsram'; 1976 | $res = $this->call($path); 1977 | 1978 | return $res; 1979 | } 1980 | 1981 | public function clonevps($post) 1982 | { 1983 | $path = 'index.php?act=clone'; 1984 | $post['migrate'] = 1; 1985 | $post['migrate_but'] = 1; 1986 | $res = $this->call($path, [], $post); 1987 | 1988 | return $res; 1989 | } 1990 | 1991 | public function migrate($post) 1992 | { 1993 | $path = 'index.php?act=migrate'; 1994 | $res = $this->call($path, [], $post); 1995 | 1996 | return $res; 1997 | } 1998 | 1999 | public function haproxy($post) 2000 | { 2001 | $path = 'index.php?act=haproxy'; 2002 | $res = $this->call($path, [], $post); 2003 | 2004 | return $res; 2005 | } 2006 | 2007 | public function listhaproxy($search = [], $page = 1, $reslen = 50) 2008 | { 2009 | if (empty($search)) { 2010 | $path = 'index.php?act=haproxy&page=' . $page . '&reslen=' . $reslen; 2011 | } else { 2012 | $path = 'index.php?act=haproxy&s_id=' . $search['s_id'] . '&s_serid=' . (empty($search['s_serid']) ? '-1' : $search['s_serid']) . '&s_vpsid=' . $search['s_vpsid'] . '&s_protocol=' . (empty($search['s_protocol']) ? '-1' : $search['s_protocol']) . '&s_src_hostname=' . $search['s_src_hostname'] . '&s_src_port=' . $search['s_src_port'] . '&s_dest_ip=' . $search['s_dest_ip'] . '&s_dest_port=' . $search['s_dest_port'] . '&haproxysearch=' . $search['haproxysearch']; 2013 | } 2014 | 2015 | $result = $this->call($path); 2016 | $ret = $result['haproxydata']; 2017 | 2018 | return $ret; 2019 | } 2020 | } // Class Ends 2021 | --------------------------------------------------------------------------------