00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 function getSoftware() {
00033 return "<a href='/docs/" . exec('ls /usr/html/docs') . "'>" . exec('ls /usr/html/docs') . "</a> (get source)";
00034
00035 }
00036
00037 function soft_ver() {
00038 exec('/bin/ls /usr/html/docs', $arr);
00039 return implode($arr);
00040 }
00041
00042 function ps() {
00043 exec('ps -w', $arr);
00044 function low_daemon($v)
00045 {
00046 return (substr($v, -1) != ']');
00047 }
00048 $p = (array_filter($arr, "low_daemon"));
00049 return implode($p);
00050 }
00051
00052 function getSerial() {
00053 $s=exec("/bin/bootblocktool -x SERNO");
00054 return substr($s,0,2).":".substr($s,2,2).":".substr($s,4,2).":".substr($s,6,2).":".substr($s,8,2).":".substr($s,10,2);
00055 }
00056
00057 function fpga() {
00058 $arr = array();
00059 $s = exec("/bin/fpcf -r 13", $arr);
00060 return implode($arr);
00061 }
00062
00063 function cat_interupts() {
00064 $arr = array();
00065 $s = exec("/bin/cat /proc/interrupts", $arr);
00066 echo implode($arr);
00067 }
00068
00069 function cat_sdram() {
00070 $arr = array();
00071 $s = exec("/bin/cat /var/log/fpga_sdram_phase", $arr);
00072 echo implode($arr);
00073 }
00074
00075
00076 function read_ip() {
00077 $myFile = "/etc/conf.d/net.eth0";
00078 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00079 $data = fread($fr, filesize($myFile));
00080 fclose($fr);
00081 $pattern = '/IP=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/';
00082 preg_match($pattern, $data, $matches);
00083 $string = implode($matches);
00084 $output = substr($string, 3);
00085 return $output;
00086 }
00087
00088
00089 function read_broadcast() {
00090 $myFile = "/etc/conf.d/net.eth0";
00091 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00092 $data = fread($fr, filesize($myFile));
00093 fclose($fr);
00094 $pattern = '/BROADCAST=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/';
00095 preg_match($pattern, $data, $matches);
00096 $string = implode($matches);
00097 $output = substr($string, 10);
00098 return $output;
00099 }
00100
00101
00102 function read_gateway() {
00103 $myFile = "/etc/conf.d/net.eth0";
00104 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00105 $data = fread($fr, filesize($myFile));
00106 fclose($fr);
00107 $pattern = '/GATEWAY=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/';
00108 preg_match($pattern, $data, $matches);
00109 $string = implode($matches);
00110 $output = substr($string, 8);
00111 return $output;
00112 }
00113
00114
00115 function read_netmask() {
00116 $myFile = "/etc/conf.d/net.eth0";
00117 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00118 $data = fread($fr, filesize($myFile));
00119 fclose($fr);
00120 $pattern = '/NETMASK=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/';
00121 preg_match($pattern, $data, $matches);
00122 $string = implode($matches);
00123 $output = substr($string, 8);
00124 return $output;
00125 }
00126
00127 function change_gateway() {
00128 global $new_gateway;
00129 echo "<p>" . $new_gateway . " is set </p>";
00130 $myFile = "/etc/conf.d/net.eth0";
00131 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00132 $data = fread($fr, filesize($myFile));
00133 $replace_value = "GATEWAY=" . $new_gateway;
00134 fclose($fr);
00135 preg_match('/GATEWAY=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/', $data, $matches);
00136 $replace = str_replace($matches[0], $replace_value, $data);
00137 $fw = fopen($myFile, 'w') or die ("Can't open file in write mode");
00138 fwrite($fw, $replace);
00139 fclose($fw);
00140 }
00141
00142 function change_broadcast() {
00143 global $new_broadcast;
00144 echo "<p>" . $new_broadcast . " is set </p>";
00145 $myFile = "/etc/conf.d/net.eth0";
00146 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00147 $data = fread($fr, filesize($myFile));
00148 $replace_value = "BROADCAST=" . $new_broadcast;
00149 fclose($fr);
00150 preg_match('/BROADCAST=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/', $data, $matches);
00151 $replace = str_replace($matches[0], $replace_value, $data);
00152 $fw = fopen($myFile, 'w') or die ("Can't open file in write mode");
00153 fwrite($fw, $replace);
00154 fclose($fw);
00155 }
00156
00157 function changeIP() {
00158 global $new_ip;
00159 echo "<p>" . $new_ip . " is set </p>";
00160 global $new_ip;
00161 $myFile = "/etc/conf.d/net.eth0";
00162 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00163 $data = fread($fr, filesize($myFile));
00164 $replace_value = "IP=" . $new_ip;
00165 fclose($fr);
00166 preg_match('/IP=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/', $data, $matches);
00167 $replace = str_replace($matches[0], $replace_value, $data);
00168 $fw = fopen($myFile, 'w') or die ("Can't open file in write mode");
00169 fwrite($fw, $replace);
00170 fclose($fw);
00171 }
00172
00173 function change_netmask() {
00174 global $new_netmask;
00175 echo "<p>" . $new_netmask . " is set </p>";
00176 $myFile = "/etc/conf.d/net.eth0";
00177 $fr = fopen($myFile, 'r') or die("Can't open file in read mode");
00178 $data = fread($fr, filesize($myFile));
00179 $replace_value = "NETMASK=" . $new_netmask;
00180 fclose($fr);
00181 preg_match('/NETMASK=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/', $data, $matches);
00182 $replace = str_replace($matches[0], $replace_value, $data);
00183 $fw = fopen($myFile, 'w') or die ("Can't open file in write mode");
00184 fwrite($fw, $replace);
00185 fclose($fw);
00186 }
00187
00188
00189 function read_date() {
00190 exec("/bin/date", $arr);
00191 return implode($arr);
00192 }
00193
00194 function read_load() {
00195 exec("/bin/cat /proc/loadavg", $arr);
00196 return implode($arr);
00197 }
00198
00199 function daemon_counter(){
00200 #this is simply to count the number of keys for use by other functions
00201 exec("ps -w", $raw_array);
00202 unset($raw_array['0']);
00203 function rm($v){
00204 return (substr($v, -1) != ']');
00205 }
00206 $no_low_level = array_values(array_filter($raw_array, "rm"));
00207 $x = count($no_low_level);
00208 return $x;
00209 }
00210 $number_of_daemons = daemon_counter();
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 $xml = new SimpleXMLElement("<?xml version='1.0'?><cam_info/>");
00270 function gen_static_xml() {
00271 global $xml;
00272 $xml->addChild ('software');
00273 $version = $xml->software->addChild('version',soft_ver());
00274 $network = $xml->software->addChild('network');
00275 $ip = $xml->software->network->addChild('ip', read_ip());
00276 $netmask = $xml->software->network->addChild('netmask', read_netmask());
00277 $broadcast = $xml->software->network->addChild('broadcast', read_broadcast());
00278 $gateway = $xml->software->network->addChild('gateway', read_gateway());
00279 $date = $xml->software->addChild('cam_date',read_date());
00280
00281
00282
00283
00284 $proc_info = $xml->software->addChild('proc_info');
00285 $load = $xml->software->proc_info->addChild('load',read_load());
00286
00287 $proc = $xml->software->proc_info->addChild('proc',"<pre>".ps()."</pre>");
00288 $xml->addChild ('hardware');
00289 $ser_no = $xml->hardware->addChild('serial_number',getSerial());
00290
00291 $rslt=$xml->asXML();
00292
00293 header("Content-Type: text/xml");
00294 header("Content-Length: ".strlen($rslt)."\n");
00295 header("Pragma: no-cache\n");
00296 printf($rslt);
00297 }
00298
00299
00300
00301 function gen_dynamic_xml($req) {
00302
00303 $xml = new SimpleXMLElement(gen_static_xml());
00304
00305 switch ($req) {
00306 case 'ps':
00307 $xml->addChild('software');
00308 $proc_info = $xml->software->addChild('proc_info');
00309 $proc = $xml->software->proc_info->addChild('proc',"<pre>".ps()."</pre>");
00310 break;
00311 case 'load':
00312 $load = $xml->software->proc_info->addChild('load',read_load());
00313 break;
00314 }
00315
00316 header("Content-Type: text/xml");
00317 header("Content-Length: ".strlen($rslt)."\n");
00318 header("Pragma: no-cache\n");
00319 $rslt=$xml->asXML();
00320 printf($rslt);
00321 }
00322
00323 $req = $_GET['req'];
00324 $q = $_GET['q'];
00325
00326 if ($_GET['new_ip'] == null) {
00327 $new_ip = $_POST['new_ip'];
00328 } elseif (!($_GET['new_ip'] == null)) {
00329 $new_ip = $_GET['new_ip'];
00330 }
00331
00332 if ($_GET['new_netmask'] == null) {
00333 $new_netmask = $_POST['new_netmask'];
00334 } elseif (!($_GET['new_netmask'] == null)) {
00335 $new_netmask = $_GET['new_netmask'];
00336 }
00337
00338 if ($_GET['new_gateway'] == null) {
00339 $new_gateway = $_POST['new_gateway'];
00340 } elseif (!($_GET['new_gateway'] == null)) {
00341 $new_gateway = $_GET['new_gateway'];
00342 }
00343
00344 if ($_GET['new_broadcast'] == null) {
00345 $new_broadcast = $_POST['new_broadcast'];
00346 } elseif (!($_GET['new_broadcast'] == null)) {
00347 $new_broadcast = $_GET['new_broadcast'];
00348 }
00349
00350 if ($req == "" && $req == null && $q == "" && $q == null) {
00351 print_use();
00352 } elseif ($q == 'change') {
00353 switch ($req) {
00354 case "ip":
00355 changeIP();
00356 echo "ip will be changed to " . $new_ip . " on reboot<p><a href='./UI.html'>return to main</a></p>";
00357 break;
00358 case "netmask":
00359 change_netmask();
00360 echo "netmask will be changed to " . $new_netmask . " on reboot<p><a href='./UI.html'>return to main</a></p>";
00361 break;
00362 case "gateway":
00363 change_gateway();
00364 echo "gateway will be changed to " . $new_gateway . " on reboot<p><a href='./UI.html'>return to main</a></p>";
00365 break;
00366 case "broadcast":
00367 change_broadcast();
00368 echo "broadcast will be changed to " . $new_broadcast . " on reboot<p><a href='./UI.html'>return to main</a></p>";
00369 break;
00370 }
00371 } else {
00372 switch ($q) {
00373 case "dynamic":
00374 gen_dynamic_xml($req);
00375 break;
00376 case "static" || "compile":
00377 gen_static_xml();
00378 break;
00379 }
00380 }
00381 function print_use() {
00382 echo "<head><style type='text/css'>code {font-family:monospace} .variable{color:red}</style></head><body>";
00383 echo "<p>Usage:</p>";
00384 echo "<p><code>?q=static</code> or <code>?q=compile</code> »
00385 print a compiled information sheet of every function</p>";
00386 echo "<p><code>?q=dynamic&req=</code> or <code></code> »
00387 print current information about one function</p>";
00388
00389 echo "<p>These Network Functions cannot be strung together using
00390 and in any case require a camera restart. They do not verify if the
00391 network selection is valid, so use at your own risk!</p>";
00392
00393 echo "<p><code>?q=change&req=ip</code> or
00394 <code>?q=change&req=ip&new_ip=</code><span class='variable'>new ip</span> » change
00395 the ip to the POST variable '<span class='variable'>new_ip</span>' or whatever is specified in the url</p>";
00396 echo "<p><code>?q=change&req=netmask</code> or
00397 <code>?q=change&req=netmask&new_netmask=</code><span class='variable'>new netmask</span>
00398 » change the netmask to the POST variable '<span class='variable'>new_netmask</span>' or
00399 whatever is specified in the url</p>";
00400 echo "<p><code>?q=change&req=gateway</code> or
00401 <code>?q=change&req=gateway&new_gateway=</code><span class='variable'>new gateway</span>
00402 » change the gateway to the POST variable '<span class='variable'>new_gateway</span>' or
00403 whatever is specified in the url</p>";
00404 echo "<p><code>?q=change&req=broadcast</code> or
00405 <code>?q=change&req=broadcast&new_broadcast=</code><span class='variable'>new broadcast</span>
00406 » change the broadcast to the POST variable '<span class='variable'>new_broadcast</span>' or
00407 whatever is specified in the url</p>";
00408 echo "</body>";
00409 }
00410
00411
00412 ?>