diff --git a/README.md b/README.md new file mode 100644 index 0000000..0894888 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Vvveb CMS cPanel Installer + +#### One-click Vvveb CMS cPanel auto-installer with MySql and SQLite support + +👉🏻 [Download](https://github.com/Vvveb/cpanel-plugin/archive/main.zip) + +| [![](https://raw.githubusercontent.com/Vvveb/cpanel-plugin/main/assets/cpanel-1.png)](https://raw.githubusercontent.com/Vvveb/cpanel-plugin/main/assets/cpanel-1.png) | [![](https://raw.githubusercontent.com/Vvveb/cpanel-plugin/main/assets/cpanel-2.png)](https://raw.githubusercontent.com/Vvveb/cpanel-plugin/main/assets/cpanel-2.png) | [![](https://raw.githubusercontent.com/Vvveb/cpanel-plugin/main/assets/cpanel-3.png)](https://raw.githubusercontent.com/Vvveb/cpanel-plugin/main/assets/cpanel-3.png) | +|:---:|:---:|:---:| + +## Install + +To install the cpanel plugin login to SSH and run the following commands to install the plugin: + +```bash +wget https://github.com/Vvveb/cpanel-plugin/archive/refs/heads/main.zip +unzip cpanel-plugin-main.zip && cd cpanel-plugin-main/ +chmod +x install.sh && ./install.sh +``` + +## License + +Copyright (c) [Vvveb](https://www.vvveb.com) + +Released under the [GPL 3](https://github.com/Vvveb/cpanel-plugin/blob/main/LICENSE) license. diff --git a/assets/cpanel-1.png b/assets/cpanel-1.png new file mode 100644 index 0000000..c14d283 Binary files /dev/null and b/assets/cpanel-1.png differ diff --git a/assets/cpanel-2.png b/assets/cpanel-2.png new file mode 100644 index 0000000..c1639c8 Binary files /dev/null and b/assets/cpanel-2.png differ diff --git a/assets/cpanel-3.png b/assets/cpanel-3.png new file mode 100644 index 0000000..62334be Binary files /dev/null and b/assets/cpanel-3.png differ diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..5c32811 --- /dev/null +++ b/install.sh @@ -0,0 +1,14 @@ +#!/bin/bash +mkdir -p /usr/local/cpanel/base/frontend/paper_lantern/vvveb + +cp vvveb.tar /usr/local/cpanel/base/frontend/paper_lantern/vvveb +cp vvveb.live.php /usr/local/cpanel/base/frontend/paper_lantern/vvveb/vvveb.live.php + +/usr/local/cpanel/scripts/install_plugin /usr/local/cpanel/base/frontend/paper_lantern/vvveb/vvveb.tar --theme paper_lantern + +mkdir -p /usr/local/cpanel/base/frontend/jupiter/vvveb + +cp vvveb.tar /usr/local/cpanel/base/frontend/jupiter/vvveb/vvveb.tar +cp vvveb.live.php /usr/local/cpanel/base/frontend/jupiter/vvveb/vvveb.live.php + +/usr/local/cpanel/scripts/install_plugin /usr/local/cpanel/base/frontend/jupiter/vvveb/vvveb.tar --theme jupiter diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..5bb632d --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,2 @@ +/usr/local/cpanel/scripts/uninstall_plugin /usr/local/cpanel/base/frontend/paper_lantern/vvveb/vvveb.tar +/usr/local/cpanel/scripts/uninstall_plugin /usr/local/cpanel/base/frontend/jupiter/vvveb/vvveb.tar diff --git a/vvveb.live.php b/vvveb.live.php new file mode 100644 index 0000000..6c8150c --- /dev/null +++ b/vvveb.live.php @@ -0,0 +1,447 @@ +header( 'Vvveb CMS' ); +$accountName = $cpanel->cpanelprint('$user'); +$hostname = $cpanel->cpanelprint('$hostname'); + +$domainData = []; +// Call the API +$response = $cpanel->uapi( + 'DomainInfo', + 'domains_data' +); + +// Handle the response +if ($response['cpanelresult']['result']['status']) { + $data = $response['cpanelresult']['result']['data']; + // Do something with the $data + // So you can see the data shape we print it here. + //var_dump($data); + $domainData = $data['addon_domains'] ?? []; + + if (isset($data['main_domain'])) { + $domainData['main'] = $data['main_domain']; + if (isset($data['sub_domains'])) { + $domainData['main']['sub_domains'] = $data['sub_domains']; + } + } else { + if (isset($data['sub_domains'])) { + $domainData = $data['sub_domains']; + } + } + +} +else { + // Report errors: + echo '
';
+    var_dump($response['cpanelresult']['result']['errors']);
+    echo '
'; +} + +//get mysql host name +$hostname = ''; +$response = $cpanel->uapi( + 'Mysql', + 'get_server_information' +); + +// Handle the response +if ($response['cpanelresult']['result']['status']) { + $data = $response['cpanelresult']['result']['data']; + // Do something with the $data + // So you can see the data shape we print it here. + $hostname = $data['host']; +} else { + // Report errors: + echo '
';
+    var_dump($response['cpanelresult']['result']['errors']);
+    echo '
'; +} + +function randomStr($length = 16) { + $string = ''; + + while (($len = strlen($string)) < $length) { + $size = $length - $len; + + $bytes = random_bytes($size); + + $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); + } + + return $string; +} + +function download($url) { + $result = false; + + if (function_exists('curl_init')) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_FAILONERROR, true); + $result = curl_exec($ch); + curl_close($ch); + } else { + if (ini_get('allow_url_fopen') == '1') { + $context_options = [ + 'http' => [ + 'timeout' => 5, + 'ignore_errors' => 1, + ], + ]; + $context = stream_context_create($context_options); + $result = file_get_contents($url, 'r', $context); + } + } + + return $result; +} + + +function saveDownload($url) { + //$temp = tmpfile(); + $f = false; + $temp = tempnam(sys_get_temp_dir(), 'vvveb_cms'); + + if ($content = download($url)) { + $f = file_put_contents($temp, $content, LOCK_EX); + + return $temp; + } + + return $f; +} + +function printStatus($status) { + echo "$status
"; +} + +//generate mysql database defaults, limit database name and user to max 30 chars +$database = substr($accountName, 0, 15) . '_vvveb_' . randomStr(8); +$database_user = substr($accountName, 0, 15) . '_vvveb_' . randomStr(8); +$database_user_password = randomStr(30); + +function installVvveb($cpanel) { + global $domainData; + + $documentroot = $_POST['documentroot']; + $domain = $_POST['domain']; + $title = $_POST['title']; + $email = $_POST['email']; + $password = $_POST['password']; + $username = $_POST['username']; + $database_engine = $_POST['database_engine']; + + $database = $_POST['database']; + $database_user = $_POST['database_user']; + $database_user_password = $_POST['database_user_password']; + $hostname = $_POST['hostname']; + $port = $_POST['port'] ?? 3306; + + + $url = 'https://www.vvveb.com/latest.zip'; + $temp = tempnam(sys_get_temp_dir(), 'vvveb_cms'); + printStatus("Downloading $url"); + + if ($zipFile = saveDownload($url)) { + + $zip = new ZipArchive; + $res = $zip->open($zipFile); + if ($res === TRUE) { + $zip->extractTo($documentroot); + printStatus("Unzip successful!"); + $zip->close(); + } else { + printStatus("Error unzipping $temp to $documentroot"); + return; + } + } else { + printStatus("Error downloading $url"); + return; + } + + /* + // setup_db_and_user not supported yet + $database = ''; + $database_user = ''; + $database_user_password = ''; + $hostname = ''; + $port = ''; + if ($database_engine == 'mysqli') { + // Call the API + $response = $cpanel->uapi( + 'Mysql', + 'setup_db_and_user', + array ( + 'prefix' => 'vvveb', + ) + ); + + // Handle the response + if ($response['cpanelresult']['result']['status']) { + $data = $response['cpanelresult']['result']['data']; + // Do something with the $data + // So you can see the data shape we print it here. + //var_dump($data); + $database = $data['database']; + $database_user = $data['database_user']; + $database_user_password = $data['database_user_password']; + $hostname = $data['hostname']; + $port = $data['port']; + } + else { + // Report errors: + printStatus("Mysql database create error"); + echo '
';
+			var_dump($response['cpanelresult']['result']['errors']);
+			echo '
'; + return; + } + } */ + if ($database_engine == 'mysqli') { + // create database + $response = $cpanel->uapi( + 'Mysql', + 'create_database', + array ( + 'name' => $database, + ) + ); + + // Handle the response + if ($response['cpanelresult']['result']['status']) { + $data = $response['cpanelresult']['result']['data']; + + printStatus("Mysql database $database created"); + + // create user + $response = $cpanel->uapi( + 'Mysql', + 'create_user', + array ( + 'name' => $database_user, + 'password' => $database_user_password, + ) + ); + + // Handle the response + if ($response['cpanelresult']['result']['status']) { + $data = $response['cpanelresult']['result']['data']; + + printStatus("Mysql user $database_user created"); + + // add user to database + $response = $cpanel->uapi( + 'Mysql', + 'set_privileges_on_database', + array ( + 'user' => $database_user, + 'database' => $database, + 'privileges' => 'ALL PRIVILEGES', + ) + ); + + // Handle the response + if ($response['cpanelresult']['result']['status']) { + $data = $response['cpanelresult']['result']['data']; + // Do something with the $data + // So you can see the data shape we print it here. + + printStatus("Mysql user $database_user assigned to $database"); + } + else { + printStatus("Failed to set privileges for $database_user to $database"); + // Report errors: + echo '
';
+								var_dump($response['cpanelresult']['result']['errors']);
+								echo '
'; + return; + } + + } + else { + printStatus("Failed to create Mysql user $database_user"); + echo '
';
+						var_dump($response['cpanelresult']['result']['errors']);
+						echo '
'; + return; + } + + } + else { + // Report errors: + printStatus("Failed to create Mysql database $database'"); + echo '
';
+				var_dump($response['cpanelresult']['result']['errors']);
+				echo '
'; + return; + } + } + + echo '
'; + printStatus("Please wait, installing ..."); + $command = "/usr/local/bin/php $documentroot/cli.php install host=$hostname user=$database_user port=$port password=$database_user_password database=$database admin[email]=$email admin[password]=$password engine=$database_engine settings[title]='$title'"; + printStatus('Running install command: ' .str_replace("[password]=$password", '[password]=******', $command)); + echo '
'; + if ($result = shell_exec($command)) { + $data = json_decode($result, true); + if ($data && isset($data['success'])) { + $url = ''; + foreach ($domainData as $domain) { + if ($domain['documentroot'] == $documentroot) { + $url = $domain['domain']; + break; + } + + if (isset($domain['sub_domains'])) { + foreach ($domain['sub_domains'] as $subdomain) { + if ($subdomain['documentroot'] == $documentroot) { + $url = $subdomain['domain']; + break 2; + } + } + } + } + if (isset($data['success'])) { + foreach ($data['success'] as $message) echo printStatus($message); + } + printStatus('Vvveb CMS Installed!'); + echo '
'; + printStatus("Login to admin dashboard | View website"); + echo '
'; + if (isset($data['errors'])) { + foreach ($data['errors'] as $message) echo printStatus($message); + } + if (isset($data['requirements'])) { + foreach ($data['requirements'] as $message) echo printStatus($message); + } + //echo $result; + } else { + printStatus('Installation failed with:'); + echo '
';
+			print_r($data);			
+			echo '
'; + echo $result; + } + } else { + printStatus('Error running cli.php!'); + echo $result; + } +} + +if ($_POST) { + installVvveb($cpanel); +} else { +?> +
+

Install Vvveb CMS

+
+
+ + + + +
+ +
+ + + +
+ +
+ + Advanced + + +
+ +
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +footer(); +$cpanel->end(); +?> diff --git a/vvveb.tar b/vvveb.tar new file mode 100644 index 0000000..a19ff14 Binary files /dev/null and b/vvveb.tar differ