/Main_Page

::You must have ninja focus to complete your mission::NinjaFocus::

WebDAV Disk Usage Report

Views:


I had to make to partitions on a web server available to users over web dav. Users connected using NetDrive on windows machines. There was a complication that disk usage was not reported correctly. Each web site had it's own dynamic partition that could be resized as a way of enforcing quotas.

The following scripts presented users with a web page that showed how space was used on each partition.

PHP, Web Dav and Web Browsers

PHP had to be disabled, otherwise someone trying to load a file over web dav to edit it, would merely receive the parsed file. i.e. a load of html output and no source code.

Web web server has to be configured to enable PHP on one specific file, the disk-usage-report.html file.

That file has to have a .html extension, because a web browser loading a file from disk, not over http won't receive a mimetype header. The browser will look to the file extension to know what to do.

disk-usage-report.html

<html><head><title>Disk Usage Statistics</title>
<!-- Copyright Kieran Whitbread 2005 -->
<style>
body {background-color:#5f99ff;font-family:verdana,arial,sans-serif}
h1 {color:#fff}
ul {display:block;padding:1em 1em;list-style-type:none;margin:0}
ul li {font-size:1.3em;font-weight:bold;padding:1em 1em;margin:1em 0;background-color:#9fc2ff}
ul li ul li {font-size:0.9em;font-weight:normal;padding:0;margin:0}
.free {list-style-image:url(free.gif)}
.used {list-style-image:url(used.gif)}
img {margin:-3em 0 0 0;border:none;position:absolute;left:22em;display:block}
</style>
</head>
<body>
<h1>Disk Usage Statistics</h1>
<p>If you need more space for your web site, please contact <a href="mailto:****">Kieran</a> with details.</p>
<ul>
<?php 
$dirHandle=opendir('./');
while (false !== ($dirs=readdir($dirHandle)))
{
	if ($dirs != "." && $dirs != ".." && is_dir('./'.$dirs) && $dirs != 'learning resources' && $dirs != 'tutorial-agenda')
	{
		$areas[]=$dirs;
	}
}
sort($areas);
for ($count=0;$count<count($areas);$count++)
{
	$allocated=round(disk_total_space('./'.$areas[$count])/1048576);
	$free=round((disk_free_space('./'.$areas[$count])/1048576));
	$used=$allocated-$free;?>
<li><?php echo ucfirst($areas[$count]);?>
<ul>
<li><img src="https://online.varndean.ac.uk/area/disk-usage-graph.php?value=<?php echo round(($used/$allocated)*100);?>" alt="" width="190" height="127" /></li>
<li class="free">Remaining Space: <?php echo number_format($free);?> <acronym title="Mega Bytes">MB</acronym> (<?php echo round(($free/$allocated)*100);?>%)</li>
<li class="used">Used Space: <?php echo number_format($used);?> <acronym title="Mega Bytes">MB</acronym> (<?php echo round(($used/$allocated)*100);?>%)</li>
<li>Total Allocation: <?php echo number_format($allocated);?> <acronym title="Mega Bytes">MB</acronym></li>
</ul></li>
<?php }
clearstatcache();

?>
</ul>

disk-usage-graph.php

<?php
// Copyright Kieran Whitbread 2005
if (isset($_GET['value']))
{
	$value=round($_GET['value']/100*360);
	$width=190;
	$height=round($width/1.5);
	$x=round($width/2);
	$y=round($height/2);
	$image = imagecreatetruecolor($width, $height);
	$bgColour = imagecolorallocate($image, 159, 194, 255);
	imagefill($image, 0, 0, $bgColour);
	$freeSpace    = imagecolorallocate($image, 19, 159, 64);
	$freeSpaceShade = imagecolorallocate($image, 12, 95, 38);
	$usedSpace    = imagecolorallocate($image, 27, 0, 255);
	$usedSpaceShade = imagecolorallocate($image, 13, 0, 127);
	$start = round($y*1.2);
	$stop = $y;
	$height=round($width/2);
	for ($i = $start; $i > $stop; $i--)
	{
		imagefilledarc($image, $x, $i, $width, $height, 180, ($value+180), $usedSpaceShade, IMG_ARC_PIE);
		imagefilledarc($image, $x, $i, $width, $height, ($value+180), 180, $freeSpaceShade, IMG_ARC_PIE);
	}
	imagefilledarc($image, $x, $y, $width, $height, 180, ($value+180), $usedSpace, IMG_ARC_PIE);
	imagefilledarc($image, $x, $y, $width, $height, ($value+180), 180, $freeSpace, IMG_ARC_PIE);
	header('Content-Type: image/png');
	imagepng($image);
	imagedestroy($image);
}
?>

Main Menu

Personal tools

Toolbox