Advertisement
TapRackPull

template.php

Jun 9th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.56 KB | None | 0 0
  1. <?PHP
  2. /* Copyright 2010, Lime Technology LLC.
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2, or (at your option)
  6. * any later version.
  7. */
  8. ?>
  9. <?php
  10. // Helper functions
  11. function my_scale($val, &$units, $precision = 2) {
  12. $unit = array('','KB','MB','GB','TB','PB','EB');
  13. $i = floor(log($val, 1000));
  14. $units = $unit[$i];
  15. return @round($val / pow(1000, $i), $precision);
  16. }
  17. function my_time($time, $fmt = "%c %Z") {
  18. echo strftime( $fmt, $time);
  19. }
  20. function my_temp($val) {
  21. echo "{$val}";
  22. if ($val != "*")
  23. echo "&deg;C";
  24. }
  25. function mk_option($val, $value, $text, $extra = "") {
  26. echo "<option value='{$value}'";
  27. if ($val == $value)
  28. echo " selected=yes";
  29. if (strlen($extra))
  30. echo " {$extra}";
  31. echo ">{$text}</option>";
  32. }
  33.  
  34. function help_link($text, $link = "") {
  35. global $page;
  36. if ($link == "") $link = $text;
  37. $href = "javascript:openHelp('$page[Plugin]/$link');";
  38. return "<a href=\"{$href}\">{$text}</a>";
  39. }
  40. function title_link() {
  41. global $page;
  42. $link = array_key_exists('Help', $page) ? $page['Help'] : $page['Title'];
  43. return help_link($page['Title'], $link);
  44. }
  45. function urlencode_path($path) {
  46. return str_replace("%2F", "/", urlencode($path));
  47. }
  48.  
  49. // Return sorted set of pages on the indicated menu.
  50. function find_pages( $menu) {
  51. global $page_array;
  52. $pages = array();
  53. foreach ($page_array as $page) {
  54. $tok = strtok( $page['Menu'], " ");
  55. while ($tok !== false) {
  56. $delim = strpos( $tok, ":");
  57. if ($delim) {
  58. $t = substr( $tok, 0, $delim);
  59. if ($t == $menu) {
  60. $key = substr( $tok, $delim+1) . $page['Name'];
  61. $pages[$key] = $page;
  62. break;
  63. }
  64. }
  65. else {
  66. if ($tok == $menu) {
  67. $pages[$page['Name']] = $page;
  68. break;
  69. }
  70. }
  71. $tok = strtok( " ");
  72. }
  73. }
  74. ksort( $pages);
  75. return $pages;
  76. }
  77.  
  78. // Suppose we want to render the page "http://tower/Main/Disk?name=disk1"
  79. // emhttp calls 'popen(cmdline)' where cmdline is:
  80.  
  81. // "cd /usr/local/emhttp; /usr/bin/php plugins/webGui/template.php name=disk1&path=Main/Disk"
  82. // argv[0] argv[1]
  83.  
  84. // The output of popen() (ie, the output generated by template.php) is written to
  85. // the http socket (after http headers have been output).
  86.  
  87. // Here's the document root of the webGui plugin
  88. $root = '/'.dirname( $argv[0]);
  89.  
  90. // Parse the 'querystring'
  91. // variables provided by emhttp:
  92. // path=<path> page path, e.g., path=Main/Disk
  93. // prev=<path> prev path, e.g., prev=Main (used to deterine if page was refreshed)
  94. parse_str($argv[1]);
  95.  
  96. // The current "task" is the first element of the path
  97. $task = strtok( $path, "/");
  98. $page = null;
  99.  
  100. // Read emhttp status
  101. $var = parse_ini_file( "/var/local/emhttp/var.ini");
  102. $sec = parse_ini_file( "/var/local/emhttp/sec.ini", TRUE);
  103. $devs = parse_ini_file( "/var/local/emhttp/devs.ini", TRUE);
  104. $disks = parse_ini_file( "/var/local/emhttp/disks.ini", TRUE);
  105. $users = parse_ini_file( "/var/local/emhttp/users.ini", TRUE);
  106. $shares = parse_ini_file( "/var/local/emhttp/shares.ini", TRUE);
  107. $sec_nfs = parse_ini_file( "/var/local/emhttp/sec_nfs.ini", TRUE);
  108. $sec_afp = parse_ini_file( "/var/local/emhttp/sec_afp.ini", TRUE);
  109.  
  110. // Build the pages
  111. $page_array = array();
  112. foreach (glob( "plugins/*/*.page", GLOB_NOSORT) as $entry) {
  113. $page = parse_ini_file( $entry);
  114. $page['Name'] = basename( $entry, ".page");
  115. $page['Root'] = dirname( $entry);
  116. $page['Plugin'] = basename( $page['Root']);
  117.  
  118. // assign defaults
  119. if (strlen($page['Author']) == 0)
  120. $page['Author'] = "anonymous";
  121. if (strlen($page['Version']) == 0)
  122. $page['Version'] = "unknown";
  123. if (strlen($page['Title']) == 0)
  124. $page['Title'] = $page['Name'];
  125. if (strlen($page['Type']) == 0)
  126. $page['Type'] = "echo 'Not much here.'";
  127.  
  128. if (strlen($page['Icon']) == 0)
  129. $page['Icon'] = "{$root}/images/default.png";
  130. else
  131. $page['Icon'] = "{$page['Root']}/{$page['Icon']}";
  132.  
  133. if (!array_key_exists( 'Menu', $page))
  134. $page['Menu'] = "";
  135.  
  136. // handle conditional inclusion on menus
  137. if (array_key_exists( 'Cond', $page)) {
  138. eval( "\$enabled=$page[Cond];");
  139. if (!$enabled)
  140. $page['Menu'] = "";
  141. }
  142.  
  143. // add to page_array
  144. $page_array[$page['Name']] = $page;
  145. }
  146.  
  147. // Here's the page we're rendering
  148. $myPage = $page_array[basename($path)];
  149.  
  150. // Gittyup
  151. ?>
  152. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  153.  
  154. <html lang="en">
  155. <head>
  156. <link rel="shortcut icon" href="<?=$root;?>/style/<?=$var['mdColor'];?>.gif" type="image/gif">
  157. <title><?=$var['NAME'];?>/<?=$myPage['Name'];?></title>
  158. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  159. <link rel="stylesheet" type="text/css" href="/plugins/webGui/style/template.css">
  160.  
  161. <script type="text/javascript">
  162. function refresh() {
  163. // disable all form elements on the page
  164. for (var i=0; i<top.window.document.forms.length; i++) {
  165. var x = top.window.document.forms[i];
  166. for(var j=0; j<x.length; j++){
  167. x.elements[j].disabled = true;
  168. }
  169. }
  170. // disable all links on the page
  171. for (var i=0; i<top.window.document.links.length; i++) {
  172. var x = top.window.document.links[i];
  173. // no cross-browser way to disable link, so just turn it gray :)
  174. x.style.color="gray";
  175. }
  176. // reload the page
  177. window.location=window.location;
  178. }
  179. function done() {
  180. var path=window.location.pathname;
  181. var x=path.indexOf("/",1);
  182. if (x != -1)
  183. path=path.substring(0,x);
  184. window.location.replace(path);
  185. }
  186. function chkDelete( form, button) {
  187. if (form.confirmDelete.checked)
  188. button.value='Delete';
  189. else
  190. button.value='Apply';
  191. }
  192. function openWindow( url, name) {
  193. var width=((screen.width*2)/3)|0;
  194. var height=((screen.height*2)/3)|0;
  195. var features="resizeable=yes,scrollbars=yes,width=" + width + ",height=" + height;
  196. var myWindow=window.open(url, name, features);
  197. myWindow.focus();
  198. return myWindow;
  199. }
  200. function openHelp( topic) {
  201. var url="http://lime-technology.com/wiki/index.php?title=Plugin/" + topic.replace(/ /g, "_");
  202. openWindow( url, "unRaidHelp");
  203. }
  204. function openLog( title) {
  205. var url="/update.htm?cmd=/usr/bin/tail -f /var/log/syslog&forkCmd=Start";
  206. var myWindow=openWindow( url, "unRaidLog");
  207. myWindow.document.title = title;
  208. return myWindow;
  209. }
  210. </script>
  211. </head>
  212.  
  213. <body>
  214.  
  215. <div class="Container">
  216. <div class="Header">
  217. <div class="Banner">
  218. <div class="BannerLogo">
  219. <a href="http://lime-technology.com"><img src="/plugins/webGui/images/logo.png"</img></a>
  220. </div>
  221. <div class="BannerTitle">
  222. <p><?=$var['NAME'];?><br><?=$var['COMMENT'];?></p>
  223. </div>
  224. <div class="BannerText">
  225. <p>unRAID Server <em><?=$var['regTy'];?></em>&nbsp;<br>version: <?=$var['version'];?>&nbsp;</p>
  226. </div>
  227. </div>
  228.  
  229. <div class="TaskBar">
  230. <? $pages = find_pages( "Tasks"); ?>
  231. <? foreach ($pages as $page): ?>
  232. <? $link="/{$page['Name']}"; ?>
  233. <? if ($page['Name']==$task): ?>
  234. <div class="tab_al"></div>
  235. <div class="tab_active"><a href="<?=$link;?>"><?=$page['Name'];?></a></div>
  236. <div class="tab_ar"></div>
  237. <? else: ?>
  238. <div class="tab_il"></div>
  239. <div class="tab_inactive"><a href="<?=$link;?>"><?=$page['Name'];?></a></div>
  240. <div class="tab_ir"></div>
  241. <? endif; ?>
  242. <? endforeach; ?>
  243. <div class="Buttons">
  244. <button type="button" onClick="javascript:openLog('<?=$var[NAME];?> system log');">Log</button>
  245. </div>
  246. </div>
  247. </div>
  248.  
  249. <div class="Content">
  250.  
  251. <? if ($myPage['Type'] == "xmenu"): ?>
  252. <? $pages = find_pages( $myPage['Name']); ?>
  253. <? else: ?>
  254. <? $pages = array(); ?>
  255. <? $pages[$myPage['Name']] = $myPage; ?>
  256. <? endif; ?>
  257.  
  258. <? foreach($pages as $page): ?>
  259. <? eval("\$page[Title]=\"$page[Title]\";"); ?>
  260. <p class="ContentTitle"><?=title_link();?></p>
  261. <hr>
  262. <? if ($page['Type'] == "menu"): ?>
  263. <div class="PanelSet">
  264. <? $pgs = find_pages( $page['Name']); ?>
  265. <? foreach($pgs as $pg): ?>
  266. <? $link="{$path}/{$pg['Name']}"; ?>
  267. <div class="Panel">
  268. <a href="<?=$link;?>">
  269. <img class="PanelImg" src="<?=$pg['Icon'];?>" title="<?=$pg['Title'];?>" alt="<?=$pg['Title'];?>"</img>
  270. <div class="PanelText"><a class="PanelText" href="<?=$link;?>"><?=$pg['Title'];?></a></div>
  271. </a>
  272. </div>
  273. <? endforeach; ?>
  274. </div>
  275. <? elseif ($page['Type'] == "php"): ?>
  276. <? include "{$page['Root']}/{$page['Name']}.php"; ?>
  277. <? else: ?>
  278. <? passthru( $page['Type']); ?>
  279. <? endif; ?>
  280. <? endforeach; ?>
  281.  
  282. </div>
  283.  
  284. <iframe id="progressFrame" name="progressFrame" frameborder="0"></iframe>
  285.  
  286. <div class="Footer">
  287. <div style="float:right;">Page author: <?=$myPage['Author'];?>, version: <?=$myPage['Version'];?>&nbsp;</div>
  288. <div>&nbsp;unRAID&#8482; webGui &copy;2010-2011 Lime Technology LLC</div>
  289. </div>
  290.  
  291. </div>
  292.  
  293. </body>
  294. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement