Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /* Copyright 2010, Lime Technology LLC.
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- */
- ?>
- <?php
- // Helper functions
- function my_scale($val, &$units, $precision = 2) {
- $unit = array('','KB','MB','GB','TB','PB','EB');
- $i = floor(log($val, 1000));
- $units = $unit[$i];
- return @round($val / pow(1000, $i), $precision);
- }
- function my_time($time, $fmt = "%c %Z") {
- echo strftime( $fmt, $time);
- }
- function my_temp($val) {
- echo "{$val}";
- if ($val != "*")
- echo "°C";
- }
- function mk_option($val, $value, $text, $extra = "") {
- echo "<option value='{$value}'";
- if ($val == $value)
- echo " selected=yes";
- if (strlen($extra))
- echo " {$extra}";
- echo ">{$text}</option>";
- }
- function help_link($text, $link = "") {
- global $page;
- if ($link == "") $link = $text;
- $href = "javascript:openHelp('$page[Plugin]/$link');";
- return "<a href=\"{$href}\">{$text}</a>";
- }
- function title_link() {
- global $page;
- $link = array_key_exists('Help', $page) ? $page['Help'] : $page['Title'];
- return help_link($page['Title'], $link);
- }
- function urlencode_path($path) {
- return str_replace("%2F", "/", urlencode($path));
- }
- // Return sorted set of pages on the indicated menu.
- function find_pages( $menu) {
- global $page_array;
- $pages = array();
- foreach ($page_array as $page) {
- $tok = strtok( $page['Menu'], " ");
- while ($tok !== false) {
- $delim = strpos( $tok, ":");
- if ($delim) {
- $t = substr( $tok, 0, $delim);
- if ($t == $menu) {
- $key = substr( $tok, $delim+1) . $page['Name'];
- $pages[$key] = $page;
- break;
- }
- }
- else {
- if ($tok == $menu) {
- $pages[$page['Name']] = $page;
- break;
- }
- }
- $tok = strtok( " ");
- }
- }
- ksort( $pages);
- return $pages;
- }
- // Suppose we want to render the page "http://tower/Main/Disk?name=disk1"
- // emhttp calls 'popen(cmdline)' where cmdline is:
- // "cd /usr/local/emhttp; /usr/bin/php plugins/webGui/template.php name=disk1&path=Main/Disk"
- // argv[0] argv[1]
- // The output of popen() (ie, the output generated by template.php) is written to
- // the http socket (after http headers have been output).
- // Here's the document root of the webGui plugin
- $root = '/'.dirname( $argv[0]);
- // Parse the 'querystring'
- // variables provided by emhttp:
- // path=<path> page path, e.g., path=Main/Disk
- // prev=<path> prev path, e.g., prev=Main (used to deterine if page was refreshed)
- parse_str($argv[1]);
- // The current "task" is the first element of the path
- $task = strtok( $path, "/");
- $page = null;
- // Read emhttp status
- $var = parse_ini_file( "/var/local/emhttp/var.ini");
- $sec = parse_ini_file( "/var/local/emhttp/sec.ini", TRUE);
- $devs = parse_ini_file( "/var/local/emhttp/devs.ini", TRUE);
- $disks = parse_ini_file( "/var/local/emhttp/disks.ini", TRUE);
- $users = parse_ini_file( "/var/local/emhttp/users.ini", TRUE);
- $shares = parse_ini_file( "/var/local/emhttp/shares.ini", TRUE);
- $sec_nfs = parse_ini_file( "/var/local/emhttp/sec_nfs.ini", TRUE);
- $sec_afp = parse_ini_file( "/var/local/emhttp/sec_afp.ini", TRUE);
- // Build the pages
- $page_array = array();
- foreach (glob( "plugins/*/*.page", GLOB_NOSORT) as $entry) {
- $page = parse_ini_file( $entry);
- $page['Name'] = basename( $entry, ".page");
- $page['Root'] = dirname( $entry);
- $page['Plugin'] = basename( $page['Root']);
- // assign defaults
- if (strlen($page['Author']) == 0)
- $page['Author'] = "anonymous";
- if (strlen($page['Version']) == 0)
- $page['Version'] = "unknown";
- if (strlen($page['Title']) == 0)
- $page['Title'] = $page['Name'];
- if (strlen($page['Type']) == 0)
- $page['Type'] = "echo 'Not much here.'";
- if (strlen($page['Icon']) == 0)
- $page['Icon'] = "{$root}/images/default.png";
- else
- $page['Icon'] = "{$page['Root']}/{$page['Icon']}";
- if (!array_key_exists( 'Menu', $page))
- $page['Menu'] = "";
- // handle conditional inclusion on menus
- if (array_key_exists( 'Cond', $page)) {
- eval( "\$enabled=$page[Cond];");
- if (!$enabled)
- $page['Menu'] = "";
- }
- // add to page_array
- $page_array[$page['Name']] = $page;
- }
- // Here's the page we're rendering
- $myPage = $page_array[basename($path)];
- // Gittyup
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html lang="en">
- <head>
- <link rel="shortcut icon" href="<?=$root;?>/style/<?=$var['mdColor'];?>.gif" type="image/gif">
- <title><?=$var['NAME'];?>/<?=$myPage['Name'];?></title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <link rel="stylesheet" type="text/css" href="/plugins/webGui/style/template.css">
- <script type="text/javascript">
- function refresh() {
- // disable all form elements on the page
- for (var i=0; i<top.window.document.forms.length; i++) {
- var x = top.window.document.forms[i];
- for(var j=0; j<x.length; j++){
- x.elements[j].disabled = true;
- }
- }
- // disable all links on the page
- for (var i=0; i<top.window.document.links.length; i++) {
- var x = top.window.document.links[i];
- // no cross-browser way to disable link, so just turn it gray :)
- x.style.color="gray";
- }
- // reload the page
- window.location=window.location;
- }
- function done() {
- var path=window.location.pathname;
- var x=path.indexOf("/",1);
- if (x != -1)
- path=path.substring(0,x);
- window.location.replace(path);
- }
- function chkDelete( form, button) {
- if (form.confirmDelete.checked)
- button.value='Delete';
- else
- button.value='Apply';
- }
- function openWindow( url, name) {
- var width=((screen.width*2)/3)|0;
- var height=((screen.height*2)/3)|0;
- var features="resizeable=yes,scrollbars=yes,width=" + width + ",height=" + height;
- var myWindow=window.open(url, name, features);
- myWindow.focus();
- return myWindow;
- }
- function openHelp( topic) {
- var url="http://lime-technology.com/wiki/index.php?title=Plugin/" + topic.replace(/ /g, "_");
- openWindow( url, "unRaidHelp");
- }
- function openLog( title) {
- var url="/update.htm?cmd=/usr/bin/tail -f /var/log/syslog&forkCmd=Start";
- var myWindow=openWindow( url, "unRaidLog");
- myWindow.document.title = title;
- return myWindow;
- }
- </script>
- </head>
- <body>
- <div class="Container">
- <div class="Header">
- <div class="Banner">
- <div class="BannerLogo">
- <a href="http://lime-technology.com"><img src="/plugins/webGui/images/logo.png"</img></a>
- </div>
- <div class="BannerTitle">
- <p><?=$var['NAME'];?><br><?=$var['COMMENT'];?></p>
- </div>
- <div class="BannerText">
- <p>unRAID Server <em><?=$var['regTy'];?></em> <br>version: <?=$var['version'];?> </p>
- </div>
- </div>
- <div class="TaskBar">
- <? $pages = find_pages( "Tasks"); ?>
- <? foreach ($pages as $page): ?>
- <? $link="/{$page['Name']}"; ?>
- <? if ($page['Name']==$task): ?>
- <div class="tab_al"></div>
- <div class="tab_active"><a href="<?=$link;?>"><?=$page['Name'];?></a></div>
- <div class="tab_ar"></div>
- <? else: ?>
- <div class="tab_il"></div>
- <div class="tab_inactive"><a href="<?=$link;?>"><?=$page['Name'];?></a></div>
- <div class="tab_ir"></div>
- <? endif; ?>
- <? endforeach; ?>
- <div class="Buttons">
- <button type="button" onClick="javascript:openLog('<?=$var[NAME];?> system log');">Log</button>
- </div>
- </div>
- </div>
- <div class="Content">
- <? if ($myPage['Type'] == "xmenu"): ?>
- <? $pages = find_pages( $myPage['Name']); ?>
- <? else: ?>
- <? $pages = array(); ?>
- <? $pages[$myPage['Name']] = $myPage; ?>
- <? endif; ?>
- <? foreach($pages as $page): ?>
- <? eval("\$page[Title]=\"$page[Title]\";"); ?>
- <p class="ContentTitle"><?=title_link();?></p>
- <hr>
- <? if ($page['Type'] == "menu"): ?>
- <div class="PanelSet">
- <? $pgs = find_pages( $page['Name']); ?>
- <? foreach($pgs as $pg): ?>
- <? $link="{$path}/{$pg['Name']}"; ?>
- <div class="Panel">
- <a href="<?=$link;?>">
- <img class="PanelImg" src="<?=$pg['Icon'];?>" title="<?=$pg['Title'];?>" alt="<?=$pg['Title'];?>"</img>
- <div class="PanelText"><a class="PanelText" href="<?=$link;?>"><?=$pg['Title'];?></a></div>
- </a>
- </div>
- <? endforeach; ?>
- </div>
- <? elseif ($page['Type'] == "php"): ?>
- <? include "{$page['Root']}/{$page['Name']}.php"; ?>
- <? else: ?>
- <? passthru( $page['Type']); ?>
- <? endif; ?>
- <? endforeach; ?>
- </div>
- <iframe id="progressFrame" name="progressFrame" frameborder="0"></iframe>
- <div class="Footer">
- <div style="float:right;">Page author: <?=$myPage['Author'];?>, version: <?=$myPage['Version'];?> </div>
- <div> unRAID™ webGui ©2010-2011 Lime Technology LLC</div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement