source: branches/FACT++_part_filenames/www/showlog/index.php@ 19365

Last change on this file since 19365 was 18513, checked in by tbretz, 9 years ago
Added pfminictrl
File size: 12.1 KB
Line 
1<?php
2
3require_once("../smartfact/config.php");
4
5function login()
6{
7 global $ldaphost;
8 global $baseDN;
9 global $groupDN;
10
11 $username = $_SERVER['PHP_AUTH_USER'];
12 $password = $_SERVER['PHP_AUTH_PW'];
13
14 $con = @ldap_connect($ldaphost);
15 if (!$con)
16 return "ldap_connect failed to ".$ldaphost;
17
18 //------------------ Look for user common name
19 $attributes = array('cn', 'mail');
20 $dn = 'ou=People,'.$baseDN;
21 $filter = '(uid='.$username.')';
22
23 $sr = @ldap_search($con, $dn, $filter, $attributes);
24 if (!$sr)
25 return "ldap_search failed for dn=".$dn.": ".ldap_error($con);
26
27 $srData = @ldap_get_entries($con, $sr);
28 if ($srData["count"]==0)
29 return "No results returned by ldap_get_entries for dn=".$dn.".";
30
31 $email =$srData[0]['mail'][0];
32 $userCommonName=$srData[0]['cn'][0];
33 $userDN =$srData[0]['dn'];
34
35 //------------------ Authenticate user
36 if (!@ldap_bind($con, $userDN, $password))
37 return "ldap_bind failed: ".ldap_error($con);
38
39 //------------------ Check if the user is in FACT ldap group
40 $attributes= array("member");
41 $filter= '(objectClass=*)';
42
43 // Get all members of the group.
44 $sr = @ldap_read($con, $groupDN, $filter, $attributes);
45 if (!$sr)
46 return "ldap_read failed for dn=".$groupDN.": ".ldap_error($con);
47
48 // retrieve the corresponding data
49 $srData = @ldap_get_entries($con, $sr);
50 if ($srData["count"]==0)
51 return "No results returned by ldap_get_entries for dn=".$dn.".";
52
53 @ldap_unbind($con);
54
55 $found = false;
56 foreach ($srData[0]['member'] as $member)
57 if (strpos($member, "cn=".$userCommonName.",")===0)
58 return "";
59
60 return "Sorry, your credentials don't match!";
61}
62
63/*
64function ascii2entities($string)
65{
66 for ($i=128; $i<256; $i++)
67 {
68 $entity = htmlentities(chr($i), ENT_QUOTES, 'cp1252');
69 $temp = substr($entity, 0, 1);
70 $temp .= substr($entity, -1, 1);
71 $string = str_replace(chr($i), $temp!='&;'?'':$entity, $string);
72 }
73 return $string;
74}
75*/
76
77function ansi_decode($matches)
78{
79 static $colors =
80 array(
81 'black',
82 'maroon',
83 'green',
84 'olive',
85 'navy',
86 'purple',
87 'teal',
88 'silver',
89 'gray',
90 'red',
91 'lime',
92 'yellow',
93 'blue',
94 'fuchsia',
95 'aqua',
96 'white'
97 );
98
99 // Default styles.
100 static $styles =
101 array(
102 'background' => null, // Default is defined by the stylesheet.
103 'blink' => false,
104 'bold' => false,
105 'color' => null, // Default is defined by the stylesheet.
106 //'inverse' => false, // Cannot be expressed in terms of CSS!
107 'italic' => false, // Not supported by DarkOwl's ANSI.
108 'line-through' => false, // Not supported by DarkOwl's ANSI.
109 'underline' => false,
110 );
111
112 static $css = '';
113
114 // Copy the previous styles.
115 $newstyles = $styles;
116 // Extract the codes from the escape sequences.
117 preg_match_all('/\d+/', $matches[0], $matches);
118
119 // Walk through the codes.
120 foreach ($matches[0] as $code)
121 {
122 switch ($code)
123 {
124 case '0':
125 // Reset all styles.
126 $newstyles['background'] = null;
127 $newstyles['blink'] = false;
128 $newstyles['bold'] = false;
129 $newstyles['color'] = null;
130 // $newstyles['inverse'] = false;
131 $newstyles['italic'] = false;
132 $newstyles['line-through'] = false;
133 $newstyles['underline'] = false;
134 break;
135
136 case '1':
137 // Set the bold style.
138 $newstyles['bold'] = true;
139 break;
140
141 case '3':
142 // Set the italic style.
143 $newstyles['italic'] = true;
144 break;
145
146 case '4':
147 case '21': // Actually double underline, but CSS doesn't support that yet.
148 // Set the underline style.
149 $newstyles['underline'] = true;
150 break;
151
152 case '5':
153 case '6': // Actually rapid blinking, but CSS doesn't support that.
154 // Set the blink style.
155 $newstyles['blink'] = true;
156 break;
157
158// case '7':
159// // Set the inverse style.
160// $newstyles['inverse'] = true;
161// break;
162
163 case '9':
164 // Set the line-through style.
165 $newstyles['line-through'] = true;
166 break;
167
168 case '2': // Previously incorrectly interpreted by Pueblo/UE as cancel bold, now still supported for backward compatibility.
169 case '22':
170 // Reset the bold style.
171 $newstyles['bold'] = false;
172 break;
173
174 case '23':
175 // Reset the italic style.
176 $newstyles['italic'] = false;
177 break;
178
179 case '24':
180 // Reset the underline style.
181 $newstyles['underline'] = false;
182 break;
183
184 case '25':
185 // Reset the blink style.
186 $newstyles['blink'] = false;
187 break;
188
189// case '27':
190// // Reset the inverse style.
191// $newstyles['inverse'] = false;
192// break;
193
194 case '29':
195 // Reset the line-through style.
196 $newstyles['line-through'] = false;
197 break;
198
199 case '30': case '31': case '32': case '33': case '34': case '35': case '36': case '37':
200 // Set the foreground color.
201 $newstyles['color'] = $code - 30;
202 break;
203
204 case '39':
205 // Reset the foreground color.
206 $newstyles['color'] = null;
207 break;
208
209 case '40': case '41': case '42': case '43': case '44': case '45': case '46': case '47':
210 // Set the background color.
211 $newstyles['background'] = $code - 40;
212 break;
213
214 case '49':
215 // Reset the background color.
216 $newstyles['background'] = null;
217 break;
218
219 default:
220 // Unsupported code; simply ignore.
221 break;
222 }
223 }
224
225 // Styles are effectively unchanged; return nothing.
226 if ($newstyles === $styles)
227 return '';
228
229 // Copy the new styles.
230 $styles = $newstyles;
231 // If there's a previous CSS in effect, close the <span>.
232 $html = $css ? '</span>' : '';
233 // Generate CSS.
234 $css = '';
235
236 // background-color property.
237 if (!is_null($styles['background']))
238 $css .= ($css ? ';' : '') . "background-color:{$colors[$styles['background']]}";
239
240 // text-decoration property.
241 if ($styles['blink'] || $styles['line-through'] || $styles['underline'])
242 {
243 $css .= ($css ? ';' : '') . 'text-decoration:';
244
245 if ($styles['blink'])
246 $css .= 'blink';
247
248 if ($styles['line-through'])
249 $css .= 'line-through';
250
251 if ($styles['underline'])
252 $css .= 'underline';
253 }
254
255 // font-weight property.
256 if ($styles['bold'] && is_null($styles['color']))
257 $css .= ($css ? ';' : '') . 'font-weight:bold';
258
259 // color property.
260 if (!is_null($styles['color']))
261 $css .= ($css ? ';' : '') . "color:{$colors[$styles['color'] | $styles['bold'] << 3]}";
262
263 // font-style property.
264 if ($styles['italic'])
265 $css .= ($css ? ';' : '') . 'font-style:italic';
266
267 // Generate and return the HTML.
268 if ($css)
269 $html .= "<span style=\"$css\">";
270
271 return $html;
272}
273
274function ansi2html($str)
275{
276 // Replace database strings
277 $str = preg_replace("/\ (([[:word:].-]+)(:[^ ]+)?(@))?([[:word:].-]+)(:([[:digit:]]+))?(\/([[:word:].-]+))/", " $2$4$5$8", $str);
278
279 // Replace special characters to their corresponding HTML entities
280 //$str = ascii2entities($str);
281 $str = htmlentities($str, ENT_NOQUOTES);
282
283 // Replace ANSI codes.
284 $str = preg_replace_callback('/(?:\e\[\d+(?:;\d+)*m)+/', 'ansi_decode', "$str\033[0m");
285
286 // Strip ASCII bell.
287 // $str = str_replace("\007", '', $str);
288
289 // Replace \n
290 // $str = str_replace("\n", "<br/>\n", $str);
291
292 // Return the parsed string.
293 return $str;
294}
295
296if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
297{
298 header('WWW-Authenticate: Basic realm="SmartFACT++"');
299 header('HTTP/1.1 401 Unauthorized');
300 return;
301}
302
303$rc = login();
304if ($rc!="")
305 return header('HTTP/1.1 401 '.$rc);
306
307$refresh = isset($_GET['refresh']) ? $_GET['refresh'] : -1;
308if ($refresh>0 && $refresh<60)
309 $refresh = 60;
310
311unset($_GET['refresh']);
312
313$prg = empty($_GET['log']) ? "dimserver" : $_GET['log'];
314$dir = empty($_GET['dir']) ? "" : $_GET['dir'];
315
316if (!strpos($prg, "/")===false || !strpos($dir, "/")===false)
317{
318 header('HTTP/1.1 403 Access forbidden.');
319 print("HTTP/1.1 403 Access forbidden.\n");
320 return;
321}
322
323if (empty($_GET['dir']))
324{
325 if ($prg=="schedule")
326 $prg = "scripts/schedule.js";
327
328 $filename = "/users/fact/operation/".$prg;
329 if (is_link($filename))
330 $filename = "/users/fact/operation/".dirname(readlink($filename))."/".$prg.".log";
331}
332
333if (empty($filename))
334 $filename = "/users/fact/".$dir."/".$prg.".log";
335
336$size = filesize($filename);
337
338$file=array();
339$fp = fopen($filename, "r");
340
341if ($fp===false)
342{
343 header('HTTP/1.1 403 Access forbidden.');
344 print("Access forbidden.\n");
345 return;
346}
347
348fseek($fp, -min(10000000, $size), SEEK_END);
349fgets($fp);
350while(!feof($fp))
351{
352 $line = fgets($fp);
353 array_push($file, $line);
354}
355fclose($fp);
356
357
358$dir = basename(dirname($filename));
359$name = basename($filename);
360?>
361
362<!DOCTYPE HTML>
363<html>
364<head>
365<?php
366if ($refresh>0)
367 print("<meta http-equiv='refresh' content='".$refresh."'>\n");
368?>
369<meta charset="UTF-8">
370<title><?php print($dir." - ".$name);?></title>
371<link rel="stylesheet" type="text/css" href="index.css" />
372<script src="jquery-2.0.0.min.js" type="text/javascript"></script>
373<script>
374$(function(){
375 $("#nav li:has(ul)").hover(function(){
376 $(this).find("ul").slideDown(200);
377 }, function(){
378 $(this).find("ul").hide();
379 });
380});
381</script>
382</head>
383<body onload="if (location.hash.length==0) location.hash = '#bottom';">
384<a class="up" href="#top">go to top &uarr;</a>
385<span id="nav">
386 <ul>
387 <li>
388 <a>Logs</a>
389 <ul>
390 <li><a href="?log=biasctrl">biasctrl</a></li>
391 <li><a href="?log=agilentctrl">agilentctrl</a></li>
392 <li><a href="?log=chatserv">chatserv</a></li>
393 <li><a href="?log=datalogger">datalogger</a></li>
394 <li><a href="?log=dimserver"><b>dimserver</b></a></li>
395 <li><a href="?log=dimctrl">dimctrl</a></li>
396 <li><a href="?log=drivectrl">drivectrl</a></li>
397 <li><a href="?log=fadctrl">fadctrl</a></li>
398 <li><a href="?log=feedback">feedback</a></li>
399 <li><a href="?log=fscctrl">fscctrl</a></li>
400 <li><a href="?log=ftmctrl">ftmctrl</a></li>
401 <li><a href="?log=gcn">gcn</a></li>
402 <li><a href="?log=gpsctrl">gpsctrl</a></li>
403 <li><a href="?log=lidctrl">lidctrl</a></li>
404 <li><a href="?log=magiclidar">magiclidar</a></li>
405 <li><a href="?log=magicweather">magicweather</a></li>
406 <li><a href="?log=mcp">mcp</a></li>
407 <li><a href="?log=pwrctrl">pwrctrl</a></li>
408 <li><a href="?log=ratecontrol">ratecontrol</a></li>
409 <li><a href="?log=ratescan">ratescan</a></li>
410 <li><a href="?log=sqmctrl">sqmctrl</a></li>
411 <li><a href="?log=temperature">temperature</a></li>
412 <li><a href="?log=timecheck">timecheck</a></li>
413 <li><a href="?log=tngweather">tngweather</a></li>
414 <li><a href="?log=pfminictrl">pfminictrl</a></li>
415 </ul>
416 </li>
417 </ul>
418</span>
419</span>
420<a class="dn" href="#bottom">go to bottom &darr;</a>
421
422
423<H2 id="top"><?php printf("%s - %s (%dkB)", $dir, $name, $size/1000);?></H2>
424
425<pre style="font-size:small;font-family:'Lucida Console',Monaco,monospace">
426<?php
427foreach ($file as $line)
428 print(ansi2html(substr($line, 0, -1))."\n");
429?>
430
431</pre>
432<div id="bottom"></div>
433</body>
434</html>
Note: See TracBrowser for help on using the repository browser.