/** * Add or Remove an order item to/from a server * * * @param integer $orderItemID * @param integer $serverID */ private static function doAddRemove($orderItemID, $serverID, $action = '') { $ret = false; if (is_numeric($orderItemID) && is_numeric($serverID) && ($action == 'add' || $action == 'remove')) { $serverID = intval($serverID); $itemID = intval($orderItemID); if ($action == 'remove') { $record = self::findByServerAndItem($serverID, $itemID); $record->delete(); $ret = true; } else { $order = OrdersItems::find($orderItemID, 'order_id', true); if (!empty($order) && is_array($order) && count($order) > 0) { $order = $order[0]; if (!isset($order['order_id']) || intval($order['order_id']) == 0) { $ret = false; } $orderID = intval($order['order_id']); $OrdersItemsServers = new self(); $OrdersItemsServers->server_id = $serverID; $OrdersItemsServers->order_id = $orderID; $OrdersItemsServers->orderitem_id = $itemID; $OrdersItemsServers->save(); $ret = true; } } // Always update server stats $Server = Servers::find($serverID); $Server->services = OrdersItemsServers::countByServerId($serverID); $Server->save(); return $ret; } return false; }
/** * Create a new website * * Executes the creation of new website in the IspConfig control panel * Note in order to not fail this command, it must meet the following requirements: * * - The customer must be registered in the db. * - The parameters must be saved in the service detail (orderitems table) * * @param array $task Must be a valid task * @return mixed True, or throw an Exception if failed. * @access public */ public function create_website(array $task) { $params = array(); try { $server = self::getServer($task['orderitem_id'], 'web'); // Get the server id if (!empty($server['server_id']) && is_numeric($server['server_id'])) { $clientId = self::get_client_id($task, $server['server_id']); // Connection to the SOAP system $client = $this->connect($server['server_id']); // Get the remote server ID set in the servers profile in ShineISP $customAttribute = CustomAttributes::getAttribute($server['server_id'], "remote_server_id"); // Get the remote server id set in ShineISP if (is_numeric($customAttribute['value'])) { $ServerId = $customAttribute['value']; // Get the Json encoded parameters in the task $parameters = json_decode($task['parameters'], true); // Get the domain $domains = OrdersItemsDomains::get_domains($task['orderitem_id']); if (!empty($domains[0]['domain'])) { $params = array('server_id' => $ServerId, 'ip_address' => '*', 'domain' => $domains[0]['domain'], 'type' => 'vhost', 'parent_domain_id' => 0, 'vhost_type' => 'name', 'hd_quota' => $parameters['webspace'], 'traffic_quota' => $parameters['trafficdata'], 'cgi' => 'n', 'ssi' => 'n', 'suexec' => 'y', 'errordocs' => 1, 'is_subdomainwww' => 1, 'subdomain' => 'www', 'php' => 'fast-cgi', 'ruby' => 'n', 'redirect_type' => '', 'redirect_path' => '', 'ssl' => 'n', 'ssl_state' => '', 'ssl_locality' => '', 'ssl_organisation' => '', 'ssl_organisation_unit' => '', 'ssl_country' => '', 'ssl_domain' => '', 'ssl_request' => '', 'ssl_cert' => '', 'ssl_bundle' => '', 'ssl_action' => '', 'stats_password' => '', 'stats_type' => 'webalizer', 'allow_override' => 'All', 'apache_directives' => '', 'php_open_basedir' => '/', 'custom_php_ini' => '', 'backup_interval' => '', 'backup_copies' => 1, 'active' => 'y', 'traffic_quota_lock' => 'n', 'pm_process_idle_timeout' => '10', 'pm_max_requests' => '0'); try { $websiteId = $client->sites_web_domain_add($this->getSession(), $clientId, $params, $readonly = false); if (!is_numeric($websiteId)) { throw new Exception("There was a problem with website creation: sites_web_domain_add doesn't return the websiteID identifier", "3505"); } } catch (SoapFault $e) { throw new Exception("There was a problem with " . $domains[0]['domain'] . " website creation: " . $e->getMessage() . " - Parameters: " . json_encode($params), "3504"); } // Add relation between order_item and server OrdersItemsServers::addServer($task['orderitem_id'], $server['server_id']); // Create the log message Shineisp_Commons_Utilities::logs("ID: " . $task['action_id'] . " - " . __METHOD__ . " - Parameters: " . json_encode($params), "ispconfig.log"); } else { throw new Exception("No domain set for the selected service in the ShineISP service order detail ID #: " . $task['orderitem_id'], "3503"); } } else { throw new Exception("No remote web server id set in the ShineISP server profile.", "3502"); } } else { throw new Exception("Web Server has not been found in IspConfig server settings.", "3501"); } // Logout from the IspConfig Remote System $client->logout($this->getSession()); return $websiteId; } catch (Exception $e) { Shineisp_Commons_Utilities::logs(__METHOD__ . ": " . $e->getMessage()); } }