create/delete vHost's simply
- GITHUB REPO - GITHUB REPO
create/delete vHost's simply
certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns -d 'jiripocta.cz,*.jiripocta.cz' | |
certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns -d 'posterus.cz,*.posterus.cz' |
find web/ -type d -exec chmod 0775 {} \; && find web/ -type f -exec chmod 0774 {} \; |
#!/bin/bash | |
adminEmail="[email protected]"; | |
ftpHost="ftp.posterus.cz" | |
domainname=$1 | |
if [ "$1" = "" ]; then | |
echo "Domain name? etc. ./ftpadd.sh example.com" | |
exit 1 | |
fi | |
safedomainname=${domainname//[^[:alnum:]]/} | |
ftppass=$(pwgen -s -1) | |
mailTemplate="$(echo " | |
Domain: http://${domainname}<br> | |
<br> | |
FTP<br> | |
Host: ${ftpHost}<br> | |
Username: ${safedomainname}<br> | |
Password: ${ftppass}<br> | |
<br> | |
")" | |
if (echo $ftppass; echo $ftppass) | pure-pw useradd $safedomainname -u $safedomainname -g www-data -d /var/www/$domainname/web/ ; then | |
pure-pw mkdb | |
else | |
echo "" | |
pure-pw list | |
echo "" | |
exit 1 | |
fi | |
echo $mailTemplate | mail -s "$(echo -e "FTP Account for Web ${domainname}\nContent-Type: text/html")" $adminEmail -aFrom:"${domainname}<root@${domainname}>" | |
echo "FTP Account ${safedomainname} created." | |
echo "--" | |
echo "Username: ${safedomainname}" | |
echo "Password: ${ftppass}" | |
echo "--" | |
exit 0 |
#!/bin/bash | |
echo $(certbot certonly --standalone --agree-tos --cert-name ftp.posterus.cz -n -m [email protected] -d ftp.posterus.cz -d ftp.jiripocta.cz --pre-hook "service apache2 stop" --post-hook "service apache2 start") \ | |
&& cd /etc/letsencrypt/live/ftp.posterus.cz/ \ | |
&& cat cert.pem privkey.pem > pure-ftpd.pem \ | |
&& rm /etc/ssl/private/pure-ftpd.pem \ | |
&& mv pure-ftpd.pem /etc/ssl/private/ \ | |
&& chmod 600 /etc/ssl/private/pure-ftpd.pem \ | |
&& service pure-ftpd restart | |
echo "DONE CERT IS INSTALLED!" |
#!/bin/bash | |
# https://gist.github.com/nosmall | |
# https://github.com/nosmall | |
if [ "$(id -u)" != 0 ]; then | |
echo "You must be root" | |
exit 1 | |
fi | |
# path to script vhost.sh | |
scriptpath="/home/jirka/vhost/" | |
# min. settings | |
backupPath="/var/webbackup" | |
adminEmail="[email protected]" | |
fromEmail="[email protected]" | |
ftpHost="ftp.jiripocta.cz" | |
mysqlHost="localhost (srv4)" | |
mysqlAdmin="mysql.jiripocta.cz" | |
mysqlAdminUser="vhost_app" | |
mysqlAdminPass="6FGXKsHzWdWoFXDB" | |
#$(date +%D) | |
today="$(date +%Y-%m-%d_%H%M%S)" | |
pwd=$(pwd) | |
ftppass=$(pwgen -s 16 1) | |
mysqlpass=$(pwgen -s 16 1) | |
vCheck=false | |
variable="" | |
safevariable="" | |
safevarisdomain="" | |
aCheck=false | |
action="" | |
dCheck=false | |
domainname="" | |
safedomainname="" | |
mysqlshortname="" | |
mysqlsafename="" | |
fCheck=true | |
addftp="" | |
mCheck=true | |
addmysql="" | |
sitesEnabled="/etc/apache2/sites-enabled/" | |
sitesAvailable="/etc/apache2/sites-available/" | |
apacheroot="/var/www/" | |
php74poold="/etc/php/7.4/fpm/pool.d/" | |
php7poold="/etc/php/7.1/fpm/pool.d/" | |
php5poold="/etc/php/5.6/fpm/pool.d/" | |
certsAvailable="/etc/letsencrypt/live/" | |
# go to path for sure | |
cd $scriptpath | |
if ! [ "$#" -eq "0" ]; then | |
action=$1 | |
if [ -n "$1" ]; then | |
aCheck=true | |
fi | |
domainname=$2 | |
safedomainname=${domainname//[^[:alnum:]]/} | |
mysqlsafename=$safedomainname | |
if [ -n "$2" ]; then | |
dCheck=true | |
fi | |
variable=$3 | |
safevariable=$(echo "$3" | sed -r 's/[[:blank:]]+/_/g') | |
safevarisdomain=${variable//[^[:alnum:]]/} | |
if [ -n "$3" ]; then | |
vCheck=true | |
fi | |
fi | |
# main menu newfilename=$(echo "co kol ikiiko lkjsd 6548 s5d64s ddd d" | sed -r 's/[[:blank:]]+/_/g') | |
while getopts "a:w:f:m:v:" opt; do | |
case "$opt" in | |
v) variable=$OPTARG | |
safevariable=$(echo "$OPTARG" | sed -r 's/[[:blank:]]+/_/g') | |
safevarisdomain=${variable//[^[:alnum:]]/} | |
vCheck=true | |
;; | |
m) addmysql=$OPTARG | |
mCheck=false | |
;; | |
f) addftp=$OPTARG | |
fCheck=false | |
;; | |
w) domainname=$OPTARG | |
safedomainname=${domainname//[^[:alnum:]]/} | |
mysqlsafename=$safedomainname | |
dCheck=true | |
;; | |
a) action=$OPTARG | |
aCheck=true | |
;; | |
esac | |
done | |
if ! $aCheck; then # -a is mandatory | |
echo "Options:" | |
echo " ./vhost.sh -a create -w domain.tld" | |
echo " ./vhost.sh -a delete -w domain.tld" | |
echo " ./vhost.sh -a list" | |
echo " ./vhost.sh -a create-redirect -w old-domain.tld -v new-domain.tld" | |
echo " ./vhost.sh -a delete-redirect -w old-domain.tld" | |
echo " ./vhost.sh -a enable -w domain.tld" | |
echo " ./vhost.sh -a disable -w domain.tld" | |
echo " ./vhost.sh -a backup -w domain.tld" | |
echo " ./vhost.sh -a restore -v /full/path/to/backup.tar.gz" | |
echo " ./vhost.sh -a reload" | |
echo " ./vhost.sh -a restart" | |
echo " ./vhost.sh -a start" | |
echo " ./vhost.sh -a stop" | |
echo " ./vhost.sh -a chmod-fix -w domain.tld" | |
echo " ./vhost.sh -a certbot -w domain.tld" | |
echo " ./vhost.sh -a certbot-wilde -w domain.tld >> DNS TXT record challenge" | |
echo " ./vhost.sh -a certbot-revoke -w domain.tld >> REVOKE AND DELETE FILES" | |
echo " ./vhost.sh -a certbot-delete -w domain.tld >> DELETE FILES ONLY" | |
echo " ./vhost.sh -a certbot-list" | |
echo "" | |
echo "Extra Opt.:" | |
echo "-f false (do not create ftp account, default value is true)" | |
echo "-m false (do not create mysql account, default value is true)" | |
echo "" | |
echo "Optional:" | |
echo "HTTPS:" | |
echo "1) Generate LE SSL Certs > ./vhost.sh -a certbot -w domain.tld" | |
echo "2) Uncomment all ## in /etc/apache2/sites-available/domain.tld.conf" | |
echo "3) Restart webserver > ./vhost.sh -a restart" | |
echo "3) Update all apache certs > certbot renew --cert-name domain1.com" | |
echo "" | |
echo "TAHAK!!!!" | |
echo "" | |
echo 'certbot certonly --standalone --agree-tos --cert-name jiripocta.cz -n -m [email protected] -d jiripocta.cz -d ftp.jiripocta.cz -d www.jiripocta.cz -d itsluzby.jiripocta.cz -d www.itsluzby.jiripocta.cz -d signature.jiripocta.cz -d www.signature.jiripocta.cz --pre-hook "service apache2 stop" --post-hook "service apache2 start"' | |
echo "" | |
echo "" | |
exit 1 | |
fi | |
if [ $action == "test" ]; then | |
echo -a akce: $action | |
echo -w domena: $domainname | |
echo safeDomena: $safedomainname | |
echo -v var: $variable | |
echo safeVar: $safevariable | |
echo safeVarisDomain: $safevarisdomain | |
exit 0 | |
fi | |
if [ $action == "list" ]; then | |
ls $sitesAvailable | |
exit 0 | |
fi | |
if [ $action == "reload" ]; then | |
# reload php fpm | |
service php7.4-fpm reload | |
service php7.1-fpm reload | |
service php5.6-fpm reload | |
# reloads apache config | |
service apache2 reload | |
exit 0 | |
fi | |
if [ $action == "restart" ]; then | |
# reload php fpm | |
service php7.4-fpm restart | |
service php7.1-fpm restart | |
service php5.6-fpm restart | |
# reloads apache config | |
service apache2 restart | |
exit 0 | |
fi | |
if [ $action == "start" ]; then | |
# reload php fpm | |
service php7.4-fpm start | |
service php7.1-fpm start | |
service php5.6-fpm start | |
# reloads apache config | |
service apache2 start | |
exit 0 | |
fi | |
if [ $action == "stop" ]; then | |
# reload php fpm | |
service php7.4-fpm stop | |
service php7.1-fpm stop | |
service php5.6-fpm stop | |
# reloads apache config | |
service apache2 stop | |
exit 0 | |
fi | |
if [ $action == "certbot-list" ]; then | |
certbot certificates | |
echo "/etc/letsencrypt/live/" | |
ls $certsAvailable | |
echo "-------------------------------------------------------------------------------" | |
exit 0 | |
fi | |
if ! $dCheck; then # -w is mandatory | |
echo "Domain name missing example.tld" | |
exit 1 | |
fi | |
if [ $action == "restore" ]; then | |
if [ ! -f "$variable" ]; then | |
echo "Error: Backup-File $variable does not exist!" | |
exit 1 | |
fi | |
cd /var/www/$domainname/ | |
#tar -xf $variable | |
tar --use-compress-program=pigz -xf $variable | |
echo "1. restore web-data: $domainname" | |
rm -rf web/ | |
#tar -xf web.tar.gz | |
tar --use-compress-program=pigz -xf web.tar.gz | |
echo "|" | |
echo "2. restore db-data: $mysqlsafename" | |
zcat db.sql.gz | mysql -u$mysqlAdminUser -p$mysqlAdminPass $mysqlsafename | |
rm -rf *.gz | |
cd $scriptpath | |
echo "|" | |
echo "3. hotovo!" | |
exit 0 | |
fi | |
if [ $action == "backup" ]; then | |
if [ ! -d "/var/www/$domainname/web" ]; then | |
echo "Error: Folder /var/www/$domainname/web does not exist!" | |
exit 1 | |
fi | |
cd /var/www/$domainname/ | |
echo "1. backup web-data: $domainname" | |
#env GZIP=-9 tar czf web.tar.gz web/ | |
tar cf - web/ | pigz -9 -p 4 > web.tar.gz | |
echo "|" | |
echo "2. backup db-data: $mysqlsafename" | |
mysqldump -u$mysqlAdminUser -p$mysqlAdminPass $mysqlsafename | gzip --best > db.sql.gz | |
echo "|" | |
echo "3. create ONE-Archiv: $today.$mysqlsafename.tar.gz" | |
#env GZIP=-9 tar czf $today.$mysqlsafename.tar.gz web.tar.gz db.sql.gz | |
tar cf - web.tar.gz db.sql.gz | pigz -1 -p 4 > $today.$mysqlsafename.tar.gz | |
chmod 700 *.gz | |
echo "|" | |
echo "4. copy $today.$mysqlsafename.tar.gz to $backupPath/$mysqlsafename/" | |
mkdir -p $backupPath/$mysqlsafename | |
cp $today.$mysqlsafename.tar.gz $backupPath/$mysqlsafename/$today.$mysqlsafename.tar.gz | |
if [ -f $backupPath/$mysqlsafename/$today.$mysqlsafename.tar.gz ]; then | |
rm -rf *.gz | |
fi | |
chmod 700 -R $backupPath | |
cd $scriptpath | |
echo "|" | |
echo "6. use it for recovery:" | |
echo "./vhost.sh -a restore -w $domainname -v $backupPath/$mysqlsafename/$today.$mysqlsafename.tar.gz" | |
echo "$today | vhost restore $domainname $backupPath/$mysqlsafename/$today.$mysqlsafename.tar.gz" >> /var/www/$domainname/log/backup.log | |
echo "" | |
exit 0 | |
fi | |
if [ $action == "certbot" ]; then | |
certbot certonly --standalone --agree-tos --cert-name $domainname -n -m [email protected] -d $domainname -d www.$domainname --pre-hook "service apache2 stop" --post-hook "service apache2 start" | |
exit 0 | |
fi | |
if [ $action == "certbot-wilde" ]; then | |
certbot certonly --manual -m [email protected] -d *.$domainname -d $domainname --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory | |
exit 0 | |
fi | |
if [ $action == "certbot-revoke" ]; then | |
certbot revoke --cert-path /etc/letsencrypt/live/$domainname/cert.pem --key-path /etc/letsencrypt/live/$domainname/privkey.pem | |
exit 0 | |
fi | |
if [ $action == "certbot-delete" ]; then | |
certbot delete --cert-name $domainname | |
exit 0 | |
fi | |
vHostTemplateRedirect="$(echo " | |
<VirtualHost *:80> | |
ServerName $domainname | |
ServerAlias www.$domainname | |
Redirect 301 / http://$variable/?$domainname | |
</VirtualHost> | |
<IfModule mod_ssl.c> | |
<VirtualHost *:443> | |
ServerAdmin webmaster@$domainname | |
ServerName $domainname | |
ServerAlias www.$domainname | |
Redirect 301 / https://$variable/?$domainname | |
#HTTPS | |
Include /etc/letsencrypt/options-ssl-apache.conf | |
SSLCertificateFile /etc/letsencrypt/live/$domainname/fullchain.pem | |
SSLCertificateKeyFile /etc/letsencrypt/live/$domainname/privkey.pem | |
</VirtualHost> | |
</IfModule>")" | |
vHostTemplate="$(echo " | |
<VirtualHost *:80> | |
ServerName $domainname | |
ServerAlias www.$domainname | |
RewriteEngine On | |
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} | |
</VirtualHost> | |
<IfModule mod_ssl.c> | |
<VirtualHost *:443> | |
#PHP 7.1 | |
<IfModule mod_fastcgi.c> | |
AddHandler php7-fcgi-${safedomainname} .php | |
Action php7-fcgi-${safedomainname} /php7-fcgi-${safedomainname} | |
Alias /php7-fcgi-${safedomainname} /usr/lib/cgi-bin/php7-fcgi-${safedomainname} | |
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi-${safedomainname} -socket /run/php/php7.4-fpm.${safedomainname}.sock -idle-timeout 300 -pass-header Authorization | |
<Directory "/usr/lib/cgi-bin"> | |
Require all granted | |
</Directory> | |
<FilesMatch "\.php$"> | |
SetHandler php7-fcgi-${safedomainname} | |
</FilesMatch> | |
</IfModule> | |
ServerAdmin webmaster@$domainname | |
ServerName $domainname | |
ServerAlias www.$domainname | |
DocumentRoot $apacheroot$domainname/web | |
<Directory /> | |
Options None | |
AllowOverride None | |
</Directory> | |
<Directory $apacheroot$domainname/web/> | |
Options FollowSymLinks | |
AllowOverride all | |
Order allow,deny | |
allow from all | |
</Directory> | |
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn, error, crit, alert, emerg | |
LogLevel error | |
#ErrorLog /dev/null | |
ErrorLog $apacheroot$domainname/log/error.log | |
#CustomLog /dev/null common | |
CustomLog $apacheroot$domainname/log/access.log combined | |
#HTTPS | |
Include /etc/letsencrypt/options-ssl-apache.conf | |
SSLCertificateFile /etc/letsencrypt/live/$domainname/fullchain.pem | |
SSLCertificateKeyFile /etc/letsencrypt/live/$domainname/privkey.pem | |
</VirtualHost> | |
</IfModule>")" | |
phpAdminTemplate="$(echo "php_admin_value[session.save_path] = ${apacheroot}${domainname}/tmp | |
php_admin_value[upload_tmp_dir] = ${apacheroot}${domainname}/tmp | |
php_admin_value[open_basedir] = ${apacheroot}${domainname}/ | |
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f no-reply@${domainname} | |
php_admin_value[disable_functions] = apache_get_modules,apache_get_version,apache_getenv,apache_note,apache_setenv,disk_free_space,diskfreespace,dl,exec,highlight_file,ini_alter,ini_restore,openlog,passthru,popen,proc_nice,shell_exec,show_source,symlink,system,posix_getpwuid,shell,proc_open,posix_uname | |
php_admin_value[upload_max_filesize] = 32M | |
php_admin_value[max_file_uploads] = 20 | |
php_admin_value[max_execution_time] = 90 | |
php_admin_value[memory_limit] = 256M | |
php_admin_value[post_max_size] = 128M | |
php_admin_flag[allow_url_fopen] = Off | |
php_admin_flag[display_errors] = Off | |
")" | |
php74PoolTemplate="$(echo "[$domainname] | |
user = $safedomainname | |
group = $safedomainname | |
listen = /run/php/php7.4-fpm.${safedomainname}.sock | |
listen.owner = www-data | |
listen.group = www-data | |
${phpAdminTemplate} | |
pm = dynamic | |
pm.max_children = 5 | |
pm.start_servers = 2 | |
pm.min_spare_servers = 1 | |
pm.max_spare_servers = 3 | |
chdir = / | |
")" | |
php7PoolTemplate="$(echo "[$domainname] | |
user = $safedomainname | |
group = $safedomainname | |
listen = /run/php/php7.1-fpm.${safedomainname}.sock | |
listen.owner = www-data | |
listen.group = www-data | |
${phpAdminTemplate} | |
pm = dynamic | |
pm.max_children = 5 | |
pm.start_servers = 2 | |
pm.min_spare_servers = 1 | |
pm.max_spare_servers = 3 | |
chdir = / | |
")" | |
php5PoolTemplate="$(echo "[$domainname] | |
user = $safedomainname | |
group = $safedomainname | |
listen = /run/php/php5.6-fpm.${safedomainname}.sock | |
listen.owner = www-data | |
listen.group = www-data | |
${phpAdminTemplate} | |
pm = dynamic | |
pm.max_children = 5 | |
pm.start_servers = 2 | |
pm.min_spare_servers = 1 | |
pm.max_spare_servers = 3 | |
chdir = / | |
")" | |
mailTemplateRedirect="$(echo " | |
Domain ${domainname} is permanently redirected to ${variable} | |
")" | |
mailTemplate="$(echo " | |
Domain: ${domainname}<br> | |
<br> | |
FTP<br> | |
Host: ${ftpHost}<br> | |
Username: ${safedomainname}<br> | |
Password: ${ftppass}<br> | |
<br> | |
MySQL<br> | |
Host: ${mysqlHost}<br> | |
Username: ${mysqlsafename}<br> | |
Password: ${mysqlpass}<br> | |
DB name: ${mysqlsafename}<br> | |
phpMyAdmin: http://${mysqlAdmin}<br> | |
<br> | |
")" | |
if [ $action == "create-redirect" ]; then | |
# checks if Vhost already exists | |
if [ -e $sitesAvailable$domainname.conf ]; then | |
echo -e "Redirect or Vhost already exists!" | |
exit 1; | |
fi | |
if ! [ -n "$variable" ]; then # -v is mandatory | |
echo "Secondary Domain name missing example.tld" | |
exit 1 | |
fi | |
# Generate HTTPS CERT | |
certbot certonly --standalone --agree-tos --cert-name $domainname -n -m [email protected] -d $domainname -d www.$domainname --pre-hook "service apache2 stop" --post-hook "service apache2 start" | |
# creates VirtualHost file | |
echo "$vHostTemplateRedirect" > $sitesAvailable$domainname.conf | |
# enables virtual host | |
a2ensite "$domainname.conf" > /dev/null | |
# reloads apache config | |
service apache2 reload > /dev/null | |
echo $mailTemplateRedirect | mail -s "$(echo -e "Redirect for host ${domainname}\nContent-Type: text/html")" $adminEmail -aFrom:"${domainname}<root@${domainname}>" | |
echo "Redirect from "$domainname" to "$variable" is active" | |
exit 0 | |
fi | |
if [ $action == "chmod-fix" ]; then | |
# checks if Vhost already exists | |
if [ ! -d "/var/www/$domainname/web" ]; then | |
echo "Error: Folder /var/www/$domainname/web does not exist!" | |
exit 1 | |
fi | |
# sets permission | |
chown -R $safedomainname:www-data $apacheroot$domainname | |
find $apacheroot$domainname -type d -exec chmod 6770 {} \; | |
find $apacheroot$domainname -type f -exec chmod 0760 {} \; | |
chmod 750 $apacheroot$domainname | |
chmod 777 ""$apacheroot$domainname"/tmp" | |
echo "Permissions for "$domainname" is now correct" | |
exit 0 | |
fi | |
if [ $action == "create" ]; then | |
# checks if domain already exists | |
if [ -e $sitesAvailable$domainname ]; then | |
echo -e "This domain already exists." | |
exit 1; | |
fi | |
# checks if the folder already exists | |
if [ -d $apacheroot$domainname ]; then | |
echo "Directory already exists!" | |
exit 1; | |
fi | |
# Generate HTTPS CERT | |
certbot certonly --standalone --agree-tos --cert-name $domainname -n -m [email protected] -d $domainname -d www.$domainname --pre-hook "service apache2 stop" --post-hook "service apache2 start" | |
sudo useradd $safedomainname --home-dir /var/www/$domainname | |
sudo usermod -a -G $safedomainname www-data | |
# creates the folder | |
mkdir -p ""$apacheroot$domainname"/"{log,tmp} | |
# copy init files | |
cp -r ""$pwd"/_host_template/" ""$pwd"/web/" | |
mv ""$pwd"/web/domains/domain.tld/" ""$pwd"/web/domains/"$domainname"" | |
mv ""$pwd"/web/" $apacheroot$domainname | |
# sets permission | |
chown -R $safedomainname:www-data $apacheroot$domainname | |
find $apacheroot$domainname -type d -exec chmod 6770 {} \; | |
find $apacheroot$domainname -type f -exec chmod 0760 {} \; | |
chmod 750 $apacheroot$domainname | |
chmod 777 ""$apacheroot$domainname"/tmp" | |
# creates VirtualHost file | |
echo "$vHostTemplate" > $sitesAvailable$domainname.conf | |
#php7.4 | |
echo "$php74PoolTemplate" > $php74poold$safedomainname.conf | |
#php7 | |
#echo "$php7PoolTemplate" > $php7poold$safedomainname.conf | |
#php5 | |
#echo "$php5PoolTemplate" > $php5poold$safedomainname.conf | |
# enables virtual host | |
a2ensite "$domainname.conf" > /dev/null | |
# reload php fpm | |
service php7.4-fpm restart | |
service php7.1-fpm restart | |
service php5.6-fpm restart | |
# reloads apache config | |
service apache2 restart > /dev/null | |
if $fCheck; then # -f is true - create ftpaccount | |
(echo $ftppass; echo $ftppass) | pure-pw useradd $safedomainname -u $safedomainname -g www-data -d /var/www/$domainname/web/ > /dev/null | |
pure-pw mkdb | |
service pure-ftpd restart | |
fi | |
if $mCheck; then # -m is true - create mysqlaccount | |
mysql -u${mysqlAdminUser} -p${mysqlAdminPass} <<-MYSQL_SCRIPT | |
CREATE DATABASE ${mysqlsafename} CHARACTER SET utf8 COLLATE utf8_general_ci; | |
CREATE USER ${mysqlsafename}@localhost IDENTIFIED BY '${mysqlpass}'; | |
GRANT ALL PRIVILEGES ON ${mysqlsafename}.* TO '${mysqlsafename}'@'localhost'; | |
GRANT USAGE ON *.* TO '${mysqlsafename}'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; | |
FLUSH PRIVILEGES; | |
MYSQL_SCRIPT | |
fi | |
#create sym-link for LOG files | |
ln -s /var/www/$domainname/log/access.log /var/www/$domainname/web/_access.log | |
ln -s /var/www/$domainname/log/error.log /var/www/$domainname/web/_error.log | |
echo $mailTemplate | mail -s "$(echo -e "Web hosting ${domainname}\nContent-Type: text/html")" $adminEmail -aFrom:"${domainname}<root@${domainname}>" | |
echo "Virtual host "$domainname" activated" | |
exit 0 | |
fi | |
if [ $action == "delete-redirect" ]; then | |
# checks if Redirect does not exists | |
if ! [ -e $sitesAvailable$domainname.conf ]; then | |
echo -e "This Redirect does not exists." | |
exit 1; | |
fi | |
# disable virtual host | |
if a2dissite -q "$domainname.conf" > /dev/null; then | |
echo "Domain "$domainname" disabled" | |
else | |
echo "An error occurred while disabling "$domainname"" | |
exit 1 | |
fi | |
# deletes virtual host file | |
if rm $sitesAvailable$domainname.conf > /dev/null; then | |
echo "VirtualHost "$domainname" deleted." | |
else | |
echo "An error occurred while deleting directory "$domainname"" | |
exit 1 | |
fi | |
# reloads apache config | |
if service apache2 reload > /dev/null; then | |
echo "Apache config reloaded" | |
else | |
echo "An error occurred while reloading apache" | |
exit 1 | |
fi | |
exit 0 | |
fi | |
if [ "$action" == "delete" ]; then | |
# checks if the domain does not exists | |
if ! [ -e $sitesAvailable$domainname.conf ]; then | |
echo -e "This domain does not exists." | |
exit 1; | |
fi | |
# checks if the folder does not exists | |
if ! [ -d $apacheroot$domainname ]; then | |
echo "Directory does not exists!" | |
exit 1; | |
fi | |
# delete ftp account | |
pure-pw userdel $safedomainname > /dev/null | |
pure-pw mkdb | |
# delete mysql user and db | |
mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -e "DROP DATABASE ${mysqlsafename};DROP USER '${mysqlsafename}'@'localhost';" 2>/dev/null | grep -v "mysql: [Warning] Using a password on the command line interface can be insecure." | |
#mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -e "DROP DATABASE ${mysqlsafename};" 2>/dev/null | grep -v "mysql: [Warning] Using a password on the command line interface can be insecure." | |
# disable virtual host | |
if a2dissite -q "$domainname.conf" > /dev/null; then | |
echo "Domain "$domainname" disabled" | |
else | |
echo "An error occurred while disabling "$domainname"" | |
exit 1 | |
fi | |
# deletes virtual host file | |
if rm $sitesAvailable$domainname.conf > /dev/null; then | |
echo "VirtualHost "$domainname" deleted." | |
else | |
echo "An error occurred while deleting directory "$domainname"" | |
exit 1 | |
fi | |
# deletes the directory | |
if rm -rf $apacheroot$domainname > /dev/null; then | |
echo "Directory "$domainname" deleted." | |
else | |
echo "An error occurred while deleting directory "$domainname"" | |
fi | |
#php7.4 | |
rm $php74poold$safedomainname.conf | |
#php7 | |
rm $php7poold$safedomainname.conf | |
#php5 | |
rm $php5poold$safedomainname.conf | |
# reload php fpm | |
service php7.4-fpm reload | |
service php7.1-fpm reload | |
service php5.6-fpm reload | |
sudo pkill -u $safedomainname | |
sudo gpasswd -d $safedomainname www-data | |
sudo userdel $safedomainname | |
sudo groupdel $safedomainname | |
# reloads apache config | |
if service apache2 reload > /dev/null; then | |
echo "Apache config reloaded" | |
else | |
echo "An error occurred while reloading apache" | |
exit 1 | |
fi | |
exit 0 | |
fi | |
if [ $action == "enable" ]; then | |
# checks if the domain does not exists | |
if ! [ -e $sitesAvailable$domainname.conf ]; then | |
echo -e "This domain does not exists." | |
exit 1; | |
fi | |
# enables virtual host | |
a2ensite "$domainname.conf" > /dev/null | |
# reload php fpm | |
service php7.4-fpm reload | |
service php7.1-fpm reload | |
service php5.6-fpm reload | |
# reloads apache config | |
service apache2 reload > /dev/null | |
echo "Virtual host "$domainname" activated" | |
exit 0 | |
fi | |
if [ "$action" == "disable" ]; then | |
# checks if the domain does not exists | |
if ! [ -e $sitesAvailable$domainname.conf ]; then | |
echo -e "This domain does not exists." | |
exit 1; | |
fi | |
# disable virtual host | |
if a2dissite -q "$domainname.conf" > /dev/null; then | |
echo "Domain "$domainname" disabled" | |
else | |
echo "An error occurred while disabling "$domainname"" | |
exit 1 | |
fi | |
# reload php fpm | |
service php7.4-fpm reload | |
service php7.1-fpm reload | |
service php5.6-fpm reload | |
sudo pkill -u $safedomainname | |
# reloads apache config | |
if service apache2 reload > /dev/null; then | |
echo "Apache config reloaded" | |
else | |
echo "An error occurred while reloading apache" | |
exit 1 | |
fi | |
exit 0 | |
fi | |
echo "Unknow action omg wtf lul!" | |
exit 1 |
backup's simply
curl https://rclone.org/install.sh | sudo bash
/etc/cron.daily/web-backup-cron-daily
#!/bin/sh
rclone delete --min-age 2d local:/var/webbackup/
rclone rmdirs --leave-root local:/var/webbackup/
cd /var/www/
## ("element1" "element2" "element3")
for vhostName in $(ls -d * | grep -E -v "html|anyelse")
do
vhost backup $vhostName > /dev/null 2>&1
done
chmod 770 -R /var/webbackup/*
rclone delete --min-age 2d homeftp:/Zalohy/srv4/webbackup/
rclone copy --ignore-existing /var/webbackup/ homeftp:/Zalohy/srv4/webbackup/
rclone rmdirs --leave-root homeftp:/Zalohy/srv4/webbackup/
rclone delete --min-age 7d safeonedrivejp:/srv4/webbackup/
rclone copy --ignore-existing /var/webbackup/ safeonedrivejp:/srv4/webbackup/
rclone rmdirs --leave-root safeonedrivejp:/srv4/webbackup/
rclone delete --min-age 2d --mega-hard-delete safemegajp:/srv4/webbackup/
rclone copy --ignore-existing /var/webbackup/ safemegajp:/srv4/webbackup/
rclone rmdirs --leave-root safemegajp:/srv4/webbackup/
/etc/cron.daily/automysqlbackup-daily
#!/bin/sh
rclone delete --min-age 2d local:/var/mysqlbackup/
rclone rmdirs --leave-root local:/var/mysqlbackup/
automysqlbackup > /dev/null 2>&1
rclone delete --min-age 5d homeftp:/Zalohy/srv4/mysqlbackup/
rclone copy --ignore-existing /var/mysqlbackup/ homeftp:/Zalohy/srv4/mysqlbackup/
rclone rmdirs --leave-root homeftp:/Zalohy/srv4/mysqlbackup/
rclone delete --min-age 7d safeonedrivejp:/srv4/mysqlbackup/
rclone copy --ignore-existing /var/mysqlbackup/ safeonedrivejp:/srv4/mysqlbackup/
rclone rmdirs --leave-root safeonedrivejp:/srv4/mysqlbackup/
rclone delete --min-age 7d --mega-hard-delete safemegajp:/srv4/mysqlbackup/
rclone copy --ignore-existing /var/mysqlbackup/ safemegajp:/srv4/mysqlbackup/
rclone rmdirs --leave-root safemegajp:/srv4/mysqlbackup/
cron for windows
@ECHO OFF
cd c:\source
REM This is the location
backup's simply
curl https://rclone.org/install.sh | sudo bash
CRON EveryDAY
#1
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Bypass -File C:\BACKUPS\Hyper-V-Backup.ps1 -BackupTo D:\BACKUPS\VMs -List C:\BACKUPS\Hyper-V-Backup-VMs.txt -Keep 1 -L D:\BACKUPS\VMs -Compress
#2
C:\BACKUPS\rclone.exe
delete --min-age 3d safeonedrivejp:/VMs/
#3
C:\BACKUPS\rclone.exe
copy --ignore-existing "D:\BACKUPS\VMs" safeonedrivejp:/VMs/