Browse Source

memcache_ui can say hello world

Frederic G. MARAND 12 years ago
parent
commit
0d12ce2a54
3 changed files with 532 additions and 202 deletions
  1. 1 202
      memcache.php
  2. 201 0
      memcache_ui.css
  3. 330 0
      memcache_ui.php

+ 1 - 202
memcache.php

@@ -330,208 +330,7 @@ function getHeader() {
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head><title>MEMCACHE INFO</title>
-<style type="text/css"><!--
-body { background:white; font-size:100.01%; margin:0; padding:0; }
-body,p,td,th,input,submit { font-size:0.8em;font-family:arial,helvetica,sans-serif; }
-* html body   {font-size:0.8em}
-* html p      {font-size:0.8em}
-* html td     {font-size:0.8em}
-* html th     {font-size:0.8em}
-* html input  {font-size:0.8em}
-* html submit {font-size:0.8em}
-td { vertical-align:top }
-a { color:black; font-weight:none; text-decoration:none; }
-a:hover { text-decoration:underline; }
-div.content { padding:1em 1em 1em 1em; position:absolute; width:97%; z-index:100; }
-
-h1.memcache { background:rgb(153,153,204); margin:0; padding:0.5em 1em 0.5em 1em; }
-* html h1.memcache { margin-bottom:-7px; }
-h1.memcache a:hover { text-decoration:none; color:rgb(90,90,90); }
-h1.memcache span.logo {
-  background:rgb(119,123,180);
-  color:black;
-  border-right: solid black 1px;
-  border-bottom: solid black 1px;
-  font-style:italic;
-  font-size:1em;
-  padding-left:1.2em;
-  padding-right:1.2em;
-  text-align:right;
-  display:block;
-  width:130px;
-  }
-h1.memcache span.logo span.name { color:white; font-size:0.7em; padding:0 0.8em 0 2em; }
-h1.memcache span.nameinfo { color:white; display:inline; font-size:0.4em; margin-left: 3em; }
-h1.memcache div.copy { color:black; font-size:0.4em; position:absolute; right:1em; }
-hr.memcache {
-  background:white;
-  border-bottom:solid rgb(102,102,153) 1px;
-  border-style:none;
-  border-top:solid rgb(102,102,153) 10px;
-  height:12px;
-  margin:0;
-  margin-top:1px;
-  padding:0;
-}
-
-ol,menu { margin:1em 0 0 0; padding:0.2em; margin-left:1em;}
-ol.menu li { display:inline; margin-right:0.7em; list-style:none; font-size:85%}
-ol.menu a {
-  background:rgb(153,153,204);
-  border:solid rgb(102,102,153) 2px;
-  color:white;
-  font-weight:bold;
-  margin-right:0em;
-  padding:0.1em 0.5em 0.1em 0.5em;
-  text-decoration:none;
-  margin-left: 5px;
-  }
-ol.menu a.child_active {
-  background:rgb(153,153,204);
-  border:solid rgb(102,102,153) 2px;
-  color:white;
-  font-weight:bold;
-  margin-right:0em;
-  padding:0.1em 0.5em 0.1em 0.5em;
-  text-decoration:none;
-  border-left: solid black 5px;
-  margin-left: 0px;
-  }
-ol.menu span.active {
-  background:rgb(153,153,204);
-  border:solid rgb(102,102,153) 2px;
-  color:black;
-  font-weight:bold;
-  margin-right:0em;
-  padding:0.1em 0.5em 0.1em 0.5em;
-  text-decoration:none;
-  border-left: solid black 5px;
-  }
-ol.menu span.inactive {
-  background:rgb(193,193,244);
-  border:solid rgb(182,182,233) 2px;
-  color:white;
-  font-weight:bold;
-  margin-right:0em;
-  padding:0.1em 0.5em 0.1em 0.5em;
-  text-decoration:none;
-  margin-left: 5px;
-  }
-ol.menu a:hover {
-  background:rgb(193,193,244);
-  text-decoration:none;
-  }
-
-
-div.info {
-  background:rgb(204,204,204);
-  border:solid rgb(204,204,204) 1px;
-  margin-bottom:1em;
-  }
-div.info h2 {
-  background:rgb(204,204,204);
-  color:black;
-  font-size:1em;
-  margin:0;
-  padding:0.1em 1em 0.1em 1em;
-  }
-div.info table {
-  border:solid rgb(204,204,204) 1px;
-  border-spacing:0;
-  width:100%;
-  }
-div.info table th {
-  background:rgb(204,204,204);
-  color:white;
-  margin:0;
-  padding:0.1em 1em 0.1em 1em;
-  }
-div.info table th a.sortable { color:black; }
-div.info table tr.tr-0 { background:rgb(238,238,238); }
-div.info table tr.tr-1 { background:rgb(221,221,221); }
-div.info table td { padding:0.3em 1em 0.3em 1em; }
-div.info table td.td-0 { border-right:solid rgb(102,102,153) 1px; white-space:nowrap; }
-div.info table td.td-n { border-right:solid rgb(102,102,153) 1px; }
-div.info table td h3 {
-  color:black;
-  font-size:1.1em;
-  margin-left:-0.3em;
-  }
-.td-0 a , .td-n a, .tr-0 a , tr-1 a {
-    text-decoration:underline;
-}
-div.info table td dl,
-div.info table td dl dt {
-  display: inline;
-}
-div.info table td dl dt {
-  font-weight: bold;
-}
-div.info table td dl dd {
-  display: inline-block;
-  margin-right: 2em;
-  margin-left: 0.5em;
-  width: 12em;
-}
-div.info table td div.slab-dump {
-  -moz-column-count: 3;
-  -moz-column-gap: 20px;
-  -webkit-column-count: 3;
-  -webkit-column-gap: 20px;
-  column-count: 3;
-  column-gap: 20px;
-}
-div.info table td a {
-  display: block;
-}
-div.graph { margin-bottom:1em }
-div.graph h2 { background:rgb(204,204,204);; color:black; font-size:1em; margin:0; padding:0.1em 1em 0.1em 1em; }
-div.graph table { border:solid rgb(204,204,204) 1px; color:black; font-weight:normal; width:100%; }
-div.graph table td.td-0 { background:rgb(238,238,238); }
-div.graph table td.td-1 { background:rgb(221,221,221); }
-div.graph table td { padding:0.2em 1em 0.4em 1em; }
-
-div.div1,div.div2 { margin-bottom:1em; width:35em; }
-div.div3 { position:absolute; left:40em; top:1em; width:580px; }
-//div.div3 { position:absolute; left:37em; top:1em; right:1em; }
-
-div.sorting { margin:1.5em 0em 1.5em 2em }
-.center { text-align:center }
-.aright { position:absolute;right:1em }
-.right { text-align:right }
-.ok { color:rgb(0,200,0); font-weight:bold}
-.failed { color:rgb(200,0,0); font-weight:bold}
-
-span.box {
-  border: black solid 1px;
-  border-right:solid black 2px;
-  border-bottom:solid black 2px;
-  padding:0 0.5em 0 0.5em;
-  margin-right:1em;
-}
-span.green { background:#60F060; padding:0 0.5em 0 0.5em}
-span.red { background:#D06030; padding:0 0.5em 0 0.5em }
-
-div.authneeded {
-  background:rgb(238,238,238);
-  border:solid rgb(204,204,204) 1px;
-  color:rgb(200,0,0);
-  font-size:1.2em;
-  font-weight:bold;
-  padding:2em;
-  text-align:center;
-  }
-
-input {
-  background:rgb(153,153,204);
-  border:solid rgb(102,102,153) 2px;
-  color:white;
-  font-weight:bold;
-  margin-right:1em;
-  padding:0.1em 0.5em 0.1em 0.5em;
-  }
-//-->
-</style>
+<link rel="stylesheet" type="text/css" href="memcache_ui.css" />
 </head>
 <body>
 <div class="head">

+ 201 - 0
memcache_ui.css

@@ -0,0 +1,201 @@
+@CHARSET "UTF-8";
+
+body { background:white; font-size:100.01%; margin:0; padding:0; }
+body,p,td,th,input,submit { font-size:0.8em;font-family:arial,helvetica,sans-serif; }
+* html body   {font-size:0.8em}
+* html p      {font-size:0.8em}
+* html td     {font-size:0.8em}
+* html th     {font-size:0.8em}
+* html input  {font-size:0.8em}
+* html submit {font-size:0.8em}
+td { vertical-align:top }
+a { color:black; font-weight:none; text-decoration:none; }
+a:hover { text-decoration:underline; }
+div.content { padding:1em 1em 1em 1em; position:absolute; width:97%; z-index:100; }
+
+h1.memcache { background:rgb(153,153,204); margin:0; padding:0.5em 1em 0.5em 1em; }
+* html h1.memcache { margin-bottom:-7px; }
+h1.memcache a:hover { text-decoration:none; color:rgb(90,90,90); }
+h1.memcache span.logo {
+  background:rgb(119,123,180);
+  color:black;
+  border-right: solid black 1px;
+  border-bottom: solid black 1px;
+  font-style:italic;
+  font-size:1em;
+  padding-left:1.2em;
+  padding-right:1.2em;
+  text-align:right;
+  display:block;
+  width:130px;
+  }
+h1.memcache span.logo span.name { color:white; font-size:0.7em; padding:0 0.8em 0 2em; }
+h1.memcache span.nameinfo { color:white; display:inline; font-size:0.4em; margin-left: 3em; }
+h1.memcache div.copy { color:black; font-size:0.4em; position:absolute; right:1em; }
+hr.memcache {
+  background:white;
+  border-bottom:solid rgb(102,102,153) 1px;
+  border-style:none;
+  border-top:solid rgb(102,102,153) 10px;
+  height:12px;
+  margin:0;
+  margin-top:1px;
+  padding:0;
+}
+
+ol,menu { margin:1em 0 0 0; padding:0.2em; margin-left:1em;}
+ol.menu li { display:inline; margin-right:0.7em; list-style:none; font-size:85%}
+ol.menu a {
+  background:rgb(153,153,204);
+  border:solid rgb(102,102,153) 2px;
+  color:white;
+  font-weight:bold;
+  margin-right:0em;
+  padding:0.1em 0.5em 0.1em 0.5em;
+  text-decoration:none;
+  margin-left: 5px;
+  }
+ol.menu a.child_active {
+  background:rgb(153,153,204);
+  border:solid rgb(102,102,153) 2px;
+  color:white;
+  font-weight:bold;
+  margin-right:0em;
+  padding:0.1em 0.5em 0.1em 0.5em;
+  text-decoration:none;
+  border-left: solid black 5px;
+  margin-left: 0px;
+  }
+ol.menu span.active {
+  background:rgb(153,153,204);
+  border:solid rgb(102,102,153) 2px;
+  color:black;
+  font-weight:bold;
+  margin-right:0em;
+  padding:0.1em 0.5em 0.1em 0.5em;
+  text-decoration:none;
+  border-left: solid black 5px;
+  }
+ol.menu span.inactive {
+  background:rgb(193,193,244);
+  border:solid rgb(182,182,233) 2px;
+  color:white;
+  font-weight:bold;
+  margin-right:0em;
+  padding:0.1em 0.5em 0.1em 0.5em;
+  text-decoration:none;
+  margin-left: 5px;
+  }
+ol.menu a:hover {
+  background:rgb(193,193,244);
+  text-decoration:none;
+  }
+
+
+div.info {
+  background:rgb(204,204,204);
+  border:solid rgb(204,204,204) 1px;
+  margin-bottom:1em;
+  }
+div.info h2 {
+  background:rgb(204,204,204);
+  color:black;
+  font-size:1em;
+  margin:0;
+  padding:0.1em 1em 0.1em 1em;
+  }
+div.info table {
+  border:solid rgb(204,204,204) 1px;
+  border-spacing:0;
+  width:100%;
+  }
+div.info table th {
+  background:rgb(204,204,204);
+  color:white;
+  margin:0;
+  padding:0.1em 1em 0.1em 1em;
+  }
+div.info table th a.sortable { color:black; }
+div.info table tr.tr-0 { background:rgb(238,238,238); }
+div.info table tr.tr-1 { background:rgb(221,221,221); }
+div.info table td { padding:0.3em 1em 0.3em 1em; }
+div.info table td.td-0 { border-right:solid rgb(102,102,153) 1px; white-space:nowrap; }
+div.info table td.td-n { border-right:solid rgb(102,102,153) 1px; }
+div.info table td h3 {
+  color:black;
+  font-size:1.1em;
+  margin-left:-0.3em;
+  }
+.td-0 a , .td-n a, .tr-0 a , tr-1 a {
+    text-decoration:underline;
+}
+div.info table td dl,
+div.info table td dl dt {
+  display: inline;
+}
+div.info table td dl dt {
+  font-weight: bold;
+}
+div.info table td dl dd {
+  display: inline-block;
+  margin-right: 2em;
+  margin-left: 0.5em;
+  width: 12em;
+}
+div.info table td div.slab-dump {
+  -moz-column-count: 3;
+  -moz-column-gap: 20px;
+  -webkit-column-count: 3;
+  -webkit-column-gap: 20px;
+  column-count: 3;
+  column-gap: 20px;
+}
+div.info table td a {
+  display: block;
+}
+div.graph { margin-bottom:1em }
+div.graph h2 { background:rgb(204,204,204);; color:black; font-size:1em; margin:0; padding:0.1em 1em 0.1em 1em; }
+div.graph table { border:solid rgb(204,204,204) 1px; color:black; font-weight:normal; width:100%; }
+div.graph table td.td-0 { background:rgb(238,238,238); }
+div.graph table td.td-1 { background:rgb(221,221,221); }
+div.graph table td { padding:0.2em 1em 0.4em 1em; }
+
+div.div1,div.div2 { margin-bottom:1em; width:35em; }
+div.div3 { position:absolute; left:40em; top:1em; width:580px; }
+//div.div3 { position:absolute; left:37em; top:1em; right:1em; }
+
+div.sorting { margin:1.5em 0em 1.5em 2em }
+.center { text-align:center }
+.aright { position:absolute;right:1em }
+.right { text-align:right }
+.ok { color:rgb(0,200,0); font-weight:bold}
+.failed { color:rgb(200,0,0); font-weight:bold}
+
+span.box {
+  border: black solid 1px;
+  border-right:solid black 2px;
+  border-bottom:solid black 2px;
+  padding:0 0.5em 0 0.5em;
+  margin-right:1em;
+}
+span.green { background:#60F060; padding:0 0.5em 0 0.5em}
+span.red { background:#D06030; padding:0 0.5em 0 0.5em }
+
+div.authneeded {
+  background:rgb(238,238,238);
+  border:solid rgb(204,204,204) 1px;
+  color:rgb(200,0,0);
+  font-size:1.2em;
+  font-weight:bold;
+  padding:2em;
+  text-align:center;
+  }
+
+input {
+  background:rgb(153,153,204);
+  border:solid rgb(102,102,153) 2px;
+  color:white;
+  font-weight:bold;
+  margin-right:1em;
+  padding:0.1em 0.5em 0.1em 0.5em;
+  }

+ 330 - 0
memcache_ui.php

@@ -0,0 +1,330 @@
+<?php
+class GraphicsContext {
+  protected $palette = array();
+}
+
+/**
+ * A wrapper for XML elements.
+ */
+class Element {
+  public $name = NULL;
+  public $attributes = array();
+  public $value = NULL;
+  public $new_line; // Add a new line after element
+
+  public function __construct($name, $attr = NULL, $value = NULL) {
+    $this->name = $name;
+    $this->attributes = $attr;
+    $this->value = $value;
+  }
+
+  public function __toString() {
+    $ret = '<'. $this->name;
+    if (!empty($this->attributes)) {
+      $ret .= ' ' . implode(' ', $this->attributes);
+    }
+    if (empty($this->value)) {
+      $ret .= ' />';
+    }
+    else {
+      $ret .= '>';
+      if ($this->value instanceof Element) {
+        $ret .= (string) $this->value; // force __toString()
+      }
+      elseif (is_array($this->value)) {
+        $ret .= implode('', $this->value);
+      }
+      else {
+        $ret .= $this->value;
+      }
+      $ret .= "</$this->name>";
+    }
+    return $ret;
+  }
+}
+
+class Context {
+  /**
+   * Directory in which the current script is located.
+   *
+   * Follow symlinks if applicable, to obtain the actual implementation
+   * directory, instead of just the main file symlink, in order to find the
+   * other files.
+   *
+   * @var string
+   */
+  protected $dirname;
+
+  /**
+   * Requested path: <$PHP_SELF>?q=a/b/c
+   *
+   * @var string
+   */
+  protected $path = NULL;
+
+  /**
+   * Graphics context
+   *
+   * @var GraphicsContext
+   */
+  protected $gc = NULL;
+
+  public function getDirname() {
+    if (!isset($this->dirname)) {
+      $this->dirname = dirname(__FILE__);
+    }
+
+    return $this->dirname;
+  }
+
+  /**
+   * Return the requested path.
+   *
+   * @param string $path
+   */
+  public function getPath() {
+    if (!isset($this->path)) {
+      $this->path = empty($_GET['q']) ? '' : $_GET['q'];
+    }
+
+    return $this->path;
+  }
+
+  /**
+   * User information: logged or not ?
+   *
+   * @var boolean
+   */
+  protected $user = FALSE;
+
+
+  function __construct() {
+    $this->getPath();
+  }
+
+  function __toString() {
+    $ret = '<pre>' . print_r($this, TRUE) . '</pre>';
+    return $ret;
+  }
+}
+
+class Page extends Element {
+  /**
+   * @var Context
+   */
+  protected $context;
+
+  /**
+   * @var array
+   */
+  protected $styles;
+
+  /**
+   * @var array
+   */
+  protected $finalized = array();
+
+  public function getHeader($name) {
+  }
+
+  public function setHeader($name, $value) {
+
+  }
+
+  public function getHead() {
+    $this->finalizeHead();
+    $head = new Element('head', NULL, $this->head);
+    $ret = (string) $head;
+    return $ret;
+  }
+
+  public function setHead($item) {
+
+  }
+
+  public function getBody() {
+    $this->finalizeBody();
+    $body = new Element('body', NULL, $this->body);
+    $ret = (string) $body;
+    return $ret;
+  }
+
+  public function setBody($fragment) {
+    $this->body[] = $fragment;
+  }
+
+  public function finalizeHead() {
+    if (isset($this->finalized['head'])) {
+      throw new Exception('Attempt to finalize already finalized head');
+    }
+    $cssLink = new Element('link', array(
+      'rel' => 'stylesheet',
+      'type' => 'text/css',
+      'href' => $this->context->getPath() .'/memcache_ui.css',
+    ));
+    $this->setHead($cssLink);
+
+    $this->finalized['head'] = TRUE;
+  }
+
+  public function finalizeBody() {
+    if (isset($this->finalized['body'])) {
+      throw new Exception('Attempt to finalize already finalized body');
+    }
+    $this->finalized['body'] = TRUE;
+  }
+
+  public function render() {
+    $html = new Element('html', NULL, $this->getHead() . $this->getBody());
+    return (string) $html;
+  }
+
+  /**
+   * Page constructor.
+   *
+   * @param Context $context
+   * @param array $item
+   *   A router info array.
+   *
+   * @see Router::getInfo()
+   */
+  public function __construct(Context $context, array $item) {
+    parent::__construct('html');
+    $this->context = $context;
+  }
+}
+
+class Router {
+  function getInfo() {
+    $ret = array(
+      '^server/(\w+)/flush/(\w+)$' => array(
+        'page class' => 'page_server_flush',
+        'page arguments' => array('$1', '$2'),
+        'title callback' => 'title_server',
+        'title arguments' => 'page arguments',
+      ),
+      '^server/(\w+)/flush$' => array(
+        'page class' => 'page_server_flush',
+        'page arguments' => array('$1'),
+        'title callback' => 'title_server',
+        'title arguments' => 'page arguments',
+      ),
+
+      '^server/(\w+)/slab/(\d+)$' => array(
+        'page class' => 'page_slab_view',
+        'page arguments' => array('$1', '$2'),
+        'title callback' => 'title_slab',
+        'title arguments' => 'page arguments',
+      ),
+
+      '^server/(\w+)/key/(.+)/delete/(\w+)$' => array(
+        'page class' => 'page_variable_delete_confirm',
+        'page arguments' => array('$1', '$2', '$3'),
+        'title callback' => 'title_variable',
+        'title arguments' => 'page arguments',
+      ),
+      '^server/(\w+)/key/(.+)/delete$' => array(
+        'page class' => 'page_variable_delete_form',
+        'page arguments' => array('$1', '$2'),
+        'title callback' => 'title_variable',
+        'title arguments' => 'page arguments',
+      ),
+
+      '^server/(\w+)/key/(.+)/dump$' => array(
+        'page class' => 'page_variable_view_php',
+        'page arguments' => array('$1', '$2'),
+        'title callback' => 'title_variable',
+        'title arguments' => 'page arguments',
+      ),
+      '^server/(\w+)/key/(.+)/php$' => array(
+        'page class' => 'page_variable_view_php',
+        'page arguments' => array('$1', '$2'),
+        'title callback' => 'title_variable',
+        'title arguments' => 'page arguments',
+      ),
+      '^server/(\w+)/key/(.+)$' => array(
+        'page class' => 'page_variable_view_text',
+        'page arguments' => array('$1', '$2'),
+        'title callback' => 'title_variable',
+        'title arguments' => 'page arguments',
+      ),
+
+      '^slabs$' => array(
+        'page class' => 'page_slab_overview',
+        'title' => 'Slabs per server',
+      ),
+
+      '^$' => array(
+        'page class' => 'Page_Main',
+        'title' => 'Overview',
+      ),
+    );
+
+    return $ret;
+  }
+
+  function getRoute() {
+    $found = FALSE;
+    $path = $this->context->getPath();
+    // echo "<pre>Path: [". $path . "]</p>";
+    $matches = array();
+    foreach ($this->getInfo() as $regex => $info) {
+      $regex = "@$regex@";
+      $count = preg_match($regex, $path, $matches);
+      // echo "<pre>$regex: $count";
+      // if ($count) print_r($matches);
+      // echo "</pre>";
+      if ($count) {
+        $found = TRUE;
+        break;
+      }
+    }
+    if ($found) {
+      // echo "Found at $regex<pre>";
+      // print_r($info);
+      $regexes = array_fill(0, count($info['page arguments']), $regex);
+      $paths = array_fill(0, count($info['page arguments']), $path);
+      $info['page arguments'] = preg_replace($regexes, $info['page arguments'], $paths);
+    }
+    else {
+      $info = NULL;
+    }
+
+    return $info;
+  }
+
+  function __construct(Context $context) {
+    $this->context = $context;
+  }
+}
+
+class Page_Main extends Page {
+  function finalizeBody() {
+    $hello = new Element('p', NULL, 'Hello world');
+    $this->setBody($hello);
+    parent::finalizeBody();
+  }
+
+}
+
+function main() {
+  $context = new Context();
+  // echo "<p>Dirname: [". $context->getDirname() . "]</p>";
+  // echo "<p>Path: [". $context->getPath() . "]</p><pre>";
+
+  $router = new Router($context);
+  $item = $router->getRoute();
+  $page = new $item['page class']($context, $item);
+  // echo '<pre>'; var_dump($page);
+  echo $page->render();
+}
+
+try {
+  main();
+}
+catch (Exception $e) {
+  echo '<pre>';
+  echo $e->getMessage() . PHP_EOL;
+  echo $e->getTraceAsString();
+  echo "</pre>";
+}