/** * Create a new client * * Executes the creation of new client 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 customer has bought a hosting plan * * @param array $task Must be a valid task * @return integer RemoteClientId * @access public */ public function create_client(array $task) { $clientId = ""; if (empty($task)) { throw new Exception('Task empty.', '3000'); } // Execute a custom event $this->events()->trigger('panels_create_client_before', __CLASS__, array('task' => $task)); $server = self::getServer($task['orderitem_id'], 'web'); // Connection to the SOAP system $client = $this->connect($server['server_id']); if (!$client) { throw new Exception("There is no way to connect the client with the IspConfig Panel.", "3010"); } try { // Get all the customer information $customer = Customers::getAllInfo($task['customer_id']); // Get the client id saved previously in the customer information page $customAttribute = CustomAttributes::getAttribute($task['customer_id'], 'client_id'); // Get the custom ISPConfig attribute set in the customer control panel if (is_numeric($customAttribute['value'])) { /** * Client_id (IspConfig Attribute Set in ShineISP database in the setup of the panel) * @see Shineisp_Controller_Plugin_SetupcPanelsModules */ $clientId = $customAttribute['value']; $record = $client->client_get($this->getSession(), $clientId); if ($record == false) { $clientId = ""; } } // Customer Profile $record['company_name'] = $customer['company']; $record['contact_name'] = $customer['firstname'] . " " . $customer['lastname']; $record['customer_no'] = $customer['customer_id']; $record['vat_id'] = $customer['vat']; $record['email'] = $customer['email']; $record['street'] = !empty($customer['Addresses'][0]['address']) ? $customer['Addresses'][0]['address'] : ""; $record['zip'] = !empty($customer['Addresses'][0]['code']) ? $customer['Addresses'][0]['code'] : ""; $record['city'] = !empty($customer['Addresses'][0]['city']) ? $customer['Addresses'][0]['city'] : ""; $record['state'] = !empty($customer['Addresses'][0]['area']) ? $customer['Addresses'][0]['area'] : ""; $record['country'] = !empty($customer['Addresses'][0]['Countries']['code']) ? $customer['Addresses'][0]['Countries']['code'] : ""; $record['mobile'] = Contacts::getContact($customer['customer_id'], "Mobile"); $record['fax'] = Contacts::getContact($customer['customer_id'], "Fax"); $record['telephone'] = Contacts::getContact($customer['customer_id']); // System Configuration $languagecode = Languages::get_code($customer['language_id']); $record['language'] = $languagecode; $record['usertheme'] = "default"; $record['template_master'] = 0; $record['template_additional'] = ""; $record['created_at'] = date(''); $record['web_php_options'] = "no,fast-cgi,cgi,mod,suphp,php-fpm"; $record['ssh_chroot'] = 'jailkit'; // Get the Json encoded parameters in the task $parameters = json_decode($task['parameters'], true); // Match all the ShineISP product system attribute and IspConfig attributes (see below about info) $retval = self::matchFieldsValues($parameters, $record); if (is_array($retval)) { $record = array_merge($record, $retval); } else { Shineisp_Commons_Utilities::logs("No hosting attribute parameters have been set in ShineISP. Check the hosting product attributes section.", "ispconfig.log"); } // Execute the SOAP action if (!empty($clientId) && is_numeric($clientId)) { $client->client_update($this->getSession(), $clientId, 1, $record); } else { $arrUsernames = array(); $arrUsernames = self::generateUsernames($customer); // Check if username is available foreach ($arrUsernames as $username) { if (!$client->client_get_by_username($this->getSession(), $username)) { break; } } // Create a random password string $password = Shineisp_Commons_Utilities::GenerateRandomString(); $record['username'] = $username; $record['password'] = $password; // Save the setup in the service setup field OrdersItems::set_setup($task['orderitem_id'], array('url' => 'http://' . $server['ip'] . ':8080', 'username' => $username, 'password' => $password), "webpanel"); // Adding the client in ISPConfig $clientId = $client->client_add($this->getSession(), 0, $record); // Update the custom customer attribute client_id CustomAttributes::saveElementsValues(array(array('client_id' => $clientId)), $task['customer_id'], "customers"); // Execute a custom event $this->events()->trigger('panels_create_client_after', __CLASS__, array('task' => $task, 'clientid' => $clientId, 'customerdata' => $record)); } // Create the log message Shineisp_Commons_Utilities::logs("ID: " . $task['action_id'] . " - " . __METHOD__ . " - Parameters: " . json_encode($record), "ispconfig.log"); // Logout from the IspConfig Remote System $client->logout($this->getSession()); return $clientId; } catch (Exception $e) { Shineisp_Commons_Utilities::logs(__METHOD__ . ": " . $e->getMessage()); echo $e->getMessage(); } }