コード例 #1
0
ファイル: CustomersController.php プロジェクト: moay/shineisp
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
     $form = $this->getForm("/admin/customers/process");
     // Add the customer custom attributes
     $form = CustomAttributes::getElements($form);
     $request = $this->getRequest();
     // Create the buttons in the edit form
     $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/customers/list", "label" => $this->translator->translate('List'), "params" => array('css' => null)), array("url" => "/admin/customers/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null)));
     try {
         // Check if we have a POST request
         if (!$request->isPost()) {
             return $this->_helper->redirector('list', 'customers', 'admin');
         }
         if ($form->isValid($request->getPost())) {
             $params = $request->getPost();
             $area = intval($params['area']);
             if ($area != 0) {
                 $province = Provinces::find($area);
                 $area = $province->code;
                 $params['area'] = $area;
             }
             $id = Customers::saveAll($params, $request->getParam('customer_id'));
             CustomAttributes::saveElementsValues($form->getSubForm('attributes')->getValues(), $request->getParam('customer_id'), "customers");
             $this->_helper->redirector('edit', 'customers', 'admin', array('id' => $id, 'mex' => $this->translator->translate('The task requested has been executed successfully.'), 'status' => 'success'));
         } else {
             $this->view->form = $form;
             $this->view->title = $this->translator->translate("Customer details");
             $this->view->description = $this->translator->translate("Here you can edit the customer details.");
             return $this->render('applicantform');
         }
     } catch (Exception $e) {
         $this->_helper->redirector('edit', 'customers', 'admin', array('id' => $id, 'mex' => $e->getMessage(), 'status' => 'danger'));
     }
 }
コード例 #2
0
ファイル: Main.php プロジェクト: moay/shineisp
 /**
  * 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();
     }
 }
コード例 #3
0
ファイル: ServersController.php プロジェクト: kokkez/shineisp
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $request = $this->getRequest();
     $id = $this->getRequest()->getParam('server_id');
     $this->view->title = $this->translator->translate("Edit Server");
     $this->view->description = $this->translator->translate("Edit the server parameters.");
     // Create the buttons in the edit form
     $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/servers/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/servers/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null)));
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('index');
     }
     // Get our form and validate it
     $form = $this->getForm('/admin/servers/process', $id);
     if (!$form->isValid($request->getPost())) {
         $this->view->form = $form;
         // Invalid entries
         return $this->render('applicantform');
         // re-render the login form
     }
     // Save the data
     $serverID = Servers::saveAll($form->getValues());
     #OrdersItemsServers::removeServer(89, $serverID);
     // Save the attributes
     $attributeValues = $form->getSubForm('attributes')->getValues();
     CustomAttributes::saveElementsValues($attributeValues, $serverID, "servers");
     return $this->_helper->redirector('edit', 'servers', 'admin', array('id' => $id));
 }