function xcopy($source, $dest, $permissions = 0755) { // Check for symlinks if (is_link($source)) { return symlink(readlink($source), $dest); } // Simple copy for a file if (is_file($source)) { return copy($source, $dest); } // Make destination directory if (!is_dir($dest)) { mkdir($dest, $permissions); } // Loop through the folder $dir = dir($source); while (false !== ($entry = $dir->read())) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Deep copy directories xcopy("{$source}/{$entry}", "{$dest}/{$entry}", $permissions); } // Clean up $dir->close(); return true; }
function xcopy($src, $dst) { $dir = opendir($src); @mkdir($dst); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . '/' . $file)) { xcopy($src . '/' . $file, $dst . '/' . $file); } else { copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); }
function xcopy($src, $dst) { // if ( file_exists( $dst ) ) { xrmdir( $dst ); } if (is_dir($src)) { mkdir($dst, 0777); $files = scandir($src); foreach ($files as $file) { if ($file != "." && $file != "..") { xcopy("{$src}/{$file}", "{$dst}/{$file}"); } } } else { if (file_exists($src)) { copy($src, $dst); } } }
if (!empty($_POST['session']) && $json->status == 'OK') { $sessionId = $_POST['session']; if ($memcache = new Memcache()) { if ($memcache->connect('localhost', 11211, 3)) { try { if ($json->status == 'OK') { $session = verify_session($memcache, $sessionId, $_SERVER, __DOMAIN__); if (!empty($session)) { if (!empty($session->admin) || !empty($session->developer) || !empty($session->content_creator)) { if (!empty($_POST['roothtml'])) { xcopy(DOCUMENT_ROOT . $_POST['roothtml'], DOCUMENT_ROOT); } if (!empty($_POST['rootemail'])) { $dirparts = explode('/', $_POST['rootemail']); $lastdir = $dirparts[sizeof($dirparts) - 1]; xcopy(DOCUMENT_ROOT . $_POST['rootemail'], DOCUMENT_ROOT . '/' . $lastdir); } delete_folder_recursive($_SERVER['DOCUMENT_ROOT'] . '/unpacked'); } } else { $json->status = 'ERROR'; $json->message = 'Invalid session'; } } } catch (PDOException $e) { error_log(__FILE__ . ' : ' . $e->getMessage()); $json->status = 'ERROR'; $json->message = 'PDOException: ' . $e->getMessage(); } catch (MemcacheException $e) { error_log(__FILE__ . ' : ' . $e->getMessage()); $json->status = 'ERROR';
function xcopy($src, $dest) { if (is_file($src)) { if (!copy($src, $dest)) { return false; } else { return true; } } $m = @dir($src); if (!is_dir($dest)) { if (!@mkdir($dest)) { return false; } } while ($f = $m->read()) { $isrc = $src . chr(47) . $f; $idest = $dest . chr(47) . $f; if (is_dir($isrc) && $f != chr(46) && $f != chr(46) . chr(46)) { if (!xcopy($isrc, $idest)) { return false; } } else { if (is_file($isrc)) { if (!copy($isrc, $idest)) { return false; } } } } return true; }
function zcopy($table) { global $config; $mssql = mssql_connect($config["mssql.host"], $config["mssql.user"], $config["mssql.pass"]); if ($mssql === false) { die("Error connecting to GP database"); } $mysql = mysqli_connect($config["mysql.host"], $config["mysql.user"], $config["mysql.pass"]); if ($mysql === false) { die("Error connecting to mysql server. " . mysqli_connect_error()); } mysqli_set_charset($mysql, "utf8"); switch ($table["type"]) { case "truncate": truncate($mysql, $table["db"], $table["table"]); break; case "lastid": $x = getLastid($mysql, $table["db"], $table["table"]); $table["sql"] .= " where dex_row_id > '{$x}'"; break; case "lastts": $x = getLastts($mysql, $table["db"], $table["table"]); $table["sql"] .= " where dex_row_ts > '{$x}'"; break; } xcopy($mssql, $mysql, $table["db"], $table["table"], $table["sql"]); mysqli_close($mysql); mssql_close($mssql); }
die; break; case -1: G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels'); G::header('location: ../login/login'); die; break; } G::LoadClass("system"); $id = strip_tags(str_replace(' ', '_', trim($_POST['form']['NAME']))); $desc = $_POST['form']['DESCRIPTION']; $fileObj = PATH_SKINS . $id . '.cnf'; if (!file_exists($fileObj)) { $oConf = new stdClass(); $oConf->name = $id; $oConf->description = $desc; $oConf->version = 1; file_put_contents($fileObj, serialize($oConf)); } $oConf = unserialize(file_get_contents($fileObj)); $contentPHP = file_get_contents(PATH_SKINS . 'green.php'); $contentPHP = str_replace('green.html', $id . '.html', $contentPHP); file_put_contents(PATH_SKINS . $id . '.php', $contentPHP); $contentHTML = file_get_contents(PATH_SKINS . 'green.html'); $contentHTML = str_replace('green', $id, $contentHTML); file_put_contents(PATH_SKINS . $id . '.html', $contentHTML); $pathImages = PATH_HTML . 'skins' . PATH_SEP . $id . PATH_SEP . 'images' . PATH_SEP; G::mk_dir($pathImages); xcopy(PATH_HTML . 'skins' . PATH_SEP . 'green' . PATH_SEP, PATH_HTML . 'skins' . PATH_SEP . $id . PATH_SEP); xcopy(PATH_HTML . 'skins' . PATH_SEP . 'green' . PATH_SEP . 'images' . PATH_SEP, PATH_HTML . 'skins' . PATH_SEP . $id . PATH_SEP . 'images' . PATH_SEP); G::Header('Location: ../../' . $id . '/setup/skinsList');
if (!empty($session->admin) || !empty($session->developer) || !empty($session->content_creator)) { // ececute the template installation process // this process does the following: // // 1. clean target app root with the exception of: // a. empty the bootstrap_template dir except the uploaded template // b. remove all other directories and their content except for the engine directory // c. remove all files except the .htaccess // // 2. unzip the uploaded template. // // 3. .... // copy($_SERVER['DOCUMENT_ROOT'] . '/' . $_POST['uuid'] . '/' . $_POST['filename'], ENGINE_ROOT . '/newsite_defaults/' . $_POST['filename']); delTree($_SERVER['DOCUMENT_ROOT'], array('engine', '.htaccess'), false); xcopy(ENGINE_ROOT . '/newsite_defaults', $_SERVER['DOCUMENT_ROOT'], 0644); } } else { $json->status = 'ERROR'; $json->message = 'Invalid session'; } } } catch (PDOException $e) { error_log(__FILE__ . ' : ' . $e->getMessage()); $json->status = 'ERROR'; $json->message = 'PDOException: ' . $e->getMessage(); } catch (MemcacheException $e) { error_log(__FILE__ . ' : ' . $e->getMessage()); $json->status = 'ERROR'; $json->message = 'MEMCACHEException: ' . $e->getMessage(); } catch (Exception $e) {
function generateConf($path, $pathTmp, $userVar) { // Crée le reperoire temporaire $pathTemporaire = $pathTmp . "/conf_tmp"; //$newPath = $path . "/test-cnf" ; if (!is_dir($pathTemporaire)) { mkdir($pathTemporaire); } // On change les parametres pour le lancement des modules $paramListCultipiStart[] = array('name' => "serverLog", 'waitAfterUS' => "1000", 'pathexe' => "tclsh", 'path' => "./serverLog/serverLog.tcl", 'xmlconf' => "./serverLog/conf.xml"); $paramListCultipiStart[] = array('name' => "serverAcqSensorV2", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverAcqSensorV2/serverAcqSensorV2.tcl", 'xmlconf' => "./serverAcqSensorV2/conf.xml"); $paramListCultipiStart[] = array('name' => "serverPlugUpdate", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverPlugUpdate/serverPlugUpdate.tcl", 'xmlconf' => "./serverPlugUpdate/conf.xml"); $paramListCultipiStart[] = array('name' => "serverMail", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverMail/serverMail.tcl", 'xmlconf' => "./serverMail/conf.xml"); $irrigationActive = readInIni($userVar, 'PARAM', 'IRRIGATION_ACTIF', "false"); if ($irrigationActive != "false") { $paramListCultipiStart[] = array('name' => "serverSupervision", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverSupervision/serverSupervision.tcl", 'xmlconf' => "./serverSupervision/conf.xml"); $paramListCultipiStart[] = array('name' => "serverSLF", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverSLF/serverSLF.tcl", 'xmlconf' => "./serverSLF/conf.xml"); } $paramListCultipiStart[] = array('name' => "serverHisto", 'waitAfterUS' => "1000", 'pathexe' => "tclsh", 'path' => "./serverHisto/serverHisto.tcl", 'xmlconf' => "./serverHisto/conf.xml"); $paramListCultipiConf[] = array("key" => "verbose", "level" => "warning"); if (!is_dir($pathTemporaire . "/bulckyPi")) { mkdir($pathTemporaire . "/bulckyPi"); } create_conf_XML($pathTemporaire . "/bulckyPi/start.xml", $paramListCultipiStart, "starts"); create_conf_XML($pathTemporaire . "/bulckyPi/conf.xml", $paramListCultipiConf); /************************* Prise ***********************************/ // On cherche le nombre de prise $prisemax = 0; foreach ($GLOBALS['IRRIGATION'] as $zone_nom => $zone) { // On ajoute les prises engrais, purge , remplissage foreach ($zone["prise"] as $prise_nom => $numero) { if ($numero > $prisemax) { $prisemax = $numero; } } foreach ($zone["plateforme"] as $plateforme_nom => $plateforme) { foreach ($plateforme["prise"] as $prise_nom => $numero) { if ($numero > $prisemax) { $prisemax = $numero; } } foreach ($plateforme["ligne"] as $ligne_numero => $ligne) { if ($ligne["prise"] > $prisemax) { $prisemax = $ligne["prise"]; } } } } // Création des répertoires if (!is_dir($pathTemporaire . "/serverPlugUpdate")) { mkdir($pathTemporaire . "/serverPlugUpdate"); } if (!is_dir($pathTemporaire . "/serverPlugUpdate/plg")) { mkdir($pathTemporaire . "/serverPlugUpdate/plg"); } if (!is_dir($pathTemporaire . "/serverPlugUpdate/prg")) { mkdir($pathTemporaire . "/serverPlugUpdate/prg"); } // Création du fichier pluga create_plugConf($pathTemporaire . "/serverPlugUpdate", $prisemax); // Création du fichier de conf // Add trace level $paramServerPlugUpdate = array(array("key" => "verbose", "level" => "info"), array("key" => "wireless_freq_plug_update", "value" => "1"), array("key" => "alarm_activ", "value" => "0000"), array("key" => "alarm_value", "value" => "6000"), array("key" => "alarm_sensor", "value" => "T"), array("key" => "alarm_sens", "value" => "+"), array("key" => "programm_activ", "value" => "off")); create_conf_XML($pathTemporaire . "/serverPlugUpdate/conf.xml", $paramServerPlugUpdate); /************************* serverSLF ***********************************/ // On change les parametres pour le server irrigation if (!is_dir($pathTemporaire . "/serverSLF")) { mkdir($pathTemporaire . "/serverSLF"); } // Add trace level $paramServerSLFXML[] = array("key" => "verbose", "level" => readInIni($userVar, 'PARAM', 'VERBOSE_SLF', 'debug')); // Add every parameters of the database $paramServerSLFXML[] = array("key" => "surpresseur,ip", "value" => $GLOBALS['SURPRESSEUR']['IP']); $paramServerSLFXML[] = array("key" => "surpresseur,prise", "value" => $GLOBALS['SURPRESSEUR']['prise']); $paramServerSLFXML[] = array("key" => "surpresseur,actif", "value" => readInIni($userVar, 'PARAM', 'SURPRESSEUR_ACTIF', "false")); $paramServerSLFXML[] = array("key" => "nbzone", "value" => count($GLOBALS['IRRIGATION'])); $paramServerSLFXML[] = array("key" => "nettoyage", "value" => readInIni($userVar, 'PARAM', 'NETTOYAGE_GOUTEUR', "false")); $paramServerSLFXML[] = array("key" => "nettoyageactif", "value" => readInIni($userVar, 'PARAM', 'NETTOYAGE_GOUTEUR_ACTIF', "false")); $ZoneIndex = 0; foreach ($GLOBALS['IRRIGATION'] as $zone_nom => $zone) { // Parametres des zones $Zone_nom_upper = str_replace(" ", "", strtoupper($zone_nom)); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",name", "value" => "ZONE " . $zone_nom); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",ip", "value" => $zone["parametres"]["IP"]); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",capteur,niveau", "value" => $zone["capteur"]["niveau_cuve"]["numero"]); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",nbplateforme", "value" => count($zone["plateforme"])); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",nbsensor", "value" => array_count_key($zone, 'capteur')); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",prise,remplissagecuve", "value" => $zone["prise"]["remplissage"]); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",prise,purge", "value" => $zone["prise"]["purge"]); for ($i = 1; $i < 4; $i++) { $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",engrais," . $i . ",temps", "value" => readInIni($userVar, 'CUVE', $Zone_nom_upper . '_ENGRAIS_' . $i, 0)); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",engrais," . $i . ",actif", "value" => readInIni($userVar, 'CUVE', $Zone_nom_upper . '_ENGRAIS_ACTIF_' . $i, "false")); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",engrais," . $i . ",prise", "value" => $zone["prise"]["engrais" . $i]); } // On indique si le remplissage doit être fait $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",remplissage,actif", "value" => readInIni($userVar, 'CUVE', $Zone_nom_upper . '_REMPLISSAGE_ACTIF', "true")); $PFIndex = 0; foreach ($zone["plateforme"] as $plateforme_nom => $plateforme) { $PF_nom_upper = strtoupper($plateforme_nom); $ligneIndex = 0; $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",name", "value" => "PF " . $plateforme_nom); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ip", "value" => $zone["parametres"]["IP"]); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",nbligne", "value" => count($plateforme["ligne"])); $tempsCycle = readInIni($userVar, 'LIGNE', $PF_nom_upper . '_TEMPS_CYCLE', 300); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",tempscycle", "value" => $tempsCycle); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",pompe,prise", "value" => $plateforme["prise"]["pompe"]); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",eauclaire,prise", "value" => $plateforme["prise"]["EV_eauclaire"]); foreach ($plateforme["ligne"] as $ligne_numero => $ligne) { $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ligne," . $ligneIndex . ",name", "value" => "Ligne " . $ligne_numero); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ligne," . $ligneIndex . ",prise", "value" => $ligne["prise"]); // On calcul le nombre de l/h : Gouteur 4 l/h --> 2 / membranes --> max 8 l/h (divisé par le nombre de ligne ) // ((nb L/h/membrane) / (nb lmax/h/membrane)) * tmpsCycle $debitMatin = readInIni($userVar, 'LIGNE', $PF_nom_upper . '_' . $ligne_numero . '_MATIN', 1.2); $tmpsOnMatin = round($debitMatin / ($GLOBALS['CONFIG']['debit_gouteur'] * $GLOBALS['CONFIG']['gouteur_membrane']) * $tempsCycle); $debitAMidi = readInIni($userVar, 'LIGNE', $PF_nom_upper . '_' . $ligne_numero . '_APRESMIDI', 1.2); $tmpsOnAMidi = round($debitAMidi / ($GLOBALS['CONFIG']['debit_gouteur'] * $GLOBALS['CONFIG']['gouteur_membrane']) * $tempsCycle); $debitNuit = readInIni($userVar, 'LIGNE', $PF_nom_upper . '_' . $ligne_numero . '_SOIR', 1.2); $tmpsOnNuit = round($debitNuit / ($GLOBALS['CONFIG']['debit_gouteur'] * $GLOBALS['CONFIG']['gouteur_membrane']) * $tempsCycle); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ligne," . $ligneIndex . ",tempsOn,matin", "value" => $tmpsOnMatin); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ligne," . $ligneIndex . ",tempsOn,apresmidi", "value" => $tmpsOnAMidi); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ligne," . $ligneIndex . ",tempsOn,nuit", "value" => $tmpsOnNuit); $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ligne," . $ligneIndex . ",active", "value" => readInIni($userVar, 'LIGNE', $PF_nom_upper . '_' . $ligne_numero . '_ACTIVE', "false")); // On sauvegarde le nombre de cycle (utilisé pour stocker le nombre d'arrosage et pour déterminer l'ordre de nettoyage) $paramServerSLFXML[] = array("key" => "zone," . $ZoneIndex . ",plateforme," . $PFIndex . ",ligne," . $ligneIndex . ",nbCycle", "value" => $PFIndex * 4 + $ligneIndex); $ligneIndex++; } $PFIndex++; } $ZoneIndex++; } // Save it create_conf_XML($pathTemporaire . "/serverSLF/conf.xml", $paramServerSLFXML); /************************* serverAcqSensorV2 ***********************************/ // On cré la conf pour les capteurs if (!is_dir($pathTemporaire . "/serverAcqSensorV2")) { mkdir($pathTemporaire . "/serverAcqSensorV2"); } foreach ($GLOBALS['IRRIGATION'] as $zone_nom => $zone) { // On cré un fichier par zone $IP = $zone["parametres"]["IP"]; // Add trace level $paramServerAcqSensor[] = array("key" => "verbose", "level" => readInIni($userVar, 'PARAM', 'VERBOSE_ACQSENSOR', "info")); $paramServerAcqSensor[] = array("key" => "simulator", "value" => "off"); $paramServerAcqSensor[] = array("key" => "auto_search", "value" => "off"); $nbSensor = 0; // Pour chaque zone , on enregistre les capteurs foreach ($zone["capteur"] as $capteur_nom => $capteur) { $nbSensor++; $numCapteur = $capteur["numero"]; $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",nom", "value" => $capteur_nom); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",type", "value" => $capteur["type"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",index", "value" => $capteur["index"]); if ($capteur["type"] == "MCP230XX") { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",nbinput", "value" => $capteur["nbinput"]); for ($i = 1; $i <= $capteur["nbinput"]; $i++) { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",input," . $i, "value" => $capteur["input," . $i]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",value," . $i, "value" => $capteur["value," . $i]); } } if ($capteur["type"] == "ADS1015") { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",input", "value" => $capteur["input"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",min", "value" => $capteur["min"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",max", "value" => $capteur["max"]); } if ($capteur["type"] == "EC") { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",comPort", "value" => $capteur["comPort"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",version", "value" => $capteur["version"]); } } foreach ($zone["plateforme"] as $plateforme_nom => $plateforme) { foreach ($plateforme["capteur"] as $capteur_nom => $capteur) { $nbSensor++; $numCapteur = $capteur["numero"]; $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",nom", "value" => $capteur_nom); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",type", "value" => $capteur["type"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",index", "value" => $capteur["index"]); if ($capteur["type"] == "MCP230XX") { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",nbinput", "value" => $capteur["nbinput"]); for ($i = 1; $i <= $capteur["nbinput"]; $i++) { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",input," . $i, "value" => $capteur["input," . $i]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",value," . $i, "value" => $capteur["value," . $i]); } } if ($capteur["type"] == "ADS1015") { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",input", "value" => $capteur["input"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",min", "value" => $capteur["min"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",max", "value" => $capteur["max"]); } } foreach ($plateforme["ligne"] as $ligne_numero => $ligne) { // On ajoute un détecteur de pression par ligne foreach ($ligne["capteur"] as $capteur_nom => $capteur) { $nbSensor++; $numCapteur = $capteur["numero"]; $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",nom", "value" => $capteur_nom); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",type", "value" => $capteur["type"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",index", "value" => $capteur["index"]); if ($capteur["type"] == "MCP230XX") { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",nbinput", "value" => $capteur["nbinput"]); for ($i = 1; $i <= $capteur["nbinput"]; $i++) { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",input," . $i, "value" => $capteur["input," . $i]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",value," . $i, "value" => $capteur["value," . $i]); } } if ($capteur["type"] == "ADS1015") { $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",input", "value" => $capteur["input"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",min", "value" => $capteur["min"]); $paramServerAcqSensor[] = array("key" => "sensor," . $numCapteur . ",max", "value" => $capteur["max"]); } } } } $paramServerAcqSensor[] = array("key" => "nbSensor", "value" => $nbSensor); // On sauvegarde $arraToSave[$IP] = $paramServerAcqSensor; unset($paramServerAcqSensor); } foreach ($GLOBALS['IRRIGATION'] as $zone_nom => $zone) { $IP = $zone["parametres"]["IP"]; if ($IP == "localhost") { $extension = ""; } else { $extension = "_" . $IP; } create_conf_XML($pathTemporaire . "/serverAcqSensorV2/conf" . $extension . ".xml", $arraToSave[$IP]); } /************************* serverHisto ***********************************/ // On cré la conf pour les capteurs if (!is_dir($pathTemporaire . "/serverHisto")) { mkdir($pathTemporaire . "/serverHisto"); } // Add trace level $paramServerHisto[] = array("key" => "verbose", "level" => readInIni($userVar, 'PARAM', 'VERBOSE_HISTO', "warning")); $paramServerHisto[] = array("key" => "logPeriode", "value" => "30"); $paramServerHisto[] = array("key" => "pathMySQL", "value" => "/usr/bin/mysql"); create_conf_XML($pathTemporaire . "/serverHisto/conf.xml", $paramServerHisto); /************************* serverLog ***********************************/ // On cré la conf pour les capteurs if (!is_dir($pathTemporaire . "/serverLog")) { mkdir($pathTemporaire . "/serverLog"); } // Add trace level switch (php_uname('s')) { case 'Windows NT': $paramServerLog[] = array("key" => "logPath", "level" => "C:/cultibox/"); break; default: $paramServerLog[] = array("key" => "logPath", "level" => "/var/log/cultipi"); break; } $paramServerLog[] = array("key" => "verbose", "value" => "warning"); create_conf_XML($pathTemporaire . "/serverLog/conf.xml", $paramServerLog); /************************* serverMail ***********************************/ // On cré la conf pour les capteurs if (!is_dir($pathTemporaire . "/serverMail")) { mkdir($pathTemporaire . "/serverMail"); } // Add trace level $paramServerMail = array(array("key" => "verbose", "level" => readInIni($userVar, 'PARAM', 'VERBOSE_MAIL', "info")), array("key" => "serverSMTP", "value" => readInIni($userVar, 'PARAM', 'MAIL_SMTP', "mail.greenbox-botanic.com")), array("key" => "port", "value" => readInIni($userVar, 'PARAM', 'MAIL_PORT', "26")), array("key" => "username", "value" => readInIni($userVar, 'PARAM', 'MAIL_USERNAME', "*****@*****.**")), array("key" => "password", "value" => readInIni($userVar, 'PARAM', 'MAIL_PASSWORD', "pssord")), array("key" => "useSSL", "value" => readInIni($userVar, 'PARAM', 'MAIL_SSL', "false"))); create_conf_XML($pathTemporaire . "/serverMail/conf.xml", $paramServerMail); /************************* serverSupervision ***********************************/ // On cré la conf pour les capteurs if (!is_dir($pathTemporaire . "/serverSupervision")) { mkdir($pathTemporaire . "/serverSupervision"); } $processSupervisionId = 0; foreach ($GLOBALS['IRRIGATION'] as $zone_nom => $zone) { // On cré un process par cuve $paramConfSupervision = array(array("key" => "action", "level" => "checkSensor"), array("key" => "eMail", "value" => readInIni($userVar, 'PARAM', 'MAIL_USERNAME', "*****@*****.**")), array("key" => "sensorName", "value" => "Niveau cuve " . $zone_nom), array("key" => "sensor", "value" => $zone['capteur']['niveau_cuve']['numero']), array("key" => "sensorOutput", "value" => "1"), array("key" => "valueSeuil", "value" => "5"), array("key" => "timeSeuilInS", "value" => "3600"), array("key" => "alertIf", "value" => "down")); // On sauvegarde create_conf_XML($pathTemporaire . "/serverSupervision/process_" . $processSupervisionId . "_checkSensor.xml", $paramConfSupervision); unset($paramConfSupervision); $processSupervisionId++; foreach ($zone["plateforme"] as $plateforme_nom => $plateforme) { foreach ($plateforme["ligne"] as $ligne_nom => $ligne) { // On cré un process par ligne d'arrosage $paramConfSupervision = array(array("key" => "action", "level" => "checkSensor"), array("key" => "eMail", "value" => readInIni($userVar, 'PARAM', 'MAIL_USERNAME', "*****@*****.**")), array("key" => "sensorName", "value" => "Pression ligne " . $ligne_nom), array("key" => "sensor", "value" => $ligne['capteur']['pression']['numero']), array("key" => "sensorOutput", "value" => "1"), array("key" => "valueSeuil", "value" => "1"), array("key" => "timeSeuilInS", "value" => "3600"), array("key" => "alertIf", "value" => "down"), array("key" => "hostnameValue", "value" => $GLOBALS['CONFIG']['nomcomplet'])); // On sauvegarde create_conf_XML($pathTemporaire . "/serverSupervision/process_" . $processSupervisionId . "_checkSensor.xml", $paramConfSupervision); unset($paramConfSupervision); $processSupervisionId++; } } } // On ajoute une vérification de la température ( inférieur à 1°C pendant 2H) $paramConfSupervision = array(array("key" => "action", "level" => "checkSensor"), array("key" => "eMail", "value" => readInIni($userVar, 'PARAM', 'MAIL_USERNAME', "*****@*****.**")), array("key" => "sensorName", "value" => "Temperature"), array("key" => "sensor", "value" => $zone['capteur']['temperature']['numero']), array("key" => "sensorOutput", "value" => "1"), array("key" => "valueSeuil", "value" => "1"), array("key" => "timeSeuilInS", "value" => "7200"), array("key" => "alertIf", "value" => "down")); // On sauvegarde create_conf_XML($pathTemporaire . "/serverSupervision/process_" . $processSupervisionId . "_checkSensor.xml", $paramConfSupervision); unset($paramConfSupervision); $processSupervisionId++; // Add trace level $paramServerSupervision = array(array("key" => "verbose", "level" => readInIni($userVar, 'PARAM', 'VERBOSE_SUPERVISION', "info")), array("key" => "nbProcess", "value" => "0")); create_conf_XML($pathTemporaire . "/serverSupervision/conf.xml", $paramServerSupervision); switch (php_uname('s')) { case 'Windows NT': // On repositionne cette conf comme celle par défaut xcopy($pathTemporaire, $path . "/00_defaultConf_Win"); // On la sauvegarde xcopy($pathTemporaire, $path . "/" . date("YmdH")); break; default: // On supprime l'ancienne conf // sudo mv /etc/bulckypi/01_defaultConf_RPi/* /tmp/ --backup=numbered exec("sudo mv {$path}/01_defaultConf_RPi/* /tmp/ --backup=numbered", $ret, $err); if ($err != 0) { echo 'Erreur suppression ancienne conf'; } // On repositionne cette conf comme celle par défaut // sudo cp -R /tmp/conf_tmp* /etc/bulckypi/01_defaultConf_RPi/ exec("sudo cp -R {$pathTemporaire}/* {$path}/01_defaultConf_RPi/", $ret, $err); if ($err != 0) { echo 'Erreur copie dans 01_defaultConf_RPi'; } // On crée le répertoire de sauvegarde // sudo mkdir /etc/bulckypi/2016041414 $err = 0; if (!is_dir($path . "/" . date("YmdH"))) { exec("sudo mkdir {$path}/" . date("YmdH"), $ret, $err); } if ($err != 0) { echo "Erreur création {$path}/" . date("YmdH"); } // On copie la conf dedans // sudo cp -R /tmp/conf_tmp/* /etc/bulckypi/2016041414/ exec("sudo cp -R {$pathTemporaire}/* {$path}/" . date("YmdH") . "/", $ret, $err); if ($err != 0) { echo "Erreur copie dans le rep {$path}/" . date("YmdH"); } // On ajoute l'ancien param.ini exec("sudo mv /tmp/param.ini {$path}/" . date("YmdH") . "/param.ini", $ret, $err); if ($err != 0) { echo 'Erreur sauvegarde ancien param.ini'; } break; } // On relance l'acquisition exec("sudo /etc/init.d/bulckypi force-reload >/dev/null 2>&1", $ret, $err); if ($err != 0) { echo 'Erreur de rechargement du service'; } }
function copyNewFiles($copyLocation) { $coderaFolder = "../../"; $jsSource = $copyLocation . "js/"; $cssSource = $copyLocation . "css/"; $phpSource = $copyLocation . "php/"; $configFile = $copyLocation . "config/version.txt"; xcopy($cssSource, $coderaFolder . "css"); xcopy($jsSource, $coderaFolder . "js"); xcopy($phpSource, $coderaFolder . "php"); xcopy($configFile, $coderaFolder . "config/version.txt"); }
function xcopy($source, $dest, $permissions = 0755) { if (is_link($source)) { return symlink(readlink($source), $dest); } if (is_file($source)) { return copy($source, $dest); } if (!is_dir($dest)) { mkdir($dest, $permissions); } $dir = dir($source); while (false !== ($entry = $dir->read())) { if ($entry == '.' || $entry == '..') { continue; } xcopy("{$source}/{$entry}", "{$dest}/{$entry}"); } $dir->close(); return true; }