function openqrm_puppet_cloud_product($cmd, $cloud_hook_config)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RootDir;
    $openqrm_server = new openqrm_server();
    $event->log("openqrm_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Handling " . $cmd . " event", "", "", 0, 0, 0);
    switch ($cmd) {
        case "add":
            $event->log("openqrm_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Handling cloud-product " . $cmd . " event", "", "", 0, 0, 0);
            // create application products
            $next_sort_id = 0;
            $db = openqrm_get_db_connection();
            $puppet = new puppet();
            $puppet_group_array = $puppet->get_available_groups();
            foreach ($puppet_group_array as $index => $puppet_app) {
                $event->log("openqrm_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Adding application " . $puppet_app . " as cloud-product", "", "", 0, 0, 0);
                $cloud_product_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                $create_application_cloudselector_config = "insert into cloud_selector (id, type, sort_id, quantity, price, name, description, state) VALUES (" . $cloud_product_id . ", 'application', " . $next_sort_id . ", 'puppet/" . $puppet_app . "', 1, '" . $puppet_app . "', '" . $puppet_app . " via puppet', 1);";
                $recordSet = $db->Execute($create_application_cloudselector_config);
                $next_sort_id++;
            }
            break;
        case "remove":
            $cloud_product_class = $RootDir . "/plugins/cloud/class/cloudselector.class.php";
            if (file_exists($cloud_product_class)) {
                require_once $cloud_product_class;
                $cloud_selector = new cloudselector();
                $cloud_selector_id_ar = $cloud_selector->get_all_ids();
                foreach ($cloud_selector_id_ar as $key => $value) {
                    $id = $value['id'];
                    $cloud_selector->get_instance_by_id($id);
                    $pos = strpos($cloud_selector->quantity, 'puppet/');
                    if ($pos !== false) {
                        $event->log("openqrm_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Removing application " . $cloud_selector->quantity . " from cloud-products", "", "", 0, 0, 0);
                        $cloud_selector->remove($id);
                    }
                }
            }
            break;
    }
}
Example #2
0
 function ProductGetDetails($method_parameters)
 {
     global $event;
     $parameter_array = explode(',', $method_parameters);
     $mode = $parameter_array[0];
     $username = $parameter_array[1];
     $password = $parameter_array[2];
     $product_id = $parameter_array[3];
     // check all user input
     for ($i = 0; $i <= 3; $i++) {
         if (!$this->check_param($parameter_array[$i])) {
             $event->log("cloudsoap->ProductGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Not allowing user-intput with special-characters : {$parameter_array[$i]}", "", "", 0, 0, 0);
             return;
         }
     }
     // check parameter count
     $parameter_count = count($parameter_array);
     if ($parameter_count != 4) {
         $event->log("cloudsoap->ProductGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Wrong parameter count {$parameter_count} ! Exiting.", "", "", 0, 0, 0);
         return;
     }
     // check authentication
     if (!$this->check_user($mode, $username, $password)) {
         $event->log("cloudsoap->ProductGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User authentication failed (mode {$mode})", "", "", 0, 0, 0);
         return;
     }
     // cloudselector enabled ?
     $cc_conf = new cloudconfig();
     $cloud_selector_enabled = $cc_conf->get_value(22);
     // cloudselector
     if (strcmp($cloud_selector_enabled, "true")) {
         $event->log("cloudsoap->ProductGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloudselector is not enabled on this Cloud.", "", "", 0, 0, 0);
         return;
     }
     $event->log("cloudsoap->ProductGetDetails", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Providing details of Cloud Product {$product_id}", "", "", 0, 0, 0);
     $cloudproduct_details = array();
     $product_id = trim($product_id);
     $cloudselector = new cloudselector();
     $cloudselector->get_instance_by_id($product_id);
     // if the product is disabled we return for the user mode
     if ($cloudselector->state == 0) {
         if (!strcmp($mode, "user")) {
             return;
         }
     }
     // fill the array to return
     $cloudproduct_details['id'] = $product_id;
     $cloudproduct_details['type'] = $cloudselector->type;
     $cloudproduct_details['sort_id'] = $cloudselector->sort_id;
     $cloudproduct_details['quantity'] = $cloudselector->quantity;
     $cloudproduct_details['price'] = $cloudselector->price;
     $cloudproduct_details['name'] = $cloudselector->name;
     $cloudproduct_details['description'] = $cloudselector->description;
     $cloudproduct_details['state'] = $cloudselector->state;
     return $cloudproduct_details;
 }