/** * Save the basic configuration. */ public function procAdvanced_MailerAdminInsertConfig() { // Get and validate the new configuration. $vars = Context::getRequestVars(); if (!$vars->sender_name) { return new Object(-1, 'msg_advanced_mailer_sender_name_is_empty'); } if (!$vars->sender_email) { return new Object(-1, 'msg_advanced_mailer_sender_email_is_empty'); } if (!Mail::isVaildMailAddress($vars->sender_email)) { return new Object(-1, 'msg_advanced_mailer_sender_email_is_invalid'); } if ($vars->reply_to && !Mail::isVaildMailAddress($vars->reply_to)) { return new Object(-1, 'msg_advanced_mailer_reply_to_is_invalid'); } // Validate the sending method. $sending_methods = Rhymix\Framework\Mail::getSupportedDrivers(); $sending_method = $vars->sending_method; if (!array_key_exists($sending_method, $sending_methods)) { return new Object(-1, 'msg_advanced_mailer_sending_method_is_invalid'); } // Validate the configuration for the selected sending method. $sending_method_config = array(); foreach ($sending_methods[$sending_method]['required'] as $conf_name) { $conf_value = $vars->{$sending_method . '_' . $conf_name} ?: null; if (!$conf_value) { return new Object(-1, 'msg_advanced_mailer_smtp_host_is_invalid'); } $sending_method_config[$conf_name] = $conf_value; } // Update the current module's configuration. $config = $this->getConfig(); $config->sender_name = $vars->sender_name; $config->sender_email = $vars->sender_email; $config->reply_to = $vars->reply_to; $config->force_sender = toBool($vars->force_sender); $config->log_sent_mail = toBool($vars->log_sent_mail); $config->log_errors = toBool($vars->log_errors); $output = getController('module')->insertModuleConfig('advanced_mailer', $config); if ($output->toBool()) { $this->setMessage('success_registed'); } else { return $output; } // Update the webmaster's name and email in the member module. getController('module')->updateModuleConfig('member', (object) array('webmaster_name' => $config->sender_name, 'webmaster_email' => $config->sender_email)); // Update system configuration. Rhymix\Framework\Config::set("mail.type", $sending_method); Rhymix\Framework\Config::set("mail.{$sending_method}", $sending_method_config); Rhymix\Framework\Config::save(); if (Context::get('success_return_url')) { $this->setRedirectUrl(Context::get('success_return_url')); } else { $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminConfig')); } }
/** * check system configuration * @return void */ function checkSystemConfiguration() { $changed = false; // Check encryption keys. if (config('crypto.encryption_key') === null) { config('crypto.encryption_key', Rhymix\Framework\Security::getRandom(64, 'alnum')); $changed = true; } if (config('crypto.authentication_key') === null) { config('crypto.authentication_key', Rhymix\Framework\Security::getRandom(64, 'alnum')); $changed = true; } if (config('crypto.session_key') === null) { config('crypto.session_key', Rhymix\Framework\Security::getRandom(64, 'alnum')); $changed = true; } // Save new configuration. if ($changed) { Rhymix\Framework\Config::save(); } }
/** * Remove FTP configuration. */ function procAdminRemoveFTPInfo() { Rhymix\Framework\Config::set('ftp.host', null); Rhymix\Framework\Config::set('ftp.port', null); Rhymix\Framework\Config::set('ftp.user', null); Rhymix\Framework\Config::set('ftp.pass', null); Rhymix\Framework\Config::set('ftp.path', null); Rhymix\Framework\Config::set('ftp.pasv', true); Rhymix\Framework\Config::set('ftp.sftp', false); Rhymix\Framework\Config::save(); $this->setMessage('success_deleted'); }
/** * @brief Install with received information */ function procInstall($install_config = null) { // Check if it is already installed if (Context::isInstalled()) { return new Object(-1, 'msg_already_installed'); } // Get install parameters. $config = Rhymix\Framework\Config::getDefaults(); if ($install_config) { $install_config = (array) $install_config; $config['db']['master']['type'] = str_replace('_innodb', '', $install_config['db_type']); $config['db']['master']['host'] = $install_config['db_hostname']; $config['db']['master']['port'] = $install_config['db_port']; $config['db']['master']['user'] = $install_config['db_userid']; $config['db']['master']['pass'] = $install_config['db_password']; $config['db']['master']['database'] = $install_config['db_database']; $config['db']['master']['prefix'] = $install_config['db_table_prefix']; $config['db']['master']['charset'] = $install_config['db_charset']; $config['db']['master']['engine'] = strpos($install_config['db_type'], 'innodb') !== false ? 'innodb' : (strpos($install_config['db_type'], 'mysql') !== false ? 'myisam' : null); $config['use_rewrite'] = $install_config['use_rewrite'] === 'Y' ? true : false; $config['url']['ssl'] = $install_config['use_ssl'] ?: 'none'; $time_zone = $install_config['time_zone']; $user_info = new stdClass(); $user_info->email_address = $install_config['email_address']; $user_info->password = $install_config['password']; $user_info->nick_name = $install_config['nick_name']; $user_info->user_id = $install_config['user_id']; } else { $config['db']['master']['type'] = str_replace('_innodb', '', $_SESSION['db_config']->db_type); $config['db']['master']['host'] = $_SESSION['db_config']->db_host; $config['db']['master']['port'] = $_SESSION['db_config']->db_port; $config['db']['master']['user'] = $_SESSION['db_config']->db_user; $config['db']['master']['pass'] = $_SESSION['db_config']->db_pass; $config['db']['master']['database'] = $_SESSION['db_config']->db_database; $config['db']['master']['prefix'] = $_SESSION['db_config']->db_prefix; $config['db']['master']['charset'] = $_SESSION['db_config']->db_charset; $config['db']['master']['engine'] = strpos($_SESSION['db_config']->db_type, 'innodb') !== false ? 'innodb' : (strpos($_SESSION['db_config']->db_type, 'mysql') !== false ? 'myisam' : null); $config['use_rewrite'] = $_SESSION['use_rewrite'] === 'Y' ? true : false; $config['url']['ssl'] = Context::get('use_ssl') ?: 'none'; $time_zone = Context::get('time_zone'); $user_info = Context::gets('email_address', 'password', 'nick_name', 'user_id'); } // Fix the database table prefix. $config['db']['master']['prefix'] = rtrim($config['db']['master']['prefix'], '_'); if ($config['db']['master']['prefix'] !== '') { $config['db']['master']['prefix'] .= '_'; } // Set the default language. $config['locale']['default_lang'] = Context::getLangType(); $config['locale']['enabled_lang'] = array($config['locale']['default_lang']); // Set the default time zone. if (strpos($time_zone, '/') !== false) { $config['locale']['default_timezone'] = $time_zone; $user_timezone = null; } else { $user_timezone = intval(Rhymix\Framework\DateTime::getTimezoneOffsetByLegacyFormat($time_zone ?: '+0900') / 3600); switch ($user_timezone) { case 9: $config['locale']['default_timezone'] = 'Asia/Seoul'; break; case 0: $config['locale']['default_timezone'] = 'Etc/UTC'; break; default: $config['locale']['default_timezone'] = 'Etc/GMT' . ($user_timezone > 0 ? '-' : '+') . abs($user_timezone); } } // Set the internal time zone. if ($config['locale']['default_timezone'] === 'Asia/Seoul') { $config['locale']['internal_timezone'] = 32400; } elseif ($user_timezone !== null) { $config['locale']['internal_timezone'] = $user_timezone * 3600; } else { $config['locale']['internal_timezone'] = 0; } // Set the default URL. $config['url']['default'] = Context::getRequestUri(); // Load the new configuration. Rhymix\Framework\Config::setAll($config); Context::loadDBInfo($config); // Check DB. $oDB = DB::getInstance(); if (!$oDB->isConnected()) { return $oDB->getError(); } // Assign a temporary administrator while installing. foreach ($user_info as $key => $val) { Context::set($key, $val, true); } $user_info->is_admin = 'Y'; Context::set('logged_info', $user_info); // Install all the modules. try { $oDB->begin(); $this->installDownloadedModule(); $oDB->commit(); } catch (Exception $e) { $oDB->rollback(); return new Object(-1, $e->getMessage()); } // Execute the install script. $scripts = FileHandler::readDir(_XE_PATH_ . 'modules/install/script', '/(\\.php)$/'); if (count($scripts)) { sort($scripts); foreach ($scripts as $script) { $script_path = FileHandler::getRealPath('./modules/install/script/'); $output = (include $script_path . $script); } } // Apply site lock. if (Context::get('use_sitelock') === 'Y') { $user_ip_range = getView('install')->detectUserIPRange(); Rhymix\Framework\Config::set('lock.locked', true); Rhymix\Framework\Config::set('lock.message', 'This site is locked.'); Rhymix\Framework\Config::set('lock.allow', array('127.0.0.1', $user_ip_range)); } // Save the new configuration. Rhymix\Framework\Config::save(); // Unset temporary session variables. unset($_SESSION['use_rewrite']); unset($_SESSION['db_config']); // Redirect to the home page. $this->setMessage('msg_install_completed'); $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : RX_BASEURL; $this->setRedirectUrl($returnUrl); return new Object(); }
/** * Migrate from previous configuration format. */ public function migrateConfig($config) { $systemconfig = array(); if (isset($config->sending_method)) { $systemconfig['mail.type'] = $config->sending_method; } elseif (isset($config->send_type)) { $systemconfig['mail.type'] = $config->send_type; } if ($systemconfig['mail.type'] === 'mail') { $systemconfig['mail.type'] = 'mailfunction'; } if (isset($config->username)) { if (in_array('username', $this->sending_methods[$config->sending_method]['conf'])) { $config->{$config->sending_method . '_username'} = $config->username; } unset($config->username); } if (isset($config->password)) { if (in_array('password', $this->sending_methods[$config->sending_method]['conf'])) { $config->{$config->sending_method . '_password'} = $config->password; } unset($config->password); } if (isset($config->domain)) { if (in_array('domain', $this->sending_methods[$config->sending_method]['conf'])) { $config->{$config->sending_method . '_domain'} = $config->domain; } unset($config->domain); } if (isset($config->api_key)) { if (in_array('api_key', $this->sending_methods[$config->sending_method]['conf'])) { $config->{$config->sending_method . '_api_key'} = $config->api_key; } unset($config->api_key); } if (isset($config->account_type)) { if (in_array('account_type', $this->sending_methods[$config->sending_method]['conf'])) { $config->{$config->sending_method . '_account_type'} = $config->account_type; } unset($config->account_type); } if (isset($config->aws_region)) { $config->ses_region = $config->aws_region; unset($config->aws_region); } if (isset($config->aws_access_key)) { $config->ses_access_key = $config->aws_access_key; unset($config->aws_access_key); } if (isset($config->aws_secret_key)) { $config->ses_secret_key = $config->aws_secret_key; unset($config->aws_secret_key); } $mail_drivers = Rhymix\Framework\Mail::getSupportedDrivers(); foreach ($mail_drivers as $driver_name => $driver_definition) { foreach ($config as $key => $value) { if (strncmp($key, $driver_name . '_', strlen($driver_name) + 1) === 0) { $subkey = substr($key, strlen($driver_name) + 1); switch ($subkey) { case 'host': case 'port': case 'security': $systemconfig["mail.{$driver_name}.smtp_" . $subkey] = $value; break; case 'username': case 'password': $systemconfig["mail.{$driver_name}." . ($driver_name === 'smtp' ? 'smtp_' : 'api_') . substr($subkey, 0, 4)] = $value; break; case 'account_type': case 'region': $systemconfig["mail.{$driver_name}.api_type"] = $value; break; case 'access_key': $systemconfig["mail.{$driver_name}.api_user"] = $value; break; case 'secret_key': $systemconfig["mail.{$driver_name}.api_pass"] = $value; break; case 'domain': $systemconfig["mail.{$driver_name}.api_domain"] = $value; break; case 'api_key': $systemconfig["mail.{$driver_name}.api_token"] = $value; break; default: break; } unset($config->{$key}); } } } if (count($systemconfig)) { foreach ($systemconfig as $key => $value) { Rhymix\Framework\Config::set($key, $value); } Rhymix\Framework\Config::save(); } unset($config->is_enabled); unset($config->sending_method); unset($config->send_type); $config->log_sent_mail = toBool($config->log_sent_mail); $config->log_errors = toBool($config->log_errors); $config->force_sender = toBool($config->force_sender); if (!isset($config->exceptions)) { $config->exceptions = array(); } return $config; }