/** * generateResetPasswordKey * generate a new key needed for password reset * @param $customerId * @return $key */ public static function generateResetPasswordKey($customerid) { $resetKey = Shineisp_Commons_Utilities::GenerateRandomPassword(24); $q = Doctrine_Query::create()->update('Customers')->set('resetpwd_key', '?', $resetKey)->set('resetpwd_expire', '?', date('Y-m-d H:i:s', time() + 2 * 3600))->where('customer_id = ?', intval($customerid))->andWhere("isp_id = ?", Isp::getCurrentId()); if ($q->execute()) { return $resetKey; } }
public function resetpwdAction() { $request = $this->getRequest(); $resetKey = $request->getParam('id'); $registry = Shineisp_Registry::getInstance(); $translator = $registry->Zend_Translate; $customer = Customers::getCustomerByResetKey($resetKey); if ($customer) { $newPwd = Shineisp_Commons_Utilities::GenerateRandomPassword(); try { // Update the record Customers::setCustomerPassword($customer[0]['customer_id'], $newPwd); // Force expire of reset link Customers::deleteResetPasswordKey($customer[0]['customer_id']); } catch (Exception $e) { echo $e->getMessage(); die; } $customer[0]['password'] = $newPwd; // Getting the email template Shineisp_Commons_Utilities::sendEmailTemplate($customer[0]['email'], 'password_new', array('fullname' => $customer[0]['lastname'], 'email' => $customer[0]['email'], ':shineisp:' => $customer, 'password' => $newPwd), null, null, null, null, $customer[0]['language_id']); $this->view->mextype = "success"; $this->view->mex = $translator->translate('Email sent'); } else { $this->view->mextype = "alert"; $this->view->mex = $translator->translate('An error occurred while setting your password. Please try again.'); } return $this->_helper->viewRenderer('password'); }
/** * Create a new ftp account * * Executes the creation of new ftp 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 * @param integer $websiteID Must be a valid websiteID * @return mixed True, or throw an Exception if failed. * @access public */ public function create_ftp(array $task, $websiteID) { if (!is_numeric($websiteID)) { throw new Exception(__METHOD__ . ": No website ID found.", "3550"); } $server = self::getServer($task['orderitem_id'], 'web'); // Get the server id if (!empty($server['server_id']) && is_numeric($server['server_id'])) { // Connection to the SOAP system $client = $this->connect($server['server_id']); $clientId = self::get_client_id($task, $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); if (empty($parameters)) { throw new Exception("No parameters found in the service", 3501); } // Get all the customer information $customer = Customers::getAllInfo($task['customer_id']); $id = rand(1, 100); // Create the username string for instance from John Doe to jdoe $username = strtolower(substr($customer['firstname'], 0, 1) . preg_replace("#[^a-zA-Z0-9]*#", "", $customer['lastname'])); $username .= "_ftp{$id}"; // Create a random password string $password = Shineisp_Commons_Utilities::GenerateRandomPassword(); $params = array('server_id' => 1, 'parent_domain_id' => $websiteID, 'username' => $username, 'password' => $password, 'quota_size' => $parameters['webspace'], 'active' => 'y', 'uid' => 'web' . $websiteID, 'gid' => 'client' . $clientId, 'dir' => '/var/www/clients/client' . $clientId . '/web' . $websiteID, 'quota_files' => -1, 'ul_ratio' => -1, 'dl_ratio' => 200, 'ul_bandwidth' => -1, 'dl_bandwidth' => 100); try { $ftpUserID = $client->sites_ftp_user_add($this->getSession(), $clientId, $params); } catch (SoapFault $e) { throw new Exception("There was a problem with FTP account creation: " . $e->getMessage(), "3506"); } // Save the setup in the service setup field OrdersItems::set_setup($task['orderitem_id'], array('host' => $server['ip'], 'username' => $username, 'password' => $password), "ftp"); // 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 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 $ftpUserID; }