/authman/index.php
PHP | 8054 lines | 5919 code | 1256 blank | 879 comment | 1416 complexity | c525aa1c23a95d0f9d0fae8dfef1e79d MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * AuthMan Free
- *
- * @copyright Copyright (c) 2008 Authman Inc. (http://www.authman.com)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
- * @link http://www.authman.com
- * @version 1.0.0
- */
- ini_set('zlib.output_compression','Off');
- define('AUTHMAN_DIR', dirname(__FILE__));
- /**
- * AuthMan Class (Free Version)
- *
- * @copyright Copyright (c) 2008 Authman Inc. (http://www.authman.com)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
- * @link http://www.authman.com
- */
- class Authman
- {
- /**
- * Class version, const
- *
- * @access private
- */
- var $AUTHMAN_VERSION = '1.1.0';
- /**
- * Apache ServerRoot
- *
- * @access private
- * @var string
- */
- var $_serverRoot = '/etc/httpd';
- /**
- * Authman directory
- *
- * private @var string
- */
- var $_basePath;
- /**
- * Default Ini file
- *
- * @access private
- * @var string
- */
- var $_iniFile = 'config/config.ini';
- /**
- * Config settings
- *
- * @access private
- * @var array
- */
- var $_configArray = array('language' => 'english',
- 'login' => 'admin',
- 'password' => 'admin',
- 'demo' => 0,
- 'manual_edit' => 1,
- 'access_file' => '.htaccess',
- 'authuser_file' => '.htpasswd',
- 'authname' => 'Protected by Authman',
- 'allowsignup' => 0,
- 'autoapprove' => 0,
- 'encryption' =>'md5');
- /**
- * Language array
- *
- * @access private
- * @var array
- */
- var $_langArray = array('messages'=>array(),
- 'warnings'=>array(),
- 'errors'=>array());
- /**
- * File Paths
- *
- * @access private
- * @var array
- */
- var $_filePathsArray = array('configfile'=>null,
- 'langfile'=>null,
- 'accessfile'=>null,
- 'authadminfile'=>null,
- 'authuserfile' =>null,
- 'authgroupfile'=>null,
- 'accessfile_dist'=>null,
- 'authuserfile_dist' =>null,
- 'authgroupfile_dist'=>null,
- 'signupfile'=>null);
- /**
- * Raw File Contents (by url hash)
- *
- * @access private
- * @var array
- */
- var $_fileContentsArray = array();
- /**
- * Parsed File Data (by url hash)
- *
- * @access private
- * @var array
- */
- var $_fileDataArray = array();
- /**
- * Access Rules Information (by url hash)
- *
- * @access private
- * @var array
- */
- var $_accessRulesArray = array();
- /**
- * Runtime variables
- *
- * @access private
- * @var array
- */
- var $_runtimeArray = null;
- /**
- * Error message
- *
- * @access private
- * @var string
- */
- var $_error = null;
- /**
- * @access private
- * @var array
- */
- var $_tplsArray = array();
- /**
- * Authman Constructor
- *
- * @access public
- * @params array|null $config
- * @return void
- */
- function Authman( $config=array() )
- {
- // base prefix
- $this->_basePath = dirname(__FILE__);
- // overwrite ini file name
- if (isset($config['ini'])) {
- $this->_iniFile = $config['ini'];
- }
- // loading ini file
- $iniFilePath = $this->makePath( $this->_basePath, $this->_iniFile );
- $this->_filePathsArray[ 'configfile' ] = $iniFilePath;
- if (is_file($iniFilePath) && is_readable($iniFilePath) ) {
- $cfg = @parse_ini_file( $iniFilePath, false );
- if (isset($cfg)) {
- $this->_configArray = array_merge($this->_configArray, $cfg);
- }
- }
- // overwrite language
- if (isset($config['language'])) {
- $this->_configArray['language'] = $config['language'];
- }
- // loading language file
- $langFilePath = $this->makePath($this->_basePath . DIRECTORY_SEPARATOR . 'languages',
- $this->_configArray['language'] . '.lng' );
- $this->_filePathsArray[ 'langfile' ] = $langFilePath;
- if (!is_file($langFilePath) || !is_readable($langFilePath) ) {
- // we will trying load default language file
- $langFilePath = $this->makePath($this->_basePath . DIRECTORY_SEPARATOR . 'languages',
- 'english.lng' );
- }
- if (is_file($langFilePath) && is_readable($langFilePath) ) {
- $this->_langArray = array_merge($this->_langArray, @parse_ini_file($langFilePath, true));
- }
- // set access file path
- $path = $this->makePath( $this->_basePath . DIRECTORY_SEPARATOR . '..',
- $this->_configArray['access_file'] );
- $this->_filePathsArray[ 'accessfile' ] = $path;
- #if (is_file($path) && is_readable($path)) {
- $this->readFileByType( 'accessfile' );
- #}
- // set admin htpasswd file path
- $basedir = $this->_basePath . DIRECTORY_SEPARATOR . 'var';
- $path = $this->makePath( $basedir, '.htadmin' );
- $this->_filePathsArray[ 'authadminfile' ] = $path;
- // set default file paths
- $path = $this->makePath( $basedir, 'htaccess_dist' );
- $this->_filePathsArray[ 'accessfile_dist' ] = $path;
- $path = $this->makePath( $basedir, 'htpasswd_dist' );
- $this->_filePathsArray[ 'authuserfile_dist' ] = $path;
- $path = $this->makePath( $basedir, 'htgroup_dist' );
- $this->_filePathsArray[ 'authgroupfile_dist' ] = $path;
- $path = $this->makePath( $basedir, 'signups' );
- $this->_filePathsArray[ 'signupfile' ] = $path;
- // loading runtime stats
- }
- /**
- * Return class version
- *
- * @access public
- * @return string
- */
- function getVersion()
- {
- return $this->AUTHMAN_VERSION;
- }
- /**
- * Return true if demo mode is on
- *
- * @access public
- * @return string
- */
- function isDemo()
- {
- return $this->_configArray['demo'] == 1;
- }
- /**
- * Return true if menual edit is allowed
- *
- * @access public
- * @return string
- */
- function isManualEdit()
- {
- return $this->_configArray['manual_edit'] == 1;
- }
- /**
- * Return configuration value by name
- *
- * @access public
- * @param string $name
- * @return string
- */
- function getConfigValue( $name )
- {
- if (!isset($name) || !isset($this->_configArray[$name])) {
- return false;
- }
- return $this->_configArray[$name];
- }
- /***************************************************************************
- * Member zone related functions
- **************************************************************************/
- /**
- * Logging as user
- *
- * @access public
- * @param string $username
- * @param string encpass
- * @return bool
- */
- function loginAs( $username, $encpass )
- {
- $_SESSION['am_u'] = base64_encode( $username );
- $_SESSION['am_c'] = md5( $encpass );
-
- $user = $this->fetchRecordByType( 'authuserfile', $username );
- if (false == $user) {
- $user = $this->fetchRecordByType( 'authadminfile', $username, true );
- if (false == $user) {
- return false;
- }
-
- $err = $this->getError();
- $this->setRuntimeValue('lastloggedin_ts', time());
- $this->setRuntimeValue('lastloggedin_ip', $_SERVER['REMOTE_ADDR'], true);
- $this->setError($err);
- }
-
- return true;
- }
-
- /**
- * Return authenticated user data
- *
- * @access public
- * @return array|false
- */
- function getAuthenticatedUser()
- {
- // checking session cookie
- $isadmin = false;
- $user = null;
- $username = $codedpass = $rawpass = null;
-
- if (isset($_SESSION) && isset($_SESSION['am_u'])
- && isset($_SESSION['am_c'])) {
- $username = base64_decode($_SESSION['am_u']);
- $codedpass = $_SESSION['am_c']; // md5
- } else if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
- $username = $_SERVER['PHP_AUTH_USER'];
- $rawpass = $_SERVER['PHP_AUTH_PW'];
- }
- if (!isset($username) || $username=='') {
- return false;
- }
-
- // checking admins first
- $user = $this->fetchRecordByType('authadminfile', $username, true);
- if ($user) {
- $isadmin = true;
- } else {
- $user = $this->fetchRecordByType('authuserfile', $username);
- }
- if (false == $user || !isset($user['pass'])) {
- return false;
- }
-
- if (isset($rawpass)) {
- $encpass = $this->htcrypt($rawpass, $user['pass']);
- if ($encpass != $user['pass']) {
- return false;
- }
- } else if (md5($user['pass']) != $codedpass) {
- return false;
- }
-
- $user['isadmin'] = $isadmin;
- return $user;
- }
- /**
- * Return true if user is authenticated
- *
- * @access public
- * @return bool
- */
- function isAuthenticated()
- {
- return false == $this->getAuthenticatedUser() ? false : true;
- }
- /**
- * Return true if user is authenticated by basic auth method
- *
- * @access public
- * @return bool
- */
- function isAuthenticatedByBasicAuth()
- {
- $user = $this->getAuthenticatedUser();
- if (false == $user) {
- return false;
- }
-
- if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
- return false;
- }
-
- $encpass = $this->htcrypt($_SERVER['PHP_AUTH_PW'], $user['pass']);
- if ($encpass != $user['pass']) {
- return false;
- }
-
- return true;
- }
- /**
- * Return true if current authenticated user has administrator priviledges
- *
- * @access public
- * @return bool
- */
- function isAdmin()
- {
- $user = $this->getAuthenticatedUser();
- if (false == $user) {
- return false;
- }
- return isset($user['isadmin']) && $user['isadmin'] ? true : false;
- }
- /***************************************************************************
- * Crypt Utilties
- **************************************************************************/
- /**
- * Encrypt text with crypt function
- *
- * @access public
- * @param string $text
- * @param string|null $salt
- * @param string|null $prefix
- * @return string
- */
- function encrypt_saltcrypt( $text, $salt='', $prefix='' )
- {
- if ($salt == 'DES') {
- $salt = CRYPT_STD_DES == 1 ? 'r1' : '';
- }
- if ($salt == 'EXT_DES') {
- $salt = CRYPT_EXT_DES == 1 ? '_J9..pre' : '';
- }
- if ($salt == 'MD5') {
- $salt = CRYPT_MD5 == 1 ? '$1$pre$' : '';
- }
- if ($salt == '') {
- mt_srand((double)microtime()*1000000);
- for ($i=0; $i<CRYPT_SALT_LENGTH; $i++)
- $salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./",
- mt_rand() & 63, 1);
- }
- return $prefix . crypt($text, $salt);
- }
- /**
- * Encrypt text with crypt function
- *
- * @access public
- * @param string $text
- * @param string|null $salt
- * @return string
- */
- function htcrypt( $text, $salt=null )
- {
- $method = $this->_configArray['encryption'];
- if (isset($salt) && substr($salt, 0, 6) == '$apr1$') {
- $method = 'md5';
- $salt = substr($salt, 6);
- }
-
- // apr1-md5
- if ($method == 'md5') {
- if (CRYPT_MD5 == 1) {
- return $this->crypt_apr1_md5($text, $salt);
- }
- }
-
- // DES
- if (!isset($salt)) {
- mt_srand((double)microtime()*1000000);
- for ($i=0; $i<CRYPT_SALT_LENGTH; $i++) {
- $salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./", mt_rand() & 63, 1);
- }
- }
-
- return crypt($text, $salt);
- }
- /**
- * Encryption function
- *
- * @access public
- * @param string $plainpasswd
- * @param string $salt
- * @return string
- */
- function crypt_apr1_md5($plainpasswd, $salt) {
- if (!isset($salt)) {
- $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
- } else {
- $salt = substr($salt, 0, 8);
- }
-
- $len = strlen($plainpasswd);
- $text = $plainpasswd.'$apr1$'.$salt;
- $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd));
- for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); }
- for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $plainpasswd{0}; }
- $bin = pack("H32", md5($text));
- for($i = 0; $i < 1000; $i++) {
- $new = ($i & 1) ? $plainpasswd : $bin;
- if ($i % 3) $new .= $salt;
- if ($i % 7) $new .= $plainpasswd;
- $new .= ($i & 1) ? $bin : $plainpasswd;
- $bin = pack("H32", md5($new));
- }
- $tmp = '';
- for ($i = 0; $i < 5; $i++) {
- $k = $i + 6;
- $j = $i + 12;
- if ($j == 16) $j = 5;
- $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
- }
- $tmp = chr(0).chr(0).$bin[11].$tmp;
- $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
- "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
- return "$"."apr1"."$".$salt."$".$tmp;
- }
-
- /***************************************************************************
- * File System Utilties
- **************************************************************************/
- /**
- * Construct path from base path and file name
- *
- * @access public
- * @param string $basePath
- * @param string $fileName
- * @param string|null $dirsep
- * @return string
- */
- function makePath($basePath, $fileName, $dirsep=DIRECTORY_SEPARATOR)
- {
- // Windows
- if (preg_match('/^[A-Z]:\\\/i', $fileName)) {
- return $this->getNormalizedPath( $fileName );
- }
- // Unix and other
- if (substr($fileName,0,1)=='/' || substr($fileName,0,1)==$dirsep) {
- return $this->getNormalizedPath( $fileName );
- }
- return $this->getNormalizedPath( $basePath . $dirsep . $fileName );
- }
- /**
- * Normalize given path
- *
- * @access public
- * @param mixed $path
- * @param string|null $dirsep
- * @return mixed
- */
- function getNormalizedPath( $path, $dirsep=DIRECTORY_SEPARATOR )
- {
- if (is_array($path)) {
- $pathArray = array();
- foreach($path as $p) {
- $pathArray[] = $this->getNormalizedPath($p, $dirsep);
- }
- return $pathArray;
- }
-
- $prefix = '';
-
- // if not Windows
- if (!preg_match('/^[A-Z]:\\\/i', $path)) {
- $prefix = $dirsep;
- }
- $path = str_replace('/', $dirsep, $path);
- $path = str_replace('\\', $dirsep, $path);
- $parts = explode($dirsep, $path);
- $todown=0;
- for ($i = count($parts)-1; $i >= 0; $i--) {
- if (empty($parts[$i]) || $parts[$i] == '.') {
- array_splice( $parts, $i, 1);
- continue;
- }
- if ($parts[$i] == '..') {
- array_splice( $parts, $i, 1);
- if ($i > 0) {
- $todown++;
- }
- continue;
- }
- if ($todown) {
- # warning: not works for complex paths like /root/path/../path/../../the/end
- array_splice( $parts, $i-($todown-1), $todown);
- $todown = 0;
- }
- }
- return $prefix . implode( $dirsep, $parts );
- }
- /**
- * Return full path to a file specified by type
- *
- * @access public
- * @param string $filetype
- * @param string|null $dir
- * @return string
- */
- function getPathByType( $filetype, $dir=DIRECTORY_SEPARATOR )
- {
- $ln = strtolower($filetype);
- if ($ln == 'protecteddirectory') {
- return $this->getNormalizedPath($this->_basePath . $dir . '..');
- }
- if ($ln == 'phpmailer') {
- return implode($dir, array($this->_basePath, 'contrib',
- 'phpmailer', 'class.phpmailer.php'));
- }
- if ($ln == 'tinymcejs') {
- return implode($dir, array($this->_basePath,
- 'contrib', 'tinymce', 'jscripts',
- 'tiny_mce', 'tiny_mce.js'));
- }
- if ($ln == 'magpierss') {
- return implode($dir, array($this->_basePath, 'contrib',
- 'magpierss', 'rss_fetch.inc'));
- }
- if (!isset($this->_filePathsArray[$filetype])) {
- return false;
- }
- return $this->_filePathsArray[$filetype];
- }
- /**
- * Return default file path by type
- *
- * @access public
- * @param string $filetype
- * @return string
- */
- function getDefaultFilePathByType( $filetype )
- {
- if ($filetype == 'authuserfile') {
- return dirname($this->getPathByType('accessfile'))
- . DIRECTORY_SEPARATOR
- . $this->getConfigValue('authuser_file');
- }
- return false;
- }
- /**
- * Returns url by type
- *
- * @access public
- * @param string $filetype
- * @param string|null $fulurl
- * @return strung
- */
- function getUrlByType( $filetype, $fullurl=false )
- {
- // base uri
- $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
- $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
- $uri_self = $_SERVER['PHP_SELF'];
- $uri = dirname($uri_self);
- if ($filetype == 'base') {
- $uri .= '/';
- }
- if ($filetype == 'protected') {
- $uri = $this->getNormalizedPath($uri . '/../', '/');
- }
- if ($filetype == 'errordocument401') {
- $uri = $uri_self .'?page=401';
- }
- if ($filetype == 'login') {
- $uri = $uri_self .'?page=login';
- }
- if ($filetype == 'tinymcejs') {
- $uri .= '/contrib/tinymce/jscripts/tiny_mce/tiny_mce.js';
- }
- if (!$fullurl) {
- return $uri;
- }
- return 'http://'.$server . ($port != 80 ? ':'.$port : '') . $uri;
- }
- /**
- * Set file path
- *
- * @access public
- * @param string $filetype
- * @param string $filepath
- * @return void
- */
- function setFilePathByType( $filetype, $filepath )
- {
- if (!isset($filepath)) {
- return false;
- }
- $hash = md5( $filepath );
- $this->_fileContentsArray[ $hash ] = null;
- $this->_fileDataArray[ $hash ] = null;
- $this->_filePathsArray[ $filetype ] = $filepath;
- }
- /**
- * Return temporary file name
- *
- * @access public
- * @return string
- */
- function getTempFilePath()
- {
- return $this->_basePath . DIRECTORY_SEPARATOR . 't_' . time() . rand(0, 1000);
- }
- /***************************************************************************
- * String functions
- **************************************************************************/
- /***************************************************************************
- * Disk Level File Operations
- **************************************************************************/
- /**
- * Write default deny file to disk
- *
- * @access private
- * @param string $filePath
- * @return bool
- */
- function writeDenyFile( $filePath )
- {
- $fh = @fopen($filePath, 'w');
- if (false == $fh) {
- return false;
- }
- @fwrite($fh, "# Automatically Created by Autman Free\n");
- @fwrite($fh, "order deny,allow\n");
- @fwrite($fh, "deny from all\n");
- @fclose($fh);
- return true;
- }
- /**
- * Read and parse file
- *
- * @access private
- * @param string $filetype
- * @return bool
- */
- function readFileByType( $filetype )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- return false;
- }
- $hash = md5($path);
- $this->_fileContentsArray[$hash] = array();
- $this->_fileDataArray[$hash] = array();
- if (!is_file($path)) {
- $this->setError( $this->E('NOSUCHFILE', $path) );
- return false;
- }
- if (is_file($path) && !is_readable($path)) {
- $this->setError( $this->E('FILENOTREADBLE', $path) );
- return false;
- }
- $fh = @fopen($path, 'r');
- if (false == $fh) {
- $this->setError( $this->E('FILEOPENFAILED', $path) );
- return false;
- }
- $contents = $buf = null;
- $maxbytes = 2048000;
- $bytes = 0;
- while (!feof($fh) && $bytes < $maxbytes && ($buf = fread($fh, $maxbytes-$bytes))) {
- $contents .= $buf;
- }
- fclose($fh);
- return $this->setFileContentsByType( $filetype, $contents );
- }
- /**
- * Save file
- *
- * @access public
- * @param string $filetype
- * @param bool|null $saveRawData
- * @param string|null $contents
- * @return bool
- */
- function saveFileByType( $filetype, $saveRawData=false, $contents=null, $parseTemplates=false )
- {
- $path = $this->getPathByType( $filetype );
- if (!$path) {
- return false;
- }
- if (!isset($contents)) {
- $contents = $this->getFileContentsByType( $filetype, $saveRawData, $parseTemplates );
- }
- // Saving in DEMO mode is disabled
- if ($this->isDemo()) {
- $this->setError( $this->W('DEMOISON') );
- return false;
- }
- if (!is_file($path) && !is_writable(dirname($path))) {
- $this->setError( $this->E('DIRNOTWRITABLE', dirname($path)) );
- return false;
- }
- if (is_file($path) && !is_writable($path)) {
- $this->setError( $this->E('FILENOTWRITABLE', $path) );
- return false;
- }
- $fh = @fopen($path, 'w');
- if (!$fh) {
- $this->setError( $this->E('FILEOPENFAILED', $path) );
- return false;
- }
- if ($contents != '') {
- if (!fwrite($fh, $contents)) {
- $this->setError( $this->E('WRITEFAILED', $path) );
- return false;
- }
- }
- @fclose($fh);
- if (!$this->readFileByType( $filetype )) {
- return false;
- }
- return true;
- }
- /**
- * Reset protected directory
- *
- * @access public
- * @retrun bool
- */
- function resetProtectedDirectory()
- {
- $src = $this->getPathByType( 'accessfile_dist');
- $dst = $this->getPathByType( 'accessfile' );
- if (false == $this->copyFile( $src, $dst )) {
- return false;
- }
- $this->readFileByType( 'accessfile' );
- $result = true;
- $filesArray = array('authuserfile'); // , 'authgroupfile');
- foreach ($filesArray as $file) {
- $src = $this->getPathByType( $file . '_dist');
- $dst = $this->getPathByType( $file );
- if (isset($src) && isset($dst) && is_file($src)) {
- if (false == $this->copyFile( $src, $dst )) {
- $result = false;
- }
- }
- }
- return $result;
- }
- /**
- * Copy file
- *
- * @access public
- * @param string $src
- * @param string $dst
- * @return bool
- */
- function copyFile( $src, $dst )
- {
- if ($src == false) {
- $this->setError( $this->E('INVALIDREQUEST') . ' [source]');
- return false;
- }
- if ($dst == false) {
- $this->setError( $this->E('INVALIDREQUEST') . ' [destination]');
- return false;
- }
- // Saving in DEMO mode is disabled
- if ($this->isDemo()) {
- $this->setError( $this->W('DEMOISON') );
- return false;
- }
- if (!is_file($dst) && !is_writable(dirname($dst))) {
- $this->setError( $this->E('DIRNOTWRITABLE', dirname($dst)) );
- return false;
- }
- if (is_file($dst) && !is_writable($dst)) {
- $this->setError( $this->E('FILENOTWRITABLE', $dst) );
- return false;
- }
- if (!is_file($src) || !is_readable($src)) {
- $this->setError( $this->E('FILENOTREADBLE', $src) );
- return false;
- }
- if (false == copy( $src, $dst )) {
- $this->setError( $this->E('FILECOPYFAILED', $src) );
- return false;
- }
- return true;
- }
- /***************************************************************************
- * Contents
- **************************************************************************/
- /**
- * Return file contents
- *
- * @access public
- * @param string $filetype
- * @param bool|null $getRawData
- * @return string
- */
- function getFileContentsByType( $filetype, $getRawData=false, $parseTemplates=false )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- return false;
- }
- $hash = md5( $path );
- if (false == $getRawData) {
- $data = $this->getFileDataByType( $filetype );
- $text = '';
- // build contents from parsed data
- if ($filetype == 'accessfile') {
- if ($parseTemplates) {
- foreach ($data as $k=>$v) {
- $data[$k] = preg_replace('/%PROTECTEDDIRECTORY%/', $am->getPathByType('protecteddirectory'), $v);
- }
- }
- $text = implode("\n", $data);
- } else if (($filetype=='authuserfile' || $filetype=='authadminfile' ||
- $filetype=='signupfile') && is_array($data)) {
- foreach ($data as $user) {
- if (isset($user['pass_raw'])) {
- // $pass = $this->encrypt_saltcrypt( $user['pass_raw'], 'DES' );
- $pass = $this->htcrypt( $user['pass_raw'] ); // salt automatically generated
- } else {
- $pass = $user['pass'];
- }
- $text .= $user['name'] . ':' . $pass;
- if (isset($user['info']) || isset($user['email'])) {
- $text .= ':';
- $text .= isset($user['info']) ? $user['info'] . ':' : '';
- if (isset($user['email'])) {
- $text .= $user['email'];
- }
- }
- if ($filetype=='signupfile') {
- $text .= ':' . (isset($user['ts']) ? $user['ts'] : '');
- $text .= ':' . (isset($user['remoteaddr']) ? $user['remoteaddr'] : '');
- $text .= ':' . (isset($user['referer']) ? $user['referer'] : '');
- }
- $text .= "\n";
- }
- }
- return $text;
- }
- /* fetching raw data */
- if (!isset($this->_fileContentsArray[ $hash ])) {
- if (false == $this->readFileByType( $filetype )) {
- return false;
- }
- }
- if (!isset($this->_fileContentsArray[ $hash ])) {
- return '';
- }
- if (!is_array($this->_fileContentsArray[$hash])) {
- return $this->_fileContentsArray[$hash];
- }
-
- return implode("\n", $this->_fileContentsArray[$hash]);
- }
- /**
- * Parse files
- *
- * @access public
- * @param string $filetype
- * @param string $contents
- * @return bool
- */
- function parseFileContentsByType( $filetype, $contents )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- $this->setError( $this->W('NOTDEFINED', $filetype) );
- return false;
- }
- $hash = md5( $path );
- $this->_fileDataArray[$hash] = array();
- $this->_accessRulesArray[$hash] = array('order'=>null);
- $lArray = split("[\n\r]+", $contents);
- // no data
- if (count($lArray) < 0) {
- return true;
- }
- if ($filetype == 'accessfile') {
- $rows = array();
- $hash = md5( $this->getPathByType( $filetype ) );
- foreach($lArray as $l) {
- if (preg_match('/^\s*Auth(User|Group)File\s+(.+)/i', $l, $matches)) {
- $authfiletype = 'auth' . strtolower($matches[1]) . 'file';
- $path = $this->makePath( $this->_serverRoot, $matches[2] );
- $this->_filePathsArray[ $authfiletype ] = $path;
- }
- if (preg_match('/^\s*AuthType\s+(.+)/i', $l, $matches)) {
- $val = strtolower(trim($matches[1]));
- $val = stripslashes($val);
- $this->_accessRulesArray[$hash]['authtype'] = $val;
- }
- if (preg_match('/^\s*AuthName\s+"?(.+?)"?\s*$/i', $l, $matches)) {
- $val = trim($matches[1]);
- $val = stripslashes( $val );
- $this->_accessRulesArray[$hash]['authname'] = $val;
- }
-
- // ip/domain access rules
- if (preg_match('/^\s*Order\s+(Allow|Deny),\s*(Allow|Deny)\s*$/i', $l, $matches)) {
- $this->_accessRulesArray[$hash]['order'] = strtolower($matches[2]);
- }
- if (preg_match('/^\s*(allow|deny)\s+from\s+(.+)$/i', $l, $matches)) {
- foreach(explode(' ', $matches[2]) as $s) {
- $s = trim($s);
- if (empty($s)) {
- continue;
- }
- $rule = strtolower($matches[1]);
- $this->_accessRulesArray[$hash][$rule][] = $s;
- }
- }
- // error document rules
- if (preg_match('/^\s*ErrorDocument\s+401\s+(.+)$/i', $l, $matches)) {
- $val = trim($matches[1]);
- $this->_accessRulesArray[$hash]['errordocument401'] = $val;
- }
- $rows[] = $l;
- }
- $this->_fileDataArray[$hash] = $rows;
- }
- if ($filetype=='authuserfile' || $filetype=='authadminfile' || $filetype=='signupfile') {
- $users = array();
- foreach($lArray as $l) {
- if (preg_match('/^\s*#/', $l)) {
- continue;
- }
- $ldArray = split(':', $l);
- if (count($ldArray) < 2) {
- continue;
- }
- $data = array('name' => $ldArray[0],
- 'pass' => $ldArray[1],
- 'info' => isset($ldArray[2]) ? $ldArray[2] : null,
- 'email' => isset($ldArray[3]) ? $ldArray[3] : null);
- if ($filetype == 'signupfile') {
- $data['ts'] = isset($ldArray[4]) ? $ldArray[4]: null;
- $data['remoteaddr'] = isset($ldArray[5]) ? $ldArray[5] : null;
- $data['referer'] = implode(':', array_slice($ldArray, 6));
- }
- $users[] = $data;
- }
- $this->_fileDataArray[$hash] = $users;
- }
- if ($filetype == 'authgroupfile') {
- }
- return true;
- }
- /**
- * Set, Parse given file contents and optionaly Save it
- *
- * @access public
- * @param string $filetype
- * @param string $contents
- * @param bool|null $saveData
- * @param bool|null $saveRawData
- * @return bool
- */
- function setFileContentsByType( $filetype, $contents, $saveData=false, $saveRawData=false )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- $this->setError( $this->W('NOTDEFINED', $filetype) );
- return false;
- }
- $hash = md5( $path );
- $this->_fileContentsArray[$hash] = $contents;
- // parse contents
- if (false == $this->parseFileContentsByType( $filetype, $contents )) {
- return false;
- }
- if ($saveData) {
- if (false == $saveRawData) {
- // build contents from parsed data
- }
- if (false == $this->saveFileByType( $filetype, $contents )) {
- return false;
- }
- }
- return true;
- }
- /***************************************************************************
- * File Data Routes
- **************************************************************************/
- /**
- * Return parsed data
- *
- * @access public
- * @param string $filetype
- * @return array
- */
- function getFileDataByType( $filetype )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- $this->setError( $this->W('NOTDEFINED', $filetype) );
- return false;
- }
- $hash = md5( $path );
- // not readed yet
- if (!isset( $this->_fileDataArray[$hash] )) {
- if (false == $this->readFileByType( $filetype )) {
- return false;
- }
- }
- return $this->_fileDataArray[$hash];
- }
- function getDefaultRecordsBytype( $filetype )
- {
- if ($filetype == 'authadminfile') {
- $pass_raw = $this->_configArray['password'];
- return array(array('name'=>$this->_configArray['login'],
- //'pass'=>$this->encrypt_saltcrypt( $pass_raw, 'DES' ),
- 'pass'=>$this->htcrypt($pass_raw, 'adminpass'),
- 'pass_raw'=>$pass_raw,
- 'info'=>'Administration',
- 'email'=>'support'));
- }
- return array();
- }
- /**
- * Update file record
- *
- * @access public
- * @param string $filetype
- * @param string|null $sortby
- * @param int|null $limit
- * @param int|null $offset
- * @return array
- */
- function getRecordsByType( $filetype, $sortby=null, $limit=99999, $offset=0, $where=false )
- {
- $recArray = $this->getFileDataByType( $filetype );
- if (false == $recArray) {
- // return default values
- return $this->getDefaultRecordsByType( $filetype );
- }
- if (false != $where && !is_array($where)) {
- $where = array($where);
- }
- // TODO sortby
- // limit, offset
- $outArray = array();
- for ($i=$offset; $i < count($recArray); ++$i) {
- if ($i-$offset >= $limit) {
- break;
- }
-
- $rec = $recArray[$i];
-
- // filtering
- if (false != $where) {
- $valid = false;
- foreach ($where as $field=>$patten) {
- foreach($rec as $k=>$v) {
- if (!is_int($field) && strcasecmp($field, $k) != 0) {
- continue;
- }
- if (preg_match("/$patten/i", $v)) {
- $valid = true;
- break;
- }
- }
- if ($valid) {
- break;
- }
- }
- if (!$valid) {
- continue;
- }
- }
- $outArray[] = $recArray[$i];
- }
- return $outArray;
- }
- function getTotalByType( $filetype, $where=false )
- {
- $recArray = $this->getFileDataByType( $filetype );
- if (false == $recArray) {
- if ($filetype == 'authadminfile') {
- return 1;
- }
- return 0;
- }
- if (false == $where) {
- return count($recArray);
- }
-
- if (!is_array($where)) {
- $where = array($where);
- }
-
- $count = 0;
-
- foreach($recArray as $rec) {
- $valid = false;
- foreach ($where as $field=>$patten) {
- foreach($rec as $k=>$v) {
- if (!is_int($field) && strcasecmp($field, $k) != 0) {
- continue;
- }
- if (preg_match("/$patten/i", $v)) {
- $valid = true;
- break;
- }
- }
- if ($valid) {
- break;
- }
- }
- if (!$valid) {
- continue;
- }
-
- $count++;
- }
- return $count;
- }
- /**
- * Fetch record by Id
- *
- * @access public
- * @param string $filetype
- * @param string $recordId
- * @param bool $checkDefault
- * @return string|array|bool
- */
- function fetchRecordByType( $filetype, $recordId, $checkDefault=false )
- {
- $dataArray = $this->getFileDataByType( $filetype );
- if (false == $dataArray || count($dataArray) < 1) {
- if (false == $checkDefault) {
- return false;
- }
- $dataArray = $this->getDefaultRecordsByType( $filetype );
- }
- if (is_null($recordId)) {
- // reset first record for authadminfile
- if ($filetype == 'authadminfile') {
- return $this->getDefaultRecordsByType( $filetype );
- }
- return false;
- }
- $found = false;
- foreach( $dataArray as $rec ) {
- if ($filetype == 'accessfile') {
- if ($recordId == 'errordocument401') {
- if (preg_match('/^\s*ErrorDocument\s+401\s+/i', $rec)) {
- $found = $rec;
- break;
- }
- } else if (preg_match('/^\s*'.$recordId.'(\s+.+)?\s*$/i', $rec)) {
- $found = $rec;
- break;
- }
- continue;
- }
- if (isset($rec['name']) && strcmp($recordId, $rec['name'])==0) {
- $found = $rec;
- break;
- }
- }
- return $found;
- }
- /**
- * Check record by Id
- *
- * @access public
- * @param string $filetype
- * @param string $recordId
- * @return bool
- */
- function isRecordByType( $filetype, $recordId )
- {
- $rec = $this->fetchRecordByType($filetype, $recordId);
- return $rec == false ? false : true;
- }
- /**
- * Update record in file
- *
- * @access public
- * @param string $filetype
- * @param string $recordId
- * @param array data
- * @return bool
- */
- function updateRecordByType( $filetype, $recordId, $data )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- $this->setError( $this->W('NOTDEFINED', $filetype) );
- return false;
- }
- $hash = md5( $path );
- if (!is_array($this->_fileDataArray[$hash])) {
- $this->_fileDataArray[$hash] = null;
- }
- if ($filetype == 'accessfile') {
- $found = false;
- $recordId = strtolower($recordId);
- foreach ($this->_fileDataArray[$hash] as $id=>$rec) {
- $rec = trim($rec);
- $args = isset($data[$recordId]) ? $data[$recordId] : '';
- if ($recordId == 'errordocument401') {
- if (preg_match('/^(\s*ErrorDocument\s+401)\s+/i', $rec, $matches)) {
- if (!isset($data)) {
- unset( $this->_fileDataArray[$hash][$id] );
- continue;
- }
- $this->_fileDataArray[$hash][$id] = $matches[1] . ' ' . $args;
- }
- // remove all allow or deny commands
- } else if (preg_match('/^\s*'.$recordId.'\s+from\s+.*$/i', $rec)) {
- unset( $this->_fileDataArray[$hash][$id] );
- } else if (preg_match('/^(\s*'.$recordId.')(.*)$/i', $rec, $matches)) {
- if (!isset($data)) {
- unset( $this->_fileDataArray[$hash][$id] );
- continue;
- }
- if ($recordId == 'authname') {
- $this->_fileDataArray[$hash][$id] = $matches[1] . ' "' . addSlashes($args) . '"';
- } else if ($recordId == 'authuserfile') {
- $this->_fileDataArray[$hash][$id] = $matches[1] . ' ' . $args;
- } else if ($recordId == 'authtype') {
- $this->_fileDataArray[$hash][$id] = $matches[1] . ' basic';
- } else if ($recordId == 'order') {
- $this->_fileDataArray[$hash][$id] = 'Order ' . ($args=='deny' ? 'Allow,Deny' : 'Deny,Allow');
- }
- $found = true;
- break;
- }
- }
-
- // special case: allow or deny commands
- if ($recordId == 'allow' || $recordId == 'deny') {
- foreach($data as $item) {
- $this->_fileDataArray[$hash][] = $recordId . ' from ' . $item;
- }
- }
-
- return $found;
- }
- // other types
- foreach ($this->_fileDataArray[$hash] as $id=>$rec) {
- if (is_null($recordId) || isset($rec['name']) && strcmp($recordId, $rec['name'])==0) {
- if (is_null($data)) {
- unset( $this->_fileDataArray[$hash][$id] );
- } else if (is_array($data)) {
- foreach ($data as $k=>$v) {
- $this->_fileDataArray[$hash][$id][$k] = $v;
- }
- }
- break;
- }
- }
- return true;
- }
- /**
- * Update file record
- *
- * @access public
- * @param string $filetype
- * @param array $data
- * @param string $curRecordId
- * @param bool|null $saveFile
- * @param bool|null $saveForce
- * @return bool
- */
- function setRecordByType( $filetype, $curRecordId, $data, $saveFile=false, $saveForce=false )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- $this->setError( $this->W('NOTDEFINED', $filetype) );
- return false;
- }
- $hash = md5( $path );
- if (false != $this->isRecordByType( $filetype, $curRecordId )) {
- // replaceing
- $this->updateRecordByType( $filetype, $curRecordId, $data );
- } else if (is_array($data)) {
- // inserting
- if ($filetype == 'accessfile') {
- $args = isset($data[$curRecordId]) ? $data[$curRecordId] : '';
- $hasAddedBy = false;
- foreach( $this->_fileDataArray[$hash] as $rec) {
- if (preg_match('/^# added by authman/i', $rec)) {
- $hasAddedBy = true;
- }
- }
- if (!$hasAddedBy) {
- $this->_fileDataArray[$hash][] = "# Added By Authman";
- }
- if ($curRecordId == 'authname') {
- $this->_fileDataArray[$hash][] = 'AuthName "' . $args . '"';
- } else if ($curRecordId == 'authtype') {
- $this->_fileDataArray[$hash][] = 'AuthType ' . $args;
- } else if ($curRecordId == 'require') {
- $this->_fileDataArray[$hash][] = 'require ' . $args;
- } else if ($curRecordId == 'authuserfile') {
- $this->_fileDataArray[$hash][] = 'AuthUserFile ' . $args;
- } else if ($curRecordId == 'errordocument401') {
- $this->_fileDataArray[$hash][] = 'ErrorDocument 401 ' . $args;
- } else if ($curRecordId == 'order') {
- $this->_fileDataArray[$hash][] = 'Order ' . ($args=='deny' ? 'Allow,Deny' : 'Deny,Allow');
- } else if ($curRecordId == 'allow' || $curRecordId == 'deny') {
- foreach($data as $item) {
- $this->_fileDataArray[$hash][] = $curRecordId . ' from ' . $item;
- }
- } else {
- $this->_fileDataArray[$hash][] = '# '. $curRecordId . ' "' . $args . '"';
- }
- // other files types
- } else {
- $this->_fileDataArray[$hash][] = $data;
- }
- }
- if ($saveFile) {
- $strerr = null;
- // save parsed data
- if (false == $this->saveFileByType( $filetype, false )) {
- $strerr = $this->getError();
- }
- $this->readFileByType( $filetype );
- if (isset($strerr)) {
- $this->setError($strerr);
- return false;
- }
- }
- return true;
- }
- /**
- * Clear all records from the file
- *
- * @access public
- * @param string $filetype
- * @param bool|null $saveFile
- * @return bool
- */
- function clearAllRecordsByType( $filetype, $saveFile=false )
- {
- $path = $this->getPathByType( $filetype );
- if (false == $path) {
- $this->setError( $this->W('NOTDEFINED', $filetype) );
- return false;
- }
- $hash = md5( $path );
- $this->_fileDataArray[$hash] = array();
- if ($saveFile) {
- $strerr = null;
- // save _RAW_ data
- if (false == $this->saveFileByType( $filetype, true, '' )) {
- $strerr = $this->getError();
- }
- $this->readFileByType( $filetype );
- if (isset($strerr)) {
- $this->setError($strerr);
- return false;
- }
- }
- return true;
- }
- function getAccessRuleByType( $filetype, $ruleName )
- {
- $hash = md5( $this->getPathByType( $filetype ) );
- if (!isset($this->_accessRulesArray[$hash])) {
- return false;
- }
- $ruleName = strtolower($ruleName);
- if (!isset($this->_accessRulesArray[$hash][$ruleName])) {
- return false;
- }
- return $this->_accessRulesArray[$hash][$ruleName];
- }
- /***************************************************************************
- *
- **************************************************************************/
- /**
- * Get template list
- *
- * @access public
- * @return array
- */
- function getTemplates()
- {
- $this->_tplsArray = array();
- $tplPath = $this->_basePath . DIRECTORY_SEPARATOR . 'templates';
- $dh = @opendir( $tplPath );
- if (false == $dh) {
- return $this->_tplsArray;
- }
- while ($e = readdir($dh)) {
- if ($e == '.' || $e == '..') {
- continue;
- }
- if (!preg_match('/^(.+)\.tpl(\.dist)?$/i', $e, $matches)) {
- continue;
- }
- $tplId = $matches[1];
- $tplDefault = isset($matches[2]) && $matches[2] == '.dist';
-
- $filePath = $tplPath . DIRECTORY_SEPARATOR . $e;
- $fh = @fopen($filePath, 'r');
- if (false == $fh) {
- continue;
- }
- $data = array();
- while ($l = fgets($fh)) {
- $data[] = $l;
- }
- @fclose($fh);
- $role = 'undefinied';
- if (preg_match('/^(useradd|useredit|userdel|userfgt|userrcv|memberaa|memberdel|memberreq)$/i', $tplId, $matches)) {
- $role = strtolower($matches[1]);
- }
- $tArray = array('path'=>$filePath,
- 'id'=>$tplId,
- 'role'=>$role,
- 'name'=>trim($data[0]),
- 'type'=>( trim($data[1]) == 'html' ? 'html' : 'plaintext' ),
- 'subject'=>trim($data[2]),
- 'contents'=>join('', array_slice($data, 3)) );
-
- if (!$tplDefault || !array_key_exists($tplId, $this->_tplsArray)) {
- $this->_tplsArray[ $tplId ] = $tArray;
- }
- }
- closedir($dh);
- return $this->_tplsArray;
- }
- function getTemplateById( $id )
- {
- if (!isset($id) || $id=='') {
- return false;
- }
- $templates = $this->getTemplates();
- if (false==$templates || !isset($templates[$id])) {
- return false;
- }
- return $templates[$id];
- }
- function getTemplateByRole( $role )
- {
- $res = false;
- $templates = $this->getTemplates();
- foreach($templates as $id=>$tpl) {
- if ($tpl['role'] == $role) {
- $res = $tpl;
- }
- }
- return $res;
- }
- function saveTemplateAs( $id, $data, $force=false )
- {
- if (!isset($id) || $id=='' || !is_array($data)) {
- $this->setError( $this->E('INVALIDREQUEST') );
- return false;
- }
- // Saving in DEMO mode is disabled
- if ($this->isDemo()) {
- $this->setError( $this->W('DEMOISON') );
- return false;
- }
- $path = $this->_basePath . DIRECTORY_SEPARATOR . 'templates';
- if (!is_dir($path)) {
- if (false == @mkdir($path, 0755)) {
- $this->setError( $this->E('MKDIRFAILED', $path) );
- return false;
- }
- $denyPath = $path . DIRECTORY_SEPARATOR
- . $this->_configArray['access_file'];
- $this->writeDenyFile( $denyPath );
- }
- $id = $this->getNormalizedPath( $id );
- $filePath = $path . $id . '.tpl';
- if (is_file($filePath) && false == $force) {
- $this->setError( $this->E('FILEEXISTS', $filePath) );
- return false;
- }
- if (is_file($filePath) && !is_writable($filePath)) {
- $this->setError( $this->W('FILEWRITABLE') );
- return false;
- }
- $fh = @fopen($filePath, 'w');
- if (false == $fh) {
- $this->setError( $this->E('FILEOPENFAILED', $filePath) );
- return false;
- }
- @fwrite($fh, $data['name'] . "\n");
- @fwrite($fh, $data['type'] . "\n");
- @fwrite($fh, $data['subject'] . "\n");
- @fwrite($fh, $data['contents'] . "\n");
- @fclose($fh);
- return true;
- }
- /**
- * @desc Delete e-mail template
- *
- * @access public
- * @param string $id
- * @param bool $force
- * @return bool
- */
- function deleteTemplate( $id, $force=false )
- {
- // Deleting in DEMO mode is disabled
- if ($this->isDemo()) {
- $this->setError( $this->W('DEMOISON') );
- return false;
- }
- // Check if
- $template = $this->getTemplateById( $id );
- if (false == $template) {
- $this->setError( $this->E('TPLNOTFOUND', $id) );
- return false;
- }
- if ($force == false) {
- if ($template['role'] != 'undefinied') {
- $this->setError( $this->E('TPLISSYSTEM') );
- return false;
- }
- }
- $path = $this->_basePath . DIRECTORY_SEPARATOR . 'templates';
- $filePath = $path . DIRECTORY_SEPARATOR . $id . '.tpl';
- if (!is_file($filePath)) {
- $this->setError( $this->E('NOSUCHFILE', $filePath) );
- return false;
- }
- if (false == @unlink($filePath)) {
- $this->setError( $this->E('FILEDELFAILED', $filePath) );
- return false;
- }
- return true;
- }
- /***************************************************************************
- * E-mail routes
- **************************************************************************/
- /**
- * Send e-mail to the user
- *
- * @access public
- * @param string|array $templateId
- * @param array $userArray
- * @return bool
- */
- function sendMail( $templateId, $userArray )
- {
- if (false == $this->hasFeature('PHPMailer')) {
- $this->setError( 'SendMail: ' . $this->W('SENDMAILFAIL_INSTALLPHPMAILER'));
- return false;
- }
- // no spam here
- if ($this->isDemo()) {
- $this->setError( 'SendMail: ' . $this->W('DEMOISON') );
- return false;
- }
- if (is_array($templateId)) {
- $tplArray = $templateId;
- $templateId = 'manual';
- } else {
- $tplArray = $this->getTemplateById( $templateId );
- if (false == $tplArray) {
- $this->setError( 'SendMail: ' . $this->E('INCORRECTARGS') . ' [template]' );
- return false;
- }
- }
- if (!isset($userArray['email']) || $userArray['email'] == '') {
- $this->setError( 'SendMail: ' . $this->E('INCORRECTARGS') . ' [email]' );
- return false;
- }
- $args = array('PROTECTEDURL'=> $this->getUrlByType('protected', true),
- 'BASEURL' => $this->getUrlByType('base', true),
- 'MEMBERURL' => $this->getUrlByType('login', true),
- 'REMOTEADDR' => $_SERVER['REMOTE_ADDR'],
- 'DATETIME' => gmdate('D dS \of M Y H:i:s e') );
- list($admin) = $this->getRecordsByType( 'authadminfile', null, 1, 0 );
- $args['ADMINREALNAME'] = $admin['info'] != '' ? $admin['info'] : "Administrator";
- $args['ADMINEMAIL'] = $admin['email'] != '' ? $admin['email'] : "postmaster@localhost";
- foreach($userArray as $k=>$v) {
- $kk = 'USER' . strtoupper($k);
- $args[$kk] = $v;
- }
- $args['USERREALNAME'] = isset($userArray['info']) && $userArray['info'] != ''
- ? $userArray['info'] : $userArray['name'];
- $args['USERPASSWORD'] = isset($userArray['pass_raw']) && $userArray['pass_raw'] != '' ? $userArray['pass_raw'] : '[ENCRYPTED: '. $userArray['pass'] .']';
- $subject = $tplArray['subject'];
- $body = $tplArray['contents'];
- foreach(array('subject', 'body') as $vname) {
- foreach( $args as $k=>$v ) {
- $$vname = str_replace('%'.$k.'%', $v, $$vname);
- }
- }
- // sending
- include_once( $this->getPathByType('PHPMailer') );
- $mail = new PHPMailer();
- $mail->CharSet = "UTF-8";
- // from administrator
- $mail->FromName = $args['ADMINREALNAME'];
- $mail->From = $args['ADMINEMAIL'];
- $mail->AddReplyTo($args['ADMINEMAIL'], $args['ADMINREALNAME']);
- $isHtml = $tplArray['type'] == 'html';
- if ($templateId=='memberdel' || $templateId=='memberaa') {
- $mail->AddAddress($args['ADMINEMAIL'], $args['ADMINREALNAME']);
- } else {
- if (!isset($args['USEREMAIL']) || $args['USEREMAIL']=='') {
- if ($isHtml) {
- $body = '<p><strong>USER ' . $userArray['name'] . ' have not E-mail address</strong></p><br />' . $body;
- } else {
- $body = 'USER ' . $userArray['name'] . " have not E-mail address\n" . $body;
- }
- $mail->AddAddress($args['ADMINEMAIL'], $args['ADMINREALNAME']);
- } else {
- $mail->AddAddress($args['USEREMAIL'], $args['USERREALNAME']);
- }
- }
- $mail->Subject = $subject;
- $mail->Body = $body;
- if ($isHtml) {
- $mail->IsHTML( true );
- $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
- }
- if (false == $mail->Send()) {
- $this->setError( 'SendMail: ' . $mail->ErrorInfo );
- return false;
- }
- return true;
- }
- function hasFeature( $feature )
- {
- $ln = strtolower($feature);
- if ($ln == 'phpmailer' || $ln == 'tinymcejs' || $ln = 'magpierss') {
- $filePath = $this->getPathByType( $ln );
- if (!is_file($filePath) || !is_readable($filePath)) {
- return false;
- }
- return true;
- }
- return true;
- }
- /***************************************************************************
- * Messages/Warnings/Errors Reporting
- **************************************************************************/
- /**
- * Messages wrapper
- *
- * @access public
- * @return string
- */
- function M()
- {
- $args = func_get_args();
- return $this->getMessage( 'messages', $args );
- }
- /**
- * Warnings wrapper
- *
- * @access public
- * @return string
- */
- function W()
- {
- $args = func_get_args();
- return $this->getMessage( 'warnings', $args );
- }
- /**
- * Errors wrapper
- *
- * @access public
- * @return string
- */
- function E()
- {
- $args = func_get_args();
- return $this->getMessage( 'errors', $args );
- }
- /**
- * Return formated message
- *
- * @access private
- * @param string $type
- * @param array $args
- * @return string
- */
- function getMessage( $type, $args )
- {
- $fmt = strtoupper(array_shift($args));
- if (isset($this->_langArray[$type]) && isset($this->_langArray[$type][$fmt])) {
- $s = vsprintf( $this->_langArray[$type][$fmt], $args);
- } else {
- $s = '[' . $type . ': ' . $fmt;
- if (count($args)) {
- $s .= ':';
- foreach ($args as $t) {
- $s .= ' ' . $t;
- }
- }
- $s .= ']';
- }
- return $s;
- }
- /**
- * Set error message
- *
- * @access protected
- * @param string|null
- */
- function setError( $error=null )
- {
- $this->_error = $error;
- if (!isset($error)) {
- return;
- }
- if (isset($php_errormsg))
- $this->_error .= ': ' . $php_errormsg;
- return;
- }
- /**
- * Return true if error string is set
- *
- * @access public
- * @return bool
- */
- function isError()
- {
- return $this->_error == '' ? false : true;
- }
- /**
- * Get error message
- *
- * @access public
- * @return string
- */
- function getError()
- {
- if (!isset(…
Large files files are truncated, but you can click here to view the full file