Exemple #1
0
 /**
  * Implements the onLoginScriptEnd listener method.
  *
  * @param iMSCP_Events_Event $event
  */
 public function onLoginScriptEnd($event)
 {
     // Say Hello World on the login page
     set_page_message('i-MSCP HelloWorld plugin says: Hello World', 'info');
     // Stop the propagation of this event to prevent execution of any other plugin that also listen on it.
     $event->stopPropagation();
 }
 /**
  * onAfterAddDomainAlias listener
  *
  * @throws iMSCP_Exception
  * @throws iMSCP_Exception_Database
  * @param iMSCP_Events_Event $event
  * @throws Exception
  */
 public function onAfterAddDomainAlias(iMSCP_Events_Event $event)
 {
     $userIdentity = iMSCP_Authentication::getInstance()->getIdentity();
     if ($userIdentity->admin_type == 'user') {
         $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array());
         $domainAliasNameAscii = $event->getParam('domainAliasName');
         # Only domain aliases which are not listed in the ignored_domains list are auto-approved
         if (!in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) {
             $username = decode_idna($userIdentity->admin_name);
             $approvalRule = $this->getConfigParam('approval_rule', true);
             $userAccounts = (array) $this->getConfigParam('user_accounts', array());
             if ($approvalRule) {
                 # Only domain aliases added by user accounts which are listed in the user_accounts list are
                 # auto-approved
                 if (!in_array($username, $userAccounts)) {
                     $username = false;
                 }
             } elseif (in_array($username, $userAccounts)) {
                 # Only domain aliases added by user accounts which are not listed in the user_accounts list are
                 # auto-approved
                 $username = false;
             }
             if ($username !== false) {
                 $db = iMSCP_Database::getInstance();
                 try {
                     $db->beginTransaction();
                     $domainAliasId = $event->getParam('domainAliasId');
                     exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId));
                     if (iMSCP_Registry::get('config')->CREATE_DEFAULT_EMAIL_ADDRESSES) {
                         if ($userIdentity->email) {
                             client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId);
                         }
                     }
                     $db->commit();
                     send_request();
                     $domainAliasName = decode_idna($domainAliasNameAscii);
                     $username = decode_idna($username);
                     write_log(sprintf('DomainAutoApproval: The %s domain alias has been auto-approved', $domainAliasName), E_USER_NOTICE);
                     write_log(sprintf('DomainAutoApproval: %s scheduled addition of domain alias: %s', $username, $domainAliasName), E_USER_NOTICE);
                     set_page_message(tr('Domain alias successfully scheduled for addition.'), 'success');
                     redirectTo('domains_manage.php');
                 } catch (iMSCP_Exception $e) {
                     $db->rollBack();
                     throw $e;
                 }
             }
         }
     }
 }
 /**
  * onAfterAddDomainAlias listener
  *
  * @throws iMSCP_Exception
  * @throws iMSCP_Exception_Database
  * @param iMSCP_Events_Event $event
  * @throws Exception
  * @return void
  */
 public function onAfterAddDomainAlias(iMSCP_Events_Event $event)
 {
     $userIdentity = iMSCP_Authentication::getInstance()->getIdentity();
     // 1. Do not act if the logged-in user is not the real client (due to changes in i-MSCP v1.2.12)
     // 2. Do not act if the event has been triggered from reseller interface
     if (isset($_SESSION['logged_from_type']) || $userIdentity->admin_type == 'reseller') {
         return;
     }
     $disallowedDomains = (array) $this->getConfigParam('ignored_domains', array());
     $domainAliasNameAscii = $event->getParam('domainAliasName');
     if (in_array(decode_idna($domainAliasNameAscii), $disallowedDomains)) {
         return;
         # Only domain aliases which are not listed in the ignored_domains list are auto-approved
     }
     $username = decode_idna($userIdentity->admin_name);
     $approvalRule = $this->getConfigParam('approval_rule', true);
     $userAccounts = (array) $this->getConfigParam('user_accounts', array());
     # 1. Only domain aliases added by user which are listed in the 'user_accounts' list are auto-approved
     # 2. Only domain aliases added by user which are not listed in the 'user_accounts' list are auto-approved
     if ($approvalRule && !in_array($username, $userAccounts) || in_array($username, $userAccounts)) {
         return;
     }
     $db = iMSCP_Database::getInstance();
     try {
         $db->beginTransaction();
         $domainAliasId = $event->getParam('domainAliasId');
         exec_query('UPDATE domain_aliasses SET alias_status = ? WHERE alias_id = ?', array('toadd', $domainAliasId));
         $config = iMSCP_Registry::get('config');
         if ($config['CREATE_DEFAULT_EMAIL_ADDRESSES'] && $userIdentity->email !== '') {
             client_mail_add_default_accounts(get_user_domain_id($userIdentity->admin_id), $userIdentity->email, $domainAliasNameAscii, 'alias', $domainAliasId);
         }
         $db->commit();
         send_request();
         write_log(sprintf('DomainAutoApproval plugin: The `%s` domain alias has been auto-approved', decode_idna($domainAliasNameAscii)), E_USER_NOTICE);
         set_page_message(tr('Domain alias auto-approved.'), 'success');
     } catch (iMSCP_Exception $e) {
         $db->rollBack();
         throw $e;
     }
 }
