Ejemplo n.º 1
0
require_once '../../libs/utilfunc.php';
require_once '../../libs/db_get_common.php';
require_once '../../libs/db_set_common.php';
if (!isset($selected_plug)) {
    $selected_plug = getvar('selected_plug');
}
if (empty($selected_plug) || !isset($selected_plug)) {
    $selected_plug = 1;
}
$chinfo = true;
$chtime = "";
$pop_up_message = "";
$pop_up_error_message = "";
$resume = array();
$index_info = array();
programs\get_program_index_info($index_info);
$plugsInfo = plugs\getDB($selected_plug);
$plugInfo = $plugsInfo[0];
$cyclic = getvar("cyclic");
$apply = getvar('apply');
$action_prog = getvar('action_prog');
$reset_old_program = getvar("reset_old_program");
$value_program = getvar('value_program');
$regul_program = getvar("regul_program");
$start_time = getvar("start_time");
$end_time = getvar("end_time");
$start = "";
$end = "";
$rep = "";
$resume_regul = array();
$type = "0";
Ejemplo n.º 2
0
<?php

require_once '../../libs/config.php';
require_once '../../libs/db_get_common.php';
require_once '../../libs/db_set_common.php';
require_once '../../libs/utilfunc.php';
require_once '../../libs/utilfunc_sd_card.php';
// Retrieve start and end param (Unix time format (s))
$sd_card = $_GET['sd_card'];
// Create all plugXX programm
// Read program index
$program_index = array();
programs\get_program_index_info($program_index);
// Foreach programm, create the programm
foreach ($program_index as $key => $value) {
    // Read from database program
    $program = create_program_from_database($main_error, $value['program_idx']);
    // Save programm on SD
    $file = "{$sd_card}/cnf/prg/" . "plu" . $value['plugv_filename'];
    save_program_on_sd($file, $program);
}
$data = array();
calendar\read_event_from_db($data);
// Read event from XML
foreach (calendar\get_external_calendar_file() as $fileArray) {
    if ($fileArray['activ'] == 1) {
        calendar\read_event_from_XML($fileArray['filename'], $data);
    }
}
if (!check_sd_card($sd_card)) {
    $main_error[] = __('ERROR_WRITE_CALENDAR');
Ejemplo n.º 3
0
function check_and_update_sd_card($sd_card = "", &$main_info_tab, &$main_error_tab)
{
    // Check and update path
    $logs = "{$sd_card}/logs";
    $cnf = "{$sd_card}/cnf";
    $plg = "{$cnf}/plg";
    $prg = "{$cnf}/prg";
    $bin = "{$sd_card}/bin";
    $recordfrequency = "1";
    $updatefrequency = "1";
    // If we are in cultipi mode, create file systeme structure
    if (!is_dir($sd_card)) {
        mkdir($sd_card);
    }
    if (!is_dir($sd_card . "/bulckyPi")) {
        mkdir($sd_card . "/bulckyPi");
    }
    if (!is_dir($sd_card . "/serverAcqSensorV2")) {
        mkdir($sd_card . "/serverAcqSensorV2");
    }
    if (!is_dir($sd_card . "/serverHisto")) {
        mkdir($sd_card . "/serverHisto");
    }
    if (!is_dir($sd_card . "/serverLog")) {
        mkdir($sd_card . "/serverLog");
    }
    if (!is_dir($sd_card . "/serverPlugUpdate")) {
        mkdir($sd_card . "/serverPlugUpdate");
    }
    if (!is_dir($sd_card . "/serverPlugUpdate/prg")) {
        mkdir($sd_card . "/serverPlugUpdate/prg");
    }
    if (!is_dir($sd_card . "/serverPlugUpdate/plg")) {
        mkdir($sd_card . "/serverPlugUpdate/plg");
    }
    if (!is_dir($sd_card . "/serverMail")) {
        mkdir($sd_card . "/serverMail");
    }
    if (!is_dir($sd_card . "/serverCultibox")) {
        mkdir($sd_card . "/serverCultibox");
    }
    if (!is_dir($sd_card . "/serverSupervision")) {
        mkdir($sd_card . "/serverSupervision");
    }
    if (!is_dir($sd_card . "/serverIrrigation")) {
        mkdir($sd_card . "/serverIrrigation");
    }
    // Create cultipi conf.xml file
    $paramListCultipiConf[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['bulckyPi']);
    create_conf_XML($sd_card . "/bulckyPi/conf.xml", $paramListCultipiConf);
    // Create cultipi start.xml file
    $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' => "serverCultibox", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverCultibox/serverCultibox.tcl", 'xmlconf' => "./serverCultibox/conf.xml");
    $paramListCultipiStart[] = array('name' => "serverMail", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverMail/serverMail.tcl", 'xmlconf' => "./serverMail/conf.xml");
    $paramListCultipiStart[] = array('name' => "serverSupervision", 'waitAfterUS' => "100", 'pathexe' => "tclsh", 'path' => "./serverSupervision/serverSupervision.tcl", 'xmlconf' => "./serverSupervision/conf.xml");
    // If there are some plugins to add in start.xml , add it
    foreach ($GLOBALS['PLUGIN'] as $plugin) {
        // Check if function exists
        if (function_exists($plugin . '\\addInStartXMLCultiCore')) {
            // Add parameters
            $paramListCultipiStart[] = call_user_func($plugin . '\\addInStartXMLCultiCore');
        }
    }
    $paramListCultipiStart[] = array('name' => "serverHisto", 'waitAfterUS' => "1000", 'pathexe' => "tclsh", 'path' => "./serverHisto/serverHisto.tcl", 'xmlconf' => "./serverHisto/conf.xml");
    create_conf_XML($sd_card . "/bulckyPi/start.xml", $paramListCultipiStart, "starts");
    // Server acq sensor
    sensors\serverAcqSensorV2_createXMLConf();
    // Server plug update
    $paramListServerPlugUpdate[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverPlugUpdate']);
    $paramListServerPlugUpdate[] = array("name" => "wireless_freq_plug_update", "value" => "{$updatefrequency}");
    $paramListServerPlugUpdate[] = array("name" => "pwm_output", "value" => $GLOBALS['PWM_OUTPUT']);
    // Add network slave
    //  <item name="module_CULTIPI,ip,0" ip="192.168.1.10" />
    if ($GLOBALS['CULTIPI']['USE_REMOTE_SLAVE'] == 1) {
        for ($index = 0; $index < $GLOBALS['CULTIPI']['REMOTE_NB_SLAVE']; $index++) {
            $paramListServerPlugUpdate[] = array("name" => "module_CULTIPI,ip," . $index, "ip" => $GLOBALS['CULTIPI']['REMOTE_SLAVE']["IP_" . $index]);
        }
    }
    create_conf_XML($sd_card . "/serverPlugUpdate/conf.xml", $paramListServerPlugUpdate);
    // Server histo
    $paramListServerHisto[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverHisto']);
    $paramListServerHisto[] = array("name" => "logPeriode", "valInSec" => $recordfrequency * 60);
    $paramListServerHisto[] = array("name" => "pathMySQL", "path" => "/usr/bin/mysql");
    create_conf_XML($sd_card . "/serverHisto/conf.xml", $paramListServerHisto);
    // Server log
    $paramListServerLog[] = array("name" => "logPath", "logfile" => "/var/log/cultipi");
    $paramListServerLog[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverLog']);
    create_conf_XML($sd_card . "/serverLog/conf.xml", $paramListServerLog);
    // Create conf for mail
    // Made when user save it conf
    // Create conf for supervision
    $paramListSupervision[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverSupervision']);
    $paramListSupervision[] = array("name" => "nbProcess", "value" => 0);
    create_conf_XML($sd_card . "/serverSupervision/conf.xml", $paramListSupervision);
    // For each process create an XML
    /*
    $paramListSupervisionProcess[] = array (
        "name" => "action",
        "level" => "checkPing"
    );    
    $paramListSupervisionProcess[] = array (
        "name" => "nbIP",
        "level" => "1"
    );
    $paramListSupervisionProcess[] = array (
        "name" => "IP,0",
        "level" => "8.8.8.8"
    );
    $paramListSupervisionProcess[] = array (
        "name" => "timeMax",
        "level" => "30"
    ); 
    $paramListSupervisionProcess[] = array (
        "name" => "error,action",
        "level" => "sendMail info@bulck.fr"
    );
    create_conf_XML($sd_card . "/serverSupervision/process_0.xml" , $paramListSupervisionProcess);
    */
    $paramListCultibox[] = array("name" => "verbose", "level" => $GLOBALS['CULTIPI']['TRACE_LEVEL']['serverCultibox']);
    $paramListCultibox[] = array("name" => "updateFreq", "level" => "6");
    create_conf_XML($sd_card . "/serverCultibox/conf.xml", $paramListCultibox);
    configuration\serverEmail_createXMLConf();
    $program = "";
    $conf_uptodate = true;
    $program_index = array();
    programs\get_program_index_info($program_index);
    $confsave_prog = true;
    foreach ($program_index as $key => $value) {
        // Read from database program
        $program = create_program_from_database($main_error, $value['program_idx']);
        $fileName = $sd_card . "/serverPlugUpdate/prg/" . "plu" . $value['plugv_filename'];
        if (!compare_program($program, $fileName)) {
            $conf_uptodate = false;
            if (!save_program_on_sd($fileName, $program)) {
                $confsave_prog = false;
            }
        }
    }
    //For plugv
    $program = create_program_from_database($main_error);
    $fileName = $sd_card . "/serverPlugUpdate/prg/" . "plugv";
    if (!save_program_on_sd($fileName, $program)) {
        $main_error_tab[] = __('ERROR_WRITE_PROGRAM');
        return ERROR_WRITE_PROGRAM;
    }
    if (!write_pluga($sd_card, $main_error)) {
        $main_error_tab[] = __('ERROR_COPY_PLUGA');
        return ERROR_COPY_PLUGA;
    }
    $plugconf = create_plugconf_from_database($GLOBALS['NB_MAX_PLUG'], $main_error);
    if (count($plugconf) > 0) {
        if (!write_plugconf($plugconf, $sd_card)) {
            $main_error_tab[] = __('ERROR_COPY_PLUG_CONF');
            return ERROR_COPY_PLUG_CONF;
        }
    }
    $data = array();
    calendar\read_event_from_db($data);
    $plgidx = create_plgidx($data);
    if (count($plgidx) > 0) {
        if (!write_plgidx($plgidx, $sd_card)) {
            $main_error_tab[] = __('ERROR_COPY_PLGIDX');
            return ERROR_COPY_PLGIDX;
        }
    } else {
        if (!check_and_copy_plgidx($sd_card)) {
            $main_error_tab[] = __('ERROR_COPY_TPL');
            return ERROR_COPY_TPL;
        }
    }
    if (!$conf_uptodate) {
        // Infor user that programms have been updated
        $main_info_tab[] = __('UPDATED_PROGRAM');
        return 0;
    }
    // Conf was up to date
    return 1;
}