1<?php 2 3/* 4 Phoronix Test Suite 5 URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/ 6 Copyright (C) 2013 - 2014, Phoronix Media 7 Copyright (C) 2013 - 2014, Michael Larabel 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21*/ 22 23class pts_webui 24{ 25 public static function load_web_interface($interface, $PATH, $page_class_location, $html_class_loation = 'html/') 26 { 27 if(!class_exists($interface) && is_file($page_class_location . $interface . '.php')) 28 { 29 require($page_class_location . $interface . '.php'); 30 31 $response = $interface::preload($PATH); 32 33 if($response === true) 34 { 35 return $interface; 36 } 37 else if($response === false) 38 { 39 return false; 40 } 41 else 42 { 43 return self::load_web_interface($response, $PATH, $page_class_location, $html_class_loation); 44 } 45 } 46 else if(is_file($html_class_loation . $interface . '.html')) 47 { 48 return $interface; 49 } 50 51 return false; 52 } 53 public static function r2d_array_to_table(&$r2d, $width = '100%') 54 { 55 $ret = '<table width="' . $width . ';">'; 56 foreach($r2d as $row => $tr) 57 { 58 if(!is_array($tr) && !is_numeric($row)) 59 { 60 $tr = array($row, $tr); 61 } 62 63 $ret .= '<tr>'; 64 if(count($tr) == 1) 65 { 66 $ret .= '<th colspan="2" style="text-align: center;">' . $tr[0] . '</th>'; 67 } 68 else 69 { 70 foreach($tr as $col_i => $col) 71 { 72 $type = $col_i == 0 ? 'th' : 'td'; 73 $ret .= '<' . $type . '>' . $col . '</' . $type . '>'; 74 } 75 } 76 $ret .= '</tr>'; 77 } 78 $ret .= '</table>'; 79 80 return $ret; 81 } 82 public static function r1d_array_to_table(&$r1d) 83 { 84 echo '<table width="100%;">'; 85 foreach($r1d as $i => $td) 86 { 87 echo '<tr>'; 88 $type = $i == 0 ? 'th' : 'td'; 89 echo '<' . $type . ' style="text-align: center;">' . $td . '</' . $type . '>'; 90 echo '</tr>'; 91 } 92 echo '</table>'; 93 } 94 public static function websocket_setup_defines() 95 { 96 $pts_ws_port = getenv('PTS_WEBSOCKET_PORT'); 97 98 // http://www.phoronix.com/forums/showthread.php?102512-Remote-gui-not-accessible-in-Phoronix-Test-Suite-5-2&p=430312#post430312 99 if(!isset($_SERVER['SERVER_ADDR'])) 100 { 101 $_SERVER['SERVER_ADDR'] = gethostbyname(gethostname()); 102 } 103 104 if($_SERVER['SERVER_ADDR'] === '::1') 105 { 106 $server_address = 'localhost'; 107 } 108 else 109 { 110 $server_address = $_SERVER['SERVER_ADDR']; 111 } 112 113 define('PTS_WEBSOCKET_SERVER', 'ws://' . $server_address . ':' . $pts_ws_port . '/'); 114 setcookie('pts_websocket_server', PTS_WEBSOCKET_SERVER, (time() + 60 * 60 * 24), '/'); 115 } 116} 117 118?> 119