Exemple #4
0
 /**
  * Builds the Debug Bar and adds it to the repsonse
  *
  * @return void
  */
 protected function buildDebugBar()
 {
     $xhtml = '<div>';
     /** @var $component iMSCP_Plugin_DebugBar_Component_Interface */
     foreach ($this->components as $component) {
         if (($tab = $component->getTab()) != '') {
             $xhtml .= '<span class="iMSCPdebug_span clickable" onclick="iMSCPdebugPanel(\'iMSCPdebug_' . $component->getIdentifier() . '\');">';
             $xhtml .= '<img src="' . $component->getIconPath() . '" width="16" height="16" style="vertical-align:middle" alt="' . $component->getIdentifier() . '" title="' . $component->getIdentifier() . '" /> ';
             $xhtml .= $tab . '</span>';
         }
         if (($panel = $component->getPanel()) != '') {
             $xhtml .= '<div id="iMSCPdebug_' . $component->getIdentifier() . '" class="iMSCPdebug_panel">' . $panel . '</div>';
         }
     }
     $xhtml .= '<span class="iMSCPdebug_span iMSCPdebug_last clickable" id="iMSCPdebug_toggler" onclick="iMSCPdebugSlideBar()">&#171;</span>';
     $xhtml .= '</div>';
     /** @var $templateEngine iMSCP_pTemplate */
     $templateEngine = $this->event->getParam('templateEngine');
     $response = $templateEngine->getLastParseResult();
     $response = preg_replace('@(</head>)@i', $this->buildHeader() . PHP_EOL . '$1', $response);
     $response = str_ireplace('</body>', '<div id="iMSCPdebug_debug">' . $xhtml . '</div></body>', $response);
     $templateEngine->replaceLastParseResult($response);
 }
Exemple #5
0
 /**
  * Implements onLoadTemplateFile listener method
  *
  * @param iMSCP_Events_Event $event
  * @return void
  */
 public function onBeforeLoadTemplateFile($event)
 {
     $this->_loadedTemplateFiles[] = realpath($event->getParam('templatePath'));
 }
Exemple #6
0
 /**
  * onBeforeAuthentication event listener
  *
  * @param iMSCP_Events_Event $event
  * @return null|string
  */
 public function onBeforeAuthentication($event)
 {
     if ($this->isWaiting() || $this->isBlocked()) {
         $event->stopPropagation();
         return $this->getLastMessage();
     }
     $this->recordAttempt();
     return null;
 }
Exemple #7
0
 /**
  * onLoginScriptEnd listener
  *
  * Create a modal dialog to allow users to choose user account they want use to login. Available users are those
  * defined in plugin configuration. If an user account doesn't exists in database, it is not showed.
  *
  * @param iMSCP_Events_Event $event
  * @return void
  */
 public function onLoginScriptEnd(iMSCP_Events_Event $event)
 {
     if ($this->getConfigParam('user_accounts') && ($jsCode = $this->getCredentialsDialog()) != '') {
         /** @var $tpl iMSCP_pTemplate */
         $tpl = $event->getParam('templateEngine');
         $tpl->replaceLastParseResult(str_replace('</head>', $jsCode . PHP_EOL . '</head>', $tpl->getLastParseResult()));
     }
 }
Exemple #8
0
 /**
  * Implements the onAfterEditDomain event
  *
  * This event is called when customer domain was edited
  *
  * @param iMSCP_Events_Event $event
  * @return void
  */
 public function onAfterEditDomain($event)
 {
     /** @var iMSCP_Config_Handler_File $cfg */
     $cfg = iMSCP_Registry::get('config');
     $query = "SELECT * FROM `ownddns` WHERE `domain_id` = ? AND `ownddns_status` = ?";
     $stmt = exec_query($query, array($event->getParam('domainId'), $cfg->ITEM_OK_STATUS));
     if ($stmt->rowCount()) {
         $query = "SELECT `domain_dns` FROM `domain` WHERE `domain_id` = ?";
         $stmt = exec_query($query, $event->getParam('domainId'));
         if ($stmt->fields['domain_dns'] == 'no') {
             exec_query("UPDATE `domain` SET `domain_dns` = 'yes' WHERE `domain_id` = ?", $event->getParam('domainId'));
             set_page_message(tr('OwnDDNS feature is activated for this customer, DNS was set back to enabled.'), 'warning');
         }
     }
 }
 /**
  * onAfterAddDomain listener
  *
  * @param iMSCP_Events_Event $event
  * @return void
  */
 public function onAfterAddDomain($event)
 {
     $userId = $event->getParam('customerId', false);
     if ($userId && isset($_POST['userpassword'])) {
         exec_query('UPDATE admin set admin_rawpasswd = ? WHERE admin_id = ?', array(clean_input($_POST['userpassword']), $userId));
     }
 }
