du2.php

This is based off of du.php, and is basically the same thing except it lets you click on folders to navigate through the directory structure and see how much space each directory is taking up.

It uses php’s shell_exec function to call the du utility on the directories it’s in. So if your host doesn’t allow you to use shell_exec, this isn’t going to work for you. If they do allow shell_exec, but do not allow ssh access then this is perfect.

You can view it here as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<HTML><HEAD><TITLE>Disk Usage Report</TITLE></HEAD><BODY>
<?php
///////////////////////////////////////////////////////////
//Disk Usage script v2                       ///
//du2.php                          ///
/////////////                         ///
//Author:  Justyn Shull                    ///
//E-mail:  justyn@justynshull.com           ///
/////////////                      ///
//based off my old du.php script:         ///
//This lists the directories in $dir with the   ///
//space they take up.  Not sorted, but allows  ///
//you to click on a directory to navigate     ///
////////////////////////////////////////////////
 
/////TODO: Fix it so you don't end up with the full path you've taken
//        eg:   du2.php?dir=../mail/../html/
 
$time1 = microtime(True);
chdir(getenv('DOCUMENT_ROOT'));
chdir("..");
$homedir = shell_exec('pwd');
echo "Home: $homedir";
if ($_GET["dir"] == "")
    //$dir = getenv('DOCUMENT_ROOT')."/.."; // *should* be the users's home
    $dir = ".";
else
    $dir = $_GET["dir"];
 
echo escapeshellarg($dir)."<br />";
chdir($dir);
echo shell_exec("pwd")."<br />";
$homeindir = strpos(shell_exec("pwd"),$homedir);
//if ($homeindir === false) die ("Invalid dir");  //hopefully this will keep us from leaving $home
 
exec('ls -la',$dirs,$rc);
if ($rc != 0) die("Error listing files");
$numdir = count($dirs) - 1;
for ($x = 1;$x <= $numdir; $x++){
    $type = substr($dirs[$x],0,1);
    if ($type == "d") {
    $lsdirs[] = substr(strrchr($dirs[$x]," "),1);
    }
}
$numdir = count($lsdirs) - 1;
 
// Print usage now
echo "<br />";
for ($x = 0; $x <= $numdir; $x++) {
    if ($x == 1) {
        echo "<a href=du2.php?dir=$dir/$lsdirs[$x]>";
        echo "<img src=\"/icons/folder.gif\" border=0></a>    ..<br />";
    } else {
    unset($du);
    exec("du -hs ".escapeshellarg($lsdirs[$x]),$du,$rc);
    if ($rc != 0) die("Error on ".$x.": ".escapeshellarg($lsdirs[$x]));
    echo "<a href=du2.php?dir=$dir/$lsdirs[$x]>";
    echo "<img src=\"/icons/folder.gif\" border=0></a>".$du[0]."<br />";
    }
}
 
 
$time2 = microtime(True); 
$dutime = ($time2 - $time1); 
echo '<p>Page generated in <b>'.$dutime.'</b> seconds</p>';
?>
 
</BODY></HTML>
Posted in PHP Scripts | Tagged , , | Leave a comment

Cosmos pictures

Pictures of my first watercooled setup.   Cable management is almost non-existent and the tubing is way too long.    I’ll post pictures of my new setup soon.

Posted in Rigs | Tagged , , | Leave a comment

du.php – PHP Disk Usage script

I’m starting to copy my scripts from https://justynshull.com/oldsite/phpscripts.html but figured I’d start with this one so I can get the syntax hilighting/formatting down with wordpress.

1
2
3
4
5
6
7
8
9
10
11
12
 <?php
 // $a = shell_exec('df -h');
//echo getenv('DOCUMENT_ROOT');
chdir(getenv('DOCUMENT_ROOT'));
chdir('..');
echo shell_exec('pwd');
$a = shell_exec('du -hx *');
//$a = shell_exec('ls -l');
echo '<h2>Disk space</h2>< pre>';
echo $a;
echo '< /pre>';
 ?>
Posted in PHP Scripts | 1 Comment

Switch to VPS and wordpress

I decided to switch my website from basic html/php to WordPress, and at the same time moved it over to my VPS.   It was being hosted on dreamhost before.

I still need to install/configure subversion, and move some of my old stuff over to wordpress.   There isn’t much to move, so it won’t be hard.    The old version of the site can be found here:

http://justynshull.com/oldsite/

Posted in Uncategorized | Leave a comment