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
<VirtualHost *>
# zalozeno: `date +%c`
ServerName ${site}
ServerAlias *.${site}
ServerAdmin ${webmaster}
DocumentRoot ${wwwroot}/${site}/www
<IfModule mod_php5.c>
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}'
</IfModule>
<IfModule mod_rewrite.c>
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]
</IfModule>
</VirtualHost>
EOF
cat > ${wwwroot}/${site}/stats/.htaccess << EOF
AuthType Basic
AuthUserFile /etc/apache2/.htpasswd
AuthGroupFile /dev/null
AuthName "statistiky pristupu"
<Limit GET POST>
require user dast
require user dfox
require user ${site}
</Limit>
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-tr
ansitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="cs" />
<title><?= $_SERVER['HTTP_HOST'] ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel='stylesheet' href='http://89.250.246.102/awstats-css/css.css' type="text/css" />
</head>
<body>
<?php
$Mesice = array( "01" => "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 '<h1>' . $_SERVER['HTTP_HOST'] . '</h1>';
$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 "<fieldset>\n <legend>" . $Year . "</legend>\n";
foreach ( $Mesice as $MesicId => $MesicName )
if ( ! $Rows[$MesicId] )
echo $MesicName . "<br />";
else
echo "<a href='" . $Rows[$MesicId] . "'>" . $MesicName . "</a><br />";
echo "</fieldset>";
}
?>
</body>
</html>