Skip to content

Commit

Permalink
import of a lot of fun updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cmelbye committed May 16, 2009
1 parent ad2b056 commit de8bda3
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
secret.php
status.log

5 changes: 5 additions & 0 deletions .htaccess
@@ -0,0 +1,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

64 changes: 64 additions & 0 deletions commands.php
@@ -0,0 +1,64 @@
<?php

class home extends command {
function get() {
echo $this->_tpl->execute( 'index' );
}

function post() {

}
}

class status extends command {
function get() {
global $statusPath;
$statuses = array();
$status_file = file_get_contents( $statusPath );

foreach( explode( "\n", $status_file ) as $line ) {
if( substr( $line, 0, 1 ) == '#' )
continue;

$line = trim( $line );
if( $line == '' )
continue;

$parts = explode( ' ', $line, 3 );
if( !isset( $parts[2] ) || ( $parts[2] == '' ) )
$parts[2] = false;

$statuses[ $parts[0] ] = array(
'status' => $parts[1],
'description' => $parts[2]
);
}

$this->_tpl->set( 'statuses', $statuses );
echo $this->_tpl->execute( 'status' );
}
}

class edit_status extends command {
function get() {
global $statusPath;
$status_data = file_get_contents( $statusPath );
$this->_tpl->set( 'status_data', $status_data );
echo $this->_tpl->execute( 'status_edit_form' );
}

function post() {
global $updatePassword, $statusPath;

$password = $_POST['update_password'];
if( $password == $updatePassword ) {
$status_data = $_POST['status_data'];
file_put_contents( $statusPath, $status_data );
header('Location: /status');
return;
} else {
header('Location: /status');
return;
}
}
}
Binary file added css/grid.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions css/ie.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions css/print.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions css/screen.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions css/style.css
@@ -0,0 +1,79 @@
h1, h2, h3, h4, h5, h6 {
font-size: 1.3em;
font-weight: bold;
}

h1 {
margin-bottom: 1em;
}

p {
margin-bottom: 1em;
}

li {
margin: 5px 0;
}

div#header {
font-size: 130%;
margin-top: 3em;
color: #007200;
font-weight: bold;
}

div#navigation {
font-size: 120%;
color: #aaa;
margin-bottom: 2em;
font-weight: bold;
}

div#navigation a {
text-decoration: none;
color: #aaa;
}

div#navigation a:hover {
color: #000;
}

div#navigation ul {
list-style-type: none;
margin: 0;
}

div#navigation ul li {
display: inline;
margin-right: 10px;
}

table.status tr.headings {
background-color: #CCC;
}
table.status tr td.service {
font-weight: bold;
}

table.status tr td.status img {
position: relative;
bottom: -3px;
margin-right: 3px;
}

form label {
font-weight: bold;
display: block;
font-size: 105%;
}

form textarea {
width: 450px;
height: 200px;
}

div#footer {
color: #aaa;
font-size: 90%;
margin-top: 1em;
}
Binary file added images/cross.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/error.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/help.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tick.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions includes/command.php
@@ -0,0 +1,10 @@
<?php

class command {
protected $_tpl;

function __construct() {
global $templatePath;
$this->_tpl = new template( $templatePath );
}
}
75 changes: 75 additions & 0 deletions includes/glue.php
@@ -0,0 +1,75 @@
<?php

