".gettext("Gestion de l'onduleur").""; // ###################### Variables ##############################// $lien = "ups.php"; $xmlfile = "/var/www/se3/ups/ups.xml"; $conffile = "/etc/nut/ups.conf"; $pmarque=$_POST['pmarque']; if ($pmarque==''){$pmarque=$_GET['pmarque'];} $pversion=$_POST['pversion']; if ($pversion==''){$pversion=$_GET['pversion'];} $pdriver=$_POST['pdriver']; if ($pdriver==''){$pdriver=$_GET['pdriver'];} $pcable=$_POST['pcable']; if ($pcable==''){$pcable=$_GET['pcable'];} $pport=$_POST['pport']; if ($pport==''){$pport=$_GET['pport'];} $ptype=$_POST['ptype']; if ($ptype==''){$ptype=$_GET['ptype'];} $action=$_POST['action']; if ($action=='')($action=$_GET['action']); $filiation = array(); $lselect = array(); $marqueOk=false; $versionOk=false; //############################# Delete ##########################################// if ($action=="Configurer") { $fp=fopen("/etc/nut/upsd.stop","w+"); fputs($fp,"stop"); fclose($fp); exec ("/usr/bin/sudo /usr/share/se3/scripts/ups.sh"); } //########################### IP Master #########################################// if ($_POST['slave']=="yes") { if ($_POST['ipslave']!="") { $ok=1;$i=1; // split ipslave $chaine=preg_split("/;/",$_POST['ipslave']); foreach($chaine as $resultat){ // verifie l ip if (!is_string($resultat)) {$ok = 0;} $ip_long = ip2long($resultat); $ip_revers = long2ip($ip_long); if($resultat != $ip_revers) {$ok=0;} if($i=="1") { $ip1=$resultat; $upsd_var = "ACL machine1 $ip1/32\nACCEPT machine1\n"; } if($i=="2") { $ip2=$resultat; $upsd_var = "ACL machine2 $ip2/32\n".$upsd_var."ACCEPT machine2\n"; } if($i=="3") { $ip3=$resultat; $upsd_var = "ACL machine3 $ip3/32\n".$upsd_var."ACCEPT machine3\n"; } if($i=="4") { $ip4=$resultat; $upsd_var = "ACL machine4 $ip4/32\n".$upsd_var."ACCEPT machine4\n"; } if($i=="5") { $ip5=$resultat; $upsd_var = "ACL machine5 $ip5/32\n".$upsd_var."ACCEPT machine5\n"; } $i++; } $upsd_var = "ACL all 0.0.0.0/0\nACL localhost 127.0.0.1/32\n".$upsd_var."ACCEPT localhost\nREJECT all\n"; if ($ok=="1") { // On cree ipslave $fp=fopen("/etc/nut/ipslave","w+"); fputs($fp,$ipslave); fclose($fp); // On cree upsd.conf $fp=fopen("/etc/nut/upsd.conf","w+"); fputs($fp,$upsd_var); fclose($fp); exec ("/usr/bin/sudo /usr/share/se3/scripts/ups.sh"); echo ""; } else { $action="Avancer"; } } } //######################## Creation du fichier ####################################// if ($pcable!='' && $pversion!='' && $pmarque!='' && $pport!='' && $pcable!='' && $pdriver!=''){ if ($pport=="1") {$pport="/dev/ttyS0";} if ($pport=="2") {$pport="/dev/ttyS1";} if ($pport=="3") {$pport="/dev/usb/hiddev0";} $texte = "[myups]\n"; if($pport=="/dev/usb/hiddev0") {$pdriver="usbhid-ups";} $texte .= "driver = $pdriver\n"; $texte .= "port = $pport\n"; if($pcable!="0") {$texte .= "cable = $pcable\n";} $texte .= "desc = $pmarque $pversion\n"; if($pdriver=="genericups") {$texte .= "upstype = $ptype\n";} $texte .= "# marque = $pmarque\n"; $texte .= "# version = $pversion\n"; $fp=fopen("/etc/nut/ups.conf","w+"); fputs($fp,$texte); fclose($fp); $upsd_var = "ACL all 0.0.0.0/0\nACL localhost 127.0.0.1/32\n".$upsd_var."ACCEPT localhost\nREJECT all\n"; $fp=fopen("/etc/nut/upsd.conf","w+"); fputs($fp,$upsd_var); fclose($fp); $fp=fopen("/etc/nut/hosts.conf","w+"); $hosts_var = "MONITOR myups@localhost \"Local UPS\"\n"; fputs($fp,$hosts_var); fclose($fp); $fp=fopen("/etc/nut/upsd.users","w+"); $users_var = "[monuser]\npassword = GwawaKaN\nallowfrom = localhost\nupsmon master\n"; fputs($fp,$users_var); fclose($fp); $fp=fopen("/etc/nut/upsmon.conf","w+"); $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"; fputs($fp,$upsmon_var); fclose($fp); echo gettext("Veuillez patienter ...!"); echo "
"; echo "Configurer"; /** * /usr/share/se3/scripts/ups.sh */ exec ("/usr/bin/sudo /usr/share/se3/scripts/ups.sh"); echo ""; exit; } //######################## Avance ################################################// if ($action=="Avancer") { if($ipslave=="") { if(file_exists("/etc/nut/ipslave")) { $fp=fopen("/etc/nut/ipslave","r"); while ($str=fgets($fp,50)) { $ip = $str; $ipslave .= $ip; } } } $text = "

