For security reason I suggest you to logon on CMSMS only via SSL. This prevents password sniffing.
Another safety measure is to protect bash script from unwanted reading. So set appropriate file permissions for the scripts.
Copy these scripts in a file (ie cmsms-rc.sh) and make it executable. (chmod +x cmsms-rc.sh)
The common part is login script that must be present in all control scripts.
Code: Select all
#!/bin/bash
username="yourusername"
password="yourpasswordhere"
sitename="http://www.yourdomainhere.com"
_cookies="./cookie"
keyname="sp_"
admin_dir="admin"
# ************** Do the login ******************************
_postdata="username=${username}&password=${password}&loginsubmit=Submit"
wget -o log -O outfile.1 --save-cookies ${_cookies} --keep-session-cookies --post-data=$_postdata ${sitename}/$admin_dir/login.php
_x=`grep -c 'password incorrect' outfile.1`
if [ $_x -gt 0 ]; then
echo "FATAL: Authentication error";
exit 1
fi
# Get the session key
_line=`cat $_cookies | grep ${keyname}`
if [ ${line:-notset} != notset ]; then
_sessionkey=`cat $_cookies | grep ${keyname} | tr '\t' , | cut -d, -f7`
else
_sessionkey=`cat log | grep ^Location | cut -d= -f2 | cut -d" " -f1`
fi
Clear cache
Code: Select all
# Clear cache
_postdata="clearcache=clear&submit=Submit"
wget -o log -O outfile.1 --load-cookies ${_cookies} --post-data=$_postdata ${sitename}/$admin_dir/siteprefs.php?${keyname}=${_sessionkey}
Code: Select all
# Set site offline
_postdata="active_tab=sitedown&editsiteprefs=true&enablesitedownmessage=0&enablesitedownmessage=1&sitedownmessage=%3Cp%3ESite+is+currently+down+for+maintenance.%3C%2Fp%3E&sitedownexcludes=&submit=Submit"
wget -o log -O outfile.1 --load-cookies ${_cookies} --post-data=$_postdata ${sitename}/$admin_dir/siteprefs.php?${keyname}=${_sessionkey}
Code: Select all
# Set site online
_postdata="active_tab=sitedown&editsiteprefs=true&enablesitedownmessage=0&sitedownmessage=%3Cp%3ESite+is+currently+down+for+maintenance.%3C%2Fp%3E&sitedownexcludes=&submit=Submit"
wget -o log -O outfile.1 --load-cookies ${_cookies} --post-data=$_postdata ${sitename}/$admin_dir/siteprefs.php?${keyname}=${_sessionkey}
Mysqldump
Code: Select all
# ************** Mysqldump ***************************
# Create Mysqldump download to your local PC
admin_file="moduleinterface.php"
date=`date '+%Y-%m-%d_%H-%M-%S'`
out_file="backup-$date.sql"
# Launch Mysqldump
querystring="mact=MysqlDump%2Cm1_%2Cdumpdatabase%2C0&m1_filename=$out_file&m1_backup=Backup+Database&m1_path=%2Fusr%2Fbin&m1_options=--opt+--verbose+--compatible%3Dmysql40+--default-character-set%3Dlatin1"
wget -a log -O outfile1.htm --load-cookies ${_cookies} ${sitename}/$admin_dir/$admin_file?${keyname}=${_sessionkey}\&$querystring
# Retrieve file
wget -a log -O $out_file --load-cookies ${_cookies} ${sitename}/$admin_dir/backups/$out_file &
wait $!
# Delete backup from server
querystring="mact=MysqlDump%2Cm1_%2Cdeletedataset%2C0&m1_filename=%2Fvar%2Fwww%2Fadmin%2Fbackups%2F$out_file&m1_delete=Delete"
wget -a log -O outfile1.htm --load-cookies ${_cookies} ${sitename}/$admin_dir/$admin_file?${keyname}=${_sessionkey}\&$querystring
Code: Select all
# ************** Filebackup ***************************
# Do a backup with Filebackup
admin_file="moduleinterface.php"
date=`date '+%Y-%m-%d_%H-%M-%S'`
out_file="filebackup-$date.tgz"
# Launch file backup
#querystring="mact=FileBackup%2Cm1_%2Cdumpdatabase%2C0&m1_filename=$out_file&m1_backup=Backup+Files&m1_path=%2Fbin&m1_bck_options=-cpzvf"
#wget -a log -O outfile1.htm --load-cookies ${_cookies} ${sitename}/$admin_dir/$admin_file?${keyname}=${_sessionkey}\&$querystring
# Retrieve file
#wget -a log -O $out_file --load-cookies ${_cookies} ${sitename}/$admin_dir/backups/$out_file &
#wait $!
# Delete backup from server
#querystring="mact=FileBackup%2Cm1_%2Cdeletedataset%2C0&m1_filename=%2Fvar%2Fwww%2Fadmin%2Fbackups%2F$out_file&m1_delete=Delete"
wget -a log -O outfile1.htm --load-cookies ${_cookies} ${sitename}/$admin_dir/$admin_file?${keyname}=${_sessionkey}\&$querystring
Almost any actions triggered in CMSMS can be replicated via scripting. If you install "Live HTTP Headers" plugin for Firefox you can read all url/get/post value when you trigger an action in you browser.
These scripts are only raw examples that can be expandend according your own needs. Moreover I haven't put any control to response value, so I don't check if there are errors or other response code from CMSMS. If you want you can improve scripts and post on the forum.
Hope this helps
regards
blast