コード例 #1
0
function dhcprelay_makefile($dh)
{
    include "config.php";
    $func_role = basename(__FILE__) . " " . __FUNCTION__;
    if (file_exists($dhcprelay_config)) {
        unlink($dhcprelay_config);
    }
    file_put_contents($dhcprelay_config, "DHCRELAYARGS=\"-a -q -A 1400\"" . chr(10), FILE_APPEND | LOCK_EX);
    file_put_contents($dhcprelay_config, "INTERFACES=\"\"" . chr(10), FILE_APPEND | LOCK_EX);
    file_put_contents($dhcprelay_config, "DHCPSERVERS=\"" . implode(",", $dh) . "\"" . chr(10), FILE_APPEND | LOCK_EX);
    echo message_addlog($func_role, "File " . $dhcprelay_config . " was created");
}
コード例 #2
0
function check_roles_facter($hw_bi, $log_data_dir)
{
    $boo_load_puppet = "0";
    $file_facter_os = $log_data_dir . "facter_os.json";
    // load roles .os
    if (file_exists($file_facter_os)) {
        // Get JSON data
        $data_os = file_get_contents($file_facter_os);
        $hw_os = json_decode($data_os, true);
        foreach ($hw_bi as $key => $val) {
            if (isset($hw_os[$key])) {
                if ($hw_bi[$key] != $hw_os[$key]) {
                    $boo_load_puppet = "1";
                }
            }
        }
    } else {
        $boo_load_puppet = "1";
        $fp = fopen($file_facter_os, "w");
        fwrite($fp, json_encode($hw_bi));
        fclose($fp);
    }
    if ($boo_load_puppet == "1") {
        include "config.php";
        $func_role = basename(__FILE__) . " " . __FUNCTION__;
        $sm_router = $hw_bi["router"];
        $sm_vpnserver = $hw_bi["vpnserver"];
        $sm_dhcpserver = $hw_bi["dhcpserver"];
        $sm_dhcprelay = $hw_bi["dhcprelay"];
        $sm_radserver = $hw_bi["radserver"];
        $sm_tftpserver = $hw_bi["tftpserver"];
        $sm_bmrserver = $hw_bi["bmrserver"];
        $sm_iptvserver = $hw_bi["iptvserver"];
        $sm_gponserver = $hw_bi["gponserver"];
        $sm_eponserver = $hw_bi["eponserver"];
        $sm_statistic = $hw_bi["statistic"];
        $sm_brasserver = $hw_bi["bras"];
        $sm_cmanager = $hw_bi["cmanager"];
        // for router
        if ($sm_router == "none") {
            $boo_prole_router = "false";
        } else {
            $boo_prole_router = "true";
        }
        // vpnserver
        if ($sm_vpnserver == "none") {
            $boo_prole_vpnserver = "false";
        } else {
            $boo_prole_vpnserver = "true";
        }
        //dhcpserver
        if ($sm_dhcpserver == "none") {
            $boo_prole_dhcpserver = "false";
        } else {
            $boo_prole_dhcpserver = "true";
        }
        //dhcprelay
        if ($sm_dhcprelay == "none") {
            $boo_prole_dhcprelay = "false";
        } else {
            $boo_prole_dhcprelay = "true";
        }
        //radserver
        if ($sm_radserver == "none") {
            $boo_prole_radserver = "false";
        } else {
            $boo_prole_radserver = "true";
        }
        //tftpserver
        if ($sm_tftpserver == "none") {
            $boo_prole_tftpserver = "false";
        } else {
            $boo_prole_tftpserver = "true";
        }
        //bmrserver
        if ($sm_bmrserver == "none") {
            $boo_prole_bmrserver = "false";
        } else {
            $boo_prole_bmrserver = "true";
        }
        //bmrserver
        if ($sm_iptvserver == "none") {
            $boo_prole_iptvserver = "false";
        } else {
            $boo_prole_iptvserver = "true";
        }
        //gponserver
        if ($sm_gponserver == "none") {
            $boo_prole_gponserver = "false";
        } else {
            $boo_prole_gponserver = "true";
        }
        //eponserver
        if ($sm_eponserver == "none") {
            $boo_prole_eponserver = "false";
        } else {
            $boo_prole_eponserver = "true";
        }
        //statistic
        if ($sm_statistic == "none") {
            $boo_prole_statistic = "false";
        } else {
            $boo_prole_statistic = "true";
        }
        //brasserver
        if ($sm_brasserver == "none") {
            $boo_prole_brasserver = "false";
        } else {
            $boo_prole_brasserver = "true";
        }
        //comx manager
        if ($sm_cmanager == "none") {
            $boo_prole_cmanager = "false";
        } else {
            $boo_prole_cmanager = "true";
        }
        //  Report, that role puppet will change
        foreach ($hw_bi as $key => $val) {
            if (isset($hw_os[$key])) {
                if ($hw_bi[$key] != $hw_os[$key]) {
                    echo message_addlog($func_role, "New puppet declaration for " . $key . " " . $hw_os[$key] . ">" . $hw_bi[$key]);
                }
            }
        }
        //create file factor for puppet
        $file_ff = $facter_dir . "viva-roles.sh";
        if (file_exists($file_ff)) {
            unlink($file_ff);
        }
        file_put_contents($file_ff, "#!" . $env . " bash" . chr(10), FILE_APPEND | LOCK_EX);
        file_put_contents($file_ff, chr(10), FILE_APPEND | LOCK_EX);
        file_put_contents($file_ff, "echo '" . $prole . "=" . $prole_router . "," . $prole_vpnserver . "," . $prole_dhcpserver . "," . $prole_dhcprelay . "," . $prole_radserver . "," . $prole_tftpserver . "," . $prole_bmrserver . "," . $prole_iptvserver . "," . $prole_gponserver . "," . $prole_eponserver . "," . $prole_statistic . "," . $prole_brasserver . "," . $prole_cmanager . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_router . "=" . $boo_prole_router . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_vpnserver . "=" . $boo_prole_vpnserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_dhcpserver . "=" . $boo_prole_dhcpserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_dhcprelay . "=" . $boo_prole_dhcprelay . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_radserver . "=" . $boo_prole_radserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_tftpserver . "=" . $boo_prole_tftpserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_bmrserver . "=" . $boo_prole_bmrserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_iptvserver . "=" . $boo_prole_iptvserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_gponserver . "=" . $boo_prole_gponserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_eponserver . "=" . $boo_prole_eponserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_statistic . "=" . $boo_prole_statistic . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_brasserver . "=" . $boo_prole_brasserver . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        file_put_contents($file_ff, "echo '" . $prole . "_" . $prole_cmanager . "=" . $boo_prole_cmanager . "'" . chr(10), FILE_APPEND | LOCK_EX);
        //--<
        echo system_exec_addlog($func_role, $chmod . " 777 " . $file_ff);
        // load puppet
        // echo system_exec_addlog_puppet($func_role, $puppet." agent -t --environment=".$puppet_env." >/dev/null");
        // rewrite .os
        $fp = fopen($file_facter_os, "w");
        fwrite($fp, json_encode($hw_bi));
        fclose($fp);
    }
    return "0";
}
コード例 #3
0
function cmanager_comx_task($id_comx_manager, $ch, $connect_url, $connect_api)
{
    include "config.php";
    $func_role = basename(__FILE__) . " " . __FUNCTION__;
    curl_setopt($ch, CURLOPT_URL, $connect_url . "get_cmanager_comx_list");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_comx_manager\":\"" . $id_comx_manager . "\",\"api\":\"" . $connect_api . "\"}");
    $return = curl_exec($ch);
    if (curl_errno($ch)) {
        echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
    } else {
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpcode == "200") {
            $r_comx = json_decode($return, true);
            foreach ($r_comx as $comx) {
                $id = $comx["id"];
                $data_file = $comx_dir . $id . ".data";
                $task_file = $comx_dir . $id . ".task";
                if (!file_exists($task_file)) {
                    $fp = fopen($data_file, "w");
                    fwrite($fp, json_encode($comx));
                    fclose($fp);
                    $execute_mode = $comx["execute"]["mode"];
                    $id_driver_mode = $comx["model"]["id_driver_mode"];
                    $vlan_check = $comx["model"]["vlan_check"];
                    $vlan_mib = $comx["model"]["vlan_mib"];
                    // begin create Local config
                    if ($execute_mode == "local") {
                        $file_exp = $tftp_cm_config . $comx["id"] . ".exp";
                        $file_tmp = $tftp_cm_config . $comx["id"] . ".tmp";
                        $id = $comx["id"];
                        $id_comx = $comx["id_comx"];
                        // TFTP mode
                        if ($id_driver_mode == "1") {
                            cmanager_comx_driver($file_exp, "0", $id_comx, $id, $ch, $connect_url, $connect_api);
                            cmanager_comx_driver($file_tmp, $id_driver_mode, $id_comx, $id, $ch, $connect_url, $connect_api);
                        }
                        // EXPECT mode
                        if ($id_driver_mode == "2") {
                            cmanager_comx_driver($file_exp, $id_driver_mode, $id_comx, $id, $ch, $connect_url, $connect_api);
                        }
                        // EXPECT Wi-Fi mode
                        if ($id_driver_mode == "3") {
                            cmanager_comx_driver($file_tmp, $id_driver_mode, $id_comx, $id, $ch, $connect_url, $connect_api);
                        }
                    }
                    // end create Local config
                    $execute_name = $driver_dir . $comx["execute"]["name"];
                    if (cmanager_comx_action($id, $ch, $connect_url, $connect_api, "prepare", "Prepare to run by " . $comx["execute"]["name"]) == "success") {
                        $execute_command = $execute_name . " " . $id . " < /dev/null >> " . $log_dir . "vivabill.log &";
                        $return = system_exec($execute_command);
                        echo system_addlog($func_role, $return, $execute_command);
                    }
                } else {
                    echo message_addlog($func_role, "Task " . $id . " is exists");
                }
            }
        } else {
            $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
        }
    }
}
コード例 #4
0
function tftp_server_modem($tftpserver, $ch, $connect_url, $connect_api)
{
    include "config.php";
    $func_role = basename(__FILE__) . " " . __FUNCTION__;
    curl_setopt($ch, CURLOPT_URL, $connect_url . "get_tftp_modem_change");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_tftp_server\":\"" . $tftpserver . "\",\"api\":\"" . $connect_api . "\"}");
    $return = curl_exec($ch);
    if (curl_errno($ch)) {
        echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
    } else {
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpcode == "200") {
            $tftp = json_decode($return, true);
            foreach ($tftp as $row) {
                // Start change TFTP modem
                $id = $row["id"];
                $idm = $row["idm"];
                $act = $row["act"];
                $file_task = $tftp_cm_process . "m" . $idm . ".task";
                if (file_exists($file_task)) {
                    echo message_addlog($func_role, "Task {$file_task} is runing by other process. Wait.");
                } else {
                    // get paramerets and create yml file
                    $config_data = tftp_generate_config_data($id, $idm, $ch, $connect_url, $connect_api);
                    // set main parameters
                    $execute_mode = $config_data["execute"]["mode"];
                    $execute_name = $driver_dir . $config_data["execute"]["name"];
                    // generate .src local config if necessary
                    if ($execute_mode == "local") {
                        if ($act == "1") {
                            tftp_generate_local_src($idm, $ch, $connect_url, $connect_api);
                        }
                    }
                    // build command and execute in thread
                    curl_setopt($ch, CURLOPT_URL, $connect_url . "set_tftp_modem_process");
                    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id\":\"" . $id . "\",\"api\":\"" . $connect_api . "\"}");
                    $return = curl_exec($ch);
                    if (curl_errno($ch)) {
                        echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
                    } else {
                        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                        if ($httpcode == "200") {
                            $result_data = json_decode($return, true);
                            $result = $result_data["result"];
                            if ($result == "success") {
                                $execute_command = $execute_name . " " . $id . " " . $idm . " " . $act . " < /dev/null >> " . $log_dir . "vivabill.log &";
                                $return = system_exec($execute_command);
                                echo system_addlog($func_role, $return, $execute_command);
                            }
                        } else {
                            $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
                            echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
                        }
                    }
                }
            }
            // Finish change TFTP modems
        } else {
            $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
        }
    }
}
コード例 #5
0
function ipfw_ipaddr_bi($router, $ch, $connect_url, $connect_api)
{
    include "config.php";
    $func_role = basename(__FILE__) . " " . __FUNCTION__;
    $config_ipaddr = array();
    curl_setopt($ch, CURLOPT_URL, $connect_url . "get_ipfw_ipaddr");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_router\":\"" . $router . "\",\"" . $connect_api . "\":\"1\"}");
    $return = curl_exec($ch);
    if (curl_errno($ch)) {
        echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
    } else {
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpcode == "200") {
            $config_ipaddr = json_decode($return, true);
        } else {
            $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
        }
    }
    $cou_ipaddr = count($config_ipaddr);
    if (count($cou_ipaddr > 0)) {
        echo message_addlog($func_role, "Get " . $cou_ipaddr . " IP from Billing");
    } else {
        echo message_addlog($func_role, "IP list from Billing is empty");
    }
    return $config_ipaddr;
}
コード例 #6
0
function task_manager($vcpid)
{
    $func_role = basename(__FILE__) . " " . __FUNCTION__;
    include "config.php";
    include "fn_core.php";
    include "fn_puppet.php";
    include "fn_ipfw.php";
    include "fn_dhcp.php";
    include "fn_vrdat.php";
    include "fn_tftp.php";
    include "fn_ovsp.php";
    include "fn_comx.php";
    $pid_file = $pid_dir . "vivabill.pid";
    if (file_exists($pid_file)) {
        // b_work -------------------------------------------------
        $a_vfpid = file($pid_file);
        $vfpid = $a_vfpid[0];
        if ($vfpid == $vcpid) {
            exec($uname . " -o", $rname_os);
            exec($uname . " -r", $rname_rel);
            exec($hostname, $rname_host);
            $name_os = $rname_os[0];
            $name_rel = $rname_rel[0];
            $name_host = $rname_host[0];
            $data = file_get_contents($home_dir . "vivabill.json");
            $config = json_decode($data, true);
            $uuid = $config["uuid"];
            $connect_url = $config["connect"]["url"] . "/viva/";
            $connect_api = $config["connect"]["api"];
            $connect_username = $config["connect"]["username"];
            $connect_password = $config["connect"]["password"];
            echo message_addlog($func_role, "Open process UUID=" . $uuid);
            $rproc = true;
            $current_maintain = "0";
            $current_notify_interval = 10;
            $counter = 0;
            // Set SSL parameters
            $ch = curl_init();
            $headers = array("Content-Type: application/json");
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($ch, CURLOPT_CAINFO, $home_dir . "viva-cert.pem");
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_USERPWD, $connect_username . ":" . $connect_password);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            //Set HW
            curl_setopt($ch, CURLOPT_URL, $connect_url . "set_hw");
            curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"uuid\":\"" . $uuid . "\",\"name_os\":\"" . $name_os . "\",\"name_rel\":\"" . $name_rel . "\",\"hostname\":\"" . $name_host . "\",\"api\":\"" . $connect_api . "\"}");
            $return = curl_exec($ch);
            if (curl_errno($ch)) {
                echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
            } else {
                $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                if ($httpcode == "200") {
                    $status_load = json_decode($return, true);
                    $status = $status_load["status"];
                    $message = $status_load["message"];
                    echo system_addlog($func_role, $status, $message);
                } else {
                    $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
                    echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
                }
            }
            echo message_addlog($func_role, "Start Task manager with API v." . $connect_api . " URL " . $connect_url);
            while ($rproc == true) {
                // Start cycle
                if (!file_exists($pid_file)) {
                    echo message_addlog($func_role, "Stop Task manager");
                    $rproc = false;
                    break;
                } else {
                    $a_vfpid = file($pid_file);
                    $vfpid = $a_vfpid[0];
                    if ($vfpid != $vcpid) {
                        echo message_addlog($func_role, "Lost process UUID=" . $uuid);
                        $rproc = false;
                        break;
                    }
                }
                // COUTNER
                if ($counter > 600) {
                    $counter = 0;
                }
                //#######################
                //# START HW SEMAPHORES #
                //#######################
                curl_setopt($ch, CURLOPT_URL, $connect_url . "get_semaphores_hw");
                curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"uuid\":\"" . $uuid . "\",\"api\":\"" . $connect_api . "\"}");
                $return = curl_exec($ch);
                if (curl_errno($ch)) {
                    echo system_addlog($func_role, "1", "URL " . $current_url . " error: " . curl_error($ch));
                } else {
                    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                    if ($httpcode == "200") {
                        $hw = json_decode($return, true);
                        // Get TASK options
                        $sm_maintain = $hw["maintain"];
                        $sm_notify_interval = $hw["notify_interval"];
                        // get PROC options
                        $router = $hw["router"];
                        $sm_vpnserver = $hw["vpnserver"];
                        $dhcpserver = $hw["dhcpserver"];
                        $sm_dhcprelay = $hw["dhcprelay"];
                        $sm_radserver = $hw["radserver"];
                        $tftpserver = $hw["tftpserver"];
                        $sm_bmrserver = $hw["bmrserver"];
                        $sm_iptvserver = $hw["iptvserver"];
                        $sm_gponserver = $hw["gponserver"];
                        $sm_eponserver = $hw["eponserver"];
                        $sm_statistic = $hw["statistic"];
                        $sm_brasserver = $hw["bras"];
                        $cmanager = $hw["cmanager"];
                        // get maintain data
                        if ($current_maintain != $sm_maintain) {
                            switch ($sm_maintain) {
                                case "0":
                                    echo message_addlog($func_role, "End of maintain");
                                    break;
                                case "1":
                                    echo message_addlog($func_role, "Begin maintain");
                                    break;
                            }
                        }
                        // get notify data
                        if ($current_notify_interval != $sm_notify_interval) {
                            echo message_addlog($func_role, "Interval queries to API set to " . $sm_notify_interval . " second");
                        }
                        $current_maintain = $sm_maintain;
                        $current_notify_interval = $sm_notify_interval;
                        if ($sm_maintain == "0") {
                            // begin task process
                            ////////////////////////
                            // PUPPET declaration //
                            ////////////////////////
                            check_roles_facter($hw, $data_dir);
                            ////////////////////////
                            // TFTP Server        //
                            ////////////////////////
                            if ($tftpserver != "none") {
                                curl_setopt($ch, CURLOPT_URL, $connect_url . "get_semaphores_tftpserver");
                                curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_tftp_server\":\"" . $tftpserver . "\",\"api\":\"" . $connect_api . "\"}");
                                $return = curl_exec($ch);
                                if (curl_errno($ch)) {
                                    echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
                                } else {
                                    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                    if ($httpcode == "200") {
                                        $tftp = json_decode($return, true);
                                        $sm_tftp_server_config = $tftp["config"];
                                        $sm_tftp_server_modem = $tftp["modem"];
                                        $sm_tftp_server_check = $tftp["check"];
                                        if ($sm_tftp_server_config == "1") {
                                            echo message_addlog($func_role, "[tftp_server_config]");
                                            tftp_server_config($tftpserver, $ch, $connect_url, $connect_api);
                                        }
                                        if ($sm_tftp_server_modem == "1") {
                                            echo message_addlog($func_role, "[tftp_server_modem]");
                                            tftp_server_modem($tftpserver, $ch, $connect_url, $connect_api);
                                        }
                                        if ($sm_tftp_server_check == "1") {
                                            echo message_addlog($func_role, "[tftp_server_check]");
                                            tftp_server_check($tftpserver, $ch, $connect_url, $connect_api);
                                        }
                                        tftp_server_task_result($tftpserver, $ch, $connect_url, $connect_api);
                                    } else {
                                        $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
                                        echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
                                    }
                                }
                            }
                            ////////////////////////
                            // DHCP Server        //
                            ////////////////////////
                            if ($dhcpserver != "none") {
                                curl_setopt($ch, CURLOPT_URL, $connect_url . "get_semaphores_dhcpserver");
                                curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_dhcp_server\":\"" . $dhcpserver . "\",\"api\":\"" . $connect_api . "\"}");
                                $return = curl_exec($ch);
                                if (curl_errno($ch)) {
                                    echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
                                } else {
                                    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                    if ($httpcode == "200") {
                                        $dhcp = json_decode($return, true);
                                        $dhcpserver_config = $dhcp["config"];
                                        $dhcpserver_update = $dhcp["update"];
                                        if ($dhcpserver_config == "1") {
                                            echo message_addlog($func_role, "[dhcpserver_config]");
                                            dhcpserver_config($dhcpserver, $ch, $connect_url, $connect_api);
                                        }
                                        if ($dhcpserver_update == "1") {
                                            echo message_addlog($func_role, "[dhcpserver_update]");
                                            dhcpserver_update($dhcpserver, $ch, $connect_url, $connect_api);
                                        }
                                    } else {
                                        $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
                                        echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
                                    }
                                }
                            }
                            ////////////////////////
                            // Router             //
                            ////////////////////////
                            if ($router != "none") {
                                curl_setopt($ch, CURLOPT_URL, $connect_url . "get_semaphores_router");
                                curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_router\":\"" . $router . "\",\"api\":\"" . $connect_api . "\"}");
                                $return = curl_exec($ch);
                                if (curl_errno($ch)) {
                                    echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
                                } else {
                                    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                    if ($httpcode == "200") {
                                        $rou = json_decode($return, true);
                                        $dhcprelay_config = $rou["dhcprelay"]["config"];
                                        $dhcprelay_update = $rou["dhcprelay"]["update"];
                                        $vrdat_update = $rou["vrdat"]["update"];
                                        $vrdat_syncro = $rou["vrdat"]["syncro"];
                                        $ipfw_update = $rou["ipfw"]["update"];
                                        $ipfw_syncro = $rou["ipfw"]["syncro"];
                                        if ($dhcprelay_config == "1") {
                                            echo message_addlog($func_role, "[dhcpdelay_config]");
                                            dhcprelay_config($router, $ch, $connect_url, $connect_api);
                                        }
                                        if ($dhcprelay_update == "1") {
                                            echo message_addlog($func_role, "[dhcpdelay_update]");
                                            dhcprelay_update($router, $ch, $connect_url, $connect_api);
                                        }
                                        if ($vrdat_update == "1") {
                                            echo message_addlog($func_role, "[vrdat_update]");
                                            vrdat_update($router, $ch, $connect_url, $connect_api);
                                        }
                                        if ($vrdat_syncro == "1" or $counter == 0) {
                                            echo message_addlog($func_role, "[vrdat_syncro]");
                                            vrdat_syncro($router, $ch, $connect_url, $connect_api);
                                        }
                                        if ($ipfw_update == "1") {
                                            echo message_addlog($func_role, "[ipfw_update]");
                                            ipfw_update($router, $ch, $connect_url, $connect_api);
                                        }
                                        if ($ipfw_syncro == "1" or $counter == 0) {
                                            echo message_addlog($func_role, "[ipfw_syncro]");
                                            ipfw_syncro($router, $ch, $connect_url, $connect_api);
                                        }
                                    } else {
                                        $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
                                        echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
                                    }
                                }
                            }
                            ////////////////////////
                            // CManager           //
                            ////////////////////////
                            if ($cmanager != "none") {
                                foreach (explode(".", $cmanager) as $id_comx_manager) {
                                    curl_setopt($ch, CURLOPT_URL, $connect_url . "get_semaphores_cmanager");
                                    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_comx_manager\":\"" . $id_comx_manager . "\",\"api\":\"" . $connect_api . "\"}");
                                    $return = curl_exec($ch);
                                    if (curl_errno($ch)) {
                                        echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
                                    } else {
                                        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                                        if ($httpcode == "200") {
                                            $cman = json_decode($return, true);
                                            $cmanager_ovsp_task = $cman["ovsp"]["task"];
                                            $cmanager_ovsp_check = $cman["ovsp"]["check"];
                                            $cmanager_comx_task = $cman["comx"]["task"];
                                            $cmanager_comx_check = $cman["comx"]["check"];
                                            if ($cmanager_ovsp_task == "1") {
                                                echo message_addlog($func_role, "[cmanager_ovsp_task]");
                                                cmanager_ovsp_task($id_comx_manager, $ch, $connect_url, $connect_api);
                                            }
                                            if ($cmanager_ovsp_check == "1") {
                                                echo message_addlog($func_role, "[cmanager_ovsp_check]");
                                                cmanager_ovsp_check($id_comx_manager, $ch, $connect_url, $connect_api);
                                            }
                                            cmanager_ovsp_task_result($id_comx_manager, $ch, $connect_url, $connect_api);
                                            if ($cmanager_comx_task == "1") {
                                                echo message_addlog($func_role, "[cmanager_comx_task]");
                                                cmanager_comx_task($id_comx_manager, $ch, $connect_url, $connect_api);
                                            }
                                            if ($cmanager_comx_check == "1") {
                                                echo message_addlog($func_role, "[cmanager_comx_check]");
                                                cmanager_comx_check($id_comx_manager, $ch, $connect_url, $connect_api);
                                            }
                                            cmanager_comx_check($id_comx_manager, $ch, $connect_url, $connect_api);
                                        }
                                    }
                                }
                            }
                            ////////////////////////
                            //                    //
                            ////////////////////////
                            ////////////////////////
                            // End of tasks       //
                            ////////////////////////
                        }
                        // end task process
                    } else {
                        $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
                        echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
                    }
                }
                sleep($current_notify_interval);
                $counter = $counter + $current_notify_interval;
            }
            // End cycle
            curl_close($ch);
            echo message_addlog($func_role, "Close process UUID=" . $uuid);
        }
        // e_work -----------------------------------------
    } else {
        echo message_addlog($func_role, "PID was not found.");
    }
}
コード例 #7
0
function cmanager_ovsp_task($id_comx_manager, $ch, $connect_url, $connect_api)
{
    include "config.php";
    $func_role = basename(__FILE__) . " " . __FUNCTION__;
    curl_setopt($ch, CURLOPT_URL, $connect_url . "get_cmanager_ovsp_list");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_comx_manager\":\"" . $id_comx_manager . "\",\"api\":\"" . $connect_api . "\"}");
    $return = curl_exec($ch);
    if (curl_errno($ch)) {
        echo system_addlog($func_role, "1", "Curl error: " . curl_error($ch));
    } else {
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpcode == "200") {
            $r_ovsp = json_decode($return, true);
            foreach ($r_ovsp as $ovsp) {
                $id = $ovsp["id"];
                $data_file = $ovsp_dir . $id . ".data";
                $task_file = $ovsp_dir . $id . ".task";
                if (!file_exists($task_file)) {
                    $fp = fopen($data_file, "w");
                    fwrite($fp, json_encode($ovsp));
                    fclose($fp);
                    $execute_name = $driver_dir . $ovsp["execute"]["name"];
                    if (cmanager_ovsp_action($id, $ch, $connect_url, $connect_api, "process", "") == "success") {
                        $execute_command = $execute_name . " " . $id . " < /dev/null >> " . $log_dir . "vivabill.log &";
                        $return = system_exec($execute_command);
                        echo system_addlog($func_role, $return, $execute_command);
                    }
                } else {
                    echo message_addlog($func_role, "Task " . $id . " is exists");
                }
            }
        } else {
            $last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            echo system_addlog($func_role, "1", "Error [" . $httpcode . "] " . $last_url);
        }
    }
}