Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function f_isempty {
- if [ "x$1" = "x" ]; then
- echo "This can't be left blank, please retry filling it"
- sleep 2
- return 1
- fi
- }
- function f_ping {
- fonction="f_ping"
- f_debug $fonction
- if [ "$pingtest" = "1" ]; then
- if ping -c 1 -w 1 -q $1 </dev/null &>/dev/null; then
- echo "$1 Answers to pings: GOOD."
- return 1
- else
- date=`date +%Y%m%d`
- echo "$1 doesn't answer to ping on $date !!! " >> $pwd_init/log/error.log
- return 2
- fi
- else
- echo "ping test disabled."
- return 0
- fi
- }
- function f_genQL {
- # This function generates the filetree to be uploaded on the server, the key auth
- # mechanism and the ".htaccess" and ".htpasswd" files.
- # !!! You should check those files before uploading them on the server
- fonction="f_genQL"
- f_debug $fonction
- ########################################
- # <DATA RECOLLECTION>
- echo "What is the site's dns (compulsary)"
- read dns
- f_isempty $dns
- if [ "x$?" = "x1" ]; then
- return 0
- fi
- if [ "`cat $datfile | grep $dns`" != '' ]; then
- echo "$dns is allready in $datfile, please check and try again!"
- return 0
- fi
- f_ping $dns
- if [ "x$?" = "x2" ]; then
- echo "$dns does not reply to ping, are you sure you want to add it? (y or n)"
- read yn
- if [ "x$yn" != "xy" ]; then
- return 0
- fi
- fi
- mkdir -p var/$dns/$genQL__dir var/keys
- echo "Which protocol does the site use (ftp or defaults as ssh)"
- read protocol
- if [ "x$protocol" != "xftp" ]; then
- protocol="ssh"
- fi
- echo "What is your login for that protocol (compulsary)"
- read l0gin
- f_isempty $l0gin
- if [ "x$protocol" = "xftp" ]; then
- echo "What is your ftp password"
- read ftpassword
- echo "On which port does the ftp server listen (defaults to 21)?"
- read $port
- if [ "x$port" = "x" ]; then
- port="21"
- fi
- elif [ "x$protocol" = "xssh" ]; then
- echo "On which port does the ssh server listen (defaults to 22)?"
- read port
- if [ "x$port" = "" ]; then
- port="x22"
- fi
- echo "Do you already have a shared key on that server? (y or n)"
- read sharedkey
- if [ "x$sharedkey" = "xy" ]; then
- ls var/keys/|cat -n
- echo "Which is the key that should be used?"
- read key
- sshkeyname=`ls var/key | sed -n "$key"p`
- elif [ "x$sharedkey" = "xn" ]; then
- echo "What should be the key's name (!avoid a name that's allready in use!)"
- read sshkeyname
- for i in `ls var/keys/`
- do
- if [ "x$i" = "x$sshkeyname" ]; then
- echo "$i is allready in use as ssh keyname"
- return 1
- fi
- done
- echo "Patience ... $rsabits bits RSA keyset is being generated"
- ssh-keygen -b $rsabits -t rsa -f key.$sshkeyname
- mv key.$sshkeyname var/keys/
- mv key.$sshkeyname.pub var/$dns/
- else
- echo "y or n ... Please try again"
- return 1
- fi
- else
- echo "ftp or ssh ... Please try again"
- return 1
- fi
- echo "What is your alternative dns (defaults as site's dns)"
- read altdns
- if [ "x$altdns" = "x" ]; then
- altdns=$dns && echo "Alternative dns set to $altdns"
- fi
- echo "What's the site's path on the server?"
- echo "!!Start at / for ssh and at ~ for ftp!!"
- read rpath
- f_isempty $rpath
- echo "At what time should the site be backed up? (defaults random)"
- read timesite
- if [ "x$timesite" = "x" ]; then
- f_randomhour
- timesite="$R" && echo "Time Site set to $timesite"
- fi
- echo "On what day(s) should the site be backed up? (defaults random)"
- read daysite
- if [ "$xdaysite" = "x" ]; then
- f_randomday
- daysite="$d" && echo "Day Site set to $daysite"
- fi
- echo "At what time should the db be backed up? (defaults random)"
- read timedb
- if [ "x$timedb" = "x" ]; then
- f_randomhour
- timedb="$R" && echo "Time db set to $timedb"
- fi
- echo "On what day(s) should the db be backed up? (defaults every day)"
- read daydb
- if [ "x$daydb" = "x" ]; then
- daydb="Mon-Tue-Wed-Thu-Fri-Sat-Sun" && echo "Day db set to $daydb"
- fi
- echo "Site's coefficient (default 1 - will be used to define disk usage)"
- read coef
- if [ "x$coef" = "x" ]; then
- coef="1"
- fi
- echo "Site Allowance in Gigabite (default 1)"
- read GB
- if [ "x$GB" = "x" ]; then
- GB="1"
- fi
- echo "Site's priority (from 0 to 10 ; smallest are done sooner - Default 5)"
- read priority
- if [ "x$priority" = "x" ]; then
- priority="5"
- fi
- echo "Is the site active (put 0 for no ; defaults as 1)"
- read active
- if [ "x$active" = "x" ]; then
- active="1"
- fi
- echo "Please enter the database server's name (defaults to localhost)"
- read dbserv
- if [ "x$dbserv" = "x" ]; then
- dbserv='localhost'
- fi
- echo "Please enter the name of the database:"
- read db
- f_isempty $db
- echo "Please enter the name of that database's user:"
- read user
- f_isempty $user
- echo "Please enter the corresponding password:"
- read pass
- f_isempty $pass
- # </DATA RECOLLECTION>
- ########################################
- # <FILE GENERATION>
- echo "Data Recollection complete, adding config to $datfile and preparing files to upload..."
- touch $datfile
- mkdir -p var/$dns/$genQL__dir/mysql
- #index.php
- echo '<?' > var/$dns/$genQL__dir/index.php
- echo \$rep_backup\ \=\ \'.\/mysql\/\'\; >> var/$dns/$genQL__dir/index.php
- echo '$heure_j = date("H-i");' >> var/$dns/$genQL__dir/index.php
- echo '$date_j = date("Ymd");' >> var/$dns/$genQL__dir/index.php
- echo \$heure_j\ \=\ str_replace\(\'-\'\,\ \'H\'\,\ \$heure_j\)\; >> var/$dns/$genQL__dir/index.php
- echo '$filename = '$db'."-".$date_j."-".$heure_j.".sql";' >> var/$dns/$genQL__dir/index.php
- echo 'echo "Your DB is being backed up<p>";' >> var/$dns/$genQL__dir/index.php
- echo 'system("'"mysqldump --host=$dbserv --user=$user --password=$pass -C -Q -e --default-character-set=utf8 $db | gzip -c > mysql/\$filename.gz"'");' >> var/$dns/$genQL__dir/index.php
- echo 'echo "Done, you can now recover the backup";' >> var/$dns/$genQL__dir/index.php
- echo "?>" >> var/$dns/$genQL__dir/index.php
- #majeur.php
- echo \<\?php > var/$dns/$genQL__dir/majeur.php
- echo echo \"Your database is being restored ...... >> var/$dns/$genQL__dir/majeur.php
- echo \<br\>\"\; >> var/$dns/$genQL__dir/majeur.php
- echo system\(\"cat mysql\/notsuperdb.sql \| mysql --host\=$dbserv --user\=$user --password\=$pass --default-character-set\=utf8 $db\"\)\; >> var/$dns/$genQL__dir/majeur.php
- echo echo \"Done, your database has been restored on this hosting.\"\; >> var/$dns/$genQL__dir/majeur.php
- echo \?\> >> var/$dns/$genQL__dir/majeur.php
- #Les .htaccess et .htpasswd
- echo "AuthUserFile "$rpath"/$genQL__dir/.htpasswd" >> var/$dns/$genQL__dir/.htaccess
- echo "AuthGroupFile /dev/null" >> var/$dns/$genQL__dir/.htaccess
- echo 'AuthName "Restraint Access"' >> var/$dns/$genQL__dir/.htaccess
- echo "AuthType Basic" >> var/$dns/$genQL__dir/.htaccess
- echo "<Limit GET POST>" >> var/$dns/$genQL__dir/.htaccess
- echo "require valid-user" >> var/$dns/$genQL__dir/.htaccess
- echo "</Limit>" >> var/$dns/$genQL__dir/.htaccess
- loginhtacces=`head -c $htstrength < /dev/urandom | uuencode -m - | tail -n 2 | head -n 1`
- passhtaccess=`head -c $htstrength < /dev/urandom | uuencode -m - | tail -n 2 | head -n 1`
- htpasswd -bc htpassword $loginhtacces $passhtaccess
- #echo "$htaccess__user:$htaccess__pwd_crptd">>$genQL__dir/.htpasswd
- touch var/$dns/$genQL__dir/index.html
- echo "AuthUserFile "$rpath"/$genQL__dir/mysql/.htpasswd" >> var/$dns/$genQL__dir/mysql/.htaccess
- echo "AuthGroupFile /dev/null" >> var/$dns/$genQL__dir/mysql/.htaccess
- echo 'AuthName "Restraint Access"' >> var/$dns/$genQL__dir/mysql/.htaccess
- echo "AuthType Basic" >> var/$dns/$genQL__dir/mysql/.htaccess
- echo "<Limit GET POST>" >> var/$dns/$genQL__dir/mysql/.htaccess
- echo "require valid-user" >> var/$dns/$genQL__dir/mysql/.htaccess
- echo "</Limit>" >> var/$dns/$genQL__dir/mysql/.htaccess
- touch var/$dns/$genQL__dir/mysql/.htpasswd
- touch var/$dns/$genQL__dir/mysql/index.html
- echo "$dns;$active;$protocol;$l0gin;$ftpassword;$sshkeyname;$loginhtacces;$passhtaccess;$altdns;$port;$rpath;$timesite;$daysite;$timedb;$daydb;$coef;$GB;$priority" >> $datfile
- # </FILE GENERATION>
- ########################################
- # Upload Files
- #scp -p $port var/$dns/$dns.pub $l0gin@:~/.ssh/authorized_keys
- #####################################
- #Should the script upload the files?
- #if [ x$protocol = "xftp" ]; then
- # echo "patience, uploading!"
- # lftp -c "open ftp.$b && user $c $d && cd www && mirror --reverse --delete var/$dns/$genQL__dir var/$dns/$genQL__dir" 2>>$pwd_init/log/error.log && echo "genQL is in place on $b"
- # elif [ "$xservice" = "xssh" ]; then
- # echo "patience, uploading!"
- # rsync -qaEzc -e ssh var/$dns/$genQL__dir root@$sme__domain:$sme__basedir/$site/html/ 2>>$pwd_init/log/error.log && echo "$genQL__dir is in place on $site"
- # ssh $sme__domain -l root "chown -R www:clients /home/e-smith/files/ibays/$site/html/" && echo "chown done"
- # OR rsync -qaEzc -e ssh var/$dns/$genQL__dir root@$site:/home/sites/$site/web/ 2>>$pwd_init/log/error.log && echo "$genQL__dir is in place on $site"
- # andthenchownthefiles
- # rep=`ssh $site -l root ls -l /home/sites/|grep $site | cut -f 4 -d"/"`
- # ssh $site -l root "chown -R apache:$rep /home/sites/$site/web/" && echo "chown done"
- # Eapeasy ! but so far, just:
- tar -czf var/$dns.tar.gz var/$dns && rm -Rf var/$dns && echo "########################################" && echo "Everything has been generated as should be, you can now proceed to upload"
- echo "/var/$dns.tar.gz in order to place the $genQL__dir"
- if [ "$xprotocol" = "xssh" ]; then
- if [ "x$sharedkey" = "xn" ]; then
- echo "key.$sshkeyname in the ~/.ssh/authorized_keys"
- fi
- fi
- echo "########################################"
- #Don't forget to put the right right on database with "mysql -u root -p"
- # REVOKE ALL PRIVILEGES ON `dbname` . * FROM 'dbuser'@'localhost';
- # GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON `dbname` . * TO 'dbuser'@'localhost';
- }
- ##################################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement