[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 4 /** 5 6 * Permet configurer l'onduleur 7 * @Version $Id: ups.php 8564 2015-03-15 13:49:49Z plouf $ 8 9 * @Projet LCS / SambaEdu 10 11 * @auteurs Philippe Chadefaux 12 13 * @Licence Distribue selon les termes de la licence GPL 14 15 * @note 16 * @sudo /usr/share/se3/scripts/ups.sh 17 */ 18 19 /** 20 21 * @Repertoire: ups 22 * file: ups.php 23 24 */ 25 26 27 28 29 // loading libs and init 30 include ("entete.inc.php"); 31 include ("ldap.inc.php"); 32 include ("ihm.inc.php"); 33 34 35 require_once ("ups.commun.php"); 36 37 //list ($idpers, $login)= isauth(); 38 //if ($idpers == "0") header("Location:$urlauth"); 39 40 41 bindtextdomain ('se3-ups', "/var/www/se3/locale"); 42 textdomain ('se3-ups'); 43 44 //aide 45 $_SESSION["pageaide"]="Gestion_de_l\'onduleur#Onduleur_unique_sur_le_serveur_Se3"; 46 47 //Si on a le droit de se connecter 48 if ($is_admin = is_admin("se3_is_admin",$login)=="Y") { 49 50 echo "<H1>".gettext("Gestion de l'onduleur")."</H1>"; 51 52 // ###################### Variables ##############################// 53 54 $lien = "ups.php"; 55 $xmlfile = "/var/www/se3/ups/ups.xml"; 56 $conffile = "/etc/nut/ups.conf"; 57 58 $pmarque=$_POST['pmarque']; 59 if ($pmarque==''){$pmarque=$_GET['pmarque'];} 60 $pversion=$_POST['pversion']; 61 if ($pversion==''){$pversion=$_GET['pversion'];} 62 $pdriver=$_POST['pdriver']; 63 if ($pdriver==''){$pdriver=$_GET['pdriver'];} 64 $pcable=$_POST['pcable']; 65 if ($pcable==''){$pcable=$_GET['pcable'];} 66 $pport=$_POST['pport']; 67 if ($pport==''){$pport=$_GET['pport'];} 68 $ptype=$_POST['ptype']; 69 if ($ptype==''){$ptype=$_GET['ptype'];} 70 71 $action=$_POST['action']; 72 if ($action=='')($action=$_GET['action']); 73 74 $filiation = array(); 75 $lselect = array(); 76 $marqueOk=false; 77 $versionOk=false; 78 79 //############################# Delete ##########################################// 80 81 if ($action=="Configurer") { 82 $fp=fopen("/etc/nut/upsd.stop","w+"); 83 fputs($fp,"stop"); 84 fclose($fp); 85 exec ("/usr/bin/sudo /usr/share/se3/scripts/ups.sh"); 86 } 87 88 89 //########################### IP Master #########################################// 90 91 if ($_POST['slave']=="yes") { 92 if ($_POST['ipslave']!="") { 93 $ok=1;$i=1; 94 // split ipslave 95 $chaine=preg_split("/;/",$_POST['ipslave']); 96 foreach($chaine as $resultat){ 97 // verifie l ip 98 if (!is_string($resultat)) {$ok = 0;} 99 $ip_long = ip2long($resultat); 100 $ip_revers = long2ip($ip_long); 101 if($resultat != $ip_revers) {$ok=0;} 102 if($i=="1") { 103 $ip1=$resultat; 104 $upsd_var = "ACL machine1 $ip1/32\nACCEPT machine1\n"; 105 } 106 if($i=="2") { 107 $ip2=$resultat; 108 $upsd_var = "ACL machine2 $ip2/32\n".$upsd_var."ACCEPT machine2\n"; 109 } 110 if($i=="3") { 111 $ip3=$resultat; 112 $upsd_var = "ACL machine3 $ip3/32\n".$upsd_var."ACCEPT machine3\n"; 113 } 114 if($i=="4") { 115 $ip4=$resultat; 116 $upsd_var = "ACL machine4 $ip4/32\n".$upsd_var."ACCEPT machine4\n"; 117 } 118 if($i=="5") { 119 $ip5=$resultat; 120 $upsd_var = "ACL machine5 $ip5/32\n".$upsd_var."ACCEPT machine5\n"; 121 } 122 $i++; 123 } 124 $upsd_var = "ACL all 0.0.0.0/0\nACL localhost 127.0.0.1/32\n".$upsd_var."ACCEPT localhost\nREJECT all\n"; 125 if ($ok=="1") { 126 // On cree ipslave 127 $fp=fopen("/etc/nut/ipslave","w+"); 128 fputs($fp,$ipslave); 129 fclose($fp); 130 // On cree upsd.conf 131 $fp=fopen("/etc/nut/upsd.conf","w+"); 132 fputs($fp,$upsd_var); 133 fclose($fp); 134 135 exec ("/usr/bin/sudo /usr/share/se3/scripts/ups.sh"); 136 echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=ups.php\">"; 137 } else { 138 $action="Avancer"; 139 } 140 } 141 } 142 143 //######################## Creation du fichier ####################################// 144 145 if ($pcable!='' && $pversion!='' && $pmarque!='' && $pport!='' && $pcable!='' && $pdriver!=''){ 146 if ($pport=="1") {$pport="/dev/ttyS0";} 147 if ($pport=="2") {$pport="/dev/ttyS1";} 148 if ($pport=="3") {$pport="/dev/usb/hiddev0";} 149 $texte = "[myups]\n"; 150 if($pport=="/dev/usb/hiddev0") {$pdriver="usbhid-ups";} 151 $texte .= "driver = $pdriver\n"; 152 $texte .= "port = $pport\n"; 153 if($pcable!="0") {$texte .= "cable = $pcable\n";} 154 $texte .= "desc = $pmarque $pversion\n"; 155 if($pdriver=="genericups") {$texte .= "upstype = $ptype\n";} 156 $texte .= "# marque = $pmarque\n"; 157 $texte .= "# version = $pversion\n"; 158 $fp=fopen("/etc/nut/ups.conf","w+"); 159 fputs($fp,$texte); 160 fclose($fp); 161 162 $upsd_var = "ACL all 0.0.0.0/0\nACL localhost 127.0.0.1/32\n".$upsd_var."ACCEPT localhost\nREJECT all\n"; 163 164 $fp=fopen("/etc/nut/upsd.conf","w+"); 165 fputs($fp,$upsd_var); 166 fclose($fp); 167 168 $fp=fopen("/etc/nut/hosts.conf","w+"); 169 $hosts_var = "MONITOR myups@localhost \"Local UPS\"\n"; 170 fputs($fp,$hosts_var); 171 fclose($fp); 172 173 $fp=fopen("/etc/nut/upsd.users","w+"); 174 $users_var = "[monuser]\npassword = GwawaKaN\nallowfrom = localhost\nupsmon master\n"; 175 fputs($fp,$users_var); 176 fclose($fp); 177 178 $fp=fopen("/etc/nut/upsmon.conf","w+"); 179 $upsmon_var = "MONITOR myups@localhost 1 monuser GwawaKaN master\nMINSUPPLIES 1\nSHUTDOWNCMD \"/sbin/shutdown -h +1\"\nPOLLFREQ 5\nPOLLFREQALERT 5\nHOSTSYNC 15\nDEADTIME 15\nPOWERDOWNFLAG /etc/killpower\nRBWARNTIME 43200\nNOCOMMWARNTIME 300\nFINALDELAY 5\nNOTIFYCMD /usr/share/se3/sbin/mail_alertes_ups.sh\nNOTIFYFLAG ONBATT SYSLOG+EXEC\n"; 180 fputs($fp,$upsmon_var); 181 fclose($fp); 182 183 echo gettext("Veuillez patienter ...!"); 184 echo "<br>"; 185 echo "<a href=ups.php?action=Configurer>Configurer</a>"; 186 187 /** 188 * /usr/share/se3/scripts/ups.sh 189 */ 190 exec ("/usr/bin/sudo /usr/share/se3/scripts/ups.sh"); 191 echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"3; URL=ups.php\">"; 192 exit; 193 } 194 195 196 //######################## Avance ################################################// 197 198 if ($action=="Avancer") { 199 if($ipslave=="") { 200 if(file_exists("/etc/nut/ipslave")) { 201 $fp=fopen("/etc/nut/ipslave","r"); 202 while ($str=fgets($fp,50)) { 203 $ip = $str; 204 $ipslave .= $ip; 205 } 206 } 207 } 208 209 $text = "<br><br>"; 210 $text .= "<form action=\"ups.php\" name=\"change\" method=\"post\" />"; 211 $text .= gettext("Indiquer l'adresse IP du serveur alimenté par cet onduleur, et qui n'a pas de càble série. Si plusieurs serveurs, séparer les adresses IP par un point virgule.\n"); 212 if($ok=="0") { 213 $text .= "<br><br><font color='red'>"; 214 $text .= gettext("Erreur sur l'adresse IP\n"); 215 $text .= "</font>"; 216 } 217 $text .= "<br><table>\n"; 218 $text .= "<tr><td>"; 219 $text .= "<input type=\"text\" name=\"ipslave\" value=\"$ipslave\" size=\"40\" />"; 220 $text .= "</td><td>"; 221 $text .= "<input type=\"hidden\" name=\"slave\" value=\"yes\" />"; 222 $text .= "<input type=\"submit\" name=\"action\" value="; 223 $text .= gettext("Valider\n"); 224 $text .= ">"; 225 $text .= "</td></tr></table><br>\n"; 226 $text .= "<i>"; 227 $text .= gettext("Cette option permet d'onduler plusieurs serveurs (LCS - SLIS - SE3) avec un seul onduleur.\n"); 228 $text .= "<br>"; 229 $text .= gettext("Ne pas oublier d'onduler le switch ;-)\n"); 230 $text .= "<br>"; 231 $text .= gettext("La machine jouant le rôle de serveur doit rester en marche tout le temps.\n"); 232 $text .= "</i>"; 233 234 echo "<div style='no-border; height: 75%'>\n"; 235 print "$text\n"; 236 echo "</div>\n"; 237 238 require ("pdp.inc.php"); 239 exit; 240 } 241 242 //#################### Verif si un onduleur existe deja ######################// 243 244 if(file_exists("/etc/nut/ups.conf") || file_exists("/etc/nut/upsmon.conf")) { 245 $text .= "<br><br><CENTER>"; 246 if (file_exists("/etc/nut/ups.conf")) { 247 $text = affichage_ups("myups@127.0.0.1"); 248 } else { 249 $ip=exec("cat /etc/nut/ipmaster"); 250 $text = affichage_ups("myups@$ip"); 251 } 252 253 $text .= "<br><br>"; 254 255 $text .= "<table><tr>"; 256 $text .= "<td><form action=\"ups.php\" name=\"codexml\" method=\"post\">"; 257 $text .= "<input type=\"submit\" name=\"action\" value=\"Configurer\" />"; 258 $text .= "</form>"; 259 $text .= "</td>"; 260 if( ! file_exists("/etc/nut/ipmaster")) { 261 $text .= "<td>"; 262 $text .= "<form action=\"ups.php\" name=\"codexml_2\" method=\"post\">"; 263 $text .= "<input type=\"submit\" name=\"action\" value=\"Avancer\" />"; 264 $text .= "</form>"; 265 $text .= "</td>"; 266 } 267 $text .= "</tr>"; 268 $text .= "</table></center>"; 269 270 $titre =gettext("UPS\n"); 271 272 echo "<div style='no-border; height: 75%'>\n"; 273 print "$text\n"; 274 echo "</div>\n"; 275 276 require ("pdp.inc.php"); 277 exit; 278 } 279 280 //######################## Parser ##################################################// 281 282 If (!($fp = fopen($xmlfile , "r"))) {die("Impossible d'ouvrir le fichier XML");} 283 284 if ($pcable=='' or $pversion=='' or $pmarque==''){ 285 $xml_parser = xml_parser_create(); 286 if ($pmarque==''){ 287 xml_set_element_handler($xml_parser, "debutElement0", "finElement"); 288 xml_set_character_data_handler($xml_parser, "characterData0"); 289 } elseif ($pversion=='') { 290 xml_set_element_handler($xml_parser, "debutElement1", "finElement"); 291 xml_set_character_data_handler($xml_parser, "characterData1"); 292 } else { 293 xml_set_element_handler($xml_parser, "debutElement2", "finElement"); 294 xml_set_character_data_handler($xml_parser, "characterData2"); 295 } 296 297 while ($data = fread($fp, 4096)) { 298 if (!xml_parse($xml_parser, $data, feof($fp))) { 299 die(sprintf("erreur XML : %s à la ligne %d", 300 xml_error_string(xml_get_error_code($xml_parser)), 301 xml_get_current_line_number($xml_parser))); 302 } 303 } 304 xml_parser_free($xml_parser); 305 } 306 307 //########################### Affichage ################################################// 308 309 $urlmark=urlencode($pmarque); 310 $urlversion=urlencode($pversion); 311 $urlcable=urlencode($pcable); 312 313 $text = "<br><a href=$lien?pmarque=$urlmark>$pmarque</a>"; 314 if ($pversion!=''){$text .= " --> <a href=$lien?pmarque=$urlmark&pversion=$urlversion>$pversion</a> ";} 315 if ($pport!=''){$text .= " --> <a href=$lien?pmarque=$urlmark&pversion=$urlversion&pport=$pport>Port $pport</a>";} 316 if ($pcable!=''){$text .= " --> <a href=$lien?pmarque=$urlmark&pversion=$urlversion&pport=$pport&pdriver=$pdriver&ptype=$ptype&pcable=$urlcable>$pcable</a>";} 317 318 $text .= "<form action=\"$lien\" name=\"codexml\" method=\"post\">"; 319 if ($pmarque=='') { 320 $text .= "<SELECT NAME='pmarque' onchange=submit()>\r\n"; 321 foreach ( $lselect as $sel_element ){ 322 $text .= "<option value='$sel_element'>$sel_element</option>\r\n"; 323 } 324 $text .= "</SELECT>\r\n"; 325 } elseif ($pversion=='') { 326 $text .= "<INPUT TYPE='hidden' NAME='pmarque' VALUE='$pmarque'/>\r\n"; 327 $text .= "<SELECT NAME='pversion' onchange=submit()>\r\n"; 328 foreach ( $lselect as $sel_element ){ 329 $text .= "<option value='$sel_element'>$sel_element</option>\r\n"; 330 } 331 $text .= "</SELECT>\r\n"; 332 } elseif ($pcable=='') { 333 $text .= "<INPUT TYPE='hidden' NAME='pmarque' VALUE='$pmarque' />\r\n"; 334 $text .= "<INPUT TYPE='hidden' NAME='pversion' VALUE='$pversion' />\r\n"; 335 $text .= "<INPUT TYPE='hidden' NAME='pdriver' VALUE='$pdriver' />\r\n"; 336 $text .= "<INPUT TYPE='hidden' NAME='pport' VALUE='$pport'/>\r\n"; 337 $text .= "<INPUT TYPE='hidden' NAME='ptype' VALUE='$ptype' />\r\n"; 338 $taille = count ($lselect); 339 if ($taille > "1") { 340 $text .= "<SELECT NAME='pcable' onchange=submit()>\r\n"; 341 foreach ( $lselect as $sel_element ){ 342 $text .= "<option value='$sel_element'>$sel_element</option>\r\n"; 343 } 344 $text .= "</SELECT>\r\n"; 345 } 346 if ($taille == "1") { 347 $pcable=$lselect[0]; 348 $text .= "<INPUT TYPE='hidden' NAME='pcable' VALUE='$pcable'/>\r\n"; 349 } 350 if ($taille == "0") { 351 $pcable=$lselect[0]; 352 $text .= "<INPUT TYPE='hidden' NAME='pcable' VALUE='0'/>\r\n"; 353 } 354 } else { 355 $text .= "<INPUT TYPE='hidden' NAME='pmarque' VALUE='$pmarque'/>\r\n"; 356 $text .= "<INPUT TYPE='hidden' NAME='pversion' VALUE='$pversion' />\r\n"; 357 $text .= "<INPUT TYPE='hidden' NAME='pdriver' VALUE='$pdriver' />\r\n"; 358 $text .= "<INPUT TYPE='hidden' NAME='pport' VALUE='$pport' />\r\n"; 359 $text .= "<INPUT TYPE='hidden' NAME='pcable' VALUE='$pcable' />\r\n"; 360 $text .= "<INPUT TYPE='hidden' NAME='ptype' VALUE='$ptype' />\r\n"; 361 } 362 363 364 if ($pmarque!='' && $pversion!='' && $pport=='') { 365 $text .= "<INPUT TYPE='hidden' NAME='pmarque' VALUE='$pmarque' />\r\n"; 366 $text .= "<INPUT TYPE='hidden' NAME='pversion' VALUE='$pversion' />\r\n"; 367 $text .= "<INPUT TYPE='hidden' NAME='pdriver' VALUE='$pdriver' />\r\n"; 368 $text .= "<INPUT TYPE='hidden' NAME='ptype' VALUE='$ptype' />\r\n"; 369 $text .= "<SELECT NAME='pport' onchange=submit()>\r\n"; 370 $text .= "<option value='1'>Port serie 1 (ttyS0)</option>\r\n"; 371 $text .= "<option value='2'>Port serie 2 (ttys1)</option>\r\n"; 372 $text .= "<option value='3'>USB </option>\r\n"; 373 $text .= "</select>\r\n"; 374 } else { 375 $text .= "$selectStr\r\n"; 376 } 377 378 $text .= "<input type=\"submit\" name=\"action\" value="; 379 $text .= gettext ("Valider\n"); 380 $text .= "></form>\n"; 381 382 383 if($pmarque=='') { 384 // $text .= "<br><br>"; 385 $text .= "<br><a href=slave_ups.php>"; 386 $text .= gettext(" Installer comme esclave\n"); 387 $text .= "</a>"; 388 $text .= "<u onmouseover=\"return escape".gettext("('Installer comme esclave, permet de partager un onduleur dont le càble est branché sur une autre machine.<br>Vous devez simplement indiquer l\'adresse IP de cette machine.<br><br><b>Attention :</b> ne pas oublier d\'onduler aussi le switch.')")."\"><img name=\"action_image2\" src=\"../elements/images/system-help.png\" alt=\"help\"></u> "; 389 } 390 $titre =gettext("UPS\n"); 391 echo "<div style='no-border;height: 75%'>\n"; 392 print "$text\n"; 393 echo "</div>\n"; 394 } else 395 echo "$html<div class=alert_msg>".gettext("Cette fonctionnalit\xe9, n\xe 396 9cessite les droits d'administrateur du serveur Se3 !")."</div>"; 397 398 399 require ("pdp.inc.php"); 400 401 ?> 402
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |