Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backup__dir="backup" && genQL__dir="genQL"
- rsabits=8192 #set the size of RSA key you want
- datfile=datfile.dat #which datfile should be used
- conffile=genQL.conf #which conf file should be used
- function f_isempty {
- if ["$0" = "" ]
- echo "$0 can not be left blank, please retry and fill it"
- return 1
- 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"
- read dns
- f_isempty $dns
- if [ "$?" = "1" ]; 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 [ "$?" = "2" ]; then
- echo "$dns does not reply to ping, are you sure you want to add it? (y or n)"
- read yn
- if [ "yn" != "y" ]
- 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 [ "$protocol" != "ftp" ]; then
- protocol="ssh"
- fi
- echo "What is your login for that protocol"
- read l0gin
- f_isempty $l0gin
- if [ "$?" = "1" ]; then
- return 0
- fi
- if [ "$protocol" = "ftp" ]; then
- echo "What is your ftp password"
- read ftpassword
- echo "On which port does the ftp server listen (defaults to 21)?"
- read $port
- if [ "$port" = "" ]; then
- port="21"
- fi
- elif [ "$protocol" = "ssh" ]
- echo "On which port does the ssh server listen (defaults to 22)?"
- read port
- if [ "$port" = "" ]; then
- port="22"
- fi
- echo "Do you already have a shared key on that server? (y or n)"
- read sharedkey
- if [ "$sharedkey" = "y" ]
- 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 [ "$sharedkey" = "n" ]
- 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 [ "$i" = "$sshkeyname" ]; then
- echo "$i is allready in use as ssh keyname"
- return 1
- fi
- done
- echo "Patience ... $bits bits RSA keyset is being generated"
- ssh-keygen -b $bits -t rsa -f key.$sshkeyname
- mv key.$sshkeyname var/keys/
- mv key.$sshkeyname.pub var/$dns/
- else
- echo "y or n ... Please try again"
- f_exit
- fi
- else
- echo "ftp or ssh ... Please try again"
- f_exit
- fi
- echo "What is your alternative dns (defaults as site's dns)"
- read altdns
- if [ altdns = "" ]; then
- altdns = $dns
- fi
- echo "What's the site's path on the server? (start at / )"
- read rpath
- f_isempty $rpath
- if [ "$?" = "1" ]; then
- return 0
- fi
- echo "At what time should the site be backed up? (defaults random)"
- read timesite
- if [ "$timesite" = "" ]; then
- f_randomhour
- timesite="$R"
- fi
- echo "On what day(s) should the site be backed up? (defaults random)"
- read daysite
- if [ "$daysite" = "" ]; then
- f_randomday
- daysite="$d"
- fi
- echo "At what time should the db be backed up? (defaults random)"
- read timedb
- if [ "$timedb" = "" ]; then
- f_randomhour
- timedb="$R"
- fi
- echo "On what day(s) should the db be backed up? (defaults every day)"
- read daydb
- if [ "$daydb" = "" ]; then
- daydb="Mon-Tue-Wed-Thu-Fri-Sat-Sun"
- fi
- echo "Site's coefficient (default 1 - will be used to define disk usage)"
- read coef
- if [ "$coef" = "" ]; then
- coef="1"
- fi
- echo "Site Allowance in Gigabite (default 1)"
- read GB
- if [ "$GB" = "" ]; then
- GB="1"
- fi
- echo "Site's priority (from 0 to 10 ; smallest are done sooner - Default 5)"
- read priority
- if [ "$priority" = "" ]; then
- priority="5"
- fi
- echo "Is the site active (put 0 for no ; defaults as 1)"
- read active
- if [ "$active" = "" ]; then
- active="1"
- fi
- echo "Please enter the database server's name (defaults to localhost)"
- read dbserv
- if [ "$dbserv" = "" ]; then
- dbserv='localhost'
- fi
- echo "Please enter the name of the database:"
- read db
- f_isempty $db
- if [ "$?" = "1" ]; then
- return 0
- fi
- echo "Please enter the name of that database's user:"
- read user
- f_isempty $user
- if [ "$?" = "1" ]; then
- return 0
- fi
- echo "Please enter the corresponding password:"
- read pass
- f_isempty $pass
- if [ "$?" = "1" ]; then
- return 0
- fi
- loginhtacces = `head -c 18 < /dev/urandom | uuencode -m - | tail -n 2 | head -n 1`
- passhtaccess = `head -c 18 < /dev/urandom | uuencode -m - | tail -n 2 | head -n 1`
- # </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
- 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 >> sites.dat
- # </FILE GENERATION>
- ########################################
- # Upload Files
- #scp -p $port var/$dns/$dns.pub $l0gin@:~/.ssh/authorized_keys
- #####################################
- #Should the script upload the files?
- #if [ $protocol = "ftp" ]; 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/log/error.log && echo "genQL is in place on $b"
- # elif [ $service = "ssh" ]; then
- # echo "patience, uploading!"
- # rsync -qaEzc -e ssh var/$dns/$genQL__dir root@$sme__domain:$sme__basedir/$site/html/ 2>>$pwd/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/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 -cvzf var/$dns.tar.gz var/$dns
- rm -Rf var/$dns
- 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 [ "$protocol" = "ssh" ]; then
- if [ "$sharedkey" = "n" ]; then
- echo "$sshkeyname in the ~/.ssh/authorized_keys"
- fi
- fi
- #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