Magellan Linux

Diff of /alx-src/trunk/alx-web/index.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 535 by niro, Wed Jun 4 23:27:34 2008 UTC revision 536 by niro, Wed Sep 17 06:17:56 2008 UTC
# Line 1  Line 1 
1  <?  <?
2   include('include/basesql.php');   include('include/basesql.php');
3   session_start();   session_start();
4   session_register('alx_sort_krit'); session_register('alx_sort_onfirst'); session_register('alx_sort_loc');   session_register('alx_sort_krit'); session_register('alx_sort_onfirst'); session_register('alx_sort_loc');
   
  $locations = sqlarr('SELECT location FROM client_locations', '', 'location');  
  $locations[] = '';  
   
  if($_SESSION['alx_sort_krit']==null)  
  {  
  $_SESSION['alx_sort_krit'] = 'serial';  
  $_SESSION['alx_sort_onfirst'] = 1;  
  $_SESSION['alx_sort_loc'] = array('DEAD'=>false);  
  foreach($locations as $l) $_SESSION['alx_sort_loc'][$l]=true;  
  }  
  if(isset($_GET['s_krit']))  
  {  
  $_SESSION['alx_sort_krit']=$_GET['s_krit'];  
  $_SESSION['alx_sort_onfirst']=0+$_GET['s_on'];  
  $_SESSION['alx_sort_loc']['DEAD']=$_GET['s_dead'];  
  foreach($locations as $l) $_SESSION['alx_sort_loc'][$l]=$_GET['s_'.$l];  
  }  
   
  function check_online($dat, $bla)  
  {  
  global $comps;  
  global $pingcmd;  
   
  if(!isset($comps[$dat['serial']])) return false;  
   
  passthru($pingcmd." ".$dat['ip']." &> /dev/null && exit 0 || exit 1",$retval);  
  if($retval==0)  
  {  
  $comps[$dat['serial']]['online'] = true;  
  $comps[$dat['serial']]['ip'] = $dat['ip'];  
  }  
  else $comps[$dat['serial']]['ip'] = '<font color=#a00000>'.$dat['ip'].' <small>(no ping)</small></font>';  
5    
6   $comps[$dat['serial']]['hostname'] = $dat['hostname'];   $locations = sqlarr('SELECT location FROM client_locations', '', 'location');
7   $comps[$dat['serial']]['mac'] = $dat['mac'];   $locations[] = '';
  }  
   
  function sortcomp($a,$b)  
  {  
  if($a['serial']<0 && $b['serial']>0) return -1;  
  if($a['serial']>0 && $b['serial']<0) return 1;  
   
  if($_SESSION['alx_sort_onfirst'])  
  {  
  if($a['online'] && !$b['online']) return -1;  
  if($b['online'] && !$a['online']) return 1;  
  }  
  if($_SESSION['alx_sort_krit']=='hostname')  
  {  
  if(strtoupper($a['hostname'])<strtoupper($b['hostname'])) return -1;  
  else if(strtoupper($a['hostname'])>strtoupper($b['hostname'])) return 1;  
  }  
  return $a['serial']-$b['serial'];  
  }  
   
  function checkif($b)  
  { if($b) return ' checked'; else return ''; }  
   
  $comps = sqlarr('SELECT s.serial, s.location, s.mac, n.hostname FROM cfg_network n,client_serials s WHERE n.serial=s.serial', 'serial');  
  sqlforeach('SELECT serial, ip, hostname, mac FROM state_connected', 'check_online', null);  
  usort($comps, 'sortcomp');  
   
  echo '<head>';  
  echo '<title>ALX Config - Index</title>';  
  echo '<script language="JavaScript">';  
  echo 'function loc(name) { window.open(\'loc.php?location=\'+name, \'\', \'width=350,height=180\'); }';  
  echo '</script>';  
  echo '</head>';  
  echo '<body onload="window.setTimeout(\'location.reload()\',60000)">';  
   
  /*  
  echo '<img src="logo.jpg" align=middle>';  
  echo '<a href="index.php" style="padding-left:170px; color:#000000;text-decoration:none; font-weight:bold">[REFRESH]</a><br>';  
   
  echo '<form action="index.php" method="get" style="margin-top:0px"><b>SORT BY</b> <input onclick="this.form.submit()" type="radio" name="s_krit" value="serial"'.checkif($_SESSION['alx_sort_krit']=='serial').'>serial <input onclick="this.form.submit()" type="radio" name="s_krit" value="hostname"'.checkif($_SESSION['alx_sort_krit']=='hostname').'>hostname';  
  echo '<input onclick="this.form.submit()" style="margin-left:125px" name="s_on" type="checkbox" value="1"'.checkif($_SESSION['alx_sort_onfirst']).'>online clients on top</form><br>';  
  */  
   
  echo '<form action="index.php" method="get" style="margin:0px">';  
  echo '<table width=480><tr>';  
  echo '<td><img src="pics/logo.jpg"></td>';  
  echo '<td align=right valign=top><a href="index.php" style="color:#000000;text-decoration:none; font-weight:bold">[REFRESH]</a></td>';  
  echo '</tr><tr>';  
  echo '<td valign=top><b>SORT BY</b> <input onclick="this.form.submit()" type="radio" name="s_krit" value="serial"'.checkif($_SESSION['alx_sort_krit']=='serial').'>serial <input onclick="this.form.submit()" type="radio" name="s_krit" value="hostname"'.checkif($_SESSION['alx_sort_krit']=='hostname').'>hostname<br>';  
  echo '<input onclick="this.form.submit()" name="s_on" style="margin-left:72px" type="checkbox" value="1"'.checkif($_SESSION['alx_sort_onfirst']).'>online clients on top</td>';  
  echo '<td align=right valign=top>';  
   
  foreach($locations as $l)  
  echo '<input onclick="this.form.submit()" type="checkbox" name="s_'.$l.'" value="1"'.checkif($_SESSION['alx_sort_loc'][$l]).'><a href="JavaScript:loc(\''.$l.'\')" style="color:#000000">'.($l=='' ? '?' : $l).'</a>';  
   
  echo '<br/>';  
  echo '<input onclick="this.form.submit()" type="checkbox" name="s_dead" value="1"'.checkif($_SESSION['alx_sort_loc']['DEAD']).'>DEACTIVATED';  
  echo '</td>';  
  echo '</tr></table><br>';  
  echo '</form>';  
   
   
  echo '<table border>';  
  echo '<tr style="font-weight:bold;background-color:#d5e5ff"><td>edit</td><td colspan=3>serial</td><td width=170>hostname</td><td width=100>ip</td>';  
  if($showversion=='on') echo '<td colspan=2>version</td>';  
  echo '<td>up/down</td></tr>';  
   
  foreach($comps as $c)  
  {  
  if(!$_SESSION['alx_sort_loc'][$c['location']]) Continue;  
  if($c['serial']<0 && !$_SESSION['alx_sort_loc']['DEAD']) Continue;  
   
  if($c['online']) $pic='online'; else $pic='offline';  
   
  if($c['serial']<0) { echo '<tr style="text-decoration:line-through; color:#aaaaaa">'; $pic = 'deact'; }  
  else echo '<tr>';  
   
  echo '<td><input type=button value="EDIT" onclick="location.href=\'show.php?id='.$c['serial'].'\'"></td>';  
  echo '<td>'.substr($c['location'],0,1).'</td>';  
  echo '<td><img src="pics/'.$pic.'.gif" alt="'.strtoupper($pic).'"></td>';  
  echo '<td width=40><b>#'.$c['serial'].'</b></td>';  
  echo '<td><nobr>'.$c['hostname'].'</nobr></td>';  
8    
9   echo '<td><nobr>'.$c['ip'].'</nobr></td>';   if($_SESSION['alx_sort_krit']==null)
10     {
11     $_SESSION['alx_sort_krit'] = 'serial';
12     $_SESSION['alx_sort_onfirst'] = 1;
13     $_SESSION['alx_sort_loc'] = array('DEAD'=>false);
14     foreach($locations as $l) $_SESSION['alx_sort_loc'][$l]=true;
15     }
16     if(isset($_GET['s_krit']))
17     {
18     $_SESSION['alx_sort_krit']=$_GET['s_krit'];
19     $_SESSION['alx_sort_onfirst']=0+$_GET['s_on'];
20     $_SESSION['alx_sort_loc']['DEAD']=$_GET['s_dead'];
21     foreach($locations as $l) $_SESSION['alx_sort_loc'][$l]=$_GET['s_'.$l];
22     }
23    
24   if($c['online'])   function check_online($dat, $bla)
25   {   {
26   if($showversion=='on')   global $comps;
27     global $pingcmd;
28    
29     if(!isset($comps[$dat['serial']])) return false;
30    
31     passthru($pingcmd." ".$dat['ip']." &> /dev/null && exit 0 || exit 1",$retval);
32     if($retval==0)
33   {   {
34   $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$c['serial'].'');   $comps[$dat['serial']]['online'] = true;
35   while ($row = mysql_fetch_row ($pubkey)) {   $comps[$dat['serial']]['ip'] = $dat['ip'];
36   # schreiben der .ssh/known_hosts file mit dem public rsa key des client,   }
37   # um die "yes" abfrage zu vermeiden   else $comps[$dat['serial']]['ip'] = '<font color=#a00000>'.$dat['ip'].' <small>(no ping)</small></font>';
  $hostfile = fopen ($home."/.ssh/known_hosts","w");  
  fwrite($hostfile,$c['ip']." ".$row[0],strlen($row[0])+strlen($c['ip'])+1);  
  fclose($hostfile);  
38    
39   $osver = exec($sshcmd.' -l root '.$c['ip'].' \'os_ver=$(<'.$mageversion.');cfg_ver=$(/sbin/magequery -n '.$alxconfig.'|cut -d" " -f5);pname=${cfg_ver%-*-*};cfg_ver=${cfg_ver/${pname}-};echo "${os_ver}:${cfg_ver}"\'');   $comps[$dat['serial']]['hostname'] = $dat['hostname'];
40   $osver = explode(':',$osver);   $comps[$dat['serial']]['mac'] = $dat['mac'];
  }  
  if($osver[0] == '') $osver[0]='unkown';  
  if($osver[1] == '') $osver[1]='unkown';  
          echo '<td>'.$osver[0].'</td>';  
          echo '<td>'.$osver[1].'</td>';  
         }  
41   }   }
42    
43   echo '<td>';   function sortcomp($a,$b)
44   if($c['online'])   {
45   {   if($a['serial']<0 && $b['serial']>0) return -1;
46   echo '<input type=button style="width:50%" value="RB" onclick="if(confirm(\'REBOOT CLIENT #'.$c['serial'].' ?\')) window.open(\'reboot.php?client='.$c['serial'].'&ip='.$c['ip'].'&op=reboot\', \'ShutdownWin\', \'width=200,height=100\')">';   if($a['serial']>0 && $b['serial']<0) return 1;
47   echo '<input type=button style="width:50%" value="SD" onclick="if(confirm(\'SHUTDOWN CLIENT #'.$c['serial'].' ?\')) window.open(\'reboot.php?client='.$c['serial'].'&ip='.$c['ip'].'&op=halt\', \'ShutdownWin\', \'width=200,height=100\')">';  
48     if($_SESSION['alx_sort_onfirst'])
49     {
50     if($a['online'] && !$b['online']) return -1;
51     if($b['online'] && !$a['online']) return 1;
52     }
53     if($_SESSION['alx_sort_krit']=='hostname')
54     {
55     if(strtoupper($a['hostname'])<strtoupper($b['hostname'])) return -1;
56     else if(strtoupper($a['hostname'])>strtoupper($b['hostname'])) return 1;
57     }
58     return $a['serial']-$b['serial'];
59   }   }
60   else echo '<input type=button style="width:100%" value="WOL" onclick="if(confirm(\'WAKE CLIENT #'.$c['serial'].' ?\')) window.open(\'wake_on_lan.php?mac='.$c['mac'].'\', \'WakeWin\', \'width=200,height=100\')">';  
61     function checkif($b)
62     { if($b) return ' checked'; else return ''; }
63    
64     $comps = sqlarr('SELECT s.serial, s.location, s.mac, n.hostname FROM cfg_network n,client_serials s WHERE n.serial=s.serial', 'serial');
65     sqlforeach('SELECT serial, ip, hostname, mac FROM state_connected', 'check_online', null);
66     usort($comps, 'sortcomp');
67    
68     echo '<head>';
69     echo '<title>ALX Config - Index</title>';
70     echo '<script language="JavaScript">';
71     echo 'function loc(name) { window.open(\'loc.php?location=\'+name, \'\', \'width=350,height=180\'); }';
72     echo '</script>';
73     echo '</head>';
74     echo '<body onload="window.setTimeout(\'location.reload()\',60000)">';
75    
76     /*
77     echo '<img src="logo.jpg" align=middle>';
78     echo '<a href="index.php" style="padding-left:170px; color:#000000;text-decoration:none; font-weight:bold">[REFRESH]</a><br>';
79    
80     echo '<form action="index.php" method="get" style="margin-top:0px"><b>SORT BY</b> <input onclick="this.form.submit()" type="radio" name="s_krit" value="serial"'.checkif($_SESSION['alx_sort_krit']=='serial').'>serial <input onclick="this.form.submit()" type="radio" name="s_krit" value="hostname"'.checkif($_SESSION['alx_sort_krit']=='hostname').'>hostname';
81     echo '<input onclick="this.form.submit()" style="margin-left:125px" name="s_on" type="checkbox" value="1"'.checkif($_SESSION['alx_sort_onfirst']).'>online clients on top</form><br>';
82     */
83    
84     echo '<form action="index.php" method="get" style="margin:0px">';
85     echo '<table width=480><tr>';
86     echo '<td><img src="pics/logo.jpg"></td>';
87     echo '<td align=right valign=top><a href="index.php" style="color:#000000;text-decoration:none; font-weight:bold">[REFRESH]</a></td>';
88     echo '</tr><tr>';
89     echo '<td valign=top><b>SORT BY</b> <input onclick="this.form.submit()" type="radio" name="s_krit" value="serial"'.checkif($_SESSION['alx_sort_krit']=='serial').'>serial <input onclick="this.form.submit()" type="radio" name="s_krit" value="hostname"'.checkif($_SESSION['alx_sort_krit']=='hostname').'>hostname<br>';
90     echo '<input onclick="this.form.submit()" name="s_on" style="margin-left:72px" type="checkbox" value="1"'.checkif($_SESSION['alx_sort_onfirst']).'>online clients on top</td>';
91     echo '<td align=right valign=top>';
92    
93     foreach($locations as $l)
94     echo '<input onclick="this.form.submit()" type="checkbox" name="s_'.$l.'" value="1"'.checkif($_SESSION['alx_sort_loc'][$l]).'><a href="JavaScript:loc(\''.$l.'\')" style="color:#000000">'.($l=='' ? '?' : $l).'</a>';
95    
96     echo '<br/>';
97     echo '<input onclick="this.form.submit()" type="checkbox" name="s_dead" value="1"'.checkif($_SESSION['alx_sort_loc']['DEAD']).'>DEACTIVATED';
98   echo '</td>';   echo '</td>';
99     echo '</tr></table><br>';
100     echo '</form>';
101    
102     echo '<table border>';
103     echo '<tr style="font-weight:bold;background-color:#d5e5ff"><td>edit</td><td colspan=3>serial</td><td width=170>hostname</td><td width=100>ip</td>';
104     if($showversion=='on') echo '<td colspan=2>version</td>';
105     echo '<td>up/down</td></tr>';
106    
107     foreach($comps as $c)
108     {
109     if(!$_SESSION['alx_sort_loc'][$c['location']]) Continue;
110     if($c['serial']<0 && !$_SESSION['alx_sort_loc']['DEAD']) Continue;
111    
112     if($c['online']) $pic='online'; else $pic='offline';
113    
114     if($c['serial']<0) { echo '<tr style="text-decoration:line-through; color:#aaaaaa">'; $pic = 'deact'; }
115     else echo '<tr>';
116    
117     echo '<td><input type=button value="EDIT" onclick="location.href=\'show.php?id='.$c['serial'].'\'"></td>';
118     echo '<td>'.substr($c['location'],0,1).'</td>';
119     echo '<td><img src="pics/'.$pic.'.gif" alt="'.strtoupper($pic).'"></td>';
120     echo '<td width=40><b>#'.$c['serial'].'</b></td>';
121     echo '<td><nobr>'.$c['hostname'].'</nobr></td>';
122    
  echo '</tr>';  
  }  
  echo '</table><br>';  
 ?>  
123     echo '<td><nobr>'.$c['ip'].'</nobr></td>';
124    
125     if($c['online'])
126     {
127     if($showversion=='on')
128     {
129     $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$c['serial'].'');
130     while ($row = mysql_fetch_row ($pubkey)) {
131     # schreiben der .ssh/known_hosts file mit dem public rsa key des client,
132     # um die "yes" abfrage zu vermeiden
133     $hostfile = fopen ($home."/.ssh/known_hosts","w");
134     fwrite($hostfile,$c['ip']." ".$row[0],strlen($row[0])+strlen($c['ip'])+1);
135     fclose($hostfile);
136    
137     $osver = exec($sshcmd.' -l root '.$c['ip'].' \'os_ver=$(<'.$mageversion.');cfg_ver=$(/sbin/magequery -n '.$alxconfig.'|cut -d" " -f5);pname=${cfg_ver%-*-*};cfg_ver=${cfg_ver/${pname}-};echo "${os_ver}:${cfg_ver}"\'');
138     $osver = explode(':',$osver);
139     }
140     if($osver[0] == '') $osver[0]='unkown';
141     if($osver[1] == '') $osver[1]='unkown';
142     echo '<td>'.$osver[0].'</td>';
143     echo '<td>'.$osver[1].'</td>';
144     }
145     }
146    
147     echo '<td>';
148     if($c['online'])
149     {
150     echo '<input type=button style="width:50%" value="RB" onclick="if(confirm(\'REBOOT CLIENT #'.$c['serial'].' ?\')) window.open(\'reboot.php?client='.$c['serial'].'&ip='.$c['ip'].'&op=reboot\', \'ShutdownWin\', \'width=200,height=100\')">';
151     echo '<input type=button style="width:50%" value="SD" onclick="if(confirm(\'SHUTDOWN CLIENT #'.$c['serial'].' ?\')) window.open(\'reboot.php?client='.$c['serial'].'&ip='.$c['ip'].'&op=halt\', \'ShutdownWin\', \'width=200,height=100\')">';
152     }
153     else echo '<input type=button style="width:100%" value="WOL" onclick="if(confirm(\'WAKE CLIENT #'.$c['serial'].' ?\')) window.open(\'wake_on_lan.php?mac='.$c['mac'].'\', \'WakeWin\', \'width=200,height=100\')">';
154     echo '</td>';
155    
156     echo '</tr>';
157     }
158     echo '</table><br>';
159    ?>

Legend:
Removed from v.535  
changed lines
  Added in v.536