<?php // Rough F@H log parser$fahLogPath = "./FAHlog.txt"; //Full path to logif (! $logFile = fopen($fahLogPath, "r")){ die("Couldn't open log file"); }$fahVersion = "Unknown"; $fahUser = "Unknown"; $fahTeam = "Unknown"; $fahUID = "Unknown"; // Set regexp for matching timestamp so I dont have to keep retyping it$timeFormat = "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]";$timeStamp = "\\[" . $timeFormat . "\\]";// Read a line from the log, will fail when we reach EOFwhile($logLine = fgets($logFile, 4096)) { // Find the version if (ereg('Folding@Home Client Version (.*)', trim($logLine), $matches)) { $fahVersion = $matches[1]; } // Find current user and team else if (ereg($timeStamp . " - User name: ([^ ]*) \\(Team ([^\\)]*).*", $logLine, $matches)) { $fahUser = $matches[1]; $fahTeam = $matches[2]; } // Get the UID else if (ereg($timeStamp . " - User ID: ([0-9A-Za-z]*).*", $logLine, $matches)) { $fahUID = $matches[1]; } else if (ereg($timeStamp . " Project: ([0-9A-Za-z]*).*", $logLine, $matches)) { // We found a new project // Previous data was for another project // And all new data is gonna be for a new project. $fahProject = $matches[1]; $fahData[$fahProject]['Project'] = $matches[1]; } else if (ereg($timeStamp . " Protein: (.*)", $logLine, $matches)) { $fahData[$fahProject]['Protein'] = trim($matches[1]); } else if (ereg("\\[(" . $timeFormat . ")\\] Completed ([0-9]*) out of ([0-9]*) .*", $logLine, $matches)) { // Above regexp matches timestamp as well as completed work $fahData[$fahProject]['StepsCurrent'] = $matches[2]; $fahData[$fahProject]['StepsTotal'] = $matches[3]; $fahData[$fahProject]['LastChecked'] = $matches[1]; // Following line casts Current divide by Total times 100 to a 2 digit integer // This will make sure we always get at least 2 digits, eg 08, 03, 16, etc $fahData[$fahProject]['StepsPercent'] = sprintf("%02d", 100 * ($matches[2] / $matches[3])); } }fclose($logFile); // Array with just the most recent project$lastData = end($fahData); ?><html><head> <title>Folding @ Home Status</title></head><body><h1>Folding@Home</h1><h2>Text Version</h2>This version is probably best suited to use in a console (command line) or something. <br>To make this work at the unix command line, add #!/usr/bin/php as the very first line and chmod +x the script. This assumes /usr/bin/php is where your php exe is. <br>Of course you'll have to edit it a fair bit to get the output nice for the console :)<p><pre><?php printf("FAH Version: %s\r\n", $fahVersion); printf("FAH User: %s\r\n", $fahUser); printf("FAH Team: %s\r\n", $fahTeam); printf("FAH UID: %s\r\n", $fahUID); printf("Last Project: %s (%s)\r\n", $lastData['Project'], $lastData['Protein']); printf("Progress: Step %s of %s (%02d%%)\r\n", $lastData['StepsCurrent'], $lastData['StepsTotal'], $lastData['StepsPercent']); ?></pre></p><h2>IRC Version</h2>Same as above, but formatted differently.<p><pre><?php printf("[[[ Folding@Home Status: Version %s, User %s, Team %s - Current Project %s %s, Progress %s%% ]]]", $fahVersion, $fahUser, $fahTeam, $lastData['Project'], $lastData['Protein'], $lastData['StepsPercent']); ?></pre></p><h2>Current Status</h2><table> <tr> <td>F@H UserName</td> <td><?php echo $fahUser; ?> (UID <? echo $fahUID; ?>)</td> </tr> <tr> <td>F@H Team</td> <td><?php echo $fahTeam; ?></td> </tr> <tr> <td>F@H Version</td> <td><?php echo $fahVersion; ?></td> </tr> <tr> <td>Current Project:</td> <td><a href='http://fah-web.stanford.edu/cgi-bin/fahproject?p=<?php echo $lastData['Project']; ?>'> <?php echo $lastData['Protein']; ?> (Project <? echo $lastData['Project'];?>)</a></td> </tr> <tr> <td>Progress:</td> <td><?php // Do pretty little graph thingy // Should make a reasonable amount of sense // Change the + 5 to another number to change the length echo "["; for ($i = 1; $i < 100; $i = $i + 5) { if ($i <= $lastData['StepsPercent']) { echo "|"; } else { echo "_"; } } echo "] ("; echo $lastData['StepsPercent']; echo "%)"; ?></td> </tr> <tr> <td>Pretty Progress</td> <td><table width='100'><tr height='24'><td bgcolor='#00FF00' width='<?php echo $lastData['StepsPercent'];?>'></td><td bgcolor='#FF0000' width='*'></td></tr></table></td> </tr></table><h2>All Jobs</h2><table> <tr> <th>Protein</th> <th>Progress</th> </tr><?phpforeach ($fahData as $fahItem){?><tr> <td> <a href='http://fah-web.stanford.edu/cgi-bin/fahproject?p=<?php echo $fahItem['Project']; ?>'> <?php echo $fahItem['Protein']; ?> (Project <? echo $fahItem['Project'];?>) </a> </td> <td><?php echo $fahItem['StepsPercent'] . "%"; ?></td></tr><?php} // End of foreach?></table></html>