1 | <?php
|
---|
2 |
|
---|
3 | require_once("smartfact/config.php");
|
---|
4 |
|
---|
5 | function 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 | /*
|
---|
64 | function 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 |
|
---|
77 | function 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 |
|
---|
274 | function 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 |
|
---|
296 | if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
|
---|
297 | {
|
---|
298 | header('WWW-Authenticate: Basic realm="SmartFACT++"');
|
---|
299 | header('HTTP/1.0 401 Unauthorized');
|
---|
300 | return;
|
---|
301 | }
|
---|
302 |
|
---|
303 | $rc = login();
|
---|
304 | if ($rc!="")
|
---|
305 | return header('HTTP/1.0 401 '.$rc);
|
---|
306 |
|
---|
307 | $refresh = isset($_GET['refresh']) ? $_GET['refresh'] : -1;
|
---|
308 | if ($refresh>0 && $refresh<60)
|
---|
309 | $refresh = 60;
|
---|
310 |
|
---|
311 | unset($_GET['refresh']);
|
---|
312 |
|
---|
313 | $prg = empty($_GET['log']) ? "dimserver" : $_GET['log'];
|
---|
314 | $dir = $_GET['dir'];
|
---|
315 |
|
---|
316 | if (!strpos($prg, "/")===false || !strpos($dir, "/")===false)
|
---|
317 | return header('HTTP/1.0 403 Access forbidden.');
|
---|
318 |
|
---|
319 | if (empty($dir))
|
---|
320 | {
|
---|
321 | if ($prg=="schedule")
|
---|
322 | $prg = "scripts/schedule.js";
|
---|
323 |
|
---|
324 | $filename = "/users/fact/operation/".$prg;
|
---|
325 | if (is_link($filename))
|
---|
326 | $filename = "/users/fact/operation/".dirname(readlink($filename))."/".$prg.".log";
|
---|
327 | }
|
---|
328 |
|
---|
329 | if (empty($filename))
|
---|
330 | $filename = "/users/fact/".$dir."/".$prg.".log";
|
---|
331 |
|
---|
332 | $size = filesize($filename);
|
---|
333 | if ($size>30000000) // 30MB
|
---|
334 | return header('HTTP/1.0 403 File too large.');
|
---|
335 |
|
---|
336 | // FIXME: Reading the file line by line avoids any danger that
|
---|
337 | // something yields a problem if files grow too large
|
---|
338 | $file = file($filename);
|
---|
339 | if ($file===false)
|
---|
340 | return header('HTTP/1.0 403 Access forbidden.');
|
---|
341 |
|
---|
342 | $max = 10000;
|
---|
343 | $pos = 500;
|
---|
344 | $n = count($file);
|
---|
345 | if ($n>$max)
|
---|
346 | {
|
---|
347 | $file[$pos] = "\n<b>[...]</b>\n\n";
|
---|
348 | array_splice($file, $pos+1, $n-$max);
|
---|
349 | }
|
---|
350 |
|
---|
351 | $dir = basename(dirname($filename));
|
---|
352 | $name = basename($filename);
|
---|
353 |
|
---|
354 | ?>
|
---|
355 | <!DOCTYPE HTML>
|
---|
356 | <html>
|
---|
357 | <head>
|
---|
358 | <?php
|
---|
359 | if ($refresh>0)
|
---|
360 | print("<meta http-equiv='refresh' content='".$refresh."'>\n");
|
---|
361 | ?>
|
---|
362 | <meta charset="UTF-8">
|
---|
363 | <title><?php print($dir." - ".$name);?></title>
|
---|
364 | <link rel="stylesheet" type="text/css" href="showlog.css" />
|
---|
365 | <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
|
---|
366 | <script>
|
---|
367 | function scroll(top)
|
---|
368 | {
|
---|
369 | document.getElementById(top?'top':'bottom').scrollIntoView(top);
|
---|
370 | }
|
---|
371 | $(document).ready(function() {
|
---|
372 | $("#nav li:has(ul)").hover(function(){
|
---|
373 | $(this).find("ul").slideDown(200);
|
---|
374 | }, function(){
|
---|
375 | $(this).find("ul").hide();
|
---|
376 | });
|
---|
377 | });
|
---|
378 | </script>
|
---|
379 | </head>
|
---|
380 | <body onload="setTimeout(function(){scroll(false);},1);">
|
---|
381 | <span onclick="scroll(true);" class="up">go to top ↑</span>
|
---|
382 | <span id="nav">
|
---|
383 | <ul>
|
---|
384 | <li>
|
---|
385 | <a>Logs</a>
|
---|
386 | <ul>
|
---|
387 | <li><a href="?log=biasctrl">biasctrl</a></li>
|
---|
388 | <li><a href="?log=agilentctrl">agilentctrl</a></li>
|
---|
389 | <li><a href="?log=chatserv">chatserv</a></li>
|
---|
390 | <li><a href="?log=datalogger">datalogger</a></li>
|
---|
391 | <li><a href="?log=dimserver"><b>dimserver</b></a></li>
|
---|
392 | <li><a href="?log=dimctrl">dimctrl</a></li>
|
---|
393 | <li><a href="?log=drivectrl">drivectrl</a></li>
|
---|
394 | <li><a href="?log=fadctrl">fadctrl</a></li>
|
---|
395 | <li><a href="?log=feedback">feedback</a></li>
|
---|
396 | <li><a href="?log=fscctrl">fscctrl</a></li>
|
---|
397 | <li><a href="?log=ftmctrl">ftmctrl</a></li>
|
---|
398 | <li><a href="?log=lidctrl">lidctrl</a></li>
|
---|
399 | <li><a href="?log=magiclidar">magiclidar</a></li>
|
---|
400 | <li><a href="?log=magicweather">magicweather</a></li>
|
---|
401 | <li><a href="?log=mcp">mcp</a></li>
|
---|
402 | <li><a href="?log=pwrctrl">pwrctrl</a></li>
|
---|
403 | <li><a href="?log=ratecontrol">ratecontrol</a></li>
|
---|
404 | <li><a href="?log=ratescan">ratescan</a></li>
|
---|
405 | <li><a href="?log=temperature">temperature</a></li>
|
---|
406 | <li><a href="?log=timecheck">timecheck</a></li>
|
---|
407 | <li><a href="?log=tngweather">tngweather</a></li>
|
---|
408 | </ul>
|
---|
409 | </li>
|
---|
410 | </ul>
|
---|
411 | </span>
|
---|
412 | </span>
|
---|
413 | <span onclick="scroll(false);" class="dn">go to bottom ↓</span>
|
---|
414 |
|
---|
415 |
|
---|
416 | <H2 id="top"><?php printf("%s - %s (%dkB)", $dir, $name, $size/1000);?></H2>
|
---|
417 |
|
---|
418 | <pre style="font-size:small;font-family:'Lucida Console',Monaco,monospace">
|
---|
419 | <?php
|
---|
420 | foreach ($file as $line)
|
---|
421 | print(ansi2html(substr($line, 0, -1))."\n");
|
---|
422 | ?>
|
---|
423 |
|
---|
424 | </pre>
|
---|
425 | <span id="bottom"></span>
|
---|
426 | </body>
|
---|
427 | </html>
|
---|