Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
432 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
secret.php | ||
status.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RewriteEngine On | ||
RewriteCond %{REQUEST_FILENAME} !-f | ||
RewriteCond %{REQUEST_FILENAME} !-d | ||
RewriteRule . /index.php | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
class command { | ||
protected $_tpl; | ||
|
||
function __construct() { | ||
global $templatePath; | ||
$this->_tpl = new template( $templatePath ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> — View configuration changes, server updates, etc.</li> | ||
<li><a href="/status">Server Status</a> — See which components of YourWiki are currently functioning properly, and which aren't.</li> | ||
</ul> |
Oops, something went wrong.