$fusion["LIGNE"] = array_merge($parametre["LIGNE"], $variable["LIGNE"]); // On sauvegarde l'ancien param.ini exec("sudo cp /var/www/mobile/param.ini /tmp/param.ini", $ret, $err); if ($err != 0) { echo 'Erreur sauvegarde ancien param.ini'; } write_ini_file($fusion, "param.ini", true); // On cré la conf if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $path = "C:/cultibox/_conf"; $pathTmp = "C:/cultibox/tmp"; } else { $path = "/etc/bulckypi"; $pathTmp = "/tmp"; } generateConf($path, $pathTmp, $fusion); } break; case 'SET_PLUG': // On récupère le numéro de la prise $prise1 = $_POST['prise1']; $prise2 = $_POST['prise2']; $temps = $_POST['temps']; $etat = $_POST['etat']; if ($prise1 != 0) { $status = forcePlug($prise1, $temps, $etat); } if ($prise2 != 0 && $status["status"] == "done") { $status = forcePlug($prise2, $temps, $etat); } echo $status["status"];
/** * Determine if we will modify my.cnf file or just create a TXT file * * @param string $file Used configuration file * @param string $name Configuration method chosen * * @return array */ function chooseConfMethod($file, $name) { echo exec("clear"); // Check the file check_file($file); // Create a new DOMDocument object $dom = new DOMDocument(); // Load the XML file check_errs($dom->load($file), false, "File " . $file . " not correctly formed.", "File " . $file . " is OK!"); // Get the server from the XML file $myServer = getServerByName($name, $file); // Get the attributes $hostname = $myServer->getAttribute('ip'); $localhost = $myServer->getAttribute('localhost'); $myAnswerConf = recup("Use the my.cnf file (y or n) [default y] ? ", "y"); if ($myAnswerConf != "n") { $myConf = recup("Path to my.cnf [default /etc/mysql/my.cnf]: ", "/etc/mysql/my.cnf"); echo "\n"; if ($localhost == "y") { check_errs(copy($myConf, $myConf . "." . $hostname . ".old"), false, "Unable to copy " . $myConf . ".", $myConf . " saved to " . $myConf . "." . $hostname . ".old"); // Selected method $method['method'] = "mysqld"; $method['filename'] = $myConf; } else { $sshPort = recup("SSH port to use [default 22]? ", "22"); $sshUser = recup("Username allowed to connect to " . $hostname . ": "); exec("scp -P " . $sshPort . " " . $sshUser . "@" . $hostname . ":" . $myConf . " " . $myConf . "." . $hostname . ".old", $result, $returnVar); check_errs($returnVar, true, "Unable to SCP", "SCP copy worked properly!"); // Copy of the .old file to the .new file in order to work check_errs(copy($myConf . "." . $hostname . ".old", $myConf . "." . $hostname . ".new"), false, "Unable to create new file " . $myConf . "." . $hostname . ".new", "New file " . $myConf . "." . $hostname . ".new successfully created!"); // Selected method $method['method'] = "mysqld"; $method['filename'] = $myConf; } } else { $file1 = recup("Filename for the server configuration output [default " . $hostname . ".txt]: ", $hostname . ".txt"); // Selected method $method['method'] = "file"; $method['filename'] = $hostname . ".txt"; } // Generate the conf return generateConf($file, $method, $name); }