"; $text .= "
"; $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"); if($ok=="0") { $text .= "

"; $text .= gettext("Erreur sur l'adresse IP\n"); $text .= ""; } $text .= "
\n"; $text .= "
"; $text .= ""; $text .= ""; $text .= ""; $text .= "\n"; print "$text\n"; echo "\n"; require ("pdp.inc.php"); exit; } //#################### Verif si un onduleur existe deja ######################// if(file_exists("/etc/nut/ups.conf") || file_exists("/etc/nut/upsmon.conf")) { $text .= "

"; if (file_exists("/etc/nut/ups.conf")) { $text = affichage_ups("myups@127.0.0.1"); } else { $ip=exec("cat /etc/nut/ipmaster"); $text = affichage_ups("myups@$ip"); } $text .= "

"; $text .= ""; $text .= ""; if( ! file_exists("/etc/nut/ipmaster")) { $text .= ""; } $text .= ""; $text .= "
"; $text .= ""; $text .= ""; $text .= ""; $text .= "
"; $text .= ""; $text .= "
"; $text .= "
"; $titre =gettext("UPS\n"); echo "
\n"; print "$text\n"; echo "
\n"; require ("pdp.inc.php"); exit; } //######################## Parser ##################################################// If (!($fp = fopen($xmlfile , "r"))) {die("Impossible d'ouvrir le fichier XML");} if ($pcable=='' or $pversion=='' or $pmarque==''){ $xml_parser = xml_parser_create(); if ($pmarque==''){ xml_set_element_handler($xml_parser, "debutElement0", "finElement"); xml_set_character_data_handler($xml_parser, "characterData0"); } elseif ($pversion=='') { xml_set_element_handler($xml_parser, "debutElement1", "finElement"); xml_set_character_data_handler($xml_parser, "characterData1"); } else { xml_set_element_handler($xml_parser, "debutElement2", "finElement"); xml_set_character_data_handler($xml_parser, "characterData2"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("erreur XML : %s à la ligne %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); } //########################### Affichage ################################################// $urlmark=urlencode($pmarque); $urlversion=urlencode($pversion); $urlcable=urlencode($pcable); $text = "
$pmarque"; if ($pversion!=''){$text .= " --> $pversion ";} if ($pport!=''){$text .= " --> Port $pport";} if ($pcable!=''){$text .= " --> $pcable";} $text .= "
"; if ($pmarque=='') { $text .= "\r\n"; } elseif ($pversion=='') { $text .= "\r\n"; $text .= "\r\n"; } elseif ($pcable=='') { $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $taille = count ($lselect); if ($taille > "1") { $text .= "\r\n"; } if ($taille == "1") { $pcable=$lselect[0]; $text .= "\r\n"; } if ($taille == "0") { $pcable=$lselect[0]; $text .= "\r\n"; } } else { $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; } if ($pmarque!='' && $pversion!='' && $pport=='') { $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; $text .= "\r\n"; } else { $text .= "$selectStr\r\n"; } $text .= "Vous devez simplement indiquer l\'adresse IP de cette machine.

Attention : ne pas oublier d\'onduler aussi le switch.')")."\">\"help\" "; } $titre =gettext("UPS\n"); echo "
\n"; print "$text\n"; echo "
\n"; } else echo "$html
".gettext("Cette fonctionnalit\xe9, n\xe 9cessite les droits d'administrateur du serveur Se3 !")."
"; require ("pdp.inc.php"); ?>