Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bainternet/Memchaced-Dashboard
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: robwithhair/Memchaced-Dashboard
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 5 commits
  • 1 file changed
  • 1 contributor

Commits on Dec 4, 2014

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7c7c864 View commit details
  2. Fixed previous mistake

    Rob Harrison committed Dec 4, 2014
    Copy the full SHA
    8efaa58 View commit details
  3. Added ability to use string 'session.save_path' in place of $servers …

    …in constructor to allow php to get the server list from the session.save_path in php.ini if memcached sessions are enabled in php.ini
    Rob Harrison committed Dec 4, 2014
    Copy the full SHA
    443f297 View commit details
  4. Improved longin security and potential interferance with other sessio…

    …n data on server
    Rob Harrison committed Dec 4, 2014
    Copy the full SHA
    25b2a7e View commit details
  5. Fixed potential interferance with session based login pages on same s…

    …erver as memcached dashboard.
    Rob Harrison committed Dec 4, 2014
    Copy the full SHA
    2f19a0d View commit details
Showing with 29 additions and 13 deletions.
  1. +29 −13 index.php
42 changes: 29 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Simple memchached dashboard
* A dead simple single file Memchaced stats dashboard.
@@ -11,18 +10,27 @@ class Simple_memchached_dashboard{
public $list = null;
public $status = null;
public $error = false;
public $server = '';
public $port = '';
public $servers = array();
private $users = array();


function __construct($server = '127.0.0.1',$port = '11211',$users = array('admin' => 'admin')){
function __construct($servers = null,$users = array('admin' => 'admin')){
session_start();
$this->users = $users;
$this->validate_login();
$this->need_login();
$this->server = $server;
$this->port = $port;
if (is_string($servers)){
if ($servers == 'localhost') $this->servers = array(array('127.0.0.1', 11211));
elseif ($servers == 'session.save_path'){
$this->servers = explode(',',ini_get('session.save_path'));
foreach($this->servers as &$server){
$server = explode(':', $server);
if (isset($server[1])) $server[1] = (int) $server[1];
}
}
}
else
$this->servers = empty($servers) ? array(array('127.0.0.1', 11211)) : $servers;
$this->setup();
$this->dashboard();
}
@@ -80,7 +88,7 @@ function login_form(){
}

function is_logged_in(){
return (isset($_SESSION['username']) && $_SESSION['username'] != '');
return (isset($_SESSION['memcached_dashboard_username']) && isset($this->users[$_SESSION['memcached_dashboard_username']]) && $_SESSION['memcached_dashboard_username'] != '');
}

function add_user($user_name,$user_pass){
@@ -89,8 +97,8 @@ function add_user($user_name,$user_pass){

function logout(){
if(isset($_GET['action']) && $_GET['action'] == 'logout') {
$_SESSION['username'] = '';
session_destroy();
unset($_SESSION['memcached_dashboard_username']);
session_write_close();
header('Location: ' . $_SERVER['PHP_SELF']);
}
}
@@ -102,7 +110,7 @@ function validate_login(){
$pass = $_POST['password'];
if ($this->user_exists($user)){
if($pass == $this->get_user_pass($user)) {
$_SESSION['username'] = $_POST['username'];
$_SESSION['memcached_dashboard_username'] = $_POST['username'];
}else {
$this->error = 'Wrong Password!';
}
@@ -125,7 +133,9 @@ function get_user_pass($user){

function setup(){
$this->memcache = new Memcache();
$this->memcache->addServer("$this->server:$this->port");
foreach($this->servers as $server){
$this->memcache->addServer($server[0], (isset($server[1]) ? $server[1] : 11211), false, 50);
}
$list = array();
$allSlabs = $this->memcache->getExtendedStats('slabs');
$items = $this->memcache->getExtendedStats('items');
@@ -495,8 +505,14 @@ function header(){
<a class="navbar-brand" href="<?= $_SERVER['PHP_SELF'] ?>">Memcached Dashboard</a>
</div>
<?php
if ($this->server != ''){
?><p class="navbar-text">Server IP: <?= $this->server ?> Port: <?= $this->port ?></p><?php
if (!empty($this->servers)){
?><p class="navbar-text">Servers: <?
$serversList = array();
foreach($this->servers as $serverArray){
$serversList[] = implode(':', $serverArray);
}
echo implode(', ', $serversList);
?></p><?php
}
if ($this->is_logged_in()){
?>