whoami7 - Manager
:
/
usr
/
local
/
nexuscore
/
Upload File:
files >> //usr/local/nexuscore/nexus_core.sh
#!/bin/bash # /** # * @version 1.0.5 # * @package NexusCore for cPanel/WHM # * @author Erik J. Hoeksma # * @url https://cloudnexus.nl # * @copyright Copyright (c) 2018 - 2019 CloudNexus All rights reserved. # * @license Commercial # * @description NexusCore allows WHM+cPanel server owners to let their # * accounts run dotnet core applications as well as using # * SQL Server for Linux. This script is the main installer. # */ # Constants APP_PATH="/usr/local/nexuscore" CPANEL_PLG_PATH="/usr/local/cpanel/whostmgr/docroot" NEXUSCORE_VERSION="1.0.5" KERNELVERSION=$(uname -a) GET_CENTOS_VERSION=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)) GET_CPANEL_VERSION=$(/usr/local/cpanel/cpanel -V) # Install SQL Server Agent (recommended) - comment if you want to disable #SQL_INSTALL_AGENT='y' # Install SQL Server Full Text Search (optional) - comment if you want to disable #SQL_INSTALL_FULLTEXT='y' # By default new dotnet core apps will run on (internal) localhost:$PORT # This port is not opened to the public, but purely for the internal hosting # by the .net kestrel hosting package. START_PORT=11000 ############################# UTILITY FUCTIONS [start] ############################# function yell() { echo "$*" >&2; } function die() { yell "$*"; yell ""; yell "-- EXECUTION HALTED --";yell "";exit 111; } function start_install { printf "\033c" cat <<EOF 888b 888 .d8888b. 8888b 888 d88P Y88b 88888b 888 888 888 888Y88b 888 .d88b. 888 888 888 888 .d8888b 888 .d88b. 888d888 .d88b. 888 Y88b888 d8P Y8b Y8bd8P 888 888 88K 888 d88""88b 888P" d8P Y8b 888 Y88888 88888888 X88K 888 888 "Y8888b. 888 888 888 888 888 88888888 888 Y8888 Y8b. .d8""8b. Y88b 888 X88 Y88b d88P Y88..88P 888 Y8b. 888 Y888 "Y8888 888 888 "Y88888 88888P' "Y8888P" "Y88P" 888 "Y8888 EOF echo "" echo "<- Starting Installation of NexusCore ->" echo "" } function start_uninstall { printf "\033c" cat <<EOF 888b 888 .d8888b. 8888b 888 d88P Y88b 88888b 888 888 888 888Y88b 888 .d88b. 888 888 888 888 .d8888b 888 .d88b. 888d888 .d88b. 888 Y88b888 d8P Y8b Y8bd8P 888 888 88K 888 d88""88b 888P" d8P Y8b 888 Y88888 88888888 X88K 888 888 "Y8888b. 888 888 888 888 888 88888888 888 Y8888 Y8b. .d8""8b. Y88b 888 X88 Y88b d88P Y88..88P 888 Y8b. 888 Y888 "Y8888 888 888 "Y88888 88888P' "Y8888P" "Y88P" 888 "Y8888 EOF yell "" yell "<- Starting Removal of NexusCore ->" yell "// ---> Before you remove NexusCore, move all of your accounts using" yell "// ---> .NET Core to 'regular' PHP hosting by changing their package" yell "// ---> to a package that doesn't contain .NET core to ensure their" yell "// ---> hosting doesn't break. " yell "// " yell "// ---> I UNDERSTAND ASP.NET CORE WILL STOP WORKING AFTER DELETION:" echo "" remove="x" while [[ $remove != [yn] ]]; do read -p '// Are you sure you want to remove NexusCore (y/n)' remove done if [ $remove = "n" ]; then die "// ---> Nexuscore removal stopped" fi } ############################# UTILTY FUCTIONS [end] ############################### ############################# GENERIC SET UP [start] ############################# ### This does a check for supported OS versions function preflight_check { yell "----------------------------------------------------------------------------------"; yell "// Starting Pre-flight check..."; local MAYOR_VERSION=(${GET_CPANEL_VERSION//./ }) if [ -e /etc/cron.d/nexuscore-logs ]; then die "// ---> NexusCore seems to be installed - try reinstalling or contact support!" fi; kernelcheck yell "// ---> Supported OS found!" if [ $MAYOR_VERSION -lt 76 ]; then die "// ---> NexusCore is only supported on WHM 76+ - detected version $MAYOR_VERSION " else yell "// ---> Supported version of WHM found" fi if pgrep "nginx" >/dev/null 2>&1 ; then yell "// ---> NGINX is running as a process. NGINX is not supported with NexusCore." die "// ---> Cancelled the installation" fi yell "// Preflight check complete" } function kernelcheck { local isvalid=0 if [ ${#GET_CENTOS_VERSION} -eq 1 ]; then if [ "7" -eq "$GET_CENTOS_VERSION" ]; then isvalid=1; fi fi if [[ $KERNELVERSION = *"lve"* ]]; then isvalid=1 fi if [ $isvalid -eq 0 ]; then die "// ---> Unsupported OS found. Supporting CentOS 7+ and CloudLinux" fi } ### This sets up the basic packages needed to run .net core function install_basics { yell "// Installing required yum packages" yell "// ---> This might take some time depending on your machine and internet connection" sudo yum -y update &>/dev/null sudo yum -y upgrade &>/dev/null sudo yum -y install epel-release &>/dev/null sudo yum -y install curl unzip zip zlib-devel inotify-tools libunwind lttng-ust libcurl openssl-libs libuuid krb5-libs libicu zlib jq &>/dev/null sudo yum -y install --enablerepo epel pwgen &>/dev/null sudo yum -y install jq --enablerepo=epel &>/dev/null yell "// Successfully installed required yum packages" } ### this adds the microsoft package repository, and installs the .net runtime function install_net_core { yell "// Installing dotnet core sdk, runtimes and hosting packages" yell "// ---> This might take some time depending on your machine and internet connection" sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm &>/dev/null sudo yum install -y aspnetcore-runtime-2.1 &>/dev/null sudo yum install -y aspnetcore-runtime-2.2 &>/dev/null sudo yum install -y aspnetcore-runtime-3.0 &>/dev/null sudo yum install -y aspnetcore-runtime-3.1 &>/dev/null yell "// Successfully installed dotnet core sdk, runtimes and hosting packages" } ### this uninstalls the .net runtime function uninstall_net_core { yell "// Uninstalling dotnet core sdk, runtimes and hosting packages" sudo yum remove -y "aspnetcore-runtime-2.1" &>/dev/null sudo yum remove -y "aspnetcore-runtime-2.2" &>/dev/null sudo yum remove -y "aspnetcore-runtime-3.0" &>/dev/null sudo yum remove -y "aspnetcore-runtime-3.1" &>/dev/null yell "// Successfully uninstalled dotnet core sdk, runtimes and hosting packages" } ### Clean up yum function post_install { yell "// Cleaning and tidying up..." sudo yum clean all > /dev/null sudo rm -rf /usr/local/cpanel/Cpanel/Config/ConfigObj/Driver/nexusfeature.json sudo cp $APP_PATH/package_ext/nexuscorefeature.json /usr/local/cpanel/Cpanel/Config/ConfigObj/Driver/ echo $NEXUSCORE_VERSION > /root/.nxc.version echo "884e16da-acd3-46ac-b3a5-f14c08b4bc4a" > /root/.nxc.cnf yell "// ALL FINISHED !" yell "// NexusCore is now installed on your WHM/cPanel server" yell "// Enjoy NexusCore !" yell "" yell "" } function setup_up_translations { /scripts/locale_import locale=en --import=/usr/local/nexuscore/assets/i18n/whm/nexuscore-en.xlf &>/dev/null /scripts/locale_import locale=ru --import=/usr/local/nexuscore/assets/i18n/whm/nexuscore-ru.xlf &>/dev/null /scripts/locale_import locale=nl --import=/usr/local/nexuscore/assets/i18n/whm/nexuscore-nl.xlf &>/dev/null /scripts/locale_import locale=de --import=/usr/local/nexuscore/assets/i18n/whm/nexuscore-de.xlf &>/dev/null /scripts/locale_import locale=pt --import=/usr/local/nexuscore/assets/i18n/whm/nexuscore-pt.xlf &>/dev/null /scripts/locale_import locale=es --import=/usr/local/nexuscore/assets/i18n/whm/nexuscore-es.xlf &>/dev/null } ### Clean up yum function post_uninstall { yell "// Cleaning and tidying up..." sudo yum clean all > /dev/null rm -rf $APP_PATH/users/* rm -rf /root/.nxc.version rm -rf /root/.nxc.cnf rm -rf /usr/local/cpanel/Cpanel/Config/ConfigObj/Driver/nexuscore* rm -rf /var/cpanel/activate/features/nexuscore* yell "// ALL FINISHED !" yell "// NexusCore is now removing from your WHM/cPanel server" yell "// Enjoy Apache+PHP+MySQL ;-) !" yell "" yell "" } ############################# GENERIC SET UP [end] ############################# ############################# WATCHERS [start] ############################# ### this function sets up services for both add/remove watchers function autoload_watcher { yell "// Installing file watchers as system service" yell "// ---> [SERVICE] Watch added accounts with dotnet" cat <<- EOT > /etc/systemd/system/nexuscore-watch-add.service [Unit] Description=NexusCore watcher for added accounts [Service] ExecStart=$APP_PATH/utils/watch_add Restart=always RestartSec=10 SyslogIdentifier=nexuscore-watch-add-ident User=root [Install] WantedBy=multi-user.target EOT yell "// ---> [SERVICE] Watch removed accounts with dotnet" cat <<- EOT > /etc/systemd/system/nexuscore-watch-remove.service [Unit] Description=NexusCore watcher for removed accounts [Service] ExecStart=$APP_PATH/utils/watch_remove Restart=always RestartSec=10 SyslogIdentifier=nexuscore-watch-remove-ident User=root [Install] WantedBy=multi-user.target EOT yell "// ---> Reloading system services" sudo systemctl daemon-reload > /dev/null yell "// ---> Setting services as auto-start" sudo systemctl enable nexuscore-watch-add.service &>/dev/null sudo systemctl enable nexuscore-watch-remove.service &>/dev/null yell "// ---> Starting services" sudo systemctl start nexuscore-watch-add.service > /dev/null sudo systemctl start nexuscore-watch-remove.service > /dev/null yell "// Succesfully installed file watching services" } function remove_watchers { yell "// Removing nexuscore services" sudo systemctl disable nexuscore-watch-add.service &>/dev/null sudo systemctl disable nexuscore-watch-remove.service &>/dev/null sudo systemctl stop nexuscore-watch-add.service &>/dev/null sudo systemctl stop nexuscore-watch-remove.service &>/dev/null sudo rm -rf /etc/systemd/system/nexuscore-watch-add.service sudo rm -rf /etc/systemd/system/nexuscore-watch-remove.service yell "// Succesfully Removed nexuscore services" } function add_cron { yell "// Setting up cron jobs" yell "// ---> Added cron for dotnet logging" cat <<- EOT > /etc/cron.d/nexuscore-logs * * * * * root /usr/local/nexuscore/utils/create_logs > /dev/null EOT yell "// ---> Added cron for NexusCore auto update" cat <<- EOT > /etc/cron.d/nexuscore-autoupdate 30 2 * * * root /usr/local/nexuscore/utils/auto_update >/dev/null EOT yell "// ---> Added cron for dotnet runtime auto update" cat <<- EOT > /etc/cron.d/nexuscore-autoupdate 30 3 * * * root /usr/local/nexuscore/utils/update_dotnet >/dev/null EOT yell "// Finished setting up cron jobs" } function remove_cron { yell "// Removing cron jobs" sudo rm -rf /etc/cron.d/nexuscore-logs sudo rm -rf /etc/cron.d/nexuscore-autoupdate yell "// Finished removing up cron jobs" } ############################# WATCHERS [end] ############################# ########################## SQL SERVER [start] ############################ function uninstall_mssql { yell "//////////////////////////////////////////////////" yell "// Microsoft SQL Server Removal" yell "//////////////////////////////////////////////////" if [ ! -e /usr/lib/systemd/system/mssql-server.service ]; then yell "// ---> Microsoft SQL Server is not installed, nothing to remove" else removeSQL="x" removeDatabases="x" while [[ $installSql != [yn] ]]; do read -p '// Would you like to remove Microsoft SQL Server for Linux? (y/n)' installSql done if [ $installSql = "n" ]; then die "// ---> Microsoft SQL Server removal cancelled!" fi sudo yum remove -y mssql-server mssql-server-agent mssql-server-fts &>/dev/null yell "// ---> Closing outbound port 1433 TCP in the firewall (SQL)" if [ -e /etc/csf/csf.conf ]; then sed -i 's/TCP_IN = "1433,/TCP_IN = "/g' /etc/csf/csf.conf &>/dev/null sed -i 's/TCP_OUT = "1433,/TCP_OUT = "/g' /etc/csf/csf.conf &>/dev/null csf -r &>/dev/null fi if [ -e /etc/apf/conf.apf ]; then sed -i 's/IG_TCP_CPORTS="1433,/IG_TCP_CPORTS="/g' /etc/apf/conf.apf &>/dev/null sed -i 's/EG_TCP_CPORTS="1433,/EG_TCP_CPORTS="/g' /etc/apf/conf.apf &>/dev/null apf -r &>/dev/null fi yell "// ---> Reloading firewall" sudo firewall-cmd --zone=public --remove-port=1433/tcp --permanent > /dev/null sudo firewall-cmd --reload > /dev/null yell "// ---> Removing cPanel package extensions" sudo rm -rf /var/cpanel/packages/extensions/nexussql sudo rm -rf /var/cpanel/packages/extensions/nexussql.tt2 uninstall_cpanel_plugin_mssql yell "// ---> Microsoft SQL Server has been removed from your system" while [[ $removeDatabases != [yn] ]]; do read -p '// Would you also like to remove all user data (databases) in /var/opt/mssql/data? (y/n)' removeDatabases done if [ $removeDatabases = "y" ]; then yell "// ---> Microsoft SQL Server user data removed" sudo rm -rf /var/opt/mssql/ fi sudo rm -rf /root/.mssql.cnf yell "// ---> Microsoft SQL Server removal completed" yell "" yell "" fi } # this function will prompt for confirmation and install SQL Server function install_mssql { yell "//////////////////////////////////////////////////" yell "// Microsoft SQL Server installation (optional)" yell "//////////////////////////////////////////////////" if [ -e /usr/lib/systemd/system/mssql-server.service ]; then yell "// ---> Microsoft SQL Server is already installed - skipping" else installSql="x" while [[ $installSql != [yn] ]]; do read -p '// Would you like to install Microsoft SQL Server for Linux? (y/n)' installSql done if [ $installSql = "y" ]; then yell "// ---> Starting SQL Server installation" yell "// ---> Verifiying system requirements" local totalRam=$(awk '/MemTotal/ {print $2}' /proc/meminfo) if [ "$totalRam" -lt 2000000 ]; then yell "// -----> Your system has less than 2GB of memory, SQL Installation will be skipped!" return fi sqlPassword=$(pwgen -y 14 1 -r \`\"\'\$\@\>\<\\\}\{\%\#\[\]\=\~) sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo &>/dev/null sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo &>/dev/null yell "// ---> Installing SQL Server packages" sudo yum install -y mssql-server > /dev/null yell "// ---> Configuring installation SQL Server packages" sudo MSSQL_PID=express ACCEPT_EULA=Y MSSQL_SA_PASSWORD=$sqlPassword /opt/mssql/bin/mssql-conf -n setup > /dev/null sudo ACCEPT_EULA=Y yum install -y mssql-tools unixODBC-devel > /dev/null echo $sqlPassword > /root/.mssql.cnf yell "// ---> Opening outbound port 1433 TCP in the firewall (SQL)" sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent > /dev/null if [ -e /etc/csf/csf.conf ]; then sed -i 's/TCP_IN = "/TCP_IN = "1433,/g' /etc/csf/csf.conf &>/dev/null sed -i 's/TCP_IN = "/TCP_OUT = "1433,/g' /etc/csf/csf.conf &>/dev/null csf -r &>/dev/null fi if [ -e /etc/apf/conf.apf ]; then sed -i 's/IG_TCP_CPORTS="/IG_TCP_CPORTS="1433,/g' /etc/apf/conf.apf &>/dev/null sed -i 's/EG_TCP_CPORTS="/EG_TCP_CPORTS="1433,/g' /etc/apf/conf.apf &>/dev/null apf -r &>/dev/null fi yell "// ---> Reloading firewall" sudo firewall-cmd --reload &>/dev/null # Add SQL Server tools to the path by default: yell "// ---> Adding SQL commandline tools to PATH" echo PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc if [ ! -z $SQL_INSTALL_AGENT ] then yell "// ---> Installing SQL Server Agent" sudo yum install -y mssql-server-agent > /dev/null fi # Optional SQL Server Full Text Search installation: if [ ! -z $SQL_INSTALL_FULLTEXT ] then yell "// ---> Installing SQL Server Full-Text Search" sudo yum install -y mssql-server-fts > /dev/null fi install_cpanel_plugin_mssql sudo chmod 755 $APP_PATH/utils/sql_server_management > /dev/null yell "// ---> Restarting SQL Server" sudo systemctl restart mssql-server &>/dev/null # Connect to server and get the version: counter=1 errstatus=1 while [ $counter -le 12 ] && [ $errstatus = 1 ] do yell "// ---> Waiting for SQL Server to start..." sleep 5s /opt/mssql-tools/bin/sqlcmd \ -S localhost \ -U SA \ -P $sqlPassword \ -Q "SELECT @@VERSION" &>/dev/null errstatus=$? ((counter++)) done # Display error if connection failed: if [ $errstatus = 1 ]; then yell "// ---> Cannot connect to SQL Server - something went wrong." else sudo chmod +x $APP_PATH/assets/sql/sp_help_revlogin.sql $APP_PATH/utils/sql_server_management exec_query "$APP_PATH/assets/sql/sp_help_revlogin.sql" rm -rf $APP_PATH/assets/sql/ fi yell "// ---> Installing WHM Package extensions for SQL Server." mkdir -p /var/cpanel/packages/extensions > /dev/null /bin/cp $APP_PATH/package_ext/nexussql /var/cpanel/packages/extensions/nexussql > /dev/null /bin/cp $APP_PATH/package_ext/nexussql.tt2 /var/cpanel/packages/extensions/nexussql.tt2 > /dev/null yell "// Finished installing SQL Server" else yell "// Skipping installing SQL Server" fi fi } ########################## SQL SERVER [end] ############################ ########################## WHM SPECIFIC [start] ########################## ### this creates WHM plugin folders where neccesary function prepare_whm_plugin_folders { yell "// Preparing WHM Plugin folders"; if [ ! -d /var/cpanel/apps ] then yell "// ---> Creating WHM Plugin folders"; sudo mkdir /var/cpanel/apps > /dev/null sudo chmod 755 /var/cpanel/apps > /dev/null yell "" fi yell "// ---> Creating folders for trigger watchers"; sudo mkdir -p $APP_PATH/tmp/add > /dev/null sudo mkdir -p $APP_PATH/tmp/remove > /dev/null sudo mkdir -p $APP_PATH/users > /dev/null if [ -z $START_PORT ]; then START_PORT="11000" fi yell "// ---> Setting default port for new netcore app: to[$START_PORT]"; echo $START_PORT > $APP_PATH/users/nexuscore.cache chmod 755 $APP_PATH/utils/* yell "// Finished preparing WHM Plugin folders"; } ### this creates WHM hooks so we can enable ASP on account creation / modification / deletion function attach_hooks { yell "// Attaching to WHM Hooks"; sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_shared.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_shared.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_create_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_create_account_pre.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account_pre.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_modify_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_modify_account.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_delete_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_delete_account.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_suspend_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_suspend_account.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_unsuspend_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_unsuspend_account.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_change_package.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_change_package_pre.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package_pre.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_rearrange_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_rearrange_account.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_backup_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_backup_account.php sudo /bin/cp $APP_PATH/hooks/nexuscore_hook_restore_account.php /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php sudo chown root:root /usr/local/cpanel/3rdparty/bin/nexuscore_hook_* sudo chmod 755 /usr/local/cpanel/3rdparty/bin/nexuscore_hook_* sudo chmod 755 $APP_PATH/utils/create_logs sudo /bin/cp $APP_PATH/nexuscore.lic /usr/local/cpanel/3rdparty/bin/ > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account.php --category Whostmgr --event Accounts::Create --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account_pre.php --category Whostmgr --event Accounts::Create --stage pre --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_modify_account.php --category Whostmgr --event Accounts::Modify --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_delete_account.php --category Whostmgr --event Accounts::Remove --stage pre --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_suspend_account.php --category Whostmgr --event Accounts::suspendacct --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_unsuspend_account.php --category Whostmgr --event Accounts::unsuspendacct --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package.php --category Whostmgr --event Accounts::change_package --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package_pre.php --category Whostmgr --event Accounts::change_package --stage pre --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_rearrange_account.php --category Whostmgr --event Accounts::rearrangeacct --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_backup_account.php --category PkgAcct --event Create --stage preFinalize --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage postExtract --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage preRestore --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage postRestore --weight 100 --manual > /dev/null yell "// Finished Attaching to WHM Hooks"; } ### this disables WHM hooks function detach_hooks { yell "// Detaching WHM Hooks" sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account.php --category Whostmgr --event Accounts::Create --stage post --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account_pre.php --category Whostmgr --event Accounts::Create --stage pre --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_modify_account.php --category Whostmgr --event Accounts::Modify --stage post --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_delete_account.php --category Whostmgr --event Accounts::Remove --stage pre --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_suspend_account.php --category Whostmgr --event Accounts::suspendacct --stage post --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_unsuspend_account.php --category Whostmgr --event Accounts::unsuspendacct --stage post --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package.php --category Whostmgr --event Accounts::change_package --stage post --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package_pre.php --category Whostmgr --event Accounts::change_package --stage pre --weight 100 --manual &>/dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_rearrange_account.php --category Whostmgr --event Accounts::rearrangeacct --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_backup_account.php --category PkgAcct --event Create --stage preFinalize --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage post --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage postExtract --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage preRestore --weight 100 --manual > /dev/null sudo /usr/local/cpanel/bin/manage_hooks delete script /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php --category PkgAcct --event Restore --stage postRestore --weight 100 --manual > /dev/null sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_create_account_pre.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_modify_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_delete_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_suspend_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_unsuspend_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_change_package_pre.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_rearrange_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_backup_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_restore_account.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore_hook_shared.php sudo rm -rf /usr/local/cpanel/3rdparty/bin/nexuscore.lic yell "// Detached WHM Hooks" } ### this copies over the WHM Plugin files function install_nexuscore_ui { yell "// Installing WHM Plugin"; yell "// ---> Copying plugin files"; sudo /bin/cp $APP_PATH/app/nexus_core.php $CPANEL_PLG_PATH/cgi > /dev/null sudo /bin/cp $APP_PATH/nexuscore.lic $CPANEL_PLG_PATH/cgi > /dev/null sudo chmod +x $CPANEL_PLG_PATH/cgi/nexus_core.php > /dev/null sudo /bin/cp $APP_PATH/assets/nexuscore.jpg $CPANEL_PLG_PATH/addon_plugins > /dev/null sudo mkdir -p /var/cpanel/packages/extensions > /dev/null sudo /bin/cp $APP_PATH/package_ext/nexuscore /var/cpanel/packages/extensions/nexuscore > /dev/null sudo /bin/cp $APP_PATH/package_ext/nexuscore.tt2 /var/cpanel/packages/extensions/nexuscore.tt2 > /dev/null yell "// ---> Registering NexusCore with WHM plugin"; sudo /usr/local/cpanel/bin/register_appconfig $APP_PATH/app/nexus_core.conf > /dev/null sudo whmapi1 set_tweaksetting key=phploader value=ioncube > /dev/null if [ ! -f /etc/nexuscore.conf ]; then cat <<- EOT > /etc/nexuscore.conf # automatically update nexuscore auto_update="1" # default starter project ("nexuscore" or "empty") starter_project="nexuscore" EOT fi yell "// Finished installing WHM Plugin"; } ### this removes the WHM Plugin files function uninstall_nexuscore_ui { yell "// Uninstalling NexusCore WHM/cPanel plugin files" sudo /bin/rm -f $CPANEL_PLG_PATH/cgi/nexus_core.php sudo /bin/rm -f $CPANEL_PLG_PATH/addon_plugins/nexuscore.jpg sudo /bin/rm -f /var/cpanel/packages/extensions/nexuscore sudo /bin/rm -f /var/cpanel/packages/extensions/nexuscore.tt2 /usr/local/cpanel/bin/unregister_appconfig nexuscore > /dev/null yell "// Uninstalled NexusCore WHM/cPanel plugin files" } function install_cpanel_plugin_dotnet { yell "// Installing cPanel dotnet core plugin"; #installing cpanel dotnet plugin yell "// ---> Copying files"; sudo chmod 755 $APP_PATH/utils/dotnet_management > /dev/null mkdir -p /usr/local/cpanel/base/frontend/paper_lantern/dotnet/ > /dev/null sudo /bin/cp -r $APP_PATH/plugin/cpanel/nexuscore-dotnet/app/* /usr/local/cpanel/base/frontend/paper_lantern/dotnet/ > /dev/null yell "// ---> Registering the dotnet core plugin with cPanel"; sudo /usr/local/cpanel/scripts/install_plugin $APP_PATH/plugin/cpanel/nexuscore-dotnet > /dev/null sudo /bin/cp $APP_PATH/nexuscore.lic /usr/local/cpanel/base/frontend/paper_lantern/dotnet/ > /dev/null yell "// Installed CPANEL dotnet core plugin"; create_feature_for_package_dotnet } function install_cpanel_plugin_mssql { yell "// Installing cPanel SQL Server plugin"; yell "// ---> Copying files"; mkdir -p /var/opt/mssql/data/dbrestores mkdir -p /usr/local/cpanel/base/frontend/paper_lantern/mssql/ > /dev/null mkdir -p /var/cpanel/perl/Cpanel/ResourceUsage/Custom/ > /dev/null sudo /bin/cp $APP_PATH/plugin/cpanel/nexuscore-stats/NexuscoreMssqlStats.pm /var/cpanel/perl/Cpanel/ResourceUsage/Custom/NexuscoreMssqlStats.pm > /dev/null sudo /bin/cp -r $APP_PATH/plugin/cpanel/nexuscore-mssql/app/* /usr/local/cpanel/base/frontend/paper_lantern/mssql/ > /dev/null yell "// ---> Registering the SQL Server plugin with cPanel"; sudo /usr/local/cpanel/scripts/install_plugin $APP_PATH/plugin/cpanel/nexuscore-mssql > /dev/null sudo chmod -R 755 /usr/local/cpanel/base/frontend/paper_lantern/mssql > /dev/null sudo /bin/cp $APP_PATH/nexuscore.lic /usr/local/cpanel/base/frontend/paper_lantern/mssql/ > /dev/null yell "// Installed cPanel SQL Server plugin"; create_feature_for_package_mssql } function install_uapi_plugin { #installing uapi modules sudo mkdir -p /usr/local/cpanel/bin/admin/NexusCore > /dev/null echo "mode=full" > /usr/local/cpanel/bin/admin/NexusCore/SqlServer.conf sudo /bin/cp $APP_PATH/plugin/uapi/SqlServer.pm /usr/local/cpanel/bin/admin/NexusCore/SqlServer > /dev/null sudo chmod +x /usr/local/cpanel/bin/admin/NexusCore/SqlServer > /dev/null sudo /bin/cp $APP_PATH/plugin/uapi/SqlServerHandler.pm /usr/local/cpanel/Cpanel/API/SqlServerHandler.pm > /dev/null } function uninstall_uapi_plugin { #uninstalling uapi modules sudo rm -rf /usr/local/cpanel/bin/admin/NexusCore/SqlServer sudo rm -rf /usr/local/cpanel/Cpanel/API/SqlServerHandler.pm } function uninstall_cpanel_plugin_dotnet { yell "// Uninstalling NexusCore cPanel plugin... ===" sudo rm -rf /usr/local/cpanel/base/frontend/paper_lantern/dotnet sudo /usr/local/cpanel/scripts/uninstall_plugin $APP_PATH/plugin/cpanel/nexuscore-dotnet > /dev/null sudo whmapi1 delete_featurelist featurelist="Dotnet Core without SQL Server" > /dev/null sudo whmapi1 killpkg pkgname="dotnet core without SQL Server" > /dev/null yell "// Uninstalled NexusCore cPanel plugin... ===" } function uninstall_cpanel_plugin_mssql { yell "// Uninstalling SQL Server cPanel plugin... ===" sudo rm -rf /usr/local/cpanel/base/frontend/paper_lantern/mssql sudo rm -rf /var/cpanel/perl/Cpanel/ResourceUsage/Custom/NexuscoreMssqlStats.pm sudo rm -rf /usr/local/cpanel/bin/admin/NexusCore/SqlServer.conf sudo /usr/local/cpanel/scripts/uninstall_plugin $APP_PATH/plugin/cpanel/nexuscore-mssql > /dev/null sudo whmapi1 delete_featurelist featurelist="Dotnet Core with SQL Server 2017" > /dev/null sudo whmapi1 killpkg pkgname="dotnet core with SQL Server" > /dev/null yell "// Uninstalled SQL Server cPanel plugin... ===" } function disable_accounts { yell "// Disabling all ASP.NET cPanel accounts ===" for filename in $APP_PATH/users/*; do disable_account $(basename "$filename") done yell "// Disabled all ASP.NET cPanel accounts ===" /scripts/rebuildhttpdconf &>/dev/null /scripts/restartsrv_httpd &>/dev/null } function disable_account { local account=$1 if [ "nexuscore.cache" != $account ]; then yell "// ---> $account" yell "// ---> Removing .NET Core service for $account" sudo systemctl disable nexuscore-account-$account.service &>/dev/null sudo systemctl stop nexuscore-account-$account.service &>/dev/null sudo rm -rf /etc/systemd/system/nexuscore-account-$account.service sudo systemctl disable nexuscore-account-$account.service &>/dev/null sudo systemctl stop nexuscore-account-$account.service &>/dev/null sudo rm -rf /etc/systemd/system/nexuscore-account-$account.service sudo systemctl disable nexuscore-watch-deployments-$account.service &>/dev/null sudo systemctl stop nexuscore-watch-deployments-$account.service &>/dev/null sudo rm -rf /etc/systemd/system/nexuscore-watch-deployments-$account.service yell "// ---> Removing apache overrides for $account" rm -rf /etc/apache2/conf.d/userdata/std/2_4/$account/**/nexuscore_http.conf &>/dev/null rm -rf /etc/apache2/conf.d/userdata/ssl/2_4/$account/**/nexuscore_https.conf &>/dev/null fi } function create_feature_for_package_dotnet { yell "// Creating WHM Featurelist for Dotnet-enabled accounts"; sudo whmapi1 create_featurelist featurelist="Dotnet Core without SQL Server" > /dev/null sudo whmapi1 update_featurelist featurelist="Dotnet Core without SQL Server" \ nexuscore_logs=1 nexuscore_info=1 nexuscore_sdks=1 nexuscore_devtools=1 nexuscore_help=1 \ nexuscore_appsettings=1 addondomains=1 csvimport=1 parkeddomains=1 analog=1 spamassassin=1 \ passengerapps=1 autoresponders=1 autossl=1 awstats=1 backup=1 \ bandwidth=1 boxtrapper=1 caldavcarddav=1 setlang=1 style=1 \ greylist=1 updatecontact=1 \ market=1 enduserlve=1 cron=1 defaultaddress=1 \ dirselector=1 diskusageviewer=1 popaccts=1 emailarchive=1 traceaddy=1 \ email_disk_usage=1 emaildomainfwd=1 blockers=1 emailtrace=1 \ filemanager=1 filerestoration=1 forwarders=1 ftpaccts=1 ftpsetup=1 \ lists=1 dnssec=1 statselect=1 changemx=1 password=1 pgp=1 \ serverstatus=1 sslinstall=1 sslmanager=1 subdomainstats=1 subdomains=1 \ nettools=1 twofactorauth=1 updatenotificationprefs=1 \ clamavconnector_scan=1 webdisk=1 webalizer=1 webmail=1 simplezoneedit=1 \ nexuscore_sqlwizard=0 nexuscore_sqloverview=0 nexuscore_sqltools=0 \ nexuscore_sql_backups=0 nexuscore_sql_connectionstring=0 \ mysql=1 phpmyadmin=1 phppgadmin=1 postgres=1 > /dev/null create_package_dotnet_hosting yell "// Done creating WHM Featurelist for DOTNET accounts"; } function create_package_dotnet_hosting { sudo whmapi1 addpkg name="dotnet core without SQL Server" \ featurelist="Dotnet Core without SQL Server" > /dev/null sudo whmapi1 addpkgext name="dotnet core without SQL Server" _PACKAGE_EXTENSIONS=nexuscore enable_dotnet_core=y > /dev/null } function create_feature_for_package_mssql { yell "// Creating WHM Featurelist for SQLServer-enabled accounts"; sudo whmapi1 create_featurelist featurelist="Dotnet Core with SQL Server 2017" > /dev/null update_sql_dotnet_feature_package create_package_mssql_hosting yell "// Done creating WHM Featurelist for SQLServer-enabled accounts"; } function update_sql_dotnet_feature_package { sudo whmapi1 update_featurelist featurelist="Dotnet Core with SQL Server 2017" \ nexuscore_logs=1 nexuscore_info=1 nexuscore_sdks=1 nexuscore_devtools=1 nexuscore_help=1 \ nexuscore_appsettings=1 addondomains=1 csvimport=1 parkeddomains=1 analog=1 spamassassin=1 \ passengerapps=1 autoresponders=1 autossl=1 awstats=1 backup=1 \ bandwidth=1 boxtrapper=1 caldavcarddav=1 setlang=1 style=1 \ greylist=1 updatecontact=1 \ market=1 enduserlve=1 cron=1 defaultaddress=1 \ dirselector=1 diskusageviewer=1 popaccts=1 emailarchive=1 traceaddy=1 \ email_disk_usage=1 emaildomainfwd=1 blockers=1 emailtrace=1 \ filemanager=1 filerestoration=1 forwarders=1 ftpaccts=1 ftpsetup=1 \ lists=1 dnssec=1 statselect=1 changemx=1 password=1 pgp=1 \ serverstatus=1 sslinstall=1 sslmanager=1 subdomainstats=1 subdomains=1 \ nettools=1 twofactorauth=1 updatenotificationprefs=1 \ clamavconnector_scan=1 webdisk=1 webalizer=1 webmail=1 simplezoneedit=1 \ nexuscore_sqlwizard=1 nexuscore_sqloverview=1 nexuscore_sqltools=1 \ nexuscore_sql_backups=1 nexuscore_sql_connectionstring=1 > /dev/null } function create_package_mssql_hosting { sudo whmapi1 addpkg name="dotnet core with SQL Server" \ featurelist="Dotnet Core with SQL Server 2017" > /dev/null sudo whmapi1 addpkgext name="dotnet core with SQL Server" _PACKAGE_EXTENSIONS=nexussql enable_sql_server=y sql_server_max_databases=5 > /dev/null sudo whmapi1 addpkgext name="dotnet core with SQL Server" _PACKAGE_EXTENSIONS=nexuscore enable_dotnet_core=y > /dev/null } function reset_features { #Dotnet Core with SQL Server 2017 local featurelists=$(echo $(whmapi1 get_available_featurelists --output=json) | jq '.data.available_featurelists | @csv') IFS=',' ; for i in $featurelists; do i=$(echo "$i" | tr -d '"') i=$(echo "$i" | tr -d '\\') reset_features_do $i done update_sql_dotnet_feature_package } function reset_features_do { local packageName=$1; if [ "$packageName" != "[" ] && [ "$packageName" != "Mail Only" ] && [ "$packageName" != "disabled" ] && [ "$packageName" != "]" ] && [ "$packageName" != "Dotnet Core with SQL Server 2017" ] && [ "$packageName" != "Dotnet Core without SQL Server" ]; then yell "// Disabling nexuscore features for feature list \"$1\"" sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_appsettings=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_help=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_logs=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_info=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_sdks=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_devtools=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_sqlwizard=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_sqloverview=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_sqltools=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_sql_backups=0 &>/dev/null sudo whmapi1 update_featurelist featurelist="$packageName" nexuscore_sql_connectionstring=0 &>/dev/null fi } function update_license { if [ -f /usr/local/nexuscore/nexuscore.lic ]; then sudo yes | /bin/cp $APP_PATH/nexuscore.lic /usr/local/cpanel/3rdparty/bin/ > /dev/null sudo yes | /bin/cp $APP_PATH/nexuscore.lic $CPANEL_PLG_PATH/cgi > /dev/null sudo yes | /bin/cp $APP_PATH/nexuscore.lic /usr/local/cpanel/base/frontend/paper_lantern/dotnet/ > /dev/null sudo yes | /bin/cp $APP_PATH/nexuscore.lic /usr/local/cpanel/base/frontend/paper_lantern/mssql/ > /dev/null yell "[NexusCore] License details updated. You should see the new license details in the WHM pugin now!" else yell "[NexusCore] No license file found at /usr/local/nexuscore/nexuscore.lic" fi } ########################## WHM SPECIFIC [end] ########################## ########################## CLI ##################### case $1 in install) start_install preflight_check install_basics prepare_whm_plugin_folders install_net_core install_nexuscore_ui autoload_watcher attach_hooks install_mssql install_cpanel_plugin_dotnet install_uapi_plugin reset_features add_cron setup_up_translations post_install ;; uninstall) start_uninstall uninstall_net_core uninstall_nexuscore_ui remove_watchers detach_hooks disable_accounts uninstall_cpanel_plugin_dotnet uninstall_uapi_plugin remove_cron uninstall_mssql post_uninstall ;; install_mssql) install_mssql ;; uninstall_mssql) uninstall_mssql ;; update_license) update_license ;; -h|--help|*) cat <<EOF 888b 888 .d8888b. 8888b 888 d88P Y88b 88888b 888 888 888 888Y88b 888 .d88b. 888 888 888 888 .d8888b 888 .d88b. 888d888 .d88b. 888 Y88b888 d8P Y8b Y8bd8P 888 888 88K 888 d88""88b 888P" d8P Y8b 888 Y88888 88888888 X88K 888 888 "Y8888b. 888 888 888 888 888 88888888 888 Y8888 Y8b. .d8""8b. Y88b 888 X88 Y88b d88P Y88..88P 888 Y8b. 888 Y888 "Y8888 888 888 "Y88888 88888P' "Y8888P" "Y88P" 888 "Y8888 https://nexuscore.io NexusCore is the easiest way to serve ASP.NET Core apps from your cPanel/WHM server. NexusCore v$NEXUSCORE_VERSION Usage: /nexus_core.sh [command] Main commands: install Installs the Nexuscore plugin for WHM completely uninstall Uninstalls the Nexuscore plugin for WHM excluding any user applications install_mssql Installs SQL Server for Linux uninstall_mssql Uninstalls SQL Server for Linux update_license Refreshes the license info placed in /usr/local/nexuscore ~~ Enjoy NexusCore ! ~~ EOF ;; esac
Copyright ©2021 || Defacer Indonesia