function fn_settings_actions_addons_webmail(&$new_value, $old_value) { if ($new_value == 'A') { // Copy data directory to "var" $dir_data = DIR_ROOT . '/var/webmail'; if (fn_copy(DIR_ADDONS . 'webmail/lib/webmail/data', $dir_data) == false) { $msg = fn_get_lang_var('text_cannot_write_directory'); fn_set_notification('E', fn_get_lang_var('error'), str_replace('[directory]', $dir_data, $msg)); $new_value = 'D'; return false; } $config = Registry::get('config'); $_settings = $dir_data . '/settings/settings.xml'; // 1 step, generate config file $xml = simplexml_load_file($_settings); $xml->Common->DBLogin = $config['db_user']; $xml->Common->DBPassword = $config['db_password']; $xml->Common->DBName = $config['db_name']; $xml->Common->DBHost = $config['db_host']; if (fn_put_contents($_settings, $xml->asXML()) == false) { $msg = fn_get_lang_var('cannot_write_file'); fn_set_notification('E', fn_get_lang_var('error'), str_replace('[file]', $_settings, $msg)); $new_value = 'D'; return false; } include DIR_ADDONS . 'webmail/lib/webmail/web/class_settings.php'; include DIR_ADDONS . 'webmail/lib/webmail/web/class_dbstorage.php'; // Init mailbee core $null = null; $settings =& Settings::CreateInstance(); $dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); $dbStorage->Connect(); $dbStorage->CreateTables($settings->DbPrefix); } }
/** * @param Account $account * @return MailProcessor */ function MailProcessor(&$account) { $this->_account =& $account; switch ($account->MailProtocol) { case MAILPROTOCOL_POP3: require_once WM_ROOTPATH . 'class_pop3storage.php'; $this->MailStorage =& new Pop3Storage($account); break; case MAILPROTOCOL_IMAP4: require_once WM_ROOTPATH . 'class_imapstorage.php'; $this->MailStorage =& new ImapStorage($account); break; case MAILPROTOCOL_WMSERVER: require_once WM_ROOTPATH . 'class_wmserverstorage.php'; $this->MailStorage =& new WMserverStorage($account); break; } $this->DbStorage =& DbStorageCreator::CreateDatabaseStorage($account); }
/** * @param Account $account * @return MailProcessor */ function MailProcessor(&$account, $notUseAccoutForDb = false) { $this->_account =& $account; switch ($account->MailProtocol) { case MAILPROTOCOL_POP3: require_once WM_ROOTPATH . 'common/class_pop3storage.php'; $this->MailStorage = new Pop3Storage($account, $this); break; case MAILPROTOCOL_IMAP4: require_once WM_ROOTPATH . 'common/class_imapstorage.php'; $this->MailStorage = new ImapStorage($account, $this); break; } if ($notUseAccoutForDb) { $null = null; $this->DbStorage =& DbStorageCreator::CreateDatabaseStorage($null); } else { $this->DbStorage =& DbStorageCreator::CreateDatabaseStorage($account); } }
/** * @param FolderCollection $folders * @return bool */ function Synchronize(&$folders) { $folderList = $folders->CreateFolderListFromTree(); //copy tree object here $inboxFolder =& $folderList->GetFolderByType(FOLDERTYPE_Inbox); if ($inboxFolder == null) { return true; } $dbStorage =& DbStorageCreator::CreateDatabaseStorage($this->Account); if (!$dbStorage->Connect()) { return false; } return $this->_synchronizeFolderWithOpenDbConnection($inboxFolder, $dbStorage); }
/** * @param int $_accountId * @param XmlDomNode $_xmlRes */ function GetFiltersList(&$_xmlRes, $_accountId) { if (!USE_DB) { $_filtersNode = new XmlDomNode('filters'); $_filtersNode->AppendAttribute('id_acct', $_accountId); $_xmlRes->XmlRoot->AppendChild($_filtersNode); return true; } $_null = null; $_dbStorage =& DbStorageCreator::CreateDatabaseStorage($_null); if ($_dbStorage->Connect()) { $_filters =& $_dbStorage->SelectFilters($_accountId); if (null !== $_filters) { $_filtersNode = new XmlDomNode('filters'); $_filtersNode->AppendAttribute('id_acct', $_accountId); $_filterKeys = array_keys($_filters->Instance()); foreach ($_filterKeys as $_key) { $_filter =& $_filters->Get($_key); if ($_filter->IsSystem) { continue; } $_filterNode = new XmlDomNode('filter', $_filter->Filter, true); $_filterNode->AppendAttribute('id', $_filter->Id); $_filterNode->AppendAttribute('field', $_filter->Field); $_filterNode->AppendAttribute('condition', $_filter->Condition); $_filterNode->AppendAttribute('action', $_filter->Action); $_filterNode->AppendAttribute('id_folder', $_filter->IdFolder); $_filterNode->AppendAttribute('applied', (int) $_filter->Applied); $_filtersNode->AppendChild($_filterNode); unset($_filterNode, $_filter); } $_xmlRes->XmlRoot->AppendChild($_filtersNode); } else { CXmlProcessing::PrintErrorAndExit(PROC_CANT_GET_FILTER_LIST, $_xmlRes); } } else { CXmlProcessing::PrintErrorAndExit(getGlobalError(), $_xmlRes); } }
/** * @static * @param int $id * @return bool */ function DeleteUserSettings($id) { $null = null; $dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($dbStorage->Connect()) { if ($dbStorage->DeleteSettingsData($id)) { return true; } } return false; }
/** * @param int $accountId */ function GetFiltersList($accountId) { global $xmlObj, $xmlRes; $null = null; $dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($dbStorage->Connect()) { $filters =& $dbStorage->SelectFilters($accountId); if ($filters != null) { $filtersNode =& new XmlDomNode('filters'); $filtersNode->AppendAttribute('id_acct', $accountId); foreach (array_keys($filters->Instance()) as $key) { $filter =& $filters->Get($key); $filterNode =& new XmlDomNode('filter', '<![CDATA[' . $filter->Filter . ']]>'); $filterNode->AppendAttribute('id', $filter->Id); $filterNode->AppendAttribute('field', $filter->Field); $filterNode->AppendAttribute('condition', $filter->Condition); $filterNode->AppendAttribute('action', $filter->Action); $filterNode->AppendAttribute('id_folder', $filter->IdFolder); $filtersNode->AppendChild($filterNode); } $xmlRes->XmlRoot->AppendChild($filtersNode); } else { printErrorAndExit(PROC_CANT_GET_FILTER_LIST, $xmlRes); } } else { printErrorAndExit(getGlobalError(), $xmlRes); } }
<?php /* * AfterLogic Admin Panel by AfterLogic Corp. <*****@*****.**> * * Copyright (C) 2002-2010 AfterLogic Corp. (www.afterlogic.com) * Distributed under the terms of the license described in LICENSE.txt * */ $db =& DbStorageCreator::CreateDatabaseStorage($this->_settings); $prefix = $this->_settings->DbPrefix; if ($db->_settings->DbType != AP_DB_MYSQL && $db->_settings->DbType != AP_DB_MSSQLSERVER) { exit('Warning: Incorrect database type. Tables can be created in MySql or MSSql database only!'); } if (!$db->Connect()) { exit('Connect Error: ' . ap_Utils::TakePhrase('WM_INFO_CONNECTUNSUCCESSFUL') . ' ' . $db->GetError()); } $bodyText = ''; if ($db->AdminAllTableCreate($bodyText)) { $bodyText = nl2br($bodyText); } else { $bodyText = '<font color="red"><b>Warning!</b></font><br />' . nl2br($bodyText); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <html> <head> <?php echo AP_META_CONTENT_TYPE; ?> <title>WebMail</title>
/** * @param Account $accout * @return CDataBaseTempFilesDriver */ function CDataBaseTempFilesDriver($account) { $this->_hash = GetSessionAttachDir(); $this->_fs = new FileSystem(INI_DIR . '/temp', strtolower($account->Email), $account->Id); $this->_folder = new Folder($account->Id, -1, GetSessionAttachDir()); $this->_db =& DbStorageCreator::CreateDatabaseStorage($account); }
/** * @param int $_deleteId * @param int $_edit_id * @param bool $_clearClassic = false * @return bool|7 (7 - logout) */ function ProcessDeleteAccount($_deleteId, &$_edit_id, $_clearClassic = false) { if (!isset($_SESSION[ACCOUNT_ID], $_SESSION[USER_ID]) || !User::AccountAccess($_deleteId)) { setGlobalError(PROC_WRONG_ACCT_ACCESS); return false; } $null = null; $_accounts = array(); $_dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($_dbStorage->Connect()) { $_accounts =& $_dbStorage->SelectAccounts($_SESSION[USER_ID]); if (!$_accounts) { setGlobalError(PROC_CANT_GET_ACCT_LIST); return false; } } else { return false; } $_is_def = false; $_is_lastdef = false; $_is_edit = false; $_c = count($_accounts); if ($_c > 1) { foreach ($_accounts as $_id => $_currAccount) { if ($_id == $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_is_def = true; } } if ($_is_def) { $_is_lastdef = true; foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_is_lastdef = false; } } } if ($_edit_id == $_deleteId) { $_is_edit = true; } } else { if ($_c == 1) { if (isset($_accounts[$_deleteId])) { $_is_edit = true; } } else { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } if ($_c > 1) { if ($_is_lastdef) { setGlobalError(ACCT_CANT_DEL_LAST_DEF_ACCT); return false; } } else { if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } return 7; } if ($_SESSION[ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_SESSION[ACCOUNT_ID] = $_id; if ($_clearClassic) { unset($_SESSION[SARRAY][FOLDER_ID], $_SESSION[SARRAY][PAGE]); } break; } } if ($_SESSION[ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId) { $_SESSION[ACCOUNT_ID] = $_id; if ($_clearClassic) { unset($_SESSION[SARRAY][FOLDER_ID], $_SESSION[SARRAY][PAGE]); } break; } } } if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } else { if ($_is_edit) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && $_currAccount[6]) { $_edit_id = $_id; break; } } if ($_SESSION[SARRAY][EDIT_ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId) { $_edit_id = $_id; break; } } } } if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } return true; }
/** * @return bool */ function SynchronizeFolders() { $result = true; $dbStorage =& DbStorageCreator::CreateDatabaseStorage($this->Account); $serverFoldersTree =& $this->GetFolders(); if ($serverFoldersTree != null && $dbStorage->Connect()) { $dbFoldersTree =& $dbStorage->GetFolders(); $serverFoldersList =& $serverFoldersTree->CreateFolderListFromTree(); $dbFoldersList =& $dbFoldersTree->CreateFolderListFromTree(); $delimiter = $this->Account->Delimiter; foreach (array_keys($serverFoldersList->Instance()) as $mkey) { $mailFolder =& $serverFoldersList->Get($mkey); $folderExist = false; foreach (array_keys($dbFoldersList->Instance()) as $skey) { $dbFolder =& $dbFoldersList->Get($skey); if (trim($mailFolder->FullName, $delimiter) == trim($dbFolder->FullName, $delimiter)) { $folderExist = true; if ($mailFolder->SubFolders != null) { foreach (array_keys($mailFolder->SubFolders->Instance()) as $subkey) { $subFld =& $mailFolder->SubFolders->Get($subkey); $subFld->IdParent = $dbFolder->IdDb; } } if ($dbFolder->Type == FOLDERTYPE_Custom && $dbFolder->Hide != $mailFolder->Hide) { $dbFolder->Hide = $mailFolder->Hide; $dbStorage->UpdateFolder($dbFolder); } break; } } if (!$folderExist) { if ($this->_settings->AllowDirectMode && $this->_settings->DirectModeIsDefault) { $mailFolder->SyncType = FOLDERSYNC_DirectMode; } $result &= $dbStorage->CreateFolder($mailFolder); } } foreach (array_keys($dbFoldersList->Instance()) as $skey) { $dbFolder =& $dbFoldersList->Get($skey); $folderExist = false; foreach (array_keys($serverFoldersList->Instance()) as $mkey) { $mailFolder =& $serverFoldersList->Get($mkey); if (trim($mailFolder->FullName, $delimiter) == trim($dbFolder->FullName, $delimiter)) { $folderExist = true; break; } } if (!$folderExist && $dbFolder->SyncType != FOLDERSYNC_DontSync) { $dbFolder->SyncType = FOLDERSYNC_DontSync; $dbStorage->UpdateFolder($dbFolder); } } } return $result; }
function DoDeleteAccount() { $_dbStorage = $_settings = $_xmlObj = $_xmlRes = $_accountId = null; $this->_initFuncArgs($_dbStorage, $_settings, $_xmlObj, $_xmlRes, $_accountId); $_idAcct = (int) $_xmlObj->GetParamValueByName('id_acct'); CXmlProcessing::CheckAccountAccess($_idAcct, $_xmlRes); $_account =& CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_accountId, false, false); $_accountToDelete =& CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_idAcct, false, false); if (!$_accountToDelete->AllowChangeSettings) { CXmlProcessing::PrintErrorAndExit(PROC_CANT_DEL_ACCT_BY_ID, $_xmlRes); } if ($_account->IsDemo || $_accountToDelete->IsDemo || $_accountToDelete->IsInternal) { CXmlProcessing::PrintErrorAndExit(PROC_CANT_DEL_ACCT_BY_ID, $_xmlRes); } $_resp = User::ProcessDeleteAccount($_idAcct, $_null); if ($_resp === false) { CXmlProcessing::PrintErrorAndExit(getGlobalError(), $_xmlRes); } if (isset($_SESSION[ACCOUNT_IDS])) { unset($_SESSION[ACCOUNT_IDS]); } $_dbStorage =& DbStorageCreator::CreateDatabaseStorage($_account); CXmlProcessing::GetAccountList($_dbStorage, $_xmlRes, $_account, -1, $_resp === 7 ? -1 : $_SESSION[ACCOUNT_ID]); }
/** * @return bool */ function SynchronizeFolders() { $result = true; if (!USE_DB) { return $result; } $dbStorage =& DbStorageCreator::CreateDatabaseStorage($this->Account); $serverFoldersTree =& $this->GetFolders(); if ($serverFoldersTree && $dbStorage->Connect()) { $dbFoldersTree =& $dbStorage->GetFolders(); $serverFoldersList =& $serverFoldersTree->CreateFolderListFromTree(); $dbFoldersList =& $dbFoldersTree->CreateFolderListFromTree(); $delimiter = $this->Account->Delimiter; $serverFoldersListKeys = array_keys($serverFoldersList->Instance()); foreach ($serverFoldersListKeys as $mkey) { $mailFolder =& $serverFoldersList->Get($mkey); $folderExist = false; $dbFoldersListKeys = array_keys($dbFoldersList->Instance()); foreach ($dbFoldersListKeys as $skey) { $dbFolder =& $dbFoldersList->Get($skey); if (trim($mailFolder->FullName, $delimiter) == trim($dbFolder->FullName, $delimiter)) { $folderExist = true; if ($mailFolder->SubFolders) { foreach (array_keys($mailFolder->SubFolders->Instance()) as $subkey) { $subFld =& $mailFolder->SubFolders->Get($subkey); $subFld->IdParent = $dbFolder->IdDb; } } if ($dbFolder->Hide != $mailFolder->Hide && $dbFolder->SyncType != FOLDERSYNC_DontSync) { $dbFolder->Hide = $mailFolder->Hide; $dbStorage->UpdateFolder($dbFolder); } break; } unset($dbFolder); } if (!$folderExist && $mailFolder) { $mailFolder->SyncType = $this->Account->GetDefaultFolderSync($this->_settings); if (FOLDERTYPE_Custom !== $mailFolder->Type) { $searchFolder =& $dbFoldersList->GetFolderByType($mailFolder->Type); if (null != $searchFolder) { $mailFolder->Type = FOLDERTYPE_Custom; } } $result &= $dbStorage->CreateFolder($mailFolder); } } $dbFoldersListKeys = array_keys($dbFoldersList->Instance()); foreach ($dbFoldersListKeys as $skey) { $dbFolder =& $dbFoldersList->Get($skey); $folderExist = false; $serverFoldersListKeys = array_keys($serverFoldersList->Instance()); foreach ($serverFoldersListKeys as $mkey) { $mailFolder =& $serverFoldersList->Get($mkey); if (trim($mailFolder->FullName, $delimiter) == trim($dbFolder->FullName, $delimiter)) { $folderExist = true; break; } unset($mailFolder); } if (!$folderExist && $dbFolder->SyncType != FOLDERSYNC_DontSync) { if ($dbFolder->SyncType == FOLDERSYNC_DirectMode && $dbFolder->MessageCount == 0) { $dbStorage->DeleteFolder($dbFolder); } else { $dbFolder->SyncType = FOLDERSYNC_DontSync; $dbStorage->UpdateFolder($dbFolder); } } } } return $result; }
/** * @param string $email * @return int */ protected function _CheckCountOfUserAccounts($email) { require_once WM_ROOTPATH . 'common/class_account.php'; require_once WM_ROOTPATH . 'common/class_dbstorage.php'; $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { throw new WebMailModelException('settings error'); } if (!$settings->IncludeLang()) { throw new WebMailModelException('lang error'); } $acct = null; $dbStorage =& DbStorageCreator::CreateDatabaseStorage($acct, $settings); if ($dbStorage->Connect()) { return $dbStorage->CheckCountOfUserAccounts($email); } throw new WebMailModelException(getGlobalError()); }
/** * Initialize driver class params */ public function InitDriver() { $this->_db =& DbStorageCreator::CreateDatabaseStorage($this->_account, $this->_settings); $this->_db->Connect(); }
header('Location: ' . USE_IFRAME_WEBMAIL . $paramsLine); exit; } require_once WM_ROOTPATH . 'common/class_settings.php'; require_once WM_ROOTPATH . 'common/class_filesystem.php'; $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { header('Location: index.php?error=3'); exit; } elseif (!$settings->IncludeLang()) { header('Location: index.php?error=6'); exit; } $nAcct = isset($_GET['nacct']) ? (int) $_GET['nacct'] : null; if ($nAcct !== null && USE_DB) { $dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($dbStorage->Connect() && $dbStorage->IsAccountInRing($_SESSION[ACCOUNT_ID], $nAcct)) { $_SESSION[ACCOUNT_ID] = $nAcct; } else { header('Location: index.php?error=2'); exit; } } $account =& Account::LoadFromDb($_SESSION[ACCOUNT_ID]); if (!$account) { header('Location: index.php?error=2'); exit; } define('defaultTitle', $settings->WindowTitle); $skins =& FileSystem::GetSkinsList(); $hasDefSettingsSkin = false;
print '</script>' . "\r\n"; @ob_flush(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <html> <body onload="parent.CheckEndCheckMailHandler();"> <?php $account =& Account::LoadFromDb($_SESSION[ACCOUNT_ID]); @ini_set('memory_limit', MEMORYLIMIT); @set_time_limit(TIMELIMIT); $GLOBALS['useFilters'] = true; if (isset($_POST['Type']) && $_POST['Type'] == 1) { $dbStorage =& DbStorageCreator::CreateDatabaseStorage($account); if ($dbStorage->Connect()) { $accounts =& $dbStorage->SelectAccounts($account->IdUser); if ($accounts !== null) { foreach ($accounts as $acct_id => $acctArray) { if ($acctArray[5]) { @flush(); ?> <script type="text/javascript"> <?php echo 'parent.SetCheckingAccountHandler("' . $acctArray[4] . '");'; ?> </script> <?php @ob_flush(); $newAcct =& Account::LoadFromDb($acct_id);
/** * @param Account $account * @return bool */ function CreateUserFromAccount(&$account) { $account->DefaultAccount = true; $null = null; $this->Account =& $account; $processor =& new MailProcessor($account); if ($processor && $processor->MailStorage->Connect()) { $dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($dbStorage && $dbStorage->Connect()) { $validate = $account->ValidateData(); if ($validate !== true) { $this->SetError($validate); return false; } else { $inboxSync = $account->MailProtocol == MAILPROTOCOL_IMAP4 ? FOLDERSYNC_AllHeadersOnly : FOLDERSYNC_NewEntireMessages; $user =& User::CreateUser(); if ($user == null) { $this->SetError(); return false; } else { if ($user->CreateAccount($account, $inboxSync)) { return true; } else { User::DeleteUserSettings($user->Id); } } } } } $this->SetError(); return false; }