/**
* glue
*
* Provides an easy way to map URLs to classes. URLs can be literal
* strings or regular expressions.
*
* When the URLs are processed:
* * deliminators (/) are automatically escaped: (\/)
* * The beginning and end are anchored (^ $)
* * An optional end slash is added (/?)
* * The i option is added for case-insensitive searches
*
* Example:
*
* $urls = array(
* '/' => 'index',
* '/page/(\d+) => 'page'
* );
*
* class page {
* function GET($matches) {
* echo "Your requested page " . $matches[1];
* }
* }
*
* glue::stick($urls);
*
*/
class glue {

/**
* stick
*
* the main static function of the glue class.
*
* @param array $urls The regex-based url to class mapping
* @throws Exception Thrown if corresponding class is not found
* @throws Exception Thrown if no match is found
* @throws BadMethodCallException Thrown if a corresponding GET,POST is not found
*
*/
static function stick ($urls) {

$method = strtolower($_SERVER['REQUEST_METHOD']);
$path = $_SERVER['REQUEST_URI'];

$found = false;

krsort($urls);

foreach ($urls as $regex => $class) {
$regex = str_replace('/', '\/', $regex);
$regex = '^' . $regex . '\/?$';
if (preg_match("/$regex/i", $path, $matches)) {
$found = true;
if (class_exists($class)) {
$obj = new $class;
if (method_exists($obj, $method)) {
$obj->$method($matches);
} else {
throw new BadMethodCallException("Method, $method, not supported.");
}
} else {
throw new Exception("Class, $class, not found.");
}
break;
}
}
if (!$found) {
throw new Exception("URL, $path, not found.");
}
}
}
24 changes: 24 additions & 0 deletions includes/helpers.php
@@ -0,0 +1,24 @@
<?php

function buildStatus( $status ) {
switch( $status ) {
case 'up':
$image = 'tick';
$text = 'Up';
break;
case 'warn':
$image = 'error';
$text = 'Warning';
break;
case 'down':
$image = 'cross';
$text = 'Down';
break;
default:
$image = 'help';
$text = 'Unknown';
break;
}

return "<img src=\"/images/$image.png\" alt=\"$image\" /> $text";
}
48 changes: 48 additions & 0 deletions includes/template.php
@@ -0,0 +1,48 @@
<?php

class template {
protected $path, $vars, $use_layout, $layout;
protected $layout_file = null;

public function __construct( $path, $use_layout = true, $layout_file = null ) {
$this->path = rtrim( $path, "/" );
$this->vars = array();
$this->use_layout = $use_layout;

if( $use_layout ) {
$this->layout = new template( $this->path, false );

if( $layout_file )
$this->layout_file = $layout_file;
else
$this->layout_file = "layout";
}
}

public function getLayout() { return $this->layout; }

public function set( $key, $value ) { $this->vars[ $key ] = $value; }

public function execute( $file ) {
$template = $this->_execute( $file );

if( $this->use_layout ) {
$this->layout->set( 'yield', $template );
return $this->getLayout()->execute( $this->layout_file );
} else {
return $template;
}
}

private function _execute( $file ) {
if( !strstr($file, ".phtml") )
$file .= ".phtml";

extract( $this->vars );
ob_start();
include( $this->path . "/" . $file );
$contents = ob_get_clean();

return $contents;
}
}
26 changes: 26 additions & 0 deletions index.php
@@ -0,0 +1,26 @@
<?php

$dir = dirname(__FILE__);

set_include_path(
$dir . '/includes' . PATH_SEPARATOR .
get_include_path()
);

$templatePath = $dir . '/templates';
$statusPath = $dir . '/status.log';

require_once 'helpers.php';
require_once 'secret.php';
require_once 'template.php';
require_once 'command.php';
require_once 'commands.php';
require_once 'glue.php';

$urls = array(
'/' => 'home',
'/status' => 'status',
'/status/edit' => 'edit_status'
);

glue::stick($urls);
9 changes: 9 additions & 0 deletions templates/index.phtml
@@ -0,0 +1,9 @@
<p>Welcome to the YourWiki Server Information Centre. Here, you'll find the absolute latest up-to-date information about the status and history of the YourWiki servers.</p>

<p>We, the systems administrators of YourWiki, keep this as a record for themselves, but we hope that it's a useful reference for some of our users, too.</p>

<h2>Useful Links</h2>
<ul>
<li><a href="/logs">Admin. Logs</a> &mdash; View configuration changes, server updates, etc.</li>
<li><a href="/status">Server Status</a> &mdash; See which components of YourWiki are currently functioning properly, and which aren't.</li>
</ul>

0 comments on commit de8bda3

Please sign in to comment.