Exemple #10
0
 /**
  * onAfterDeleteDomainAlias event listener
  *
  * @param iMSCP_Events_Event $event
  * @return void
  */
 public function onAfterDeleteDomainAlias(iMSCP_Events_Event $event)
 {
     exec_query('UPDATE opendkim SET opendkim_status = ? WHERE alias_id = ?', array('todelete', $event->getParam('domainAliasId')));
 }
Exemple #11
0
/**
 * Init layout
 *
 * @author Laurent Declercq <*****@*****.**>
 * @param iMSCP_Events_Event $event
 * @return void
 * @todo Use cookies to store user UI properties (Remember me implementation?)
 */
function layout_init($event)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    if ($cfg->DEBUG) {
        $themesAssetsVersion = time();
    } else {
        $themesAssetsVersion = $cfg->THEME_ASSETS_VERSION;
    }
    ini_set('default_charset', 'UTF-8');
    if (isset($_SESSION['user_theme_color'])) {
        $color = $_SESSION['user_theme_color'];
    } elseif (isset($_SESSION['user_id'])) {
        $userId = isset($_SESSION['logged_from_id']) ? $_SESSION['logged_from_id'] : $_SESSION['user_id'];
        $color = layout_getUserLayoutColor($userId);
        $_SESSION['user_theme_color'] = $color;
    } else {
        $colors = layout_getAvailableColorSet();
        $color = array_shift($colors);
    }
    /** @var $tpl iMSCP_pTemplate */
    $tpl = $event->getParam('templateEngine');
    $tpl->assign(array('THEME_CHARSET' => 'UTF-8', 'THEME_ASSETS_PATH' => '/themes/' . $cfg->USER_INITIAL_THEME . '/assets', 'THEME_ASSETS_VERSION' => $themesAssetsVersion, 'THEME_COLOR' => $color, 'ISP_LOGO' => isset($_SESSION['user_id']) ? layout_getUserLogo() : '', 'JS_TRANSLATIONS' => i18n_getJsTranslations()));
    $tpl->parse('LAYOUT', 'layout');
}
 /**
  * Check plugin compatibility
  *
  * @param iMSCP_Events_Event $event
  */
 protected function checkCompat(iMSCP_Events_Event $event)
 {
     if ($event->getParam('pluginName') == $this->getName()) {
         $config = iMSCP_Registry::get('config');
         if (isset($config['WEBMAIL_PACKAGES']) && !in_array('Roundcube', getWebmailList())) {
             set_page_message(tr('This plugin require the i-MSCP Roundcube package.'), 'error');
             $event->stopPropagation();
         }
     }
 }
Exemple #13
0
 /**
  * onAfterDeleteCustomer event listener
  *
  * @param iMSCP_Events_Event $event
  * @return void
  */
 public function onAfterDeleteCustomer($event)
 {
     exec_query('UPDATE mailman SET mailman_status = ? WHERE mailman_admin_id = ?', array('todelete', $event->getParam('customerId')));
 }
Exemple #14
0
/**
 * Check domain account state (status and expires date)
 *
 * Note: Listen to the onBeforeSetIdentity event triggered in the iMSCP_Authentication component.
 *
 * @param iMSCP_Events_Event $event An iMSCP_Events_Events object representing an onBeforeSetIdentity event.
 * @return void
 */
function login_checkDomainAccount($event)
{
    /** @var $identity stdClass */
    $identity = $event->getParam('identity');
    if ($identity->admin_type == 'user') {
        $query = '
			SELECT
				domain_expires, domain_status, admin_status
			FROM
				domain
			INNER JOIN
				admin ON(domain_admin_id = admin_id)
			WHERE
				domain_admin_id = ?
        ';
        $stmt = exec_query($query, $identity->admin_id);
        $isAccountStateOk = true;
        if ($stmt->fields['admin_status'] != 'ok' || $stmt->fields['domain_status'] != 'ok') {
            $isAccountStateOk = false;
            set_page_message(tr('Your account is currently under maintenance or disabled. Please, contact your reseller.'), 'error');
        } else {
            $domainExpireDate = $stmt->fields['domain_expires'];
            if ($domainExpireDate && $domainExpireDate < time()) {
                $isAccountStateOk = false;
                set_page_message(tr('Your account has expired.'), 'error');
            }
        }
        if (!$isAccountStateOk) {
            redirectTo('index.php');
        }
    }
}
Exemple #15
0
 /**
  * Constructor
  *
  * @param Exception $exception
  */
 public function __construct(Exception $exception)
 {
     parent::__construct('onUncaughtException', array('exception' => $exception));
 }