/** * Update the Configuration of the Hosting Plan * * * Update the configuration of the service selected * with the new parameters of the service. * * IMPORTANT: * We have to sync the parameters with the Isp Panel selected */ public function updateconfAction() { $id = $this->getRequest()->getParam('id'); if (is_numeric($id)) { // Get the service information $service = OrdersItems::getAllInfo($id, "product_id"); if (!empty($service['product_id'])) { // Get the system parameters/attributes of the service selected $sysattributes = ProductsAttributes::getSysAttributes($service['product_id']); // Update the parameters in the service order detail OrdersItems::updateSysParameters($id, $sysattributes); } $this->_helper->redirector('edit', 'ordersitems', 'admin', array('id' => $id, 'mex' => $this->translator->translate('The task requested has been executed successfully.'), 'status' => 'success')); } else { $this->_helper->redirector('list', 'orders', 'admin', array('mex' => $this->translator->translate('Service item not found.'), 'status' => 'danger')); } }
/** * Send the email profile to the user */ public function sendMail($task) { $ISP = ISP::getByCustomerId($task['customer_id']); if (!$ISP || !isset($ISP['isp_id']) || !is_numeric($ISP['isp_id'])) { // ISP not found, can't send mail return false; } // Get the service details $service = OrdersItems::getAllInfo($task['orderitem_id']); // If the setup has been written by the task action then ... if (!empty($service['setup'])) { $setup = json_decode($service['setup'], true); // Get the service/product name $productname = !empty($service['Products']['ProductsData'][0]['name']) ? $service['Products']['ProductsData'][0]['name'] : ""; $welcome_mail = !empty($service['Products']['welcome_mail_id']) && intval($service['Products']['welcome_mail_id']) > 0 ? intval($service['Products']['welcome_mail_id']) : 'new_hosting'; // new_hosting = fallback to old method if no template is set // Check if the customer is present in the service and if there is a welcome_mail set for the bought product if (!empty($service['Orders']['Customers'])) { // Getting the customer $customer = $service['Orders']['Customers']; $strSetup = ""; foreach ($setup as $section => $details) { $strSetup .= strtoupper($section) . "<hr/>"; foreach ($details as $label => $detail) { $strSetup .= "{$label}: " . $detail . "<br/>"; } $strSetup .= "<br/>"; } Shineisp_Commons_Utilities::sendEmailTemplate($ISP['email'], $welcome_mail, array('setup' => $strSetup, 'fullname' => $customer['firstname'] . " " . $customer['lastname'], 'hostingplan' => $productname, 'controlpanel' => $ISP['website'] . ":8080", 'signature' => $ISP['company']), null, null, null, $ISP, $customer['language_id']); } } }
/** * CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES * Check all the services [domains, products] and create the orders for each customer only if the service has been set as renewable * @return void */ public static function checkServices() { try { $i = 0; $customers = array(); /* We have to start to get all the domains that them expiring date is today then we have to create a custom array sorted by customerID in order to group services and domains of a specific customer. */ // Get all the active domains that expire in 1 day $domains = Domains::getExpiringDomainsByDays(1, Statuses::id("active", "domains")); if ($domains) { Shineisp_Commons_Utilities::log("There are (" . count($domains) . ") new domains to renew"); // Create the customer group list for the email summary foreach ($domains as $domain) { if (is_numeric($domain['reseller'])) { $invoice_dest = Customers::getAllInfo($domain['reseller']); $customers[$domain['customer_id']]['id'] = $invoice_dest['customer_id']; $customers[$domain['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company']; $customers[$domain['customer_id']]['email'] = $invoice_dest['email']; $customers[$domain['customer_id']]['language_id'] = $invoice_dest['language_id']; } else { $customers[$domain['customer_id']]['id'] = $domain['customer_id']; $customers[$domain['customer_id']]['fullname'] = $domain['fullname']; $customers[$domain['customer_id']]['email'] = $domain['email']; $customers[$domain['customer_id']]['language_id'] = $domain['language_id']; } $customers[$domain['customer_id']]['products'][$i]['name'] = $domain['domain']; $customers[$domain['customer_id']]['products'][$i]['type'] = "domain"; $customers[$domain['customer_id']]['products'][$i]['renew'] = $domain['renew']; $customers[$domain['customer_id']]['products'][$i]['expiring_date'] = $domain['expiringdate']; $customers[$domain['customer_id']]['products'][$i]['days'] = $domain['days']; // Get the last old order item id if (!empty($domain['oldorders'])) { // find the domain foreach ($domain['oldorders'] as $olditemorder) { // Get all the information from the old order $olditem = OrdersItems::getAllInfo($olditemorder['orderitem_id']); // Check if the old order item refers to the domain selected if (!empty($olditem['parameters']) && !empty($olditem['Orders']['OrdersItemsDomains'][0]['Domains']['tld_id'])) { // Get the old configuration parameters $params = json_decode($olditem['parameters'], true); // Zend_Debug::dump($olditem); // Zend_Debug::dump($params); // Zend_Debug::dump($domain['domain']); // Extract the domain name and match it with the domain selected if (!empty($params['domain']) && $params['domain']['name'] == $domain['domain']) { $customers[$domain['customer_id']]['products'][$i]['oldorderitemid'] = $olditemorder['orderitem_id']; } } } } Shineisp_Commons_Utilities::log("- " . $domain['domain']); $i++; } } /* * Now we have to get the services expired and we have to sum the previous $customers array with these * new information. */ // Get all the services active that expire the day after $services = OrdersItems::getExpiringServicesByDays(1, Statuses::id("complete", "orders")); if ($services) { Shineisp_Commons_Utilities::log("There are (" . count($services) . ") new services to renew"); // Create the customer group list for the email summary foreach ($services as $service) { if (is_numeric($service['reseller'])) { $invoice_dest = Customers::getAllInfo($service['reseller']); $customers[$service['customer_id']]['id'] = $invoice_dest['customer_id']; $customers[$service['customer_id']]['fullname'] = $invoice_dest['firstname'] . " " . $invoice_dest['lastname'] . " " . $invoice_dest['company']; $customers[$service['customer_id']]['email'] = $invoice_dest['email']; $customers[$service['customer_id']]['password'] = $invoice_dest['password']; $customers[$service['customer_id']]['language_id'] = $invoice_dest['language_id']; } else { $customers[$service['customer_id']]['id'] = $service['id']; $customers[$service['customer_id']]['fullname'] = $service['fullname']; $customers[$service['customer_id']]['email'] = $service['email']; $customers[$service['customer_id']]['password'] = $service['password']; $customers[$service['customer_id']]['language_id'] = $service['language_id']; } $customers[$service['customer_id']]['products'][$i]['name'] = $service['product']; $customers[$service['customer_id']]['products'][$i]['type'] = "service"; $customers[$service['customer_id']]['products'][$i]['renew'] = $service['renew']; $customers[$service['customer_id']]['products'][$i]['expiring_date'] = $service['expiringdate']; $customers[$service['customer_id']]['products'][$i]['days'] = $service['days']; $customers[$service['customer_id']]['products'][$i]['oldorderitemid'] = $service['detail_id']; Shineisp_Commons_Utilities::log("- " . $service['product']); $i++; } } // Create the email messages for the customers if (count($customers) > 0) { foreach ($customers as $customer) { $items = ""; // **** CREATE THE ORDER FOR ALL THE AUTORENEWABLE DOMAINS/SERVICES *** // ============================================================ // Renew all the services and domain where the customer has choosen the autorenew of the service. $orderID = Orders::renewOrder($customer['id'], $customer['products']); if (is_numeric($orderID)) { $link = Fastlinks::findlinks($orderID, $customer['id'], 'orders'); // Create the fast link to include in the email if (!empty($link[0]['code'])) { $url = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/" . $link[0]['code']; } else { $url = "http://" . $_SERVER['HTTP_HOST']; } Shineisp_Commons_Utilities::sendEmailTemplate($customer['email'], 'order_renew', array('fullname' => $customer['fullname'], ':shineisp:' => $customer, 'url' => $url), null, null, null, null, $customer['language_id'], Settings::findbyParam('cron_notify')); } } } /* * Now we have to set as expired all the domains records that the date is the date of the expiring of the domain * // Expired */ $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('expired', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', 0)->addWhere('DATEDIFF(d.expiring_date, CURRENT_DATE) >= ?', 0); $dq->execute(null, Doctrine::HYDRATE_ARRAY); /* * Now we have to set as closed all the domains records that the date is older of -2 days * // Closed */ $dq = Doctrine_Query::create()->update('Domains d')->set('d.status_id', Statuses::id('suspended', 'domains'))->where('DATEDIFF(d.expiring_date, CURRENT_DATE) <= ?', -2); $dq->execute(null, Doctrine::HYDRATE_ARRAY); /* * Now we have to set as expired all the services records * // Expired */ $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('expired', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', 0); $dq->execute(null, Doctrine::HYDRATE_ARRAY); /* * Now we have to set as deleted all the services records * // Deleted */ $dq = Doctrine_Query::create()->update('OrdersItems oi')->set('oi.status_id', Statuses::id('deleted', 'orders'))->where('DATEDIFF(oi.date_end, CURRENT_DATE) <= ?', -2); $dq->execute(null, Doctrine::HYDRATE_ARRAY); Shineisp_Commons_Utilities::sendEmailTemplate(null, 'cron', array('cronjob' => 'Check Services'), null, null, null, null, null, Settings::findbyParam('cron_notify')); } catch (Exception $e) { Shineisp_Commons_Utilities::logs($e->getMessage(), "cron.log"); return false; } return true; }
/** * Create a new email account * * Executes the creation of new email account 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 Web domain must be registered in IspConfig * * @param array $task Must be a valid task * @return mixed True, or throw an Exception if failed. * @access public */ public function create_mail(array $task) { $emailUserID = false; $server = self::getServer($task['orderitem_id'], 'mail'); // Get the service details $service = OrdersItems::getAllInfo($task['orderitem_id']); if (!empty($service)) { // Get the Json encoded parameters in the task $parameters = json_decode($task['parameters'], true); if (empty($parameters)) { throw new Exception("No parameters found in the service", 3501); } // 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 domain set in the orderitems bought from the customer $domains = OrdersItemsDomains::get_domains($task['orderitem_id']); // For each domain bought in the service ... foreach ($domains as $domain) { $email = 'info@' . $domain['domain']; // Create a random password string $password = Shineisp_Commons_Utilities::GenerateRandomString(); $params = array('server_id' => $ServerId, 'domain' => $domain['domain'], 'active' => 'y'); try { // Get the domain name ID $record = $client->mail_domain_get_by_domain($this->getSession(), $domain['domain']); // Create the mail domain if (empty($record['domain_id'])) { $domainId = $client->mail_domain_add($this->getSession(), $clientId, $params); } else { $domainId = $record['domain_id']; } } catch (SoapFault $e) { throw new Exception("There was a problem with the Mail Domain creation: " . $e->getMessage() . " - " . __METHOD__ . " - Parameters: " . json_encode($params), "3506"); } $defaultQuota = Shineisp_Commons_Utilities::MB2Bytes(100); // 100MB default value $params = array('server_id' => $ServerId, 'email' => $email, 'login' => $email, 'password' => $password, 'uid' => 5000, 'gid' => 5000, 'maildir' => '/var/vmail/' . $domain['domain'] . "/info", 'quota' => !empty($parameters['mailquota']) && is_numeric($parameters['mailquota']) && $parameters['mailquota'] > 0 ? Shineisp_Commons_Utilities::MB2Bytes($parameters['mailquota']) : $defaultQuota, 'cc' => '', 'homedir' => '', 'autoresponder' => 'n', 'autoresponder_start_date' => '', 'autoresponder_end_date' => '', 'autoresponder_text' => '', 'move_junk' => 'n', 'custom_mailfilter' => '', 'postfix' => 'y', 'access' => 'n', 'disableimap' => 'n', 'disablepop3' => 'n', 'disabledeliver' => 'n', 'disablesmtp' => 'n'); try { // Create the mailbox $emailUserID = $client->mail_user_add($this->getSession(), $clientId, $params); } catch (SoapFault $e) { throw new Exception("There was a problem with Email account creation: " . $e->getMessage() . " - " . __METHOD__ . " - Parameters: " . json_encode($params), "3506"); } // Save the setup in the service setup field OrdersItems::set_setup($task['orderitem_id'], array('username' => $email, 'password' => $password), "emails"); // 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 remote mail server id set in the ShineISP server profile.", "3502"); } } else { throw new Exception("Mail Server has not been found in IspConfig server settings.", "3501"); } } // Logout from the IspConfig Remote System $client->logout($this->getSession()); return $emailUserID; }