create_awstats.sh
#!/bin/sh
set -e
if [ "$1" = '' ]; then
echo "Usage $0 /path/to/some.domain.name.tld"
exit 1
else
site="$1"
fi
cd $site
mkdir awstats
cp /root/awstats.index awstats/index.php
test -L www/stats && rm www/stats
ln -s $site/awstats www/stats
addsite.sh
#!/bin/sh
# creates a new www-site for virtual hosting and sets all needed
wwwroot="/var/www"
if [ "$1" = '' ]; then
echo "Creates a new www-site for virtual hosting and sets all needed."
echo "Usage $0 some.domain.name.tld [webmaster@some.domain.name.tld]"
exit 1
else
site="$1"
fi
if [ "$2" = '' ]; then
webmaster='webmaster@example.com'
else
webmaster="$2"
fi
if [ -d "${wwwroot}/${site}" ]; then
echo "Site ${site} already exists. Ignoring."
echo ""
exit 2
fi
echo "Creating site ${site} (webmaster: ${webmaster})"
echo "Creating directory structure..."
mkdir ${wwwroot}/${site}
mkdir ${wwwroot}/${site}/www
mkdir ${wwwroot}/${site}/logs
mkdir ${wwwroot}/${site}/tmp
mkdir ${wwwroot}/${site}/stats
mkdir ${wwwroot}/${site}/stats2
mkdir ${wwwroot}/${site}/awstats
mkdir ${wwwroot}/${site}/errors
echo "Creating robots.txt..."
cat > ${wwwroot}/${site}/www/robots.txt << EOF
User-agent: ia_archiver
Disallow: /
EOF
echo "Creating symlink for /stats..."
ln -s -f ${wwwroot}/${site}/awstats ${wwwroot}/${site}/www/stats
ln -s -f ${wwwroot}/${site}/stats2 ${wwwroot}/${site}/www/stats2
echo "Creating symlink for /errors..."
ln -s -f ${wwwroot}/${site}/errors ${wwwroot}/${site}/www/errors
echo "Writing config files:"
echo " - Apache"
cat > /etc/apache2/sites-available/${site} << EOF
# zalozeno: `date +%c`
ServerName ${site}
ServerAlias *.${site}
ServerAdmin ${webmaster}
DocumentRoot ${wwwroot}/${site}/www
php_admin_value doc_root '${wwwroot}/${site}'
php_admin_value open_basedir '${wwwroot}/${site}:/tmp'
php_admin_value sendmail_path '/usr/sbin/phpmail postmaster@${site}'
RewriteEngine On
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www\.(.+)/(.*)$ [NC]
RewriteRule ^.*$ http://%1/%2 [R=301,L]
RewriteCond %{REQUEST_URI} ^/webmail/? [NC]
RewriteRule ^.*$ https://www.example.com/webmail/ [R=302,L]
EOF
cat > ${wwwroot}/${site}/stats/.htaccess << EOF
AuthType Basic
AuthUserFile /etc/apache2/.htpasswd
AuthGroupFile /dev/null
AuthName "statistiky pristupu"
require user dast
require user dfox
require user ${site}
EOF
cp ${wwwroot}/${site}/stats/.htaccess ${wwwroot}/${site}/stats2/.htaccess
cp ${wwwroot}/${site}/stats/.htaccess ${wwwroot}/${site}/awstats/.htaccess
cp /root/awstats.index ${wwwroot}/${site}/awstats/index.php
echo "Setting password for /stats..."
passwd=$(pwgen -n -s 8 1)
/usr/bin/htpasswd -sb /etc/apache2/.htpasswd ${site} ${passwd}
echo "New password for stats set: USER=${site}, PASSWORD=${passwd}"
echo "${site} ${passwd}" >> "/etc/awstats/awstats.htpasswd.open.txt"
echo "Changing file attributes..."
chown -R www-data:www-data ${wwwroot}/${site}
find ${wwwroot}/${site} -type d -exec chmod 775 {} \;
find ${wwwroot}/${site} -type f -exec chmod 664 {} \;
echo "Enabling site ${site}..."
/usr/sbin/a2ensite ${site}
echo "Reloading Apache..."
/etc/init.d/apache2 reload
echo "Sending mail to webmaster..."
mail -s "Virtualni server ${site} vytvoren" ${webmaster} << EOF
Byl aktivovan novy virtualni hosting.
Informace o serveru jsou prilozeny na konci e-mailu.
Webhosting (generovano automaticky)
--- 8< --------------------------------------------
virtualni server: ${site}
e-mail webmastera: ${webmaster}
jmeno ke statistikam: ${site}
heslo ke statistikam: ${passwd}
EOF
echo "Site ${site} successfully created. DONE. :)"
echo ""
exit 0
----
awstats.index
= $_SERVER['HTTP_HOST'] ?>
"Leden" , "02" => "..nor" , "03" => "B..ezen" , "04" => "Duben" ,
"05" => "Kv..ten" ,
"06" => "..erven" , "07" => "..ervenec" , "08" => "Srpen" , "09" => "Z....i" ,
"10" => "....jen" ,
"11" => "Listopad" , "12" => "Prosinec"
);
echo '' . $_SERVER['HTTP_HOST'] . '
';
$Seznam = array( );
if ( $handle = opendir( '.' ) )
{
while ( $file = readdir( $handle ) )
{
if ( preg_match( "#awstats.([^\.]{1,}).([^\.]{1,}).([0-9]{6}).html#" , $file , $output )
)
$Seznam[substr( $output[3] , 0 , 4 )][substr( $output[3] , 4 )] = $file ;
}
closedir($handle);
}
krsort( $Seznam );
foreach( $Seznam as $Year => $Rows )
{
echo "";
}
?>