PageRenderTime 60ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 1ms

/authman/index.php

https://bitbucket.org/dahlo/roster
PHP | 8054 lines | 5919 code | 1256 blank | 879 comment | 1416 complexity | c525aa1c23a95d0f9d0fae8dfef1e79d MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * AuthMan Free
  4. *
  5. * @copyright Copyright (c) 2008 Authman Inc. (http://www.authman.com)
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
  7. * @link http://www.authman.com
  8. * @version 1.0.0
  9. */
  10. ini_set('zlib.output_compression','Off');
  11. define('AUTHMAN_DIR', dirname(__FILE__));
  12. /**
  13. * AuthMan Class (Free Version)
  14. *
  15. * @copyright Copyright (c) 2008 Authman Inc. (http://www.authman.com)
  16. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
  17. * @link http://www.authman.com
  18. */
  19. class Authman
  20. {
  21. /**
  22. * Class version, const
  23. *
  24. * @access private
  25. */
  26. var $AUTHMAN_VERSION = '1.1.0';
  27. /**
  28. * Apache ServerRoot
  29. *
  30. * @access private
  31. * @var string
  32. */
  33. var $_serverRoot = '/etc/httpd';
  34. /**
  35. * Authman directory
  36. *
  37. * private @var string
  38. */
  39. var $_basePath;
  40. /**
  41. * Default Ini file
  42. *
  43. * @access private
  44. * @var string
  45. */
  46. var $_iniFile = 'config/config.ini';
  47. /**
  48. * Config settings
  49. *
  50. * @access private
  51. * @var array
  52. */
  53. var $_configArray = array('language' => 'english',
  54. 'login' => 'admin',
  55. 'password' => 'admin',
  56. 'demo' => 0,
  57. 'manual_edit' => 1,
  58. 'access_file' => '.htaccess',
  59. 'authuser_file' => '.htpasswd',
  60. 'authname' => 'Protected by Authman',
  61. 'allowsignup' => 0,
  62. 'autoapprove' => 0,
  63. 'encryption' =>'md5');
  64. /**
  65. * Language array
  66. *
  67. * @access private
  68. * @var array
  69. */
  70. var $_langArray = array('messages'=>array(),
  71. 'warnings'=>array(),
  72. 'errors'=>array());
  73. /**
  74. * File Paths
  75. *
  76. * @access private
  77. * @var array
  78. */
  79. var $_filePathsArray = array('configfile'=>null,
  80. 'langfile'=>null,
  81. 'accessfile'=>null,
  82. 'authadminfile'=>null,
  83. 'authuserfile' =>null,
  84. 'authgroupfile'=>null,
  85. 'accessfile_dist'=>null,
  86. 'authuserfile_dist' =>null,
  87. 'authgroupfile_dist'=>null,
  88. 'signupfile'=>null);
  89. /**
  90. * Raw File Contents (by url hash)
  91. *
  92. * @access private
  93. * @var array
  94. */
  95. var $_fileContentsArray = array();
  96. /**
  97. * Parsed File Data (by url hash)
  98. *
  99. * @access private
  100. * @var array
  101. */
  102. var $_fileDataArray = array();
  103. /**
  104. * Access Rules Information (by url hash)
  105. *
  106. * @access private
  107. * @var array
  108. */
  109. var $_accessRulesArray = array();
  110. /**
  111. * Runtime variables
  112. *
  113. * @access private
  114. * @var array
  115. */
  116. var $_runtimeArray = null;
  117. /**
  118. * Error message
  119. *
  120. * @access private
  121. * @var string
  122. */
  123. var $_error = null;
  124. /**
  125. * @access private
  126. * @var array
  127. */
  128. var $_tplsArray = array();
  129. /**
  130. * Authman Constructor
  131. *
  132. * @access public
  133. * @params array|null $config
  134. * @return void
  135. */
  136. function Authman( $config=array() )
  137. {
  138. // base prefix
  139. $this->_basePath = dirname(__FILE__);
  140. // overwrite ini file name
  141. if (isset($config['ini'])) {
  142. $this->_iniFile = $config['ini'];
  143. }
  144. // loading ini file
  145. $iniFilePath = $this->makePath( $this->_basePath, $this->_iniFile );
  146. $this->_filePathsArray[ 'configfile' ] = $iniFilePath;
  147. if (is_file($iniFilePath) && is_readable($iniFilePath) ) {
  148. $cfg = @parse_ini_file( $iniFilePath, false );
  149. if (isset($cfg)) {
  150. $this->_configArray = array_merge($this->_configArray, $cfg);
  151. }
  152. }
  153. // overwrite language
  154. if (isset($config['language'])) {
  155. $this->_configArray['language'] = $config['language'];
  156. }
  157. // loading language file
  158. $langFilePath = $this->makePath($this->_basePath . DIRECTORY_SEPARATOR . 'languages',
  159. $this->_configArray['language'] . '.lng' );
  160. $this->_filePathsArray[ 'langfile' ] = $langFilePath;
  161. if (!is_file($langFilePath) || !is_readable($langFilePath) ) {
  162. // we will trying load default language file
  163. $langFilePath = $this->makePath($this->_basePath . DIRECTORY_SEPARATOR . 'languages',
  164. 'english.lng' );
  165. }
  166. if (is_file($langFilePath) && is_readable($langFilePath) ) {
  167. $this->_langArray = array_merge($this->_langArray, @parse_ini_file($langFilePath, true));
  168. }
  169. // set access file path
  170. $path = $this->makePath( $this->_basePath . DIRECTORY_SEPARATOR . '..',
  171. $this->_configArray['access_file'] );
  172. $this->_filePathsArray[ 'accessfile' ] = $path;
  173. #if (is_file($path) && is_readable($path)) {
  174. $this->readFileByType( 'accessfile' );
  175. #}
  176. // set admin htpasswd file path
  177. $basedir = $this->_basePath . DIRECTORY_SEPARATOR . 'var';
  178. $path = $this->makePath( $basedir, '.htadmin' );
  179. $this->_filePathsArray[ 'authadminfile' ] = $path;
  180. // set default file paths
  181. $path = $this->makePath( $basedir, 'htaccess_dist' );
  182. $this->_filePathsArray[ 'accessfile_dist' ] = $path;
  183. $path = $this->makePath( $basedir, 'htpasswd_dist' );
  184. $this->_filePathsArray[ 'authuserfile_dist' ] = $path;
  185. $path = $this->makePath( $basedir, 'htgroup_dist' );
  186. $this->_filePathsArray[ 'authgroupfile_dist' ] = $path;
  187. $path = $this->makePath( $basedir, 'signups' );
  188. $this->_filePathsArray[ 'signupfile' ] = $path;
  189. // loading runtime stats
  190. }
  191. /**
  192. * Return class version
  193. *
  194. * @access public
  195. * @return string
  196. */
  197. function getVersion()
  198. {
  199. return $this->AUTHMAN_VERSION;
  200. }
  201. /**
  202. * Return true if demo mode is on
  203. *
  204. * @access public
  205. * @return string
  206. */
  207. function isDemo()
  208. {
  209. return $this->_configArray['demo'] == 1;
  210. }
  211. /**
  212. * Return true if menual edit is allowed
  213. *
  214. * @access public
  215. * @return string
  216. */
  217. function isManualEdit()
  218. {
  219. return $this->_configArray['manual_edit'] == 1;
  220. }
  221. /**
  222. * Return configuration value by name
  223. *
  224. * @access public
  225. * @param string $name
  226. * @return string
  227. */
  228. function getConfigValue( $name )
  229. {
  230. if (!isset($name) || !isset($this->_configArray[$name])) {
  231. return false;
  232. }
  233. return $this->_configArray[$name];
  234. }
  235. /***************************************************************************
  236. * Member zone related functions
  237. **************************************************************************/
  238. /**
  239. * Logging as user
  240. *
  241. * @access public
  242. * @param string $username
  243. * @param string encpass
  244. * @return bool
  245. */
  246. function loginAs( $username, $encpass )
  247. {
  248. $_SESSION['am_u'] = base64_encode( $username );
  249. $_SESSION['am_c'] = md5( $encpass );
  250. $user = $this->fetchRecordByType( 'authuserfile', $username );
  251. if (false == $user) {
  252. $user = $this->fetchRecordByType( 'authadminfile', $username, true );
  253. if (false == $user) {
  254. return false;
  255. }
  256. $err = $this->getError();
  257. $this->setRuntimeValue('lastloggedin_ts', time());
  258. $this->setRuntimeValue('lastloggedin_ip', $_SERVER['REMOTE_ADDR'], true);
  259. $this->setError($err);
  260. }
  261. return true;
  262. }
  263. /**
  264. * Return authenticated user data
  265. *
  266. * @access public
  267. * @return array|false
  268. */
  269. function getAuthenticatedUser()
  270. {
  271. // checking session cookie
  272. $isadmin = false;
  273. $user = null;
  274. $username = $codedpass = $rawpass = null;
  275. if (isset($_SESSION) && isset($_SESSION['am_u'])
  276. && isset($_SESSION['am_c'])) {
  277. $username = base64_decode($_SESSION['am_u']);
  278. $codedpass = $_SESSION['am_c']; // md5
  279. } else if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
  280. $username = $_SERVER['PHP_AUTH_USER'];
  281. $rawpass = $_SERVER['PHP_AUTH_PW'];
  282. }
  283. if (!isset($username) || $username=='') {
  284. return false;
  285. }
  286. // checking admins first
  287. $user = $this->fetchRecordByType('authadminfile', $username, true);
  288. if ($user) {
  289. $isadmin = true;
  290. } else {
  291. $user = $this->fetchRecordByType('authuserfile', $username);
  292. }
  293. if (false == $user || !isset($user['pass'])) {
  294. return false;
  295. }
  296. if (isset($rawpass)) {
  297. $encpass = $this->htcrypt($rawpass, $user['pass']);
  298. if ($encpass != $user['pass']) {
  299. return false;
  300. }
  301. } else if (md5($user['pass']) != $codedpass) {
  302. return false;
  303. }
  304. $user['isadmin'] = $isadmin;
  305. return $user;
  306. }
  307. /**
  308. * Return true if user is authenticated
  309. *
  310. * @access public
  311. * @return bool
  312. */
  313. function isAuthenticated()
  314. {
  315. return false == $this->getAuthenticatedUser() ? false : true;
  316. }
  317. /**
  318. * Return true if user is authenticated by basic auth method
  319. *
  320. * @access public
  321. * @return bool
  322. */
  323. function isAuthenticatedByBasicAuth()
  324. {
  325. $user = $this->getAuthenticatedUser();
  326. if (false == $user) {
  327. return false;
  328. }
  329. if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
  330. return false;
  331. }
  332. $encpass = $this->htcrypt($_SERVER['PHP_AUTH_PW'], $user['pass']);
  333. if ($encpass != $user['pass']) {
  334. return false;
  335. }
  336. return true;
  337. }
  338. /**
  339. * Return true if current authenticated user has administrator priviledges
  340. *
  341. * @access public
  342. * @return bool
  343. */
  344. function isAdmin()
  345. {
  346. $user = $this->getAuthenticatedUser();
  347. if (false == $user) {
  348. return false;
  349. }
  350. return isset($user['isadmin']) && $user['isadmin'] ? true : false;
  351. }
  352. /***************************************************************************
  353. * Crypt Utilties
  354. **************************************************************************/
  355. /**
  356. * Encrypt text with crypt function
  357. *
  358. * @access public
  359. * @param string $text
  360. * @param string|null $salt
  361. * @param string|null $prefix
  362. * @return string
  363. */
  364. function encrypt_saltcrypt( $text, $salt='', $prefix='' )
  365. {
  366. if ($salt == 'DES') {
  367. $salt = CRYPT_STD_DES == 1 ? 'r1' : '';
  368. }
  369. if ($salt == 'EXT_DES') {
  370. $salt = CRYPT_EXT_DES == 1 ? '_J9..pre' : '';
  371. }
  372. if ($salt == 'MD5') {
  373. $salt = CRYPT_MD5 == 1 ? '$1$pre$' : '';
  374. }
  375. if ($salt == '') {
  376. mt_srand((double)microtime()*1000000);
  377. for ($i=0; $i<CRYPT_SALT_LENGTH; $i++)
  378. $salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./",
  379. mt_rand() & 63, 1);
  380. }
  381. return $prefix . crypt($text, $salt);
  382. }
  383. /**
  384. * Encrypt text with crypt function
  385. *
  386. * @access public
  387. * @param string $text
  388. * @param string|null $salt
  389. * @return string
  390. */
  391. function htcrypt( $text, $salt=null )
  392. {
  393. $method = $this->_configArray['encryption'];
  394. if (isset($salt) && substr($salt, 0, 6) == '$apr1$') {
  395. $method = 'md5';
  396. $salt = substr($salt, 6);
  397. }
  398. // apr1-md5
  399. if ($method == 'md5') {
  400. if (CRYPT_MD5 == 1) {
  401. return $this->crypt_apr1_md5($text, $salt);
  402. }
  403. }
  404. // DES
  405. if (!isset($salt)) {
  406. mt_srand((double)microtime()*1000000);
  407. for ($i=0; $i<CRYPT_SALT_LENGTH; $i++) {
  408. $salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./", mt_rand() & 63, 1);
  409. }
  410. }
  411. return crypt($text, $salt);
  412. }
  413. /**
  414. * Encryption function
  415. *
  416. * @access public
  417. * @param string $plainpasswd
  418. * @param string $salt
  419. * @return string
  420. */
  421. function crypt_apr1_md5($plainpasswd, $salt) {
  422. if (!isset($salt)) {
  423. $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
  424. } else {
  425. $salt = substr($salt, 0, 8);
  426. }
  427. $len = strlen($plainpasswd);
  428. $text = $plainpasswd.'$apr1$'.$salt;
  429. $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd));
  430. for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); }
  431. for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $plainpasswd{0}; }
  432. $bin = pack("H32", md5($text));
  433. for($i = 0; $i < 1000; $i++) {
  434. $new = ($i & 1) ? $plainpasswd : $bin;
  435. if ($i % 3) $new .= $salt;
  436. if ($i % 7) $new .= $plainpasswd;
  437. $new .= ($i & 1) ? $bin : $plainpasswd;
  438. $bin = pack("H32", md5($new));
  439. }
  440. $tmp = '';
  441. for ($i = 0; $i < 5; $i++) {
  442. $k = $i + 6;
  443. $j = $i + 12;
  444. if ($j == 16) $j = 5;
  445. $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
  446. }
  447. $tmp = chr(0).chr(0).$bin[11].$tmp;
  448. $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
  449. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
  450. "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
  451. return "$"."apr1"."$".$salt."$".$tmp;
  452. }
  453. /***************************************************************************
  454. * File System Utilties
  455. **************************************************************************/
  456. /**
  457. * Construct path from base path and file name
  458. *
  459. * @access public
  460. * @param string $basePath
  461. * @param string $fileName
  462. * @param string|null $dirsep
  463. * @return string
  464. */
  465. function makePath($basePath, $fileName, $dirsep=DIRECTORY_SEPARATOR)
  466. {
  467. // Windows
  468. if (preg_match('/^[A-Z]:\\\/i', $fileName)) {
  469. return $this->getNormalizedPath( $fileName );
  470. }
  471. // Unix and other
  472. if (substr($fileName,0,1)=='/' || substr($fileName,0,1)==$dirsep) {
  473. return $this->getNormalizedPath( $fileName );
  474. }
  475. return $this->getNormalizedPath( $basePath . $dirsep . $fileName );
  476. }
  477. /**
  478. * Normalize given path
  479. *
  480. * @access public
  481. * @param mixed $path
  482. * @param string|null $dirsep
  483. * @return mixed
  484. */
  485. function getNormalizedPath( $path, $dirsep=DIRECTORY_SEPARATOR )
  486. {
  487. if (is_array($path)) {
  488. $pathArray = array();
  489. foreach($path as $p) {
  490. $pathArray[] = $this->getNormalizedPath($p, $dirsep);
  491. }
  492. return $pathArray;
  493. }
  494. $prefix = '';
  495. // if not Windows
  496. if (!preg_match('/^[A-Z]:\\\/i', $path)) {
  497. $prefix = $dirsep;
  498. }
  499. $path = str_replace('/', $dirsep, $path);
  500. $path = str_replace('\\', $dirsep, $path);
  501. $parts = explode($dirsep, $path);
  502. $todown=0;
  503. for ($i = count($parts)-1; $i >= 0; $i--) {
  504. if (empty($parts[$i]) || $parts[$i] == '.') {
  505. array_splice( $parts, $i, 1);
  506. continue;
  507. }
  508. if ($parts[$i] == '..') {
  509. array_splice( $parts, $i, 1);
  510. if ($i > 0) {
  511. $todown++;
  512. }
  513. continue;
  514. }
  515. if ($todown) {
  516. # warning: not works for complex paths like /root/path/../path/../../the/end
  517. array_splice( $parts, $i-($todown-1), $todown);
  518. $todown = 0;
  519. }
  520. }
  521. return $prefix . implode( $dirsep, $parts );
  522. }
  523. /**
  524. * Return full path to a file specified by type
  525. *
  526. * @access public
  527. * @param string $filetype
  528. * @param string|null $dir
  529. * @return string
  530. */
  531. function getPathByType( $filetype, $dir=DIRECTORY_SEPARATOR )
  532. {
  533. $ln = strtolower($filetype);
  534. if ($ln == 'protecteddirectory') {
  535. return $this->getNormalizedPath($this->_basePath . $dir . '..');
  536. }
  537. if ($ln == 'phpmailer') {
  538. return implode($dir, array($this->_basePath, 'contrib',
  539. 'phpmailer', 'class.phpmailer.php'));
  540. }
  541. if ($ln == 'tinymcejs') {
  542. return implode($dir, array($this->_basePath,
  543. 'contrib', 'tinymce', 'jscripts',
  544. 'tiny_mce', 'tiny_mce.js'));
  545. }
  546. if ($ln == 'magpierss') {
  547. return implode($dir, array($this->_basePath, 'contrib',
  548. 'magpierss', 'rss_fetch.inc'));
  549. }
  550. if (!isset($this->_filePathsArray[$filetype])) {
  551. return false;
  552. }
  553. return $this->_filePathsArray[$filetype];
  554. }
  555. /**
  556. * Return default file path by type
  557. *
  558. * @access public
  559. * @param string $filetype
  560. * @return string
  561. */
  562. function getDefaultFilePathByType( $filetype )
  563. {
  564. if ($filetype == 'authuserfile') {
  565. return dirname($this->getPathByType('accessfile'))
  566. . DIRECTORY_SEPARATOR
  567. . $this->getConfigValue('authuser_file');
  568. }
  569. return false;
  570. }
  571. /**
  572. * Returns url by type
  573. *
  574. * @access public
  575. * @param string $filetype
  576. * @param string|null $fulurl
  577. * @return strung
  578. */
  579. function getUrlByType( $filetype, $fullurl=false )
  580. {
  581. // base uri
  582. $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
  583. $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
  584. $uri_self = $_SERVER['PHP_SELF'];
  585. $uri = dirname($uri_self);
  586. if ($filetype == 'base') {
  587. $uri .= '/';
  588. }
  589. if ($filetype == 'protected') {
  590. $uri = $this->getNormalizedPath($uri . '/../', '/');
  591. }
  592. if ($filetype == 'errordocument401') {
  593. $uri = $uri_self .'?page=401';
  594. }
  595. if ($filetype == 'login') {
  596. $uri = $uri_self .'?page=login';
  597. }
  598. if ($filetype == 'tinymcejs') {
  599. $uri .= '/contrib/tinymce/jscripts/tiny_mce/tiny_mce.js';
  600. }
  601. if (!$fullurl) {
  602. return $uri;
  603. }
  604. return 'http://'.$server . ($port != 80 ? ':'.$port : '') . $uri;
  605. }
  606. /**
  607. * Set file path
  608. *
  609. * @access public
  610. * @param string $filetype
  611. * @param string $filepath
  612. * @return void
  613. */
  614. function setFilePathByType( $filetype, $filepath )
  615. {
  616. if (!isset($filepath)) {
  617. return false;
  618. }
  619. $hash = md5( $filepath );
  620. $this->_fileContentsArray[ $hash ] = null;
  621. $this->_fileDataArray[ $hash ] = null;
  622. $this->_filePathsArray[ $filetype ] = $filepath;
  623. }
  624. /**
  625. * Return temporary file name
  626. *
  627. * @access public
  628. * @return string
  629. */
  630. function getTempFilePath()
  631. {
  632. return $this->_basePath . DIRECTORY_SEPARATOR . 't_' . time() . rand(0, 1000);
  633. }
  634. /***************************************************************************
  635. * String functions
  636. **************************************************************************/
  637. /***************************************************************************
  638. * Disk Level File Operations
  639. **************************************************************************/
  640. /**
  641. * Write default deny file to disk
  642. *
  643. * @access private
  644. * @param string $filePath
  645. * @return bool
  646. */
  647. function writeDenyFile( $filePath )
  648. {
  649. $fh = @fopen($filePath, 'w');
  650. if (false == $fh) {
  651. return false;
  652. }
  653. @fwrite($fh, "# Automatically Created by Autman Free\n");
  654. @fwrite($fh, "order deny,allow\n");
  655. @fwrite($fh, "deny from all\n");
  656. @fclose($fh);
  657. return true;
  658. }
  659. /**
  660. * Read and parse file
  661. *
  662. * @access private
  663. * @param string $filetype
  664. * @return bool
  665. */
  666. function readFileByType( $filetype )
  667. {
  668. $path = $this->getPathByType( $filetype );
  669. if (false == $path) {
  670. return false;
  671. }
  672. $hash = md5($path);
  673. $this->_fileContentsArray[$hash] = array();
  674. $this->_fileDataArray[$hash] = array();
  675. if (!is_file($path)) {
  676. $this->setError( $this->E('NOSUCHFILE', $path) );
  677. return false;
  678. }
  679. if (is_file($path) && !is_readable($path)) {
  680. $this->setError( $this->E('FILENOTREADBLE', $path) );
  681. return false;
  682. }
  683. $fh = @fopen($path, 'r');
  684. if (false == $fh) {
  685. $this->setError( $this->E('FILEOPENFAILED', $path) );
  686. return false;
  687. }
  688. $contents = $buf = null;
  689. $maxbytes = 2048000;
  690. $bytes = 0;
  691. while (!feof($fh) && $bytes < $maxbytes && ($buf = fread($fh, $maxbytes-$bytes))) {
  692. $contents .= $buf;
  693. }
  694. fclose($fh);
  695. return $this->setFileContentsByType( $filetype, $contents );
  696. }
  697. /**
  698. * Save file
  699. *
  700. * @access public
  701. * @param string $filetype
  702. * @param bool|null $saveRawData
  703. * @param string|null $contents
  704. * @return bool
  705. */
  706. function saveFileByType( $filetype, $saveRawData=false, $contents=null, $parseTemplates=false )
  707. {
  708. $path = $this->getPathByType( $filetype );
  709. if (!$path) {
  710. return false;
  711. }
  712. if (!isset($contents)) {
  713. $contents = $this->getFileContentsByType( $filetype, $saveRawData, $parseTemplates );
  714. }
  715. // Saving in DEMO mode is disabled
  716. if ($this->isDemo()) {
  717. $this->setError( $this->W('DEMOISON') );
  718. return false;
  719. }
  720. if (!is_file($path) && !is_writable(dirname($path))) {
  721. $this->setError( $this->E('DIRNOTWRITABLE', dirname($path)) );
  722. return false;
  723. }
  724. if (is_file($path) && !is_writable($path)) {
  725. $this->setError( $this->E('FILENOTWRITABLE', $path) );
  726. return false;
  727. }
  728. $fh = @fopen($path, 'w');
  729. if (!$fh) {
  730. $this->setError( $this->E('FILEOPENFAILED', $path) );
  731. return false;
  732. }
  733. if ($contents != '') {
  734. if (!fwrite($fh, $contents)) {
  735. $this->setError( $this->E('WRITEFAILED', $path) );
  736. return false;
  737. }
  738. }
  739. @fclose($fh);
  740. if (!$this->readFileByType( $filetype )) {
  741. return false;
  742. }
  743. return true;
  744. }
  745. /**
  746. * Reset protected directory
  747. *
  748. * @access public
  749. * @retrun bool
  750. */
  751. function resetProtectedDirectory()
  752. {
  753. $src = $this->getPathByType( 'accessfile_dist');
  754. $dst = $this->getPathByType( 'accessfile' );
  755. if (false == $this->copyFile( $src, $dst )) {
  756. return false;
  757. }
  758. $this->readFileByType( 'accessfile' );
  759. $result = true;
  760. $filesArray = array('authuserfile'); // , 'authgroupfile');
  761. foreach ($filesArray as $file) {
  762. $src = $this->getPathByType( $file . '_dist');
  763. $dst = $this->getPathByType( $file );
  764. if (isset($src) && isset($dst) && is_file($src)) {
  765. if (false == $this->copyFile( $src, $dst )) {
  766. $result = false;
  767. }
  768. }
  769. }
  770. return $result;
  771. }
  772. /**
  773. * Copy file
  774. *
  775. * @access public
  776. * @param string $src
  777. * @param string $dst
  778. * @return bool
  779. */
  780. function copyFile( $src, $dst )
  781. {
  782. if ($src == false) {
  783. $this->setError( $this->E('INVALIDREQUEST') . ' [source]');
  784. return false;
  785. }
  786. if ($dst == false) {
  787. $this->setError( $this->E('INVALIDREQUEST') . ' [destination]');
  788. return false;
  789. }
  790. // Saving in DEMO mode is disabled
  791. if ($this->isDemo()) {
  792. $this->setError( $this->W('DEMOISON') );
  793. return false;
  794. }
  795. if (!is_file($dst) && !is_writable(dirname($dst))) {
  796. $this->setError( $this->E('DIRNOTWRITABLE', dirname($dst)) );
  797. return false;
  798. }
  799. if (is_file($dst) && !is_writable($dst)) {
  800. $this->setError( $this->E('FILENOTWRITABLE', $dst) );
  801. return false;
  802. }
  803. if (!is_file($src) || !is_readable($src)) {
  804. $this->setError( $this->E('FILENOTREADBLE', $src) );
  805. return false;
  806. }
  807. if (false == copy( $src, $dst )) {
  808. $this->setError( $this->E('FILECOPYFAILED', $src) );
  809. return false;
  810. }
  811. return true;
  812. }
  813. /***************************************************************************
  814. * Contents
  815. **************************************************************************/
  816. /**
  817. * Return file contents
  818. *
  819. * @access public
  820. * @param string $filetype
  821. * @param bool|null $getRawData
  822. * @return string
  823. */
  824. function getFileContentsByType( $filetype, $getRawData=false, $parseTemplates=false )
  825. {
  826. $path = $this->getPathByType( $filetype );
  827. if (false == $path) {
  828. return false;
  829. }
  830. $hash = md5( $path );
  831. if (false == $getRawData) {
  832. $data = $this->getFileDataByType( $filetype );
  833. $text = '';
  834. // build contents from parsed data
  835. if ($filetype == 'accessfile') {
  836. if ($parseTemplates) {
  837. foreach ($data as $k=>$v) {
  838. $data[$k] = preg_replace('/%PROTECTEDDIRECTORY%/', $am->getPathByType('protecteddirectory'), $v);
  839. }
  840. }
  841. $text = implode("\n", $data);
  842. } else if (($filetype=='authuserfile' || $filetype=='authadminfile' ||
  843. $filetype=='signupfile') && is_array($data)) {
  844. foreach ($data as $user) {
  845. if (isset($user['pass_raw'])) {
  846. // $pass = $this->encrypt_saltcrypt( $user['pass_raw'], 'DES' );
  847. $pass = $this->htcrypt( $user['pass_raw'] ); // salt automatically generated
  848. } else {
  849. $pass = $user['pass'];
  850. }
  851. $text .= $user['name'] . ':' . $pass;
  852. if (isset($user['info']) || isset($user['email'])) {
  853. $text .= ':';
  854. $text .= isset($user['info']) ? $user['info'] . ':' : '';
  855. if (isset($user['email'])) {
  856. $text .= $user['email'];
  857. }
  858. }
  859. if ($filetype=='signupfile') {
  860. $text .= ':' . (isset($user['ts']) ? $user['ts'] : '');
  861. $text .= ':' . (isset($user['remoteaddr']) ? $user['remoteaddr'] : '');
  862. $text .= ':' . (isset($user['referer']) ? $user['referer'] : '');
  863. }
  864. $text .= "\n";
  865. }
  866. }
  867. return $text;
  868. }
  869. /* fetching raw data */
  870. if (!isset($this->_fileContentsArray[ $hash ])) {
  871. if (false == $this->readFileByType( $filetype )) {
  872. return false;
  873. }
  874. }
  875. if (!isset($this->_fileContentsArray[ $hash ])) {
  876. return '';
  877. }
  878. if (!is_array($this->_fileContentsArray[$hash])) {
  879. return $this->_fileContentsArray[$hash];
  880. }
  881. return implode("\n", $this->_fileContentsArray[$hash]);
  882. }
  883. /**
  884. * Parse files
  885. *
  886. * @access public
  887. * @param string $filetype
  888. * @param string $contents
  889. * @return bool
  890. */
  891. function parseFileContentsByType( $filetype, $contents )
  892. {
  893. $path = $this->getPathByType( $filetype );
  894. if (false == $path) {
  895. $this->setError( $this->W('NOTDEFINED', $filetype) );
  896. return false;
  897. }
  898. $hash = md5( $path );
  899. $this->_fileDataArray[$hash] = array();
  900. $this->_accessRulesArray[$hash] = array('order'=>null);
  901. $lArray = split("[\n\r]+", $contents);
  902. // no data
  903. if (count($lArray) < 0) {
  904. return true;
  905. }
  906. if ($filetype == 'accessfile') {
  907. $rows = array();
  908. $hash = md5( $this->getPathByType( $filetype ) );
  909. foreach($lArray as $l) {
  910. if (preg_match('/^\s*Auth(User|Group)File\s+(.+)/i', $l, $matches)) {
  911. $authfiletype = 'auth' . strtolower($matches[1]) . 'file';
  912. $path = $this->makePath( $this->_serverRoot, $matches[2] );
  913. $this->_filePathsArray[ $authfiletype ] = $path;
  914. }
  915. if (preg_match('/^\s*AuthType\s+(.+)/i', $l, $matches)) {
  916. $val = strtolower(trim($matches[1]));
  917. $val = stripslashes($val);
  918. $this->_accessRulesArray[$hash]['authtype'] = $val;
  919. }
  920. if (preg_match('/^\s*AuthName\s+"?(.+?)"?\s*$/i', $l, $matches)) {
  921. $val = trim($matches[1]);
  922. $val = stripslashes( $val );
  923. $this->_accessRulesArray[$hash]['authname'] = $val;
  924. }
  925. // ip/domain access rules
  926. if (preg_match('/^\s*Order\s+(Allow|Deny),\s*(Allow|Deny)\s*$/i', $l, $matches)) {
  927. $this->_accessRulesArray[$hash]['order'] = strtolower($matches[2]);
  928. }
  929. if (preg_match('/^\s*(allow|deny)\s+from\s+(.+)$/i', $l, $matches)) {
  930. foreach(explode(' ', $matches[2]) as $s) {
  931. $s = trim($s);
  932. if (empty($s)) {
  933. continue;
  934. }
  935. $rule = strtolower($matches[1]);
  936. $this->_accessRulesArray[$hash][$rule][] = $s;
  937. }
  938. }
  939. // error document rules
  940. if (preg_match('/^\s*ErrorDocument\s+401\s+(.+)$/i', $l, $matches)) {
  941. $val = trim($matches[1]);
  942. $this->_accessRulesArray[$hash]['errordocument401'] = $val;
  943. }
  944. $rows[] = $l;
  945. }
  946. $this->_fileDataArray[$hash] = $rows;
  947. }
  948. if ($filetype=='authuserfile' || $filetype=='authadminfile' || $filetype=='signupfile') {
  949. $users = array();
  950. foreach($lArray as $l) {
  951. if (preg_match('/^\s*#/', $l)) {
  952. continue;
  953. }
  954. $ldArray = split(':', $l);
  955. if (count($ldArray) < 2) {
  956. continue;
  957. }
  958. $data = array('name' => $ldArray[0],
  959. 'pass' => $ldArray[1],
  960. 'info' => isset($ldArray[2]) ? $ldArray[2] : null,
  961. 'email' => isset($ldArray[3]) ? $ldArray[3] : null);
  962. if ($filetype == 'signupfile') {
  963. $data['ts'] = isset($ldArray[4]) ? $ldArray[4]: null;
  964. $data['remoteaddr'] = isset($ldArray[5]) ? $ldArray[5] : null;
  965. $data['referer'] = implode(':', array_slice($ldArray, 6));
  966. }
  967. $users[] = $data;
  968. }
  969. $this->_fileDataArray[$hash] = $users;
  970. }
  971. if ($filetype == 'authgroupfile') {
  972. }
  973. return true;
  974. }
  975. /**
  976. * Set, Parse given file contents and optionaly Save it
  977. *
  978. * @access public
  979. * @param string $filetype
  980. * @param string $contents
  981. * @param bool|null $saveData
  982. * @param bool|null $saveRawData
  983. * @return bool
  984. */
  985. function setFileContentsByType( $filetype, $contents, $saveData=false, $saveRawData=false )
  986. {
  987. $path = $this->getPathByType( $filetype );
  988. if (false == $path) {
  989. $this->setError( $this->W('NOTDEFINED', $filetype) );
  990. return false;
  991. }
  992. $hash = md5( $path );
  993. $this->_fileContentsArray[$hash] = $contents;
  994. // parse contents
  995. if (false == $this->parseFileContentsByType( $filetype, $contents )) {
  996. return false;
  997. }
  998. if ($saveData) {
  999. if (false == $saveRawData) {
  1000. // build contents from parsed data
  1001. }
  1002. if (false == $this->saveFileByType( $filetype, $contents )) {
  1003. return false;
  1004. }
  1005. }
  1006. return true;
  1007. }
  1008. /***************************************************************************
  1009. * File Data Routes
  1010. **************************************************************************/
  1011. /**
  1012. * Return parsed data
  1013. *
  1014. * @access public
  1015. * @param string $filetype
  1016. * @return array
  1017. */
  1018. function getFileDataByType( $filetype )
  1019. {
  1020. $path = $this->getPathByType( $filetype );
  1021. if (false == $path) {
  1022. $this->setError( $this->W('NOTDEFINED', $filetype) );
  1023. return false;
  1024. }
  1025. $hash = md5( $path );
  1026. // not readed yet
  1027. if (!isset( $this->_fileDataArray[$hash] )) {
  1028. if (false == $this->readFileByType( $filetype )) {
  1029. return false;
  1030. }
  1031. }
  1032. return $this->_fileDataArray[$hash];
  1033. }
  1034. function getDefaultRecordsBytype( $filetype )
  1035. {
  1036. if ($filetype == 'authadminfile') {
  1037. $pass_raw = $this->_configArray['password'];
  1038. return array(array('name'=>$this->_configArray['login'],
  1039. //'pass'=>$this->encrypt_saltcrypt( $pass_raw, 'DES' ),
  1040. 'pass'=>$this->htcrypt($pass_raw, 'adminpass'),
  1041. 'pass_raw'=>$pass_raw,
  1042. 'info'=>'Administration',
  1043. 'email'=>'support'));
  1044. }
  1045. return array();
  1046. }
  1047. /**
  1048. * Update file record
  1049. *
  1050. * @access public
  1051. * @param string $filetype
  1052. * @param string|null $sortby
  1053. * @param int|null $limit
  1054. * @param int|null $offset
  1055. * @return array
  1056. */
  1057. function getRecordsByType( $filetype, $sortby=null, $limit=99999, $offset=0, $where=false )
  1058. {
  1059. $recArray = $this->getFileDataByType( $filetype );
  1060. if (false == $recArray) {
  1061. // return default values
  1062. return $this->getDefaultRecordsByType( $filetype );
  1063. }
  1064. if (false != $where && !is_array($where)) {
  1065. $where = array($where);
  1066. }
  1067. // TODO sortby
  1068. // limit, offset
  1069. $outArray = array();
  1070. for ($i=$offset; $i < count($recArray); ++$i) {
  1071. if ($i-$offset >= $limit) {
  1072. break;
  1073. }
  1074. $rec = $recArray[$i];
  1075. // filtering
  1076. if (false != $where) {
  1077. $valid = false;
  1078. foreach ($where as $field=>$patten) {
  1079. foreach($rec as $k=>$v) {
  1080. if (!is_int($field) && strcasecmp($field, $k) != 0) {
  1081. continue;
  1082. }
  1083. if (preg_match("/$patten/i", $v)) {
  1084. $valid = true;
  1085. break;
  1086. }
  1087. }
  1088. if ($valid) {
  1089. break;
  1090. }
  1091. }
  1092. if (!$valid) {
  1093. continue;
  1094. }
  1095. }
  1096. $outArray[] = $recArray[$i];
  1097. }
  1098. return $outArray;
  1099. }
  1100. function getTotalByType( $filetype, $where=false )
  1101. {
  1102. $recArray = $this->getFileDataByType( $filetype );
  1103. if (false == $recArray) {
  1104. if ($filetype == 'authadminfile') {
  1105. return 1;
  1106. }
  1107. return 0;
  1108. }
  1109. if (false == $where) {
  1110. return count($recArray);
  1111. }
  1112. if (!is_array($where)) {
  1113. $where = array($where);
  1114. }
  1115. $count = 0;
  1116. foreach($recArray as $rec) {
  1117. $valid = false;
  1118. foreach ($where as $field=>$patten) {
  1119. foreach($rec as $k=>$v) {
  1120. if (!is_int($field) && strcasecmp($field, $k) != 0) {
  1121. continue;
  1122. }
  1123. if (preg_match("/$patten/i", $v)) {
  1124. $valid = true;
  1125. break;
  1126. }
  1127. }
  1128. if ($valid) {
  1129. break;
  1130. }
  1131. }
  1132. if (!$valid) {
  1133. continue;
  1134. }
  1135. $count++;
  1136. }
  1137. return $count;
  1138. }
  1139. /**
  1140. * Fetch record by Id
  1141. *
  1142. * @access public
  1143. * @param string $filetype
  1144. * @param string $recordId
  1145. * @param bool $checkDefault
  1146. * @return string|array|bool
  1147. */
  1148. function fetchRecordByType( $filetype, $recordId, $checkDefault=false )
  1149. {
  1150. $dataArray = $this->getFileDataByType( $filetype );
  1151. if (false == $dataArray || count($dataArray) < 1) {
  1152. if (false == $checkDefault) {
  1153. return false;
  1154. }
  1155. $dataArray = $this->getDefaultRecordsByType( $filetype );
  1156. }
  1157. if (is_null($recordId)) {
  1158. // reset first record for authadminfile
  1159. if ($filetype == 'authadminfile') {
  1160. return $this->getDefaultRecordsByType( $filetype );
  1161. }
  1162. return false;
  1163. }
  1164. $found = false;
  1165. foreach( $dataArray as $rec ) {
  1166. if ($filetype == 'accessfile') {
  1167. if ($recordId == 'errordocument401') {
  1168. if (preg_match('/^\s*ErrorDocument\s+401\s+/i', $rec)) {
  1169. $found = $rec;
  1170. break;
  1171. }
  1172. } else if (preg_match('/^\s*'.$recordId.'(\s+.+)?\s*$/i', $rec)) {
  1173. $found = $rec;
  1174. break;
  1175. }
  1176. continue;
  1177. }
  1178. if (isset($rec['name']) && strcmp($recordId, $rec['name'])==0) {
  1179. $found = $rec;
  1180. break;
  1181. }
  1182. }
  1183. return $found;
  1184. }
  1185. /**
  1186. * Check record by Id
  1187. *
  1188. * @access public
  1189. * @param string $filetype
  1190. * @param string $recordId
  1191. * @return bool
  1192. */
  1193. function isRecordByType( $filetype, $recordId )
  1194. {
  1195. $rec = $this->fetchRecordByType($filetype, $recordId);
  1196. return $rec == false ? false : true;
  1197. }
  1198. /**
  1199. * Update record in file
  1200. *
  1201. * @access public
  1202. * @param string $filetype
  1203. * @param string $recordId
  1204. * @param array data
  1205. * @return bool
  1206. */
  1207. function updateRecordByType( $filetype, $recordId, $data )
  1208. {
  1209. $path = $this->getPathByType( $filetype );
  1210. if (false == $path) {
  1211. $this->setError( $this->W('NOTDEFINED', $filetype) );
  1212. return false;
  1213. }
  1214. $hash = md5( $path );
  1215. if (!is_array($this->_fileDataArray[$hash])) {
  1216. $this->_fileDataArray[$hash] = null;
  1217. }
  1218. if ($filetype == 'accessfile') {
  1219. $found = false;
  1220. $recordId = strtolower($recordId);
  1221. foreach ($this->_fileDataArray[$hash] as $id=>$rec) {
  1222. $rec = trim($rec);
  1223. $args = isset($data[$recordId]) ? $data[$recordId] : '';
  1224. if ($recordId == 'errordocument401') {
  1225. if (preg_match('/^(\s*ErrorDocument\s+401)\s+/i', $rec, $matches)) {
  1226. if (!isset($data)) {
  1227. unset( $this->_fileDataArray[$hash][$id] );
  1228. continue;
  1229. }
  1230. $this->_fileDataArray[$hash][$id] = $matches[1] . ' ' . $args;
  1231. }
  1232. // remove all allow or deny commands
  1233. } else if (preg_match('/^\s*'.$recordId.'\s+from\s+.*$/i', $rec)) {
  1234. unset( $this->_fileDataArray[$hash][$id] );
  1235. } else if (preg_match('/^(\s*'.$recordId.')(.*)$/i', $rec, $matches)) {
  1236. if (!isset($data)) {
  1237. unset( $this->_fileDataArray[$hash][$id] );
  1238. continue;
  1239. }
  1240. if ($recordId == 'authname') {
  1241. $this->_fileDataArray[$hash][$id] = $matches[1] . ' "' . addSlashes($args) . '"';
  1242. } else if ($recordId == 'authuserfile') {
  1243. $this->_fileDataArray[$hash][$id] = $matches[1] . ' ' . $args;
  1244. } else if ($recordId == 'authtype') {
  1245. $this->_fileDataArray[$hash][$id] = $matches[1] . ' basic';
  1246. } else if ($recordId == 'order') {
  1247. $this->_fileDataArray[$hash][$id] = 'Order ' . ($args=='deny' ? 'Allow,Deny' : 'Deny,Allow');
  1248. }
  1249. $found = true;
  1250. break;
  1251. }
  1252. }
  1253. // special case: allow or deny commands
  1254. if ($recordId == 'allow' || $recordId == 'deny') {
  1255. foreach($data as $item) {
  1256. $this->_fileDataArray[$hash][] = $recordId . ' from ' . $item;
  1257. }
  1258. }
  1259. return $found;
  1260. }
  1261. // other types
  1262. foreach ($this->_fileDataArray[$hash] as $id=>$rec) {
  1263. if (is_null($recordId) || isset($rec['name']) && strcmp($recordId, $rec['name'])==0) {
  1264. if (is_null($data)) {
  1265. unset( $this->_fileDataArray[$hash][$id] );
  1266. } else if (is_array($data)) {
  1267. foreach ($data as $k=>$v) {
  1268. $this->_fileDataArray[$hash][$id][$k] = $v;
  1269. }
  1270. }
  1271. break;
  1272. }
  1273. }
  1274. return true;
  1275. }
  1276. /**
  1277. * Update file record
  1278. *
  1279. * @access public
  1280. * @param string $filetype
  1281. * @param array $data
  1282. * @param string $curRecordId
  1283. * @param bool|null $saveFile
  1284. * @param bool|null $saveForce
  1285. * @return bool
  1286. */
  1287. function setRecordByType( $filetype, $curRecordId, $data, $saveFile=false, $saveForce=false )
  1288. {
  1289. $path = $this->getPathByType( $filetype );
  1290. if (false == $path) {
  1291. $this->setError( $this->W('NOTDEFINED', $filetype) );
  1292. return false;
  1293. }
  1294. $hash = md5( $path );
  1295. if (false != $this->isRecordByType( $filetype, $curRecordId )) {
  1296. // replaceing
  1297. $this->updateRecordByType( $filetype, $curRecordId, $data );
  1298. } else if (is_array($data)) {
  1299. // inserting
  1300. if ($filetype == 'accessfile') {
  1301. $args = isset($data[$curRecordId]) ? $data[$curRecordId] : '';
  1302. $hasAddedBy = false;
  1303. foreach( $this->_fileDataArray[$hash] as $rec) {
  1304. if (preg_match('/^# added by authman/i', $rec)) {
  1305. $hasAddedBy = true;
  1306. }
  1307. }
  1308. if (!$hasAddedBy) {
  1309. $this->_fileDataArray[$hash][] = "# Added By Authman";
  1310. }
  1311. if ($curRecordId == 'authname') {
  1312. $this->_fileDataArray[$hash][] = 'AuthName "' . $args . '"';
  1313. } else if ($curRecordId == 'authtype') {
  1314. $this->_fileDataArray[$hash][] = 'AuthType ' . $args;
  1315. } else if ($curRecordId == 'require') {
  1316. $this->_fileDataArray[$hash][] = 'require ' . $args;
  1317. } else if ($curRecordId == 'authuserfile') {
  1318. $this->_fileDataArray[$hash][] = 'AuthUserFile ' . $args;
  1319. } else if ($curRecordId == 'errordocument401') {
  1320. $this->_fileDataArray[$hash][] = 'ErrorDocument 401 ' . $args;
  1321. } else if ($curRecordId == 'order') {
  1322. $this->_fileDataArray[$hash][] = 'Order ' . ($args=='deny' ? 'Allow,Deny' : 'Deny,Allow');
  1323. } else if ($curRecordId == 'allow' || $curRecordId == 'deny') {
  1324. foreach($data as $item) {
  1325. $this->_fileDataArray[$hash][] = $curRecordId . ' from ' . $item;
  1326. }
  1327. } else {
  1328. $this->_fileDataArray[$hash][] = '# '. $curRecordId . ' "' . $args . '"';
  1329. }
  1330. // other files types
  1331. } else {
  1332. $this->_fileDataArray[$hash][] = $data;
  1333. }
  1334. }
  1335. if ($saveFile) {
  1336. $strerr = null;
  1337. // save parsed data
  1338. if (false == $this->saveFileByType( $filetype, false )) {
  1339. $strerr = $this->getError();
  1340. }
  1341. $this->readFileByType( $filetype );
  1342. if (isset($strerr)) {
  1343. $this->setError($strerr);
  1344. return false;
  1345. }
  1346. }
  1347. return true;
  1348. }
  1349. /**
  1350. * Clear all records from the file
  1351. *
  1352. * @access public
  1353. * @param string $filetype
  1354. * @param bool|null $saveFile
  1355. * @return bool
  1356. */
  1357. function clearAllRecordsByType( $filetype, $saveFile=false )
  1358. {
  1359. $path = $this->getPathByType( $filetype );
  1360. if (false == $path) {
  1361. $this->setError( $this->W('NOTDEFINED', $filetype) );
  1362. return false;
  1363. }
  1364. $hash = md5( $path );
  1365. $this->_fileDataArray[$hash] = array();
  1366. if ($saveFile) {
  1367. $strerr = null;
  1368. // save _RAW_ data
  1369. if (false == $this->saveFileByType( $filetype, true, '' )) {
  1370. $strerr = $this->getError();
  1371. }
  1372. $this->readFileByType( $filetype );
  1373. if (isset($strerr)) {
  1374. $this->setError($strerr);
  1375. return false;
  1376. }
  1377. }
  1378. return true;
  1379. }
  1380. function getAccessRuleByType( $filetype, $ruleName )
  1381. {
  1382. $hash = md5( $this->getPathByType( $filetype ) );
  1383. if (!isset($this->_accessRulesArray[$hash])) {
  1384. return false;
  1385. }
  1386. $ruleName = strtolower($ruleName);
  1387. if (!isset($this->_accessRulesArray[$hash][$ruleName])) {
  1388. return false;
  1389. }
  1390. return $this->_accessRulesArray[$hash][$ruleName];
  1391. }
  1392. /***************************************************************************
  1393. *
  1394. **************************************************************************/
  1395. /**
  1396. * Get template list
  1397. *
  1398. * @access public
  1399. * @return array
  1400. */
  1401. function getTemplates()
  1402. {
  1403. $this->_tplsArray = array();
  1404. $tplPath = $this->_basePath . DIRECTORY_SEPARATOR . 'templates';
  1405. $dh = @opendir( $tplPath );
  1406. if (false == $dh) {
  1407. return $this->_tplsArray;
  1408. }
  1409. while ($e = readdir($dh)) {
  1410. if ($e == '.' || $e == '..') {
  1411. continue;
  1412. }
  1413. if (!preg_match('/^(.+)\.tpl(\.dist)?$/i', $e, $matches)) {
  1414. continue;
  1415. }
  1416. $tplId = $matches[1];
  1417. $tplDefault = isset($matches[2]) && $matches[2] == '.dist';
  1418. $filePath = $tplPath . DIRECTORY_SEPARATOR . $e;
  1419. $fh = @fopen($filePath, 'r');
  1420. if (false == $fh) {
  1421. continue;
  1422. }
  1423. $data = array();
  1424. while ($l = fgets($fh)) {
  1425. $data[] = $l;
  1426. }
  1427. @fclose($fh);
  1428. $role = 'undefinied';
  1429. if (preg_match('/^(useradd|useredit|userdel|userfgt|userrcv|memberaa|memberdel|memberreq)$/i', $tplId, $matches)) {
  1430. $role = strtolower($matches[1]);
  1431. }
  1432. $tArray = array('path'=>$filePath,
  1433. 'id'=>$tplId,
  1434. 'role'=>$role,
  1435. 'name'=>trim($data[0]),
  1436. 'type'=>( trim($data[1]) == 'html' ? 'html' : 'plaintext' ),
  1437. 'subject'=>trim($data[2]),
  1438. 'contents'=>join('', array_slice($data, 3)) );
  1439. if (!$tplDefault || !array_key_exists($tplId, $this->_tplsArray)) {
  1440. $this->_tplsArray[ $tplId ] = $tArray;
  1441. }
  1442. }
  1443. closedir($dh);
  1444. return $this->_tplsArray;
  1445. }
  1446. function getTemplateById( $id )
  1447. {
  1448. if (!isset($id) || $id=='') {
  1449. return false;
  1450. }
  1451. $templates = $this->getTemplates();
  1452. if (false==$templates || !isset($templates[$id])) {
  1453. return false;
  1454. }
  1455. return $templates[$id];
  1456. }
  1457. function getTemplateByRole( $role )
  1458. {
  1459. $res = false;
  1460. $templates = $this->getTemplates();
  1461. foreach($templates as $id=>$tpl) {
  1462. if ($tpl['role'] == $role) {
  1463. $res = $tpl;
  1464. }
  1465. }
  1466. return $res;
  1467. }
  1468. function saveTemplateAs( $id, $data, $force=false )
  1469. {
  1470. if (!isset($id) || $id=='' || !is_array($data)) {
  1471. $this->setError( $this->E('INVALIDREQUEST') );
  1472. return false;
  1473. }
  1474. // Saving in DEMO mode is disabled
  1475. if ($this->isDemo()) {
  1476. $this->setError( $this->W('DEMOISON') );
  1477. return false;
  1478. }
  1479. $path = $this->_basePath . DIRECTORY_SEPARATOR . 'templates';
  1480. if (!is_dir($path)) {
  1481. if (false == @mkdir($path, 0755)) {
  1482. $this->setError( $this->E('MKDIRFAILED', $path) );
  1483. return false;
  1484. }
  1485. $denyPath = $path . DIRECTORY_SEPARATOR
  1486. . $this->_configArray['access_file'];
  1487. $this->writeDenyFile( $denyPath );
  1488. }
  1489. $id = $this->getNormalizedPath( $id );
  1490. $filePath = $path . $id . '.tpl';
  1491. if (is_file($filePath) && false == $force) {
  1492. $this->setError( $this->E('FILEEXISTS', $filePath) );
  1493. return false;
  1494. }
  1495. if (is_file($filePath) && !is_writable($filePath)) {
  1496. $this->setError( $this->W('FILEWRITABLE') );
  1497. return false;
  1498. }
  1499. $fh = @fopen($filePath, 'w');
  1500. if (false == $fh) {
  1501. $this->setError( $this->E('FILEOPENFAILED', $filePath) );
  1502. return false;
  1503. }
  1504. @fwrite($fh, $data['name'] . "\n");
  1505. @fwrite($fh, $data['type'] . "\n");
  1506. @fwrite($fh, $data['subject'] . "\n");
  1507. @fwrite($fh, $data['contents'] . "\n");
  1508. @fclose($fh);
  1509. return true;
  1510. }
  1511. /**
  1512. * @desc Delete e-mail template
  1513. *
  1514. * @access public
  1515. * @param string $id
  1516. * @param bool $force
  1517. * @return bool
  1518. */
  1519. function deleteTemplate( $id, $force=false )
  1520. {
  1521. // Deleting in DEMO mode is disabled
  1522. if ($this->isDemo()) {
  1523. $this->setError( $this->W('DEMOISON') );
  1524. return false;
  1525. }
  1526. // Check if
  1527. $template = $this->getTemplateById( $id );
  1528. if (false == $template) {
  1529. $this->setError( $this->E('TPLNOTFOUND', $id) );
  1530. return false;
  1531. }
  1532. if ($force == false) {
  1533. if ($template['role'] != 'undefinied') {
  1534. $this->setError( $this->E('TPLISSYSTEM') );
  1535. return false;
  1536. }
  1537. }
  1538. $path = $this->_basePath . DIRECTORY_SEPARATOR . 'templates';
  1539. $filePath = $path . DIRECTORY_SEPARATOR . $id . '.tpl';
  1540. if (!is_file($filePath)) {
  1541. $this->setError( $this->E('NOSUCHFILE', $filePath) );
  1542. return false;
  1543. }
  1544. if (false == @unlink($filePath)) {
  1545. $this->setError( $this->E('FILEDELFAILED', $filePath) );
  1546. return false;
  1547. }
  1548. return true;
  1549. }
  1550. /***************************************************************************
  1551. * E-mail routes
  1552. **************************************************************************/
  1553. /**
  1554. * Send e-mail to the user
  1555. *
  1556. * @access public
  1557. * @param string|array $templateId
  1558. * @param array $userArray
  1559. * @return bool
  1560. */
  1561. function sendMail( $templateId, $userArray )
  1562. {
  1563. if (false == $this->hasFeature('PHPMailer')) {
  1564. $this->setError( 'SendMail: ' . $this->W('SENDMAILFAIL_INSTALLPHPMAILER'));
  1565. return false;
  1566. }
  1567. // no spam here
  1568. if ($this->isDemo()) {
  1569. $this->setError( 'SendMail: ' . $this->W('DEMOISON') );
  1570. return false;
  1571. }
  1572. if (is_array($templateId)) {
  1573. $tplArray = $templateId;
  1574. $templateId = 'manual';
  1575. } else {
  1576. $tplArray = $this->getTemplateById( $templateId );
  1577. if (false == $tplArray) {
  1578. $this->setError( 'SendMail: ' . $this->E('INCORRECTARGS') . ' [template]' );
  1579. return false;
  1580. }
  1581. }
  1582. if (!isset($userArray['email']) || $userArray['email'] == '') {
  1583. $this->setError( 'SendMail: ' . $this->E('INCORRECTARGS') . ' [email]' );
  1584. return false;
  1585. }
  1586. $args = array('PROTECTEDURL'=> $this->getUrlByType('protected', true),
  1587. 'BASEURL' => $this->getUrlByType('base', true),
  1588. 'MEMBERURL' => $this->getUrlByType('login', true),
  1589. 'REMOTEADDR' => $_SERVER['REMOTE_ADDR'],
  1590. 'DATETIME' => gmdate('D dS \of M Y H:i:s e') );
  1591. list($admin) = $this->getRecordsByType( 'authadminfile', null, 1, 0 );
  1592. $args['ADMINREALNAME'] = $admin['info'] != '' ? $admin['info'] : "Administrator";
  1593. $args['ADMINEMAIL'] = $admin['email'] != '' ? $admin['email'] : "postmaster@localhost";
  1594. foreach($userArray as $k=>$v) {
  1595. $kk = 'USER' . strtoupper($k);
  1596. $args[$kk] = $v;
  1597. }
  1598. $args['USERREALNAME'] = isset($userArray['info']) && $userArray['info'] != ''
  1599. ? $userArray['info'] : $userArray['name'];
  1600. $args['USERPASSWORD'] = isset($userArray['pass_raw']) && $userArray['pass_raw'] != '' ? $userArray['pass_raw'] : '[ENCRYPTED: '. $userArray['pass'] .']';
  1601. $subject = $tplArray['subject'];
  1602. $body = $tplArray['contents'];
  1603. foreach(array('subject', 'body') as $vname) {
  1604. foreach( $args as $k=>$v ) {
  1605. $$vname = str_replace('%'.$k.'%', $v, $$vname);
  1606. }
  1607. }
  1608. // sending
  1609. include_once( $this->getPathByType('PHPMailer') );
  1610. $mail = new PHPMailer();
  1611. $mail->CharSet = "UTF-8";
  1612. // from administrator
  1613. $mail->FromName = $args['ADMINREALNAME'];
  1614. $mail->From = $args['ADMINEMAIL'];
  1615. $mail->AddReplyTo($args['ADMINEMAIL'], $args['ADMINREALNAME']);
  1616. $isHtml = $tplArray['type'] == 'html';
  1617. if ($templateId=='memberdel' || $templateId=='memberaa') {
  1618. $mail->AddAddress($args['ADMINEMAIL'], $args['ADMINREALNAME']);
  1619. } else {
  1620. if (!isset($args['USEREMAIL']) || $args['USEREMAIL']=='') {
  1621. if ($isHtml) {
  1622. $body = '<p><strong>USER ' . $userArray['name'] . ' have not E-mail address</strong></p><br />' . $body;
  1623. } else {
  1624. $body = 'USER ' . $userArray['name'] . " have not E-mail address\n" . $body;
  1625. }
  1626. $mail->AddAddress($args['ADMINEMAIL'], $args['ADMINREALNAME']);
  1627. } else {
  1628. $mail->AddAddress($args['USEREMAIL'], $args['USERREALNAME']);
  1629. }
  1630. }
  1631. $mail->Subject = $subject;
  1632. $mail->Body = $body;
  1633. if ($isHtml) {
  1634. $mail->IsHTML( true );
  1635. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
  1636. }
  1637. if (false == $mail->Send()) {
  1638. $this->setError( 'SendMail: ' . $mail->ErrorInfo );
  1639. return false;
  1640. }
  1641. return true;
  1642. }
  1643. function hasFeature( $feature )
  1644. {
  1645. $ln = strtolower($feature);
  1646. if ($ln == 'phpmailer' || $ln == 'tinymcejs' || $ln = 'magpierss') {
  1647. $filePath = $this->getPathByType( $ln );
  1648. if (!is_file($filePath) || !is_readable($filePath)) {
  1649. return false;
  1650. }
  1651. return true;
  1652. }
  1653. return true;
  1654. }
  1655. /***************************************************************************
  1656. * Messages/Warnings/Errors Reporting
  1657. **************************************************************************/
  1658. /**
  1659. * Messages wrapper
  1660. *
  1661. * @access public
  1662. * @return string
  1663. */
  1664. function M()
  1665. {
  1666. $args = func_get_args();
  1667. return $this->getMessage( 'messages', $args );
  1668. }
  1669. /**
  1670. * Warnings wrapper
  1671. *
  1672. * @access public
  1673. * @return string
  1674. */
  1675. function W()
  1676. {
  1677. $args = func_get_args();
  1678. return $this->getMessage( 'warnings', $args );
  1679. }
  1680. /**
  1681. * Errors wrapper
  1682. *
  1683. * @access public
  1684. * @return string
  1685. */
  1686. function E()
  1687. {
  1688. $args = func_get_args();
  1689. return $this->getMessage( 'errors', $args );
  1690. }
  1691. /**
  1692. * Return formated message
  1693. *
  1694. * @access private
  1695. * @param string $type
  1696. * @param array $args
  1697. * @return string
  1698. */
  1699. function getMessage( $type, $args )
  1700. {
  1701. $fmt = strtoupper(array_shift($args));
  1702. if (isset($this->_langArray[$type]) && isset($this->_langArray[$type][$fmt])) {
  1703. $s = vsprintf( $this->_langArray[$type][$fmt], $args);
  1704. } else {
  1705. $s = '[' . $type . ': ' . $fmt;
  1706. if (count($args)) {
  1707. $s .= ':';
  1708. foreach ($args as $t) {
  1709. $s .= ' ' . $t;
  1710. }
  1711. }
  1712. $s .= ']';
  1713. }
  1714. return $s;
  1715. }
  1716. /**
  1717. * Set error message
  1718. *
  1719. * @access protected
  1720. * @param string|null
  1721. */
  1722. function setError( $error=null )
  1723. {
  1724. $this->_error = $error;
  1725. if (!isset($error)) {
  1726. return;
  1727. }
  1728. if (isset($php_errormsg))
  1729. $this->_error .= ': ' . $php_errormsg;
  1730. return;
  1731. }
  1732. /**
  1733. * Return true if error string is set
  1734. *
  1735. * @access public
  1736. * @return bool
  1737. */
  1738. function isError()
  1739. {
  1740. return $this->_error == '' ? false : true;
  1741. }
  1742. /**
  1743. * Get error message
  1744. *
  1745. * @access public
  1746. * @return string
  1747. */
  1748. function getError()
  1749. {
  1750. if (!isset($this->_error)) {
  1751. return $this->M('UNKNOWNERROR');
  1752. }
  1753. return $this->_error;
  1754. }
  1755. /**
  1756. * Clear error variable
  1757. *
  1758. * @access public
  1759. * @return void
  1760. */
  1761. function clearError()
  1762. {
  1763. $this->_error = null;
  1764. }
  1765. /**
  1766. * Return runtime errors and warnings
  1767. *
  1768. * @access public
  1769. * @param bool $onlyCritical (default is false)
  1770. * @return array
  1771. */
  1772. function getRuntimeErrors( $onlyCritical=false )
  1773. {
  1774. $wArray = array();
  1775. // 1001 Config file doesn't exist
  1776. // Recoverable: Yes
  1777. // Action: start configuration wizard
  1778. $configPath = $this->_filePathsArray['configfile'];
  1779. if (!is_file($configPath)) {
  1780. $wArray[] = array('errno'=>1001,
  1781. 'message'=>'Configuration file does not exist: ' . $configPath,
  1782. 'recover'=>false, // true
  1783. 'critial'=>false);
  1784. }
  1785. // 1002 Config file is not readble
  1786. // Recoverable: No
  1787. // Recomendation: change file rights manually
  1788. if (is_file($configPath) && !is_readable($configPath)) {
  1789. $wArray[] = array('errno'=>1002,
  1790. 'recover'=>false,
  1791. 'message'=>'Configuration file is not readable: ' . $configPath,
  1792. 'critial'=>false);
  1793. }
  1794. // 1003 Language file doesn't exist
  1795. // Recoverable: Yes
  1796. // Action: download language file
  1797. // Recomendation: or change config settings
  1798. $langFilePath = $this->_filePathsArray['langfile'];
  1799. if (!is_file($langFilePath)) {
  1800. $wArray[] = array('errno'=>1003,
  1801. 'recover'=>false, // true
  1802. 'message'=>'Language file does not exist: ' . $langFilePath);
  1803. }
  1804. // 1004 Default (English) Language file doesn't exist
  1805. // Recoverable: Yes
  1806. // Action: download default language file
  1807. $langFilePath = $this->makePath($this->_basePath . DIRECTORY_SEPARATOR . 'languages',
  1808. 'english.lng' );
  1809. if (!is_file($langFilePath)) {
  1810. $mesg = 'Default language (ENGLISH) file does not exist: ' . $langFilePath;
  1811. $wArray[] = array('errno'=>1004,
  1812. 'recover'=>false, // true
  1813. 'message'=>$mesg,
  1814. 'critical'=>true);
  1815. }
  1816. // File languages/.htaccess does not exist
  1817. // File templates/.htaccess does not exist
  1818. // File config/.htaccess does not exist
  1819. if (!$onlyCritical) {
  1820. return $wArray;
  1821. }
  1822. $cArray = array();
  1823. foreach($wArray as $wItem) {
  1824. if (!isset($wItem['critical']) || !$wItem['critical']) {
  1825. continue;
  1826. }
  1827. $cArray[] = $wItem;
  1828. }
  1829. return $cArray;
  1830. }
  1831. /***************************************************************************
  1832. * Runtime Variables
  1833. **************************************************************************/
  1834. function hasRuntimeValue( $name )
  1835. {
  1836. if (!isset($this->_runtimeArray)) {
  1837. // loading runtime variables
  1838. if (false == $this->loadRuntime()) {
  1839. return false;
  1840. }
  1841. }
  1842. if (!array_key_exists($name, $this->_runtimeArray)) {
  1843. return false;
  1844. }
  1845. return true;
  1846. }
  1847. function loadRuntime()
  1848. {
  1849. $this->_runtimeArray = array();
  1850. $basedir = $this->_basePath . DIRECTORY_SEPARATOR . 'var';
  1851. $filePath = $this->makePath( $basedir, 'runtime.ini' );
  1852. if (is_file($filePath) && is_readable($filePath)) {
  1853. $rt = @parse_ini_file( $filePath );
  1854. if ($rt != false) {
  1855. $this->_runtimeArray = $rt;
  1856. }
  1857. }
  1858. return true;
  1859. }
  1860. function getRuntimeValue( $name )
  1861. {
  1862. if (false == $this->hasRuntimeValue($name)) {
  1863. return false;
  1864. }
  1865. return $this->_runtimeArray[$name];
  1866. }
  1867. function setRuntimeValue( $name, $value, $saveFile=false )
  1868. {
  1869. if (is_string($value)) {
  1870. $value = trim($value, "\r\n");
  1871. }
  1872. if ($this->hasRuntimeValue($name) && $this->getRuntimeValue( $name ) == $value) {
  1873. return true;
  1874. }
  1875. if (is_null($value)) {
  1876. if (!isset($this->_runtimeArray[$name])) {
  1877. return true;
  1878. }
  1879. unset($this->_runtimeArray[$name]);
  1880. } else {
  1881. $this->_runtimeArray[$name] = $value;
  1882. }
  1883. if (false == $saveFile) {
  1884. return true;
  1885. }
  1886. // Saving in DEMO mode is disabled
  1887. if ($this->isDemo()) {
  1888. //$this->setError( $this->W('DEMOISON') );
  1889. //return false;
  1890. return true;
  1891. }
  1892. $basedir = $this->_basePath . DIRECTORY_SEPARATOR . 'var';
  1893. $filePath = $this->makePath( $basedir, 'runtime.ini' );
  1894. if (!is_dir($basedir)) {
  1895. if (false == @mkdir($basedir, 0755)) {
  1896. $this->setError( $this->E('MKDIRFAILED', $basedir) );
  1897. return false;
  1898. }
  1899. $denyPath = $basedir . DIRECTORY_SEPARATOR
  1900. . $this->_configArray['access_file'];
  1901. $this->writeDenyFile( $denyPath );
  1902. }
  1903. if (!is_file($filePath) && !is_writable($basedir)) {
  1904. $this->setError( $this->E('DIRNOTWRITABLE', $basedir) );
  1905. return false;
  1906. }
  1907. if (is_file($filePath) && !is_writable($filePath)) {
  1908. $this->setError( $this->E('FILENOTWRITABLE', $path) );
  1909. return false;
  1910. }
  1911. $fh = @fopen($filePath, 'w');
  1912. if (false == $fh) {
  1913. $this->setError( $this->E('FILEOPENFAILED', $filePath) );
  1914. return false;
  1915. }
  1916. @fwrite($fh, "# Automatically Created by Autman Free\n");
  1917. @fwrite($fh, "[runtime]\n");
  1918. foreach( $this->_runtimeArray as $k=>$v) {
  1919. @fwrite($fh, $k .'=' );
  1920. if (is_bool($v)) {
  1921. @fwrite($fh, $value ? '"1"' : '"0"');
  1922. } else {
  1923. @fwrite($fh, '"'.$v.'"');
  1924. }
  1925. @fwrite($fh, "\n");
  1926. }
  1927. @fclose($fh);
  1928. return true;
  1929. }
  1930. /***************************************************************************
  1931. * RSS, NEWs
  1932. **************************************************************************/
  1933. /**
  1934. * Returns RSS product news as HTML code
  1935. *
  1936. * @access public
  1937. * @params void
  1938. * @return string
  1939. */
  1940. function newsFetchAsHTML()
  1941. {
  1942. $text = '';
  1943. if (!$this->hasFeature('magpierss')) {
  1944. return 'Server does not support this feature';
  1945. }
  1946. $disableCaching = false;
  1947. $cachedir = $this->_basePath . DIRECTORY_SEPARATOR . 'var'
  1948. . DIRECTORY_SEPARATOR . 'cache';
  1949. if (!defined('MAGPIE_CACHE_DIR')) {
  1950. define('MAGPIE_CACHE_DIR', $cachedir);
  1951. }
  1952. // increase default cache time (1h) up to 24h
  1953. if (!defined('MAGPIE_CACHE_AGE')) {
  1954. define('MAGPIE_CACHE_AGE', 3600*24);
  1955. }
  1956. if (!is_dir($cachedir)) {
  1957. if (!@mkdir($cachedir, 0755)) {
  1958. $disableCaching = true;
  1959. } else {
  1960. $denyPath = $cachedir . DIRECTORY_SEPARATOR
  1961. . $this->_configArray['access_file'];
  1962. $this->writeDenyFile( $denyPath );
  1963. }
  1964. }
  1965. if (!is_dir($cachedir) && !is_writable($cachedir)) {
  1966. $disableCaching = true;
  1967. }
  1968. if ($disableCaching) {
  1969. define('MAGPIE_CACHE_ON', false);
  1970. }
  1971. include_once( $this->getPathByType('magpierss') ); // rss_fetch.inc
  1972. $url = 'http://www.authman.com/rss/free/';
  1973. #$rss = fetch_rss( $url );
  1974. if (!$rss) {
  1975. return 'Sorry, disable due to timeout';
  1976. }
  1977. foreach ( $rss->items as $item ) {
  1978. $text .= '<div id="item">';
  1979. $text .= sprintf('<div id="title"><a href="%s" base="_top">%s</a></div>',
  1980. $item['link'], $item['title']);
  1981. if (isset($item['content']) && isset($item['content']['encoded'])) {
  1982. $description = $item['content']['encoded'];
  1983. } else {
  1984. $description = '<pre>' . $item['description'] .'</pre>';
  1985. }
  1986. $text .= '<div id="description">' . $description . '</div>';
  1987. $text .= '</div>';
  1988. }
  1989. return $text;
  1990. }
  1991. }
  1992. // the end of authman class
  1993. /**
  1994. * Users and group management
  1995. *
  1996. * @return void
  1997. */
  1998. function showPage_users()
  1999. {
  2000. global $am;
  2001. // Checking access rights
  2002. if (!$am->isAdmin()) {
  2003. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  2004. showPage_401( true );
  2005. exit;
  2006. }
  2007. $error = $message = null;
  2008. $action = getParam('action', null, 'attribute');
  2009. // ------------- Ajax Actions ----------------
  2010. // Ajax Acitons: Sending email to an user
  2011. if ($action == 'mailtouser') {
  2012. $body = getParam('body', null, 'htmlcode');
  2013. $subject = getParam('subject', 'Subject not set', 'subject');
  2014. // building pseudo-template
  2015. $templateArray = array('role'=>'undefinied',
  2016. 'type'=>getParam('type', 'plaintext', 'attribute'),
  2017. 'subject'=>$subject,
  2018. 'contents'=>$body);
  2019. $userData = array();
  2020. $username = getParam('username', null, 'username');
  2021. if (!isset($username) || $username == '') {
  2022. $error = $am->E('INVALIDREQUEST') . ' [username]';
  2023. }
  2024. // checking for special username: SELECTED
  2025. if (!isset($error)) {
  2026. if (getParam('username') == 'SELECTED') {
  2027. $usernames = getParam('usernames', null, 'username');
  2028. if (!is_array($usernames)) {
  2029. $error = $am->E('INVALIDREQUEST') . ' [usernames]';
  2030. }
  2031. } else {
  2032. $usernames = array($username);
  2033. }
  2034. }
  2035. // real sending emal to the user(s)
  2036. if (!isset($error)) {
  2037. foreach($usernames as $uname) {
  2038. if (!($userData = $am->fetchRecordByType('authuserfile', $uname))) {
  2039. $error = $am->E('USERNOTEXISTS', $uname);
  2040. break;
  2041. }
  2042. if (!$am->sendMail($templateArray, $userData)) {
  2043. $error = $am->E('SENDINGFAILED') . ': ' . $am->getError();
  2044. break;
  2045. }
  2046. }
  2047. }
  2048. // follow-up
  2049. if (!isset($error)) {
  2050. $message = $am->M('INFO_EMAILSENT');
  2051. }
  2052. if (!isset($error)) {
  2053. echo '<div class="message">' . fmt_message($message) . "</div>\n";
  2054. } else {
  2055. echo '<div class="warning">' . fmt_message($error) . "</div>\n";
  2056. }
  2057. return;
  2058. }
  2059. // Ajax Acitons: Checking given username
  2060. if ($action == 'checkusername') {
  2061. $username = getParam('username', null, 'username');
  2062. if ($am->isRecordByType('authuserfile', $username)) {
  2063. echo 'USERFOUND';
  2064. } else {
  2065. echo 'NOSUCHUSER';
  2066. }
  2067. return;
  2068. }
  2069. // ------------- General variables ----------------
  2070. $limit = 10;
  2071. if (hasParam('limit')) {
  2072. $limit = getParam('limit', 10, 'int');
  2073. $_SESSION['user_limit'] = $limit;
  2074. } else if (isset($_SESSION['user_limit'])) {
  2075. $limit = $_SESSION['user_limit'];
  2076. }
  2077. $p = 1;
  2078. if (hasParam('p')) {
  2079. $p = getParam('p', 1, 'int' );
  2080. $_SESSION['user_p'] = $p;
  2081. } else if (isset($_SESSION['user_p'])) {
  2082. $p = $_SESSION['user_p'];
  2083. }
  2084. if (empty($limit)) {
  2085. $p = 1;
  2086. }
  2087. $offset = ($p-1) * $limit;
  2088. // ------------- Actions ----------------
  2089. // Action: Add user
  2090. if ($action == 'adduser') {
  2091. $username = getParam('username', null, 'username');
  2092. if (!isset($username) || $username == '') {
  2093. $error = $am->E('INVALIDREQUEST') . ' [username]';
  2094. } else if ($am->isRecordByType('authuserfile', $username)) {
  2095. $error = $am->E('USEREXISTS', $username);
  2096. }
  2097. $password = getParam('password', null, 'password');
  2098. if (!isset($error)) {
  2099. if ($password == '') {
  2100. $error = $am->E('INVALIDREQUEST') . ' [password]';
  2101. } else if (strlen($password) < 4) {
  2102. $error = $am->E('PASSWORDTOOSHORT', 4);
  2103. }
  2104. }
  2105. $data = array('name' => $username,
  2106. 'pass_raw'=> $password,
  2107. 'info' => getParam('realname', null, 'field'),
  2108. 'email' => getParam('email', null, 'email'));
  2109. if (!isset($error)) {
  2110. if (!$am->setRecordByType('authuserfile', null, $data, true)) {
  2111. $error = $am->E('USERINSERTFAILED', $username)
  2112. . ': ' . $am->getError();
  2113. }
  2114. }
  2115. if (!isset($error)) {
  2116. $message = $am->M('USERINSSUCCESS', $username);
  2117. $action = 'updateuser';
  2118. }
  2119. // sending notification via e-mail
  2120. $am->setRuntimeValue('useradd_sendmail', hasParam('sendmail'), true);
  2121. if (!isset($error) && hasParam('sendmail')) {
  2122. $template = getParam('template', 'useradd', 'attribute');
  2123. if (false == $am->sendMail($template, $data )) {
  2124. $error = $am->getError();
  2125. }
  2126. }
  2127. // Action: Edit user
  2128. } else if ($action == 'updateuser') {
  2129. $oldusername = getParam('oldusername', null, 'username');
  2130. if (!$am->isRecordByType('authuserfile', $oldusername)) {
  2131. $error = $am->E('INVALIDREQUEST') . ' [curusername]';
  2132. }
  2133. $username = getParam('username', null, 'username');
  2134. if (!isset($username) || $username == '') {
  2135. $error = $am->E('INVALIDREQUEST') . ' [username]';
  2136. }
  2137. if ($oldusername != $username && $am->isRecordByType('authuserfile', $username)) {
  2138. $error = $am->E('USEREXISTS', $username);
  2139. }
  2140. $data = array('name' =>$username,
  2141. 'info' =>getParam('realname', null, 'field'),
  2142. 'email'=>getParam('email', null, 'email'));
  2143. if (hasParam('password')) {
  2144. $pass = getParam('password', null, 'password');
  2145. if (isset($pass) && $pass != '') {
  2146. $data['pass_raw'] = $pass;
  2147. }
  2148. }
  2149. if (!isset($error)) {
  2150. if (!$am->setRecordByType( 'authuserfile', $oldusername, $data, true)) {
  2151. $error = $am->E('USERUPDATEFAILED', $username)
  2152. . ': ' . $am->getError();
  2153. }
  2154. }
  2155. if (!isset($error)) {
  2156. $message = $am->M('USERUPDSUCCESS', $username);
  2157. }
  2158. // sending notification e-mail
  2159. $am->setRuntimeValue('useredit_sendmail', hasParam('sendmail'), true);
  2160. if (!isset($error) && hasParam('sendmail')) {
  2161. $template = getParam('template', 'useredit', 'attribute');
  2162. if (!$am->sendMail($template, $data)) {
  2163. $error = $am->getError();
  2164. }
  2165. }
  2166. // Action: Delete user
  2167. } else if ($action == 'deleteuser') {
  2168. $username = getParam('username', null, 'username');
  2169. if (!$am->isRecordByType('authuserfile', $username)) {
  2170. $error = $am->E('USERNOTEXISTS', $username);
  2171. }
  2172. if (!isset($error)) {
  2173. if (!$am->setRecordByType('authuserfile', $username, null, true)) {
  2174. $error = $am->E('USERDELETEFAILED', $username)
  2175. . ': ' . $am->getError();
  2176. }
  2177. }
  2178. if (!isset($error)) {
  2179. $message = $am->M('USERDELETED', $username);
  2180. }
  2181. // Action: delete selected users
  2182. } else if ($action == 'deleteselusers') {
  2183. $usernames = getParam('usernames', null, 'username');
  2184. foreach($usernames as $username) {
  2185. if (!$am->isRecordByType('authuserfile', $username)) {
  2186. $error = $am->E('USERNOTEXISTS', $username);
  2187. break;
  2188. }
  2189. if (!$am->setRecordByType('authuserfile', $username, null, true)) {
  2190. $error = $am->E('USERDELETEFAILED', $username)
  2191. . ': ' . $am->getError();
  2192. break;
  2193. }
  2194. }
  2195. if (!isset($error)) {
  2196. $message = $am->M('USERSSELDELETED');
  2197. }
  2198. // Action: Delete All Users
  2199. } else if ($action == 'deleteallusers') {
  2200. if (!isset($error)) {
  2201. if (false == $am->clearAllRecordsByType( 'authuserfile', true )) {
  2202. $error = $am->E('USERSDELALLFAILED') . ': ' . $am->getError();
  2203. }
  2204. }
  2205. if (!isset($error)) {
  2206. $message = $am->M('USERSALLDELETED');
  2207. }
  2208. }
  2209. // ------------- HTML Preparing ----------------
  2210. $searchtext = '';
  2211. if (hasParam('searchtext')) {
  2212. $searchtext = getParam('searchtext', null, 'field');
  2213. $_SESSION['searchtext'] = $searchtext;
  2214. } else if (isset($_SESSION['searchtext'])) {
  2215. $searchtext = $_SESSION['searchtext'];
  2216. }
  2217. $usersArray = $am->getRecordsByType('authuserfile', 'name', $limit, $offset, $searchtext);
  2218. $groupsArray = $am->getRecordsByType('authgroupfile', 'g_name');
  2219. web_header( $am->M('SUBTITLE_USERS') );
  2220. web_menu();
  2221. echo '<div id="righty">';
  2222. // ------------- Information ----------------
  2223. echo '<div class="pagenotes">';
  2224. echo '<h4>' . $am->M('SUBTITLE_USERS') . '</h4>';
  2225. echo '<div><div class="name">AuthUserFile</div>';
  2226. echo '<div class="value">';
  2227. $file = $am->getPathByType('authuserfile');
  2228. echo $file == '' ? $am->W('NOTDEFINED', 'AuthUserFile') : $file;
  2229. echo '</div></div>';
  2230. echo '<div><div class="name">' . $am->M('TOTALMEMBERS') . '</div>';
  2231. echo '<div class="value">' . $am->getTotalByType('authuserfile', $searchtext) . '</div></div>';
  2232. echo '</div>';
  2233. // ------------- Message ----------------
  2234. web_message( $message, $error );
  2235. ?>
  2236. <h1><?php echo $am->M('SUBTITLE_USERS') ?></h1>
  2237. <?php
  2238. $authuserfile = $am->getPathByType('authuserfile');
  2239. if (false == $authuserfile) {
  2240. echo '<div class="block">';
  2241. echo $am->M('NOTES_NODEFAUTHUSERFILE');
  2242. echo '</div>';
  2243. }
  2244. ?>
  2245. <div id="userSearch">
  2246. <form id="userSearch_form" name="userSearch_form">
  2247. <fieldset>
  2248. <input id="userSearch_searchtext" type="text" name="searchtext" maxlength="255" class="required" value="<?php echo $searchtext ?>" />
  2249. <input type="hidden" name="page" value="users" />
  2250. <input type="hidden" name="action" value="search" />
  2251. <input type="submit" id="userMail_submit" name="submit" value="<?php echo $am->M('BTN_FILTER') ?>" />
  2252. <input type="submit" id="userMail_submit" name="submit" value="<?php echo $am->M('BTN_RESET') ?>" onClick="javascript:$($(userSearch_form).searchtext).value = ''; return true;" />
  2253. </fieldset>
  2254. </form>
  2255. </div>
  2256. <div class="spacer30"></div>
  2257. <!-- USERS add form -->
  2258. <div id="userAdd" style="display: none;">
  2259. <form id="userAdd_form" name="userAdd_form">
  2260. <div id="userAdd_checkUsername" style="float:right;"></div>
  2261. <p id="userAdd_form_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  2262. <fieldset>
  2263. <legend><?php echo $am->M('LEGEND_USERNEW') ?></legend>
  2264. <div>
  2265. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  2266. <input id="userAdd_username" type="text" name="username" maxlength="255" class="required" />
  2267. <input id="userAdd_check" name="check" type="button" value="<?php echo $am->M('CHECK') ?>" onclick="javascript:usersCheckUsername('userAdd');" />
  2268. </div>
  2269. <div>
  2270. <label for="password" class="required"><?php echo $am->M('FIELD_PASSWORD') ?></label>
  2271. <input id="userAdd_password" type="text" name="password" maxlength="255" class="required" />
  2272. <input type="button" value="<?php echo $am->M('GENERATE') ?>" onclick="javascript:mainGeneratePassword('userAdd');" />
  2273. </div>
  2274. <div>
  2275. <label for="realname"><?php echo $am->M('FIELD_REALNAME') ?></label>
  2276. <input id="userAdd_realname" type="text" name="realname" size="40" maxlength="255" />
  2277. </div>
  2278. <div>
  2279. <label for="email"><?php echo $am->M('FIELD_EMAIL') ?></label>
  2280. <input id="userAdd_email" type="text" name="email" size="40" maxlength="255" />
  2281. </div>
  2282. <div class="dashed"></div>
  2283. <?php
  2284. $sendMail = true;
  2285. if (!$am->hasFeature('PHPMailer')) {
  2286. $sendMail = false;
  2287. } else if ($am->hasRuntimeValue('useradd_sendmail') &&
  2288. $am->getRuntimeValue('useradd_sendmail') != "1") {
  2289. $sendMail = false;
  2290. }
  2291. ?>
  2292. <div>
  2293. <label for="sendmail"><?php echo $am->M('FIELD_WELCOMEEMAIL') ?></label>
  2294. <input type="checkbox" id="userAdd_sendmail" name="sendmail" value="1"
  2295. <?php if ($sendMail) { echo ' checked="checked" '; } ?>
  2296. onClick="javascript:usersOnChangeSendMail('userAdd');" /> <?php echo $am->M('SEND') ?>
  2297. </div>
  2298. <?php
  2299. if (!$am->hasFeature('PHPMailer')) {
  2300. echo '<div class="block">';
  2301. echo $am->W('SENDMAILFAIL_INSTALLPHPMAILER');
  2302. echo '</div>';
  2303. }
  2304. ?>
  2305. <div id="userAdd_showtemplate" style="display:<?php echo $sendMail ? 'block' : 'none' ?>;">
  2306. <label for="template"><?php echo $am->M('FIELD_EMAILTEMPLATE') ?></label>
  2307. <select id="userAdd_template" name="template">
  2308. <option value=""><?php echo $am->M('SELECTONE') ?></option>
  2309. <?php
  2310. foreach ($am->getTemplates() as $id=>$tpl) {
  2311. echo '<option value="' . addslashes($id).'"';
  2312. if ($tpl['role'] == 'useradd') {
  2313. echo ' selected="selected"';
  2314. }
  2315. echo '>';
  2316. echo $tpl['name'] . '</option>';
  2317. }
  2318. ?>
  2319. </select>
  2320. </div>
  2321. </fieldset>
  2322. <div class="buttonrow">
  2323. <input type="hidden" name="action" value="adduser" />
  2324. <input type="hidden" name="page" value="users" />
  2325. <?php echo htmlSubmit('submit'); ?>
  2326. <?php echo htmlReset('reset', 'onClick="javascript:usersResetForm(\'userAdd\'); return false;"' ); ?>
  2327. <input type="submit" id="userAdd_cancel" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:usersShowForm('userAdd','hide'); return false;" />
  2328. </div>
  2329. </form>
  2330. </div>
  2331. <!-- end of USERS add form -->
  2332. <!-- USERS edit form -->
  2333. <div id="userEdit" style="display: none;">
  2334. <form id="userEdit_form" name="userEdit_form">
  2335. <p id="userEdit_form_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  2336. <fieldset>
  2337. <legend><?php echo $am->M('LEGEND_USEREDIT') ?></legend>
  2338. <div>
  2339. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  2340. <input id="userEdit_username" name="username" type="text" maxlength="255" class="required" />
  2341. </div>
  2342. <div>
  2343. <label for="password"><?php echo $am->M('FIELD_NEWPASSWORD') ?></label>
  2344. <input id="userEdit_password" name="password" type="text" maxlength="255" />
  2345. <input type="button" value="<?php echo $am->M('GENERATE') ?>" onclick="javascript:mainGeneratePassword('userEdit');" />
  2346. </div>
  2347. <div>
  2348. <label for="realname"><?php echo $am->M('FIELD_REALNAME') ?></label>
  2349. <input id="userEdit_realname" name="realname" type="text" size="40" maxlength="255" />
  2350. </div>
  2351. <div>
  2352. <label for="email"><?php echo $am->M('FIELD_EMAIL') ?></label>
  2353. <input id="userEdit_email" name="email" type="text" size="40" maxlength="255" />
  2354. </div>
  2355. <div class="dashed"></div>
  2356. <?php
  2357. # by default sending email is off
  2358. $sendMail = false;
  2359. if (!$am->hasFeature('PHPMailer')) {
  2360. $sendMail = false;
  2361. } else if ($am->hasRuntimeValue('useredit_sendmail') &&
  2362. $am->getRuntimeValue('useredit_sendmail') == "1") {
  2363. $sendMail = true;
  2364. }
  2365. ?>
  2366. <div>
  2367. <label for="sendmail"><?php echo $am->M('FIELD_UPDATEEMAIL') ?></label>
  2368. <input type="checkbox" id="userEdit_sendmail" name="sendmail" value="1"
  2369. <?php if ($sendMail) { echo ' checked="checked" '; } ?>
  2370. onClick="javascript:usersOnChangeSendMail('userEdit');" /> <?php echo $am->M('SEND') ?>
  2371. </div>
  2372. <?php
  2373. if (!$am->hasFeature('PHPMailer')) {
  2374. echo '<div class="block">';
  2375. echo $am->W('SENDMAILFAIL_INSTALLPHPMAILER');
  2376. echo '</div>';
  2377. }
  2378. ?>
  2379. <div id="userEdit_showtemplate" style="display:<?php echo $sendMail ? 'block' : 'none' ?>;">
  2380. <label for="template"><?php echo $am->M('FIELD_EMAILTEMPLATE') ?></label>
  2381. <select id="userEdit_template" name="template">
  2382. <option value=""><?php echo $am->M('SELECTONE') ?></option>
  2383. <?php
  2384. foreach ($am->getTemplates() as $id=>$tpl) {
  2385. echo '<option value="' .addslashes($id).'"';
  2386. if ($tpl['role'] == 'useredit') {
  2387. echo ' selected="selected"';
  2388. }
  2389. echo '>';
  2390. echo $tpl['name'] . '</option>';
  2391. }
  2392. ?>
  2393. </select>
  2394. </div>
  2395. </fieldset>
  2396. <div class="buttonrow">
  2397. <input type="hidden" id="userEdit_oldusername" name="oldusername" value="" />
  2398. <input type="hidden" name="action" value="updateuser" />
  2399. <input type="hidden" name="page" value="users" />
  2400. <?php echo htmlSubmit('submit'); ?>
  2401. <?php echo htmlReset('reset', 'onClick="javascript:usersResetForm(\'userEdit\'); return false;"' ); ?>
  2402. <input type="submit" id="userEdit_cancel" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:usersShowForm('userEdit',''); return false;" />
  2403. </div>
  2404. </form>
  2405. </div>
  2406. <!-- end of USERS edit form -->
  2407. <!-- USER delete form -->
  2408. <div id="userDelete" style="display: none;">
  2409. <form id="userDelete_form" name="userDelete">
  2410. <fieldset>
  2411. <legend><?php echo $am->M('LEGEND_USERDELETE') ?></legend>
  2412. <p id="userDelete_form_msg" class="formmessage"><?php echo $am->M('Q_USERDELETE'); ?></p>
  2413. </fieldset>
  2414. <div class="buttonrow">
  2415. <input type="hidden" name="username" value="" />
  2416. <input type="hidden" name="page" value="users" />
  2417. <input type="hidden" name="action" value="deleteuser" />
  2418. <input type="submit" id="userDelete_submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  2419. <input type="submit" id="userDelete_cancel" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:usersShowForm('userDelete','hide'); return false;" />
  2420. </div>
  2421. </form>
  2422. </div>
  2423. <!-- end of USER delete form -->
  2424. <!-- USERS delete selected form -->
  2425. <div id="usersDelSel" style="display: none;">
  2426. <form id="usersDelSel_form" name="usersDelSel">
  2427. <fieldset>
  2428. <legend><?php echo $am->M('LEGEND_USERDELSEL') ?></legend>
  2429. <p id="usersDelSel_form_msg" class="formmessage"><?php echo $am->M('Q_USERDELSEL'); ?></p>
  2430. </fieldset>
  2431. <div class="buttonrow">
  2432. <input type="hidden" name="page" value="users" />
  2433. <input type="hidden" name="action" value="deleteselusers" />
  2434. <input type="submit" id="usersDelSel_submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  2435. <input type="submit" id="usersDelSel_cancel" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:usersShowForm('usersDelSel','hide'); return false;" />
  2436. </div>
  2437. </form>
  2438. </div>
  2439. <!-- end of USERS delete selected form -->
  2440. <!-- USERS delete all form -->
  2441. <div id="usersDelAll" style="display: none;">
  2442. <form id="usersDelAll_form" name="usersDelSel">
  2443. <fieldset>
  2444. <legend><?php echo $am->M('LEGEND_USERDELALL') ?></legend>
  2445. <p id="usersDelAll_form_msg" class="formmessage"><?php echo $am->M('Q_USERDELALL'); ?></p>
  2446. </fieldset>
  2447. <div class="buttonrow">
  2448. <input type="hidden" name="page" value="users" />
  2449. <input type="hidden" name="action" value="deleteallusers" />
  2450. <input type="submit" id="usersDelAll_submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  2451. <input type="submit" id="usersDelAll_cancel" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:usersShowForm('usersDelAll','hide'); return false;" />
  2452. </div>
  2453. </form>
  2454. </div>
  2455. <!-- end of USERS delete all form -->
  2456. <!-- USERS userMail form -->
  2457. <div id="userMail" style="display: none;">
  2458. <form id="userMail_form" name="userMail">
  2459. <fieldset>
  2460. <legend><?php echo $am->M('LEGEND_BASETEMPLATESEL') ?></legend>
  2461. <div>
  2462. <label for="templateid" class=""><?php echo $am->M('FIELD_BASETPLNAME') ?></label>
  2463. <select id="templateid" onChange="javascript:usersOnChangeTemplate( 'userMail', this.value );">
  2464. <option id="userMail_default_templateid" value=""><?php echo $am->M('OPTS_CUSTOMEMAIL') ?></option>
  2465. <option value="">------</option>
  2466. <?php
  2467. $tplsArray = $am->getTemplates();
  2468. foreach($tplsArray as $id=>$tpl) {
  2469. print '<option value="' . addslashes($id) . '">' . $tpl['name'] . '</option>';
  2470. }
  2471. ?>
  2472. </select>
  2473. </div>
  2474. </fieldset>
  2475. <p id="userMail_form_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  2476. <!-- subject, body etc -->
  2477. <fieldset>
  2478. <legend><?php echo $am->M('LEGEND_MAILSEND') ?></legend>
  2479. <div>
  2480. <label for="userMail_mailto" class=""><?php echo $am->M('FIELD_MAILTO') ?></label>
  2481. <span id="userMail_mailto"></span>
  2482. </div>
  2483. <div>
  2484. <label for="subject" class="required"><?php echo $am->M('FIELD_MAILSUBJECT') ?></label>
  2485. <input id="userMail_subject" name="subject" type="text" maxlength="255" class="required" />
  2486. </div>
  2487. <div>
  2488. <label for="type" class="required"><?php echo $am->M('FIELD_MAILTYPE') ?></label>
  2489. <input checked="checked" onClick="javascript:usersOnChangeTemplateType('userMail');" type="radio" class="required" id="userMail_type" name="type" value="plaintext" />PlainText
  2490. <input onClick="javascript:usersOnChangeTemplateType('userMail');" type="radio" class="required" id="userMail_type" name="type" value="html" />HTML
  2491. </div>
  2492. <div>
  2493. <label for="body" class="required"><?php echo $am->M('FIELD_MAILBODY') ?></label>
  2494. </div>
  2495. <div>
  2496. <textarea class="htmlcontent required" id="userMail_body" name="body" wrap="off"></textarea>
  2497. <div id='userMail_templatevar'>
  2498. <?php echo $am->M('INSERT') . ': '; echo htmlSelectTemplateVar('userMail_body'); ?>
  2499. </div>
  2500. </div>
  2501. </fieldset>
  2502. <div class="buttonrow">
  2503. <div id="userMail_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SENDING') ?></span></div>
  2504. <input type="hidden" name="username" value="" />
  2505. <input type="hidden" name="page" value="users" />
  2506. <input type="hidden" name="action" value="mailtouser" />
  2507. <input type="submit" id="userMail_submit" name="submit" value="<?php echo $am->M('BTN_SEND') ?>" />
  2508. <input type="submit" id="userMail_clear" name="clear" value="<?php echo $am->M('BTN_CLEAR') ?>" onClick="javascript:usersResetForm('userMail'); return false;" />
  2509. <input type="submit" id="userMail_cancel" name="cancel" value="<?php echo $am->M('BTN_CANCEL') ?>" onClick="javascript:usersShowForm('userMail','hide'); return false;" />
  2510. </div>
  2511. </form>
  2512. </div>
  2513. <!-- end of USERS userMail form -->
  2514. <div class="spacer30"></div>
  2515. <?php
  2516. $prefix = 'index.php?page=users&';
  2517. web_stepper( $prefix, $am->getTotalByType('authuserfile', $searchtext), $limit, $p);
  2518. ?>
  2519. <form id="usersList" name="usersList" method="post" action="index.php">
  2520. <table class="list">
  2521. <tr class="header">
  2522. <th><input type="checkbox" name="usernames" value="" onClick="javascript:usersCheckUsers();"/></th>
  2523. <th><?php echo $am->M('FIELD_USERNAME') ?></th>
  2524. <th><?php echo $am->M('FIELD_REALNAME') ?></th>
  2525. <th><?php echo $am->M('FIELD_EMAIL') ?></th>
  2526. <th>Action</th>
  2527. </tr>
  2528. <?php
  2529. foreach ($usersArray as $user) {
  2530. $uname = addslashes($user['name']);
  2531. print '<tr>';
  2532. print '<td id="check"><input type="checkbox" name="usernames[]" value="' . $uname . '" /></td>';
  2533. print '<td id="name">' . $user['name'] . '</td>';
  2534. print '<td>'. $user['info'] .'&nbsp;</td>';
  2535. print '<td>';
  2536. if (isset($user['email']) && $user['email'] != '') {
  2537. echo '<a href="javascript:usersShowForm(\'userMail\', \''.$uname.'\');"> '. $user['email'] . '</a>';
  2538. } else {
  2539. echo $user['email'];
  2540. }
  2541. print '&nbsp;</td>';
  2542. print '<td id="action"><a href="javascript:usersShowForm(\'userEdit\', \''.$uname.'\');"><img src="images/edit.gif" border="0" alt="Edit"></a>';
  2543. print ' | <a href="javascript:usersShowForm(\'userDelete\', \''.$uname.'\');"><img src="images/decline.gif" border="0" alt="Delete"></a></td>';
  2544. print '</tr>';
  2545. }
  2546. ?>
  2547. </table>
  2548. <div class="listActions">
  2549. <div class="listLeft">
  2550. <select id="groupaction" onChange="javascript:usersShowForm(this.value, 'show'); $('deflistUserActions').selected=true;">
  2551. <option id="deflistUserActions" value=""><?php echo $am->M('SELECTACTION') ?></option>
  2552. <option value="usersMailSel" class="yellow-item"><?php echo $am->M('SENDMAILSEL') ?></option>
  2553. <option value="usersDelSel" class="warn-item"><?php echo $am->M('DELETESELECTED') ?></option>
  2554. <option value="usersDelAll" class="warn-item"><?php echo $am->M('DELETEALL') ?></option>
  2555. </select>
  2556. </div>
  2557. <div class="listRight">
  2558. <a href="javascript:usersShowForm('userAdd','show');"><?php echo $am->M('ADDNEWUSER') ?></a>
  2559. </div>
  2560. </div>
  2561. <input type="hidden" name="page" value="users" />
  2562. <input type="hidden" name="action" value="" />
  2563. </form>
  2564. <div class="spacer30"></div>
  2565. <?php if ($am->hasFeature('tinymcejs')) { ?>
  2566. <script type="text/javascript" xml:space="preserve">
  2567. //<![CDATA[
  2568. tinyMCE.init({
  2569. mode : "none",
  2570. <?php if ($am->isDemo()) { echo "plugins : \"noneditable\",\n"; } ?>
  2571. theme : "simple"
  2572. });
  2573. //]]>
  2574. </script>
  2575. <?php } ?>
  2576. <?php
  2577. print "\n<script type=\"text/javascript\" xml:space=\"preserve\">\n//<![CDATA[\n";
  2578. print "var users = new Array();\n";
  2579. foreach ($usersArray as $user) {
  2580. $uname = addslashes($user['name']);
  2581. print 'users["'.$uname.'"] = new Array();' . "\n";
  2582. foreach ($user as $k=>$v) {
  2583. if ($k == 'pass' || $k == 'pass_raw') {
  2584. continue;
  2585. }
  2586. echo ' users["'.$uname.'"]["'.$k.'"] = "'. addslashes($v) . '";' . "\n";
  2587. }
  2588. }
  2589. echo getJsArray('emailTemplates');
  2590. // ------------- EDIT USERS - JS values --------------
  2591. if ($action == 'updateuser' && hasParam('username')) {
  2592. $uname = addslashes( getParam('username', null, 'username') );
  2593. echo "usersShowForm('userEdit', '" . $uname . "');\n";
  2594. }
  2595. // ------------- ADD USER - JS values --------------
  2596. if ($action == 'adduser' && isset($error)) {
  2597. echo "usersShowForm('userAdd', 'show');\n";
  2598. }
  2599. print "//]]>\n</script>\n";
  2600. echo '</div>'; // righty
  2601. web_footer();
  2602. }
  2603. /* the end of 'users' module */
  2604. /**
  2605. * Manage new user requests
  2606. *
  2607. * @return void
  2608. */
  2609. function showPage_signups()
  2610. {
  2611. global $am;
  2612. // Checking access rights
  2613. if (!$am->isAdmin()) {
  2614. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  2615. showPage_401( true );
  2616. exit;
  2617. }
  2618. $error = $message = null;
  2619. $action = getParam('action', null, 'attribute');
  2620. // ------------- Ajax Actions ----------------
  2621. // Ajax Action: checkusername
  2622. if ($action == 'checkusername') {
  2623. $username = getParam('username', null, 'username');
  2624. if ($am->isRecordByType('authuserfile', $username)) {
  2625. echo 'USERFOUND';
  2626. } else {
  2627. echo 'NOSUCHUSER';
  2628. }
  2629. return;
  2630. }
  2631. // ------------- General variables ----------------
  2632. $limit = 10;
  2633. if (hasParam('limit')) {
  2634. $limit = getParam('limit', 10, 'int');
  2635. $_SESSION['user_limit'] = $limit;
  2636. } else if (isset($_SESSION['user_limit'])) {
  2637. $limit = $_SESSION['user_limit'];
  2638. }
  2639. $p = 1;
  2640. if (hasParam('p')) {
  2641. $p = getParam('p', 1, 'int' );
  2642. $_SESSION['user_p'] = $p;
  2643. } else if (isset($_SESSION['user_p'])) {
  2644. $p = $_SESSION['user_p'];
  2645. }
  2646. if (empty($limit)) {
  2647. $p = 1;
  2648. }
  2649. $offset = ($p-1) * $limit;
  2650. // ------------- Actions ----------------
  2651. // Action: approve
  2652. if ($action == 'approve') {
  2653. $username = getParam('username', null, 'username');
  2654. if (!isset($username) || $username == '') {
  2655. $error = $am->E('INVALIDREQUEST') . ' [username]';
  2656. } else if ($am->isRecordByType('authuserfile', $username)) {
  2657. $error = $am->E('USEREXISTS', $username);
  2658. }
  2659. $password = getParam('password', null, 'password');
  2660. if (empty($password)) {
  2661. $error = $am->E('INVALIDREQUEST') . ' [password]';
  2662. }
  2663. $data = array('name'=>$username,
  2664. 'pass_raw'=>$password,
  2665. 'info'=>getParam('realname', null, 'field'),
  2666. 'email'=>getParam('email', null, 'email'));
  2667. if (!isset($error)) {
  2668. if (false == $am->setRecordByType( 'authuserfile', null, $data, true )) {
  2669. $error = $am->E('USERINSERTFAILED', $username)
  2670. . ': ' . $am->getError();
  2671. }
  2672. }
  2673. if (!isset($error)) {
  2674. if (!$am->setRecordByType('signupfile', $username, null, true)) {
  2675. $error = $am->E('USERDELETEFAILED', $username)
  2676. . ': ' . $am->getError();
  2677. }
  2678. }
  2679. if (!isset($error)) {
  2680. $message = $am->M('USERINSSUCCESS', $username);
  2681. $action = false;
  2682. }
  2683. // sending notification e-mail
  2684. $am->setRuntimeValue('useradd_sendmail', hasParam('sendmail'), true);
  2685. if (!isset($error) && hasParam('sendmail')) {
  2686. $template = getParam('template', 'useradd', 'attribute');
  2687. if (false == $am->sendMail($template, $data )) {
  2688. $error = $am->getError();
  2689. }
  2690. }
  2691. // Action: delete
  2692. } else if ($action == 'delete') {
  2693. $username = getParam('username', null, 'username');
  2694. if (!$am->isRecordByType('signupfile', $username)) {
  2695. $error = $am->E('USERNOTEXISTS', $username);
  2696. }
  2697. if (!isset($error)) {
  2698. if (false == $am->setRecordByType( 'signupfile', $username, null, true )) {
  2699. $error = $am->E('USERDELETEFAILED', $username) .
  2700. ': ' . $am->getError();
  2701. }
  2702. }
  2703. if (!isset($error)) {
  2704. $message = $am->M('MSG_SIGNUPUSERDELETED', $username);
  2705. }
  2706. // Action: delete selected users
  2707. } else if ($action == 'deleteselected') {
  2708. $usernames = getParam('usernames', null, 'username');
  2709. foreach($usernames as $username) {
  2710. if (!$am->isRecordByType('signupfile', $username)) {
  2711. $error = $am->E('USERNOTEXISTS', $username);
  2712. break;
  2713. }
  2714. if (false == $am->setRecordByType('signupfile', $username, null, true)) {
  2715. $error = $am->E('USERDELETEFAILED', $username) . ': ' . $am->getError();
  2716. break;
  2717. }
  2718. }
  2719. if (!isset($error)) {
  2720. $message = $am->M('USERSSELDELETED');
  2721. }
  2722. // Action: delete ALL
  2723. } else if ($action == 'deleteall') {
  2724. if (!isset($error)) {
  2725. if (false == $am->clearAllRecordsByType('signupfile', true)) {
  2726. $error = $am->E('SIGNUPUSERSDELALLFAILED')
  2727. . ': ' . $am->getError();
  2728. }
  2729. }
  2730. if (!isset($error)) {
  2731. $message = $am->M('MSG_SIGNUPUSERSALLDELETED');
  2732. }
  2733. }
  2734. $signupsArray = $am->getRecordsByType( 'signupfile', 'name', $limit, $offset );
  2735. web_header( $am->M('SUBTITLE_SIGNUPS'));
  2736. web_menu();
  2737. echo '<div id="righty">';
  2738. // ------------- Information ----------------
  2739. echo '<div class="pagenotes">';
  2740. echo '<h4>' . $am->M('SUBTITLE_SIGNUPS') . '</h4>';
  2741. echo '<div><div class="name">' . $am->M('SINGUPREQUESTS') . '</div>';
  2742. echo '<div class="value">' . $am->getTotalByType('signupfile') . '</div></div>';
  2743. echo '</div>';
  2744. // ------------- Message ----------------
  2745. web_message( $message, $error );
  2746. ?>
  2747. <h1><?php echo $am->M('SUBTITLE_SIGNUPS') ?></h1>
  2748. <?php
  2749. $file = $am->getPathByType('signupfile');
  2750. if (false == $file) {
  2751. echo '<div class="block">';
  2752. echo 'No signup file found';
  2753. echo '</div>';
  2754. }
  2755. ?>
  2756. <div class="spacer30"></div>
  2757. <!-- approve / add form -->
  2758. <div id="approve_container" style="display: none;">
  2759. <form id="approve" name="approve" method="post">
  2760. <fieldset>
  2761. <legend><?php echo $am->M('LEGEND_SIGNUPINFORMATION') ?></legend>
  2762. <div>
  2763. <label for="datetime"><?php echo $am->M('FIELD_DATETIME') ?></label>
  2764. <span id="approve_datetime" name="datetime"></span>
  2765. </div>
  2766. <div>
  2767. <label for="remoteaddr"><?php echo $am->M('FIELD_REMOTEADDR') ?></label>
  2768. <span id="approve_remoteaddr" name="remoteaddr"></span>
  2769. </div>
  2770. <div>
  2771. <label for="referer"><?php echo $am->M('FIELD_REFERER') ?></label>
  2772. <span id="approve_referer" name="referer"></span>
  2773. </div>
  2774. </fieldset>
  2775. <div id="approve_checkusername" style="float:right;"></div>
  2776. <p id="approve_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  2777. <fieldset>
  2778. <legend><?php echo $am->M('LEGEND_SIGNUPAPPROVE') ?></legend>
  2779. <div>
  2780. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  2781. <input id="approve_username" type="text" name="username" maxlength="255" class="required" />
  2782. <input id="approve_check" name="check" type="button" value="<?php echo $am->M('CHECK') ?>" onclick="javascript:mainCheckUsername2('approve');" />
  2783. </div>
  2784. <div>
  2785. <label for="password" class="required"><?php echo $am->M('FIELD_PASSWORD') ?></label>
  2786. <input id="approve_password" type="text" name="password" maxlength="255" class="required" />
  2787. <input type="button" value="<?php echo $am->M('GENERATE') ?>" onclick="javascript:mainGeneratePassword2('approve');" />
  2788. </div>
  2789. <div>
  2790. <label for="realname"><?php echo $am->M('FIELD_REALNAME') ?></label>
  2791. <input id="approve_realname" type="text" name="realname" size="40" maxlength="255" />
  2792. </div>
  2793. <div>
  2794. <label for="email"><?php echo $am->M('FIELD_EMAIL') ?></label>
  2795. <input id="approve_email" type="text" name="email" size="40" maxlength="255" />
  2796. </div>
  2797. <div class="dashed"></div>
  2798. <?php
  2799. $sendMail = true;
  2800. if (false == $am->hasFeature('PHPMailer')) {
  2801. $sendMail = false;
  2802. } else if ($am->hasRuntimeValue('useradd_sendmail') && $am->getRuntimeValue('useradd_sendmail') != "1") {
  2803. $sendMail = false;
  2804. }
  2805. ?>
  2806. <div>
  2807. <label for="sendmail"><?php echo $am->M('FIELD_WELCOMEEMAIL') ?></label>
  2808. <input type="checkbox" id="approve_sendmail" name="sendmail" value="1"
  2809. <?php if ($sendMail) { echo ' checked="checked" '; } ?>
  2810. onClick="javascript:mainOnChangeSendMail2('approve');" /> <?php echo $am->M('SEND') ?>
  2811. </div>
  2812. <?php if (false == $am->hasFeature('PHPMailer')) {
  2813. echo '<div class="block">';
  2814. echo $am->W('SENDMAILFAIL_INSTALLPHPMAILER');
  2815. echo '</div>';
  2816. }
  2817. ?>
  2818. <div id="approve_showtemplate" style="display:<?php echo $sendMail ? 'block' : 'none' ?>;">
  2819. <label for="template"><?php echo $am->M('FIELD_EMAILTEMPLATE') ?></label>
  2820. <select id="approve_template" name="template">
  2821. <option value=""><?php echo $am->M('SELECTONE') ?></option>
  2822. <?php
  2823. foreach ($am->getTemplates() as $id=>$tpl) {
  2824. echo '<option value="' . addslashes($id).'"';
  2825. if ($tpl['role'] == 'useradd') {
  2826. echo ' selected="selected"';
  2827. }
  2828. echo '>';
  2829. echo $tpl['name'] . '</option>';
  2830. }
  2831. ?>
  2832. </select>
  2833. </div>
  2834. </fieldset>
  2835. <div class="buttonrow">
  2836. <input type="hidden" name="action" value="approve" />
  2837. <input type="hidden" name="page" value="signups" />
  2838. <?php echo htmlSubmit('submit'); ?>
  2839. <?php echo htmlReset('reset', 'onClick="javascript:signupsResetForm(\'approve\'); return false;"' ); ?>
  2840. <?php echo htmlInput('submit', 'approve_cancel', $am->M('CANCEL'), "onClick=\"javascript:signupsShowForm('approve','hide'); return false;\"") ?>
  2841. </div>
  2842. </form>
  2843. <div class="spacer30"></div>
  2844. </div>
  2845. <!-- end of approve / add form -->
  2846. <!-- Signup delete form -->
  2847. <div id="delete_container" style="display: none;">
  2848. <form id="delete" name="delete">
  2849. <fieldset>
  2850. <legend><?php echo $am->M('LEGEND_SIGNUPDELETE') ?></legend>
  2851. <p id="delete_msg" class="formmessage"><?php echo $am->M('Q_SIGNUPDELETE'); ?></p>
  2852. </fieldset>
  2853. <div class="buttonrow">
  2854. <input type="hidden" name="username" value="" />
  2855. <input type="hidden" name="page" value="signups" />
  2856. <input type="hidden" name="action" value="delete" />
  2857. <input type="submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  2858. <input type="submit" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:signupsShowForm('delete','hide'); return false;" />
  2859. </div>
  2860. </form>
  2861. <div class="spacer30"></div>
  2862. </div>
  2863. <!-- end of Signup delete form -->
  2864. <!-- USERS delete selected form -->
  2865. <div id="deleteselected_container" style="display: none;">
  2866. <form id="deleteselected" name="deleteselected" method="post">
  2867. <fieldset>
  2868. <legend><?php echo $am->M('LEGEND_USERDELSEL') ?></legend>
  2869. <p id="deleteselected_msg" class="formmessage"><?php echo $am->M('Q_USERDELSEL'); ?></p>
  2870. </fieldset>
  2871. <div class="buttonrow">
  2872. <input type="hidden" name="page" value="signups" />
  2873. <input type="hidden" name="action" value="deleteselected" />
  2874. <input type="submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  2875. <input type="submit" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:signupsShowForm('deleteselected','hide'); return false;" />
  2876. </div>
  2877. </form>
  2878. <div class="spacer30"></div>
  2879. </div>
  2880. <!-- end of USERS delete selected form -->
  2881. <!-- USERS delete all form -->
  2882. <div id="deleteall_container" style="display: none;">
  2883. <form id="deleteall" name="deleteall" method="post">
  2884. <fieldset>
  2885. <legend><?php echo $am->M('LEGEND_SIGNUPUSERDELALL') ?></legend>
  2886. <p id="deleteall_msg" class="formmessage"><?php echo $am->M('Q_USERDELALL'); ?></p>
  2887. </fieldset>
  2888. <div class="buttonrow">
  2889. <input type="hidden" name="page" value="signups" />
  2890. <input type="hidden" name="action" value="deleteall" />
  2891. <input type="submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  2892. <input type="submit" name="cancel" value="<?php echo $am->M('CANCEL') ?>" onClick="javascript:signupsShowForm('deleteall','hide'); return false;" />
  2893. </div>
  2894. </form>
  2895. <div class="spacer30"></div>
  2896. </div>
  2897. <!-- end of USERS delete all form -->
  2898. <?php
  2899. $prefix = 'index.php?page=signups&';
  2900. web_stepper( $prefix, $am->getTotalByType('signupfile'), $limit, $p);
  2901. ?>
  2902. <form id="usersList" name="usersList" method="post" action="index.php">
  2903. <table class="list">
  2904. <tr class="header">
  2905. <th><input type="checkbox" name="usernames" value="" onClick="javascript:usersCheckUsers();"/></th>
  2906. <th><?php echo $am->M('FIELD_USERNAME') ?></th>
  2907. <th><?php echo $am->M('FIELD_REALNAME') ?></th>
  2908. <th><?php echo $am->M('FIELD_EMAIL') ?></th>
  2909. <th><?php echo $am->M('FIELD_REMOTEADDR') ?></th>
  2910. <th>Action</th>
  2911. </tr>
  2912. <?php
  2913. foreach ($signupsArray as $data) {
  2914. $uname = addslashes($data['name']);
  2915. print '<tr>';
  2916. print '<td id="check"><input type="checkbox" name="usernames[]" value="' . $uname . '" /></td>';
  2917. print '<td id="name">' . $data['name'] . '</td>';
  2918. print '<td>'. $data['info'] .'&nbsp;</td>';
  2919. print '<td>';
  2920. echo $data['email'];
  2921. print '&nbsp;</td>';
  2922. // remoteaddr
  2923. echo '<td>';
  2924. echo $data['remoteaddr'];
  2925. // echo '<br />';
  2926. // echo htmlspecialchars($data['referer']);
  2927. echo '</td>';
  2928. print '<td id="action"><a href="javascript:signupsShowForm(\'approve\', \''.$uname.'\');"><img src="images/approve.gif" border="0" alt="Approve"></a>';
  2929. print ' | <a href="javascript:signupsShowForm(\'delete\', \''.$uname.'\');"><img src="images/decline.gif" border="0" alt="Decline"></a></td>';
  2930. print '</tr>';
  2931. }
  2932. ?>
  2933. </table>
  2934. <div class="listActions">
  2935. <div class="listLeft">
  2936. <select id="groupaction" onChange="javascript:signupsShowForm(this.value, 'show'); $('deflistActions').selected=true;">
  2937. <option id="deflistActions" value=""><?php echo $am->M('SELECTACTION') ?></option>
  2938. <option value="">-------------------</option>
  2939. <option value="deleteselected"><?php echo $am->M('DELETESELECTED') ?></option>
  2940. <?php if (count($signupsArray) > 0) { ?>
  2941. <option value="deleteall"><?php echo $am->M('DELETEALL') ?></option>
  2942. <?php } ?>
  2943. </select>
  2944. </div>
  2945. </div>
  2946. <input type="hidden" name="page" value="signups" />
  2947. <input type="hidden" name="action" value="" />
  2948. </form>
  2949. <div class="spacer30"></div>
  2950. <?php
  2951. print "\n<script type=\"text/javascript\" xml:space=\"preserve\">\n//<![CDATA[\n";
  2952. print "var signups = new Array();\n";
  2953. foreach ($signupsArray as $data) {
  2954. $uname = addslashes($data['name']);
  2955. print 'signups["'.$uname.'"] = new Array();' . "\n";
  2956. foreach ($data as $k=>$v) {
  2957. if ($k == 'referer') {
  2958. $v = strlen($v) > 40 ? substr($v, 0, 40) . '...' : $v;
  2959. }
  2960. if ($k == 'ts') {
  2961. $v = gmdate('D, d M Y H:i:s', $v) . ' GMT';
  2962. }
  2963. echo ' signups["'.$uname.'"]["'.$k.'"] = "'. addslashes($v) . '";' . "\n";
  2964. }
  2965. }
  2966. // ------------- EDIT Signup JS values --------------
  2967. if ($action == 'approve' && hasParam('username')) {
  2968. $uname = addslashes( getParam('username', null, 'username') );
  2969. echo "signupsShowForm('approve', '" . $uname . "');\n";
  2970. }
  2971. print "//]]>\n</script>\n";
  2972. echo '</div>'; // righty
  2973. web_footer();
  2974. }
  2975. /* the end of signups module */
  2976. /**
  2977. * System Operations
  2978. *
  2979. * @return void
  2980. */
  2981. function showPage_settings()
  2982. {
  2983. global $am;
  2984. if (!$am->isAdmin( true )) {
  2985. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  2986. showPage_401();
  2987. exit;
  2988. }
  2989. $message = $error = null;
  2990. $action = getParam('action', null, 'attribute');
  2991. ### ADMIN: update
  2992. if ($action == 'updateadmin') {
  2993. $username = getParam('username', null, 'username');
  2994. if ($username == '') {
  2995. $error = $am->E('INVALIDREQUEST');
  2996. }
  2997. if (!isset($error)) {
  2998. list($admin) = $am->getRecordsByType( 'authadminfile', null, 1, 0 );
  2999. $data = $admin;
  3000. $data['name'] = $username;
  3001. $data['info'] = getParam('realname', null, 'field');
  3002. $data['email'] = getParam('email', null, 'email');
  3003. if (hasParam('password')) {
  3004. $rawpass = getParam('password', null, 'password');
  3005. if (isset($rawpass) && $rawpass != '') {
  3006. $data['pass'] = $am->htcrypt($rawpass);
  3007. }
  3008. }
  3009. # update / insert
  3010. if (!$am->setRecordByType( 'authadminfile', null, $data, true, true )) {
  3011. $error = $am->E('ADMINUPDATEFAILED', $username).': '.$am->getError();
  3012. }
  3013. }
  3014. if (!isset($error)) {
  3015. $am->loginAs( $data['name'], $data['pass']);
  3016. $message = $am->M('ADMINUPDSUCCESS', $username);
  3017. }
  3018. }
  3019. ### ADMIN: download file
  3020. if ($action == 'downloadfile') {
  3021. $filetype = getParam('filetype', null, 'attribute');
  3022. $contents = $am->getFileContentsByType($filetype, true); // raw
  3023. if (!$am->isError()) {
  3024. header('Content-Type: text/plain');
  3025. header('Content-Disposition: attachment; filename='.$filetype.'.txt');
  3026. echo $contents;
  3027. return;
  3028. }
  3029. $error = $am->getError();
  3030. }
  3031. ### ADMIN: download apache files
  3032. if ($action == 'downloadapache') {
  3033. $zip_path = '/usr/bin/zip';
  3034. if (!is_file($zip_path) || !is_executable($zip_path)) {
  3035. $error = 'ZIP archiver not found';
  3036. }
  3037. $filesArray = array($am->getPathByType('accessfile'),
  3038. $am->getPathByType('authadminfile'),
  3039. $am->getPathByType('authuserfile'),
  3040. $am->getPathByType('accessfile_dist'),
  3041. $am->getPathByType('authuserfile_dist'));
  3042. // $am->getPathByType('authgroupfile'),
  3043. // $am->getPathByType('authgroupfile_dist'));
  3044. $zip_file = $am->getTempFilePath() . '.zip';
  3045. ob_start();
  3046. foreach ($filesArray as $filepath) {
  3047. $cmd = $zip_path . ' -u ' . $zip_file . ' ' . $filepath;
  3048. $retval = null;
  3049. passthru( $cmd, $retval );
  3050. }
  3051. // $val = ob_get_contents();
  3052. ob_end_clean();
  3053. if (!isset($error)) {
  3054. header('Content-Type: application/x-zip-compressed');
  3055. header('Content-Disposition: attachment; filename=authman_files.zip');
  3056. header('Content-Transfer-Encoding: binary');
  3057. readfile( $zip_file );
  3058. unlink( $zip_file );
  3059. return;
  3060. }
  3061. }
  3062. ### ADMIN: update file (ajax)
  3063. if ($action == 'savefile') {
  3064. $filetype = getParam('filetype', null, 'attribute');
  3065. $contents = getParam('contents', null, 'htmlcode');
  3066. $filepath = $am->getPathByType($filetype);
  3067. // save contents as raw data
  3068. if (!isset($error)) {
  3069. $results = $am->setFileContentsByType( $filetype, $contents, true, true);
  3070. if (!$results) {
  3071. $error = $am->getError();
  3072. }
  3073. }
  3074. if (!isset($error)) {
  3075. $message = $am->M('FILEUPDSUCCESS', $filepath);
  3076. }
  3077. if (!isset($error)) {
  3078. print '<div class="message">' . fmt_message($message) . "</div>\n";
  3079. } else {
  3080. print '<div class="warning">' . fmt_message($error) . "</div>\n";
  3081. }
  3082. return; // ajax only
  3083. }
  3084. ### ADMIN: reset protected (ajax)
  3085. if ($action == 'resetprotected') {
  3086. if (false == $am->resetProtectedDirectory()) {
  3087. $error = $am->getError();
  3088. }
  3089. if (!isset($error)) {
  3090. $message = $am->M('REBLDSUCCESS');
  3091. }
  3092. if (!isset($error)) {
  3093. print '<div class="message">' . fmt_message($message) . "</div>\n";
  3094. } else {
  3095. print '<div class="warning">' . fmt_message($error) . "</div>\n";
  3096. }
  3097. exit;
  3098. }
  3099. ### ADMIN: adding & updating email template
  3100. if ($action == 'addtemplate' || $action == 'updatetemplate') {
  3101. if ($action == 'updatetemplate') {
  3102. $templateid = getParam('templateid', null, 'field');
  3103. if (!isset($templateid) || $templateid=='') {
  3104. $error = $am->E('INVALIDREQUEST') . ' [templateid]';
  3105. }
  3106. } else {
  3107. $templateid = time();
  3108. }
  3109. $name = getParam('templatename', null, 'field');
  3110. $type = getParam('templatetype', null, 'attribute');
  3111. $subject = getParam('templatesubject', null, 'subject');
  3112. $body = getParam('templatebody', null, 'htmlcode');
  3113. if (!isset($error)) {
  3114. if (!isset($name) || $name=='') {
  3115. $error = $am->E('INVALIDREQUEST') . ' [name]';
  3116. } else if (!isset($type) || $type=='') {
  3117. $error = $am->E('INVALIDREQUEST') . ' [type]';
  3118. }
  3119. }
  3120. if (!isset($error)) {
  3121. $data = array('name'=>$name,
  3122. 'type'=>$type,
  3123. 'contents'=>$body,
  3124. 'subject'=>$subject);
  3125. $force = $action == 'updatetemplate';
  3126. if (false == $am->saveTemplateAs( $templateid, $data, $force )) {
  3127. $error = $am->getError();
  3128. }
  3129. }
  3130. if (!isset($error)) {
  3131. if ($action == 'addtemplate') {
  3132. $action = 'updatetemplate';
  3133. $message = $am->M('MSG_TPLCREATED');
  3134. } else {
  3135. $message = $am->M('MSG_TPLUPDATED');
  3136. }
  3137. }
  3138. }
  3139. ### ADMIN: adding & updating email template
  3140. if ($action == 'deletetemplate') {
  3141. $templateid = getParam('templateid', null, 'field');
  3142. if (!isset($templateid) || $templateid=='') {
  3143. $error = $am->E('INVALIDREQUEST') . ' [templateid]';
  3144. }
  3145. if (false == $am->deleteTemplate( $templateid )) {
  3146. $error = $am->getError();
  3147. }
  3148. if (isset($error)) {
  3149. $action = 'updatetemplate';
  3150. } else {
  3151. $templateid = null;
  3152. $message = $am->M('MSG_TPLDELETED');
  3153. }
  3154. }
  3155. $tplsArray = $am->getTemplates();
  3156. web_header( $am->M('SUBTITLE_SETTINGS') );
  3157. web_menu();
  3158. ?>
  3159. <div id="righty">
  3160. <!-- Top Page Notes -->
  3161. <div class="pagenotes">
  3162. <h4><?php echo $am->M('SUBTITLE_SETTINGS') ?></h4>
  3163. <div><div class="name"><?php echo $am->M('PROTECTEDDIRECTORY') ?></div>
  3164. <div class="value"><?php echo $am->getPathByType('protecteddirectory') ?></div></div>
  3165. <div><div class="name">SystemAuthFile</div>
  3166. <div class="value"><?php echo $am->getPathByType('authadminfile') ?></div></div>
  3167. </div>
  3168. <!-- Submenu -->
  3169. <div id="#menuright" class="actions">
  3170. <ul>
  3171. <li><a href="javascript:void(0);" onClick="javascript:setsShowForm('editAdmin','show');"><?php echo $am->M('MENU_EDITADMIN') ?></a></li>
  3172. <li><a href="javascript:void(0);" onClick="javascript:setsShowForm('chooseTpl','show');"><?php echo $am->M('MENU_EMAILTPLS') ?></a></li>
  3173. <li><a href="javascript:void(0);" onClick="javascript:setsShowForm('downFiles','show');"><?php echo $am->M('MENU_DOWNLOAD') ?></a></li>
  3174. <li><a href="javascript:void(0);" onClick="javascript:setsShowForm('prefFiles','show');"><?php echo $am->M('MENU_PREFFILES') ?></a></li>
  3175. <li><a href="javascript:void(0);" onClick="javascript:setsShowForm('resetProtected','show');"><?php echo $am->M('MENU_PROTDIR') ?></a></li>
  3176. </ul>
  3177. </div>
  3178. <!-- Page Message -->
  3179. <?php
  3180. web_message( $message, $error );
  3181. ?>
  3182. <!-- Settings FORM: EDIT ADMIN Account -->
  3183. <div id="editAdmin" style="display: none;">
  3184. <h1><?php echo $am->M('EDITADMIN') ?></h1>
  3185. <form id="editAdmin_form" name="editAdmin_form" method="post">
  3186. <p id="editAdmin_form_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  3187. <fieldset>
  3188. <legend>Account Details</legend>
  3189. <div>
  3190. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  3191. <input id="username" type="text" name="username" maxlength="255" class="required" />
  3192. </div>
  3193. <div>
  3194. <label for="password"><?php echo $am->M('FIELD_NEWPASSWORD') ?></label>
  3195. <input id="password" type="text" name="password" maxlength="255" />
  3196. <input type="button" value="<?php echo $am->M('GENERATE') ?>" onclick="javascript:mainGeneratePassword('editAdmin');" />
  3197. </div>
  3198. <div>
  3199. <label for="realname"><?php echo $am->M('FIELD_REALNAME') ?></label>
  3200. <input id="realname" type="text" name="realname" size="40" maxlength="255" />
  3201. </div>
  3202. <div>
  3203. <label for="email"><?php echo $am->M('FIELD_EMAIL') ?></label>
  3204. <input id="email" type="text" name="email" size="40" maxlength="255" />
  3205. </div>
  3206. </fieldset>
  3207. <div class="buttonrow">
  3208. <div id="editAdmin_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" />
  3209. <span><?php echo $am->M('SAVING') ?></span>
  3210. </div>
  3211. <input type="hidden" name="page" value="settings" />
  3212. <input type="hidden" name="action" value="updateadmin" />
  3213. <?php echo htmlSubmit('submit') ?>
  3214. <?php echo htmlReset('reset', 'onClick="javascript:setsResetForm(\'editAdmin\'); return false;"') ?>
  3215. <input type="submit" id="cancel" value="<?php echo $am->M('CANCEL') ?>"
  3216. onClick="javascript:setsShowForm('editAdmin','hide'); return false;" />
  3217. </div>
  3218. </form>
  3219. </div>
  3220. <!-- Settings FORM: DOWNLOAD Apache Files -->
  3221. <div id="downFiles" style="display: none;">
  3222. <h1><?php echo $am->M('DOWNLOADFILES') ?></h1>
  3223. <div class="block">
  3224. <?php
  3225. echo '<a href="index.php?page=settings&action=downloadapache">';
  3226. echo $am->M('CLICKHERE') .'</a> '. $am->M('TODOWNAPACHEFILES');
  3227. ?>
  3228. </div>
  3229. </div>
  3230. <!-- Settings Form: Prefered Files (ajax) -->
  3231. <div id="prefFiles" style="display: none;">
  3232. <h1><?php echo $am->M('PREFFILES') ?></h1>
  3233. <div class="block"><?php echo $am->M('DESCR_PREFFILES') ?></div>
  3234. <!-- DIST: ACCESS FILE -->
  3235. <form id="daccessfile_form" name="daccessfile_form" onSubmit="javascript:setsPrefFilesUpdate('daccessfile');return false;" method="post">
  3236. <?php
  3237. $filepath = $am->getPathByType('accessfile_dist');
  3238. print '<div id="daccessfile_message">';
  3239. if (false == $filepath) {
  3240. print '<div class="warning">' . $am->W('NOTDEFINED', 'AccessFile (prefered)') . '</div>';
  3241. }
  3242. print '</div>';
  3243. ?>
  3244. <fieldset>
  3245. <legend>AccessFile</legend>
  3246. <div><textarea class="filecontent" name="contents" id="daccessfile_contents"
  3247. wrap="off"><?php echo $am->getFileContentsByType('accessfile_dist', true); ?></textarea>
  3248. </div>
  3249. <div class="fieldnotes"><?php echo $am->M('PREFFILERESTAS', $am->getPathByType('accessfile')) ?></div>
  3250. </fieldset>
  3251. <div class="buttonrow">
  3252. <div id="daccessfile_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3253. <input type="hidden" name="filetype" value="accessfile_dist">
  3254. <input type="hidden" name="ajax" value="1">
  3255. <input type="hidden" name="action" value="savefile">
  3256. <input type="hidden" name="page" value="settings">
  3257. <?php echo htmlSubmit('daccessfile_submit') ?>
  3258. <?php echo htmlReset('daccessfile_reset') ?>
  3259. <?php if (is_file($am->getPathByType('accessfile_dist'))) { ?>
  3260. | <a href="javascript:setsPrefFilesDownload('accessfile_dist');"><?php echo $am->M('DOWNLOAD') ?></a>
  3261. <?php } else { ?>
  3262. | <strong style="color: red;">File not found</strong>
  3263. <?php } ?>
  3264. </div>
  3265. </form>
  3266. <div class="spacer30"></div>
  3267. <!-- DIST: AUTH USER FILE -->
  3268. <form id="dauthuserfile_form" name="dauthuserfile_form" onSubmit="javascript:setsPrefFilesUpdate('dauthuserfile');return false;" method="post">
  3269. <?php
  3270. $filepath = $am->getPathByType('authuserfile_dist');
  3271. print '<div id="dauthuserfile_message">';
  3272. if (false == $filepath) {
  3273. print '<div class="warning">' . $am->W('NOTDEFINED', 'AccessFile (prefered)') . '</div>';
  3274. }
  3275. print '</div>';
  3276. ?>
  3277. <fieldset>
  3278. <legend>AuthUserFile</legend>
  3279. <div><textarea class="filecontent" name="contents" id="dauthuserfile_contents"
  3280. wrap="off"><?php echo $am->getFileContentsByType('authuserfile_dist', true); ?></textarea>
  3281. </div>
  3282. <div class="fieldnotes">
  3283. <?php
  3284. echo $am->M('PREFFILERESTAS', $am->getPathByType('authuserfile'));
  3285. echo '<br />' . $am->M('DEPENSONACCESSFILE');
  3286. ?></div>
  3287. </fieldset>
  3288. <div class="buttonrow">
  3289. <div id="dauthuserfile_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3290. <input type="hidden" name="filetype" value="authuserfile_dist">
  3291. <input type="hidden" name="ajax" value="1">
  3292. <input type="hidden" name="action" value="savefile">
  3293. <input type="hidden" name="page" value="settings">
  3294. <?php echo htmlSubmit('dauthuserfile_submit') ?>
  3295. <?php echo htmlReset('dauthuserfile_reset') ?>
  3296. <?php if (is_file($am->getPathByType('authuserfile_dist'))) { ?>
  3297. | <a href="javascript:setsPrefFilesDownload('authuserfile_dist');"><?php echo $am->M('DOWNLOAD') ?></a>
  3298. <?php } else { ?>
  3299. | <strong style="color: red;">File not found</strong>
  3300. <?php } ?>
  3301. </div>
  3302. </form>
  3303. <div class="spacer30"></div>
  3304. <!-- DIST: AUTH GROUP FILE -->
  3305. <!--
  3306. <form id="dauthgroupfile_form" name="dauthgroupfile_form" onSubmit="javascript:setsPrefFilesUpdate('dauthgroupfile');return false;">
  3307. <?php
  3308. $filepath = $am->getPathByType('authgroupfile_dist');
  3309. print '<div id="dauthgroupfile_message">';
  3310. if (false == $filepath) {
  3311. print '<div class="warning">' . $am->W('NOTDEFINED', 'AccessFile (prefered)') . '</div>';
  3312. } else if (!is_file($filepath)) {
  3313. print '<div class="warning">' . $am->E('NOSUCHFILE', $filepath) . '</div>';
  3314. }
  3315. print '</div>';
  3316. ?>
  3317. <fieldset>
  3318. <legend>AuthGroupFile</legend>
  3319. <div><textarea class="filecontent" name="contents" id="dauthgroupfile_contents"
  3320. wrap="off"><?php echo $am->getFileContentsByType('authgroupfile_dist', true); ?></textarea>
  3321. </div>
  3322. <div class="fieldnotes"><?php echo $am->M('PREFFILERESTAS', $am->getPathByType('authgroupfile')) ?></div>
  3323. </fieldset>
  3324. <div class="buttonrow">
  3325. <div id="dauthgroupfile_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3326. <input type="hidden" name="filetype" value="authgroupfile_dist">
  3327. <input type="hidden" name="ajax" value="1">
  3328. <input type="hidden" name="action" value="savefile">
  3329. <input type="hidden" name="page" value="settings">
  3330. <?php echo htmlSubmit('dauthgroupfile_submit') ?>
  3331. <?php echo htmlReset('dauthgroupfile_reset') ?>
  3332. | <a href="javascript:setsPrefFilesDownload('authgroupfile_dist');"><?php echo $am->M('DOWNLOAD') ?></a>
  3333. </div>
  3334. </form>
  3335. -->
  3336. </div>
  3337. <!-- Settings Form: Reset Protected Directory (ajax) -->
  3338. <div id="resetProtected" style="display: none;">
  3339. <h1><?php echo $am->M('REBLPROTDIR') ?></h1>
  3340. <div class="block"><?php echo $am->M('DESCR_REBLDPROTDIR') ?></div>
  3341. <form id="resetProtected_form" name="resetProtected_form" method="post">
  3342. <fieldset>
  3343. <legend><?php echo $am->M('NOTES') ?></legend>
  3344. <?php echo $am->M('NOTES_REBLDPROTDIR') ?>
  3345. </fieldset>
  3346. <div class="buttonrow">
  3347. <div id="resetProtected_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3348. <input type="hidden" name="ajax" value="1" />
  3349. <input type="hidden" name="page" value="settings" />
  3350. <input type="hidden" name="action" value="resetprotected" />
  3351. <?php echo htmlInput( 'submit', 'resetProtected_submit', $am->M('CONFIRM') ) ?>
  3352. <?php echo htmlInput( 'submit', 'resetProtected_cancel', $am->M('CANCEL'), 'onClick="javascript:setsShowForm(\'resetProtected\',\'hide\'); return false;"') ?>
  3353. </div>
  3354. </form>
  3355. </div>
  3356. <!-- Settings Form: Edit Email Templates -->
  3357. <div id="chooseTpl" style="display: none;">
  3358. <h1><?php echo $am->M('EDITEMAILTPLS') ?></h1>
  3359. <form id="chooseTpl_form" name="chooseTpl_form">
  3360. <fieldset>
  3361. <legend><?php echo $am->M('LEGEND_TEMPLATESEL') ?></legend>
  3362. <div>
  3363. <label for="templateid" class="required"><?php echo $am->M('FIELD_TPLNAME') ?></label>
  3364. <select id="templateid" onChange="javascript:setsOnChangeTemplate( this.value );">
  3365. <option id="chooseTpl_default" value=""><?php echo $am->M('SELECTONE') ?></option>
  3366. <?php
  3367. foreach($tplsArray as $id=>$tpl) {
  3368. print '<option value="' . $id . '">' . $tpl['name'] . '</option>';
  3369. }
  3370. ?>
  3371. </select>
  3372. | <a href="javascript:setsOnNewTemplate();">Add New</a>
  3373. </div>
  3374. </fieldset>
  3375. </form>
  3376. <div class="spacer30"></div>
  3377. </div>
  3378. <div id="addTpl" style="display: none;">
  3379. <form id="addTpl_form" name="addTpl_form" method="post" method="post">
  3380. <p id="addTpl_form_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  3381. <fieldset>
  3382. <legend><?php echo $am->M('LEGEND_TEMPLATENEW') ?></legend>
  3383. <div>
  3384. <label for="templatename" class="required"><?php echo $am->M('FIELD_TPLNAME') ?></label>
  3385. <input id="templatename" name="templatename" type="text" maxlength="255" class="required" />
  3386. </div>
  3387. <div>
  3388. <label for="type" class="required"><?php echo $am->M('FIELD_TPLTYPE') ?></label>
  3389. <input onClick="javascript:setsOnChangeTemplateType('addTpl');" type="radio" class="required" id="templatetype" name="templatetype" value="plaintext" checked="checked" />PlainText
  3390. <input onClick="javascript:setsOnChangeTemplateType('addTpl');" type="radio" class="required" id="templatetype" name="templatetype" value="html" />HTML
  3391. </div>
  3392. <div>
  3393. <label for="templatesubject" class=""><?php echo $am->M('FIELD_TPLSUBJECT') ?></label>
  3394. <input id="templatesubject" name="templatesubject" type="text" maxlength="255" class="" />
  3395. </div>
  3396. <div>
  3397. <label for="templatebody" class=""><?php echo $am->M('FIELD_TPLBODY') ?></label>
  3398. </div>
  3399. <div>
  3400. <textarea class="htmlcontent" id="addTpl_templatebody" name="templatebody" wrap="off"></textarea>
  3401. </div>
  3402. <div id='addTpl_templatevar'>
  3403. <?php echo $am->M('INSERT') . ': '; echo htmlSelectTemplateVar('addTpl_templatebody'); ?>
  3404. </div>
  3405. </fieldset>
  3406. <div class="buttonrow">
  3407. <input type="hidden" name="page" value="settings" />
  3408. <input type="hidden" name="action" value="addtemplate" />
  3409. <?php echo htmlSubmit('submit') ?>
  3410. <input type="submit" id="cancel" value="<?php echo $am->M('CANCEL') ?>"
  3411. onClick="javascript:setsShowForm('addTpl','hide'); return false;" />
  3412. </div>
  3413. </form>
  3414. </div>
  3415. <div id="editTpl" style="display: none;">
  3416. <form id="editTpl_form" name="editTpl_form" method="post">
  3417. <p id="editTpl_form_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  3418. <fieldset>
  3419. <legend><?php echo $am->M('LEGEND_TEMPLATEEDIT') ?></legend>
  3420. <div>
  3421. <label for="templatename" class="required"><?php echo $am->M('FIELD_TPLNAME') ?></label>
  3422. <input id="templatename" name="templatename" type="text" maxlength="255" class="required" />
  3423. </div>
  3424. <div>
  3425. <label for="type" class="required"><?php echo $am->M('FIELD_TPLTYPE') ?></label>
  3426. <input onClick="javascript:setsOnChangeTemplateType('editTpl');" type="radio" class="required" id="templatetype" name="templatetype" value="plaintext" />PlainText
  3427. <input onClick="javascript:setsOnChangeTemplateType('editTpl');" type="radio" class="required" id="templatetype" name="templatetype" value="html" />HTML
  3428. </div>
  3429. <div>
  3430. <label for="templatesubject" class=""><?php echo $am->M('FIELD_TPLSUBJECT') ?></label>
  3431. <input id="templatesubject" name="templatesubject" type="text" maxlength="255" class="" />
  3432. </div>
  3433. <div>
  3434. <label for="templatebody" class=""><?php echo $am->M('FIELD_TPLBODY') ?></label>
  3435. </div>
  3436. <div>
  3437. <textarea class="htmlcontent" id="editTpl_templatebody" name="templatebody" wrap="off"></textarea>
  3438. </div>
  3439. <div id='editTpl_templatevar'>
  3440. <?php echo $am->M('INSERT') . ': '; echo htmlSelectTemplateVar('editTpl_templatebody'); ?>
  3441. </div>
  3442. </fieldset>
  3443. <div class="buttonrow">
  3444. <div id="editTpl_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3445. <input type="hidden" id="templateid" name="templateid" value="" />
  3446. <input type="hidden" name="page" value="settings" />
  3447. <input type="hidden" name="action" value="updatetemplate" />
  3448. <?php echo htmlSubmit('submit') ?>
  3449. <?php echo htmlReset('reset', 'onClick="javascript:setsResetForm(\'editTpl\'); return false;"') ?>
  3450. <?php echo htmlInput( 'submit', 'delete_submit', $am->M('BTN_DELETE'), 'onClick="javascript:return setsOnDeleteTemplate();"' ) ?>
  3451. <input type="submit" id="cancel" value="<?php echo $am->M('CANCEL') ?>"
  3452. onClick="javascript:setsShowForm('editTpl','hide'); return false;" />
  3453. </div>
  3454. </form>
  3455. </div>
  3456. <div class="spacer30"></div>
  3457. <?php if ($am->hasFeature('tinymcejs')) { ?>
  3458. <script type="text/javascript" xml:space="preserve">
  3459. //<![CDATA[
  3460. tinyMCE.init({
  3461. mode : "none",
  3462. <?php if ($am->isDemo()) { echo "plugins : \"noneditable\",\n"; } ?>
  3463. theme : "simple"
  3464. });
  3465. //]]>
  3466. </script>
  3467. <?php } ?>
  3468. <script type="text/javascript" xml:space="preserve">
  3469. //<![CDATA[
  3470. <?php
  3471. // Javascript code: updateadmin
  3472. if ($action == 'updateadmin' && (isset($error) || isset($message))) {
  3473. print "setsShowForm('editAdmin','show');\n";
  3474. }
  3475. echo getJsArray('emailTemplates');
  3476. // Edit template js
  3477. if ($action == 'updatetemplate' && isset($templateid) && (isset($error) || isset($message))) {
  3478. print "setsSetChooseTpl('$templateid');\n";
  3479. print "setsShowForm('editTpl','" . $templateid . "');\n";
  3480. }
  3481. // Add template js
  3482. if ($action == 'addtemplate' && isset($error)) {
  3483. print "setsShowForm('addTpl','show');\n";
  3484. }
  3485. // Delete template js
  3486. if ($action == 'deletetemplate' && (isset($error) || isset($message))) {
  3487. print "setsShowForm('chooseTpl','show');\n";
  3488. }
  3489. ?>
  3490. //]]>
  3491. </script>
  3492. <!-- end of righty -->
  3493. </div>
  3494. <?php
  3495. web_footer();
  3496. }
  3497. /* the end of the settings module */
  3498. /**
  3499. * Files module
  3500. * Edit raw file: .htaccess, .htpasswd
  3501. *
  3502. * @return void
  3503. */
  3504. function showPage_files()
  3505. {
  3506. global $am;
  3507. // check access rights
  3508. if (!$am->isAdmin()) {
  3509. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  3510. showPage_401( true );
  3511. exit;
  3512. }
  3513. $message = $error = null;
  3514. $action = getParam('action', null, 'attribute');
  3515. // Action: 'downloadfile': download raw file
  3516. if ($action == 'downloadfile') {
  3517. $filetype = getParam('filetype', null, 'attribute');
  3518. $contents = $am->getFileContentsByType($filetype, true);
  3519. if (!$am->isError()) {
  3520. header('Content-Type: text/plain');
  3521. header('Content-Disposition: attachment; filename='.$filetype.'.txt');
  3522. echo $contents;
  3523. return;
  3524. }
  3525. $error = $am->getError();
  3526. }
  3527. // Action: 'savefile': save raw file
  3528. if ($action == 'savefile') {
  3529. $filetype = getParam('filetype', null, 'attribute');
  3530. $contents = getParam('contents', null, 'htmlcode');
  3531. $filepath = $am->getPathByType($filetype);
  3532. if (!$am->isManualEdit()) {
  3533. $error = $am->W('MANUALEDITOFF');
  3534. }
  3535. // save contents as raw data
  3536. if (!isset($error)) {
  3537. $results = $am->setFileContentsByType( $filetype, $contents, true, true);
  3538. if (!$results) {
  3539. $error = $am->getError();
  3540. }
  3541. }
  3542. if (!isset($error)) {
  3543. $message = $am->M('FILEUPDSUCCESS', $filepath);
  3544. }
  3545. // authuserfile and authgroupfile are updated via ajax request
  3546. if ($filetype == 'authuserfile' || $filetype == 'authgroupfile') {
  3547. if (empty($error)) {
  3548. print '<div class="message">' . fmt_message($message) . "</div>\n";
  3549. } else {
  3550. print '<div class="warning">' . fmt_message($error) . "</div>\n";
  3551. }
  3552. return;
  3553. }
  3554. }
  3555. web_header( $am->M('SUBTITLE_FILES') );
  3556. web_menu();
  3557. ?>
  3558. <div id="righty">
  3559. <div class="pagenotes">
  3560. <h4><?php echo $am->M('SUBTITLE_FILES') ?></h4>
  3561. <div><div class="name">DocumentRoot</div>
  3562. <div class="value"><?php echo $_SERVER['DOCUMENT_ROOT']; ?></div></div>
  3563. <div><div class="name">IP Address</div>
  3564. <div class="value"><?php echo $_SERVER['REMOTE_ADDR']; ?></div></div>
  3565. </div>
  3566. <?php
  3567. // ------------- Message ----------------
  3568. web_message( $message, $error );
  3569. // ------------- AccessFile ----------------
  3570. $filepath = $am->getPathByType('accessfile');
  3571. print '<div id="accessfile_message">';
  3572. if (!is_file($filepath)) {
  3573. print '<div class="block">';
  3574. print '<img src="images/icon_warning.gif" width="20" height="20" align="left" />';
  3575. print $am->M('NOTES_NOACCESSFILE', $filepath);
  3576. print '</div>';
  3577. }
  3578. print '</div>';
  3579. ?>
  3580. <form id="accessfile_form" name="accessfile_form" method="post" action="index.php">
  3581. <fieldset>
  3582. <legend>AccessFile</legend>
  3583. <div>
  3584. <textarea wrap="off" name="contents" id="accessfile_contents"
  3585. <?php echo $am->isDemo() || !$am->isManualEdit() ? ' readonly' : ''; ?>
  3586. class="filecontent"><?php echo $am->getFileContentsByType('accessfile', true); ?></textarea>
  3587. </div>
  3588. <div class="fieldnotes">File: <?php echo $filepath ?></div>
  3589. </fieldset>
  3590. <div class="buttonrow">
  3591. <input type="hidden" name="filetype" value="accessfile">
  3592. <input type="hidden" name="action" value="savefile">
  3593. <input type="hidden" name="page" value="files">
  3594. <?php
  3595. if ($am->isManualEdit()) {
  3596. echo htmlSubmit('accessfile_submit');
  3597. echo htmlReset('accessfile_reset');
  3598. if (is_file($filepath)) {
  3599. echo '| <a href="javascript:filesDownload(\'accessfile\');">' . $am->M('DOWNLOAD') . '</a>';
  3600. }
  3601. }
  3602. ?>
  3603. </div>
  3604. </form>
  3605. <div class="spacer30"></div>
  3606. <?php
  3607. $filepath = $am->getPathByType('authuserfile');
  3608. print '<div id="authuserfile_message">';
  3609. if (false == $filepath) {
  3610. print '<div class="block">';
  3611. print $am->M('NOTES_NOAUTHFILEDEF', 'AuthUserFile');
  3612. print '</div>';
  3613. } else if (!is_file($filepath)) {
  3614. print '<div class="block">'. $am->E('NOSUCHFILE', $filepath) .'</div>';
  3615. }
  3616. print '</div>';
  3617. if (false != $filepath) {
  3618. ?>
  3619. <form id="authuserfile_form" name="authuserfile_form" method="post" action="index.php">
  3620. <fieldset>
  3621. <legend>AuthUserFile</legend>
  3622. <div>
  3623. <textarea wrap="off" name="contents" id="authuserfile_contents"
  3624. <?php echo $am->isDemo() || !$am->isManualEdit() ? ' readonly' : 'onKeyUp="javascript:filesOnChangeContents(\'authuserfile\');"'; ?>
  3625. class="filecontent"><?php echo $am->getFileContentsByType('authuserfile', true); ?></textarea>
  3626. </div>
  3627. <div class="fieldnotes">File: <?php echo $filepath ?></div>
  3628. </fieldset>
  3629. <div class="buttonrow">
  3630. <div id="authuserfile_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3631. <input type="hidden" name="filetype" value="authuserfile" />
  3632. <input type="hidden" name="action" value="savefile" />
  3633. <input type="hidden" name="page" value="files" />
  3634. <?php
  3635. if ($am->isManualEdit()) {
  3636. echo htmlSubmit('authuserfile_submit', 'onClick="javascript:filesUpdateContents(\'authuserfile\'); return false;"');
  3637. echo htmlReset('authuserfile_reset');
  3638. if (is_file($filepath)) {
  3639. echo '| <a href="javascript:filesDownload(\'authuserfile\');">' . $am->M('DOWNLOAD') . '</a>';
  3640. }
  3641. }
  3642. ?>
  3643. </div>
  3644. </form>
  3645. <?php
  3646. }
  3647. // ------------- Auth Group ----------------
  3648. echo '<!--';
  3649. $filepath = $am->getPathByType('authgroupfile');
  3650. print '<div id="authgroupfile_message">';
  3651. if (false == $filepath) {
  3652. print '<div class="warning">'. $am->w('NOTDEFINED', 'AuthGroupFile') .'</div>';
  3653. } else if (!is_file($filepath)) {
  3654. print '<div class="warning">'. $am->E('NOSUCHFILE', $filepath) .'</div>';
  3655. }
  3656. print '</div>';
  3657. if (false != $filepath) {
  3658. ?>
  3659. <form id="authgroupfile_form" name="authgroupfile_form" method="post" action="index.php">
  3660. <fieldset>
  3661. <legend>AuthGroupFile</legend>
  3662. <div>
  3663. <textarea wrap="off" nowrap name="contents" id="authgroupfile_contents"
  3664. <?php echo $am->isDemo() || !$am->isManualEdit() ? ' readonly' : 'onKeyUp="javascript:filesOnChangeContents(\'authgroupfile\');"'; ?>
  3665. class="filecontent"><?php echo $am->getFileContentsByType('authgroupfile', true); ?></textarea>
  3666. </div>
  3667. <div class="fieldnotes">File: <?php echo $filepath ?></div>
  3668. </fieldset>
  3669. <div class="buttonrow">
  3670. <div id="authgroupfile_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3671. <input type="hidden" name="filetype" value="authgroupfile" />
  3672. <input type="hidden" name="action" value="savefile" />
  3673. <input type="hidden" name="page" value="files" />
  3674. <input type="submit" id="authgroupfile_submit"
  3675. <?php
  3676. echo 'value="'.(is_file($filepath) ? $am->M('UPDATEFILE') : $am->M('CREATEFILE')).'"';
  3677. echo $am->isDemo() || !$am->isManualEdit() ? ' disabled' : '';
  3678. ?> onClick="javascript:filesUpdateContents('authgroupfile'); return false;" />
  3679. <input type="reset" id="authgroupfile_reset"
  3680. <?php
  3681. echo 'value="' . $am->M('RESET') . '"';
  3682. echo $am->isDemo() || !$am->isManualEdit() ? ' disabled' : '';
  3683. ?>/>
  3684. | <a href="javascript:filesDownload('authgroupfile');"><?php echo $am->M('DOWNLOAD') ?></a>
  3685. </div>
  3686. </form>
  3687. <?php
  3688. }
  3689. echo '-->';
  3690. echo '<div class="spacer30"></div>';
  3691. echo '</div>'; // righty
  3692. web_footer();
  3693. }
  3694. /* the end of files module */
  3695. /**
  3696. * Access module
  3697. *
  3698. * @return void
  3699. */
  3700. function showPage_access()
  3701. {
  3702. global $am;
  3703. // check access rights
  3704. if (!$am->isAdmin()) {
  3705. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  3706. showPage_401( true );
  3707. exit;
  3708. }
  3709. $message = $error = null;
  3710. $action = getParam('action', null, 'attribute');
  3711. // Ajax Action: updateaccess
  3712. if ($action == 'updateaccess') {
  3713. $filepath = $am->getPathByType( 'accessfile' );
  3714. $authtype = getParam('authtype', null, 'attribute');
  3715. if ($authtype != 'basic') {
  3716. $error = $am->E('INVALIDREQUEST') . ' [authtype]';
  3717. }
  3718. // RequireRules
  3719. $requireargs = 'valid-user';
  3720. // authname
  3721. if (!isset($error)) {
  3722. $authname = getParam('authname', null, 'htmlcode');
  3723. if ($authname == '') {
  3724. $error = $am->E('INVALIDREQUEST') . ' [authname]';
  3725. }
  3726. }
  3727. // authuserfile
  3728. if (!isset($error)) {
  3729. $authuserfile = getParam('authuserfile', null, 'filepath');
  3730. if ($authuserfile == '' && hasParam('defauthuserfile')) {
  3731. $authuserfile = $am->getDefaultFilePathByType('authuserfile');
  3732. }
  3733. $am->setFilePathByType('authuserfile', $authuserfile);
  3734. if (!is_file($authuserfile) && !hasParam('createmissingfiles')) {
  3735. $error = $am->E('NOSUCHFILE', $authuserfile);
  3736. }
  3737. }
  3738. // error document 401
  3739. if (!isset($error)) {
  3740. $errordocument401 = null;
  3741. if (hasParam('enableerrordocument401')) {
  3742. $errordocument401 = getParam('errordocument401', null, 'url');
  3743. if ($errordocument401=='' && hasParam('deferrordocument401')) {
  3744. $errordocument401 = $am->getUrlByType('errordocument401');
  3745. }
  3746. }
  3747. $am->setFilePathByType('errordocument401', $errordocument401);
  3748. }
  3749. // ip/domain access rules
  3750. $order = getParam('order', null, 'attribute');
  3751. if ($order != 'deny' && $order != 'allow') {
  3752. $order = null;
  3753. }
  3754. if (!isset($error)) {
  3755. $am->setRecordByType( 'accessfile', 'require', array('require'=>$requireargs));
  3756. $authArray = array('authtype', 'authname', 'authuserfile', 'errordocument401', 'order');
  3757. foreach( $authArray as $auth) {
  3758. if (!isset($$auth) || $$auth=='') {
  3759. $am->setRecordByType( 'accessfile', $auth, null );
  3760. } else {
  3761. $am->setRecordByType( 'accessfile', $auth, array($auth=>$$auth));
  3762. }
  3763. }
  3764. // ip/domain access rules
  3765. $allowRecs = getParam('access_allow');
  3766. if (is_array($allowRecs) && count($allowRecs)) {
  3767. $am->setRecordByType( 'accessfile', 'allow', $allowRecs);
  3768. }
  3769. $denyRecs = getParam('access_deny');
  3770. if (is_array($denyRecs) && count($denyRecs)) {
  3771. $am->setRecordByType( 'accessfile', 'deny', $denyRecs);
  3772. }
  3773. }
  3774. // creating empty files
  3775. if (!isset($error) && hasParam('createmissingfiles')) {
  3776. $authuserfile = $am->getPathBytype('authuserfile');
  3777. if (!is_file($authuserfile) && !$am->saveFileByType( 'authuserfile' )) {
  3778. $error = $am->getError();
  3779. }
  3780. }
  3781. // saving
  3782. if (!isset($error)) {
  3783. if (!$am->saveFileByType( 'accessfile' )) {
  3784. $error = $am->getError();
  3785. }
  3786. }
  3787. if (isset($error)) {
  3788. print '<div class="warning">' . fmt_message($error) . "</div>\n";
  3789. return;
  3790. }
  3791. $message = $am->M('FILEUPDSUCCESS', $filepath);
  3792. print '<div class="message">' . fmt_message($message) . "</div>\n";
  3793. return; // ajax
  3794. }
  3795. web_header( $am->M('SUBTITLE_ACCESS') );
  3796. web_menu();
  3797. ?>
  3798. <div id="righty">
  3799. <!-- Top page information -->
  3800. <div class="pagenotes">
  3801. <h4><?php echo $am->M('SUBTITLE_ACCESS') ?></h4>
  3802. <div><div class="name">AccessFile</div>
  3803. <div class="value"><?php echo $am->getPathByType('accessfile') ?></div></div>
  3804. <div><div class="name">IP Address</div>
  3805. <div class="value"><?php echo $_SERVER['REMOTE_ADDR']; ?></div></div>
  3806. </div>
  3807. <?php
  3808. // ------------- Message ----------------
  3809. web_message( $message, $error );
  3810. $noaccessfile = false;
  3811. $accessFilePath = $am->getPathByType('accessfile');
  3812. if (!is_file($accessFilePath)) {
  3813. echo '<div id="noaccessfile_msg" class="block">';
  3814. echo '<img src="images/icon_warning.gif" width="20" height="20" align="left" />';
  3815. echo $am->M('NOTES_NOACCESSFILE', $accessFilePath);
  3816. echo '</div>';
  3817. $noaccessfile = true;
  3818. } else {
  3819. echo '<div id="noaccessfile_msg" class="block" style="display:none;"></div>';
  3820. }
  3821. ?>
  3822. <form id="edit_form" name="edit_form" onSubmit="javascript:accessOnSubmit('edit_form'); return false;">
  3823. <!-- ACCESS RULES -->
  3824. <fieldset>
  3825. <legend><?php echo $am->M('LEGEND_ACCESSRULES') ?></legend>
  3826. <div>
  3827. <label for="authtype" class="required">AuthType</label>
  3828. <select id="authtype" name="authtype">
  3829. <option value="basic" class="cyan-item" selected="selected">Basic</option>
  3830. </select>
  3831. </div>
  3832. <?php
  3833. $authname = $am->getAccessRuleByType('accessfile', 'authname');
  3834. if ($noaccessfile || !isset($authname) || $authname=='') {
  3835. $authname = $am->getConfigValue('authname');
  3836. }
  3837. ?>
  3838. <div>
  3839. <label for="authname" class="required">AuthName</label>
  3840. <input id="authname" type="text" name="authname" size="40" maxlength="255" class="required"
  3841. value="<?php echo htmlEncode($authname) ?>" />
  3842. </div>
  3843. <div>
  3844. <label for="required" class="required">Require Policy</label>
  3845. <select id="require" name="require" class="required">
  3846. <option value="valid-user" class="green-item"><?php echo $am->M('REQUIRE_ALLVALIDUSERS') ?></option>
  3847. </select>
  3848. </div>
  3849. <?php
  3850. $def_authuserfile = $am->getDefaultFilePathByType('authuserfile');
  3851. $authuserfile = htmlEncode($am->getPathByType('authuserfile'));
  3852. if ($noaccessfile) {
  3853. $authuserfile = $def_authuserfile;
  3854. }
  3855. ?>
  3856. <div>
  3857. <label for="authuserfile" class="required">AuthUserFile</label>
  3858. <input id="authuserfile" type="text" name="authuserfile" size="40" maxlength="255" class="required"
  3859. <?php if ($def_authuserfile==$authuserfile) { echo " disabled "; } ?>
  3860. value="<?php echo $authuserfile ?>" />
  3861. <nobr>
  3862. <input type="checkbox" id="defauthuserfile" name="defauthuserfile" value="1"
  3863. <?php if ($def_authuserfile==$authuserfile) { echo " checked=\"checked\" "; } ?>
  3864. onClick="javascript:accessOnDefAuthUserFile('edit_form');" /> <?php echo $am->M('USEDEFAULT') ?>
  3865. </nobr>
  3866. </div>
  3867. </fieldset>
  3868. <!-- MISSING FILES -->
  3869. <fieldset>
  3870. <legend><?php echo $am->M('LEGEND_MISSINGFILES') ?></legend>
  3871. <div>
  3872. <label for="createmissingfiles" class=""><?php echo $am->M('FIELD_MISSINGFILES') ?></label>
  3873. <input type="checkbox" id="createmissingfiles" name="createmissingfiles" value="1"
  3874. <?php if (!hasParam('createmissingfiles')) { echo ' checked="checked"'; } ?> />
  3875. <?php echo $am->M('FLDNOTES_MISSINGFILES') ?>
  3876. </div>
  3877. </fieldset>
  3878. <!-- IP/DOMAIN Access rules -->
  3879. <fieldset>
  3880. <legend><?php echo $am->M('LEGEND_IPDOMAINRULES') ?></legend>
  3881. <div>
  3882. <label for="order" class="optional"><?php echo $am->M('FIELD_DEFAULTRULE') ?></label>
  3883. <select name="order" id="order" class="optional">
  3884. <option value="">| Not set... </option>
  3885. <option <?php
  3886. if ($am->getAccessRuleByType('accessfile', 'order') == 'allow') {
  3887. echo ' selected="selected" ';
  3888. } ?>
  3889. style="background: #efe;" value="allow">Allow from all</option>
  3890. <option <?php
  3891. if ($am->getAccessRuleByType('accessfile', 'order') == 'deny') {
  3892. echo ' selected="selected" ';
  3893. } ?>
  3894. style="background: #fee;" value="deny">Deny from all</option>
  3895. </select>
  3896. <a id="help-order" href="javascript:void(0);" onClick="$('access-order-description').show(); $('help-order').hide();"><img src="images/help.png" alt="Help" /></a>
  3897. </div>
  3898. <div id="access-order-description" class="block-help" style="display: none;">
  3899. Controls the default access state and the order in which Allow and Deny are evaluated.
  3900. <a target="_blank" class="linkexternal" href="http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order">more</a>
  3901. </div>
  3902. <div>
  3903. <table width="100%">
  3904. <tr>
  3905. <td><?php echo $am->M('FIELD_ALLOWEDHOSTS') ?></td>
  3906. <td><?php echo $am->M('FIELD_DENIEDHOSTS') ?></td>
  3907. </tr>
  3908. <td width="50%"><select id="access_allow" name="access_allow[]" size="5" multiple class="optional" style='width: 100%; background: #efe;' onChange='accessListChoose("access_allow");'>
  3909. <option value="">-- add new --</option>
  3910. </select>
  3911. </td>
  3912. <td width="50%"><select id="access_deny" name="access_deny[]" size="5" multiple class="optional" style='width: 100%; background: #fee;' onChange='accessListChoose("access_deny");'>
  3913. <option value="">-- add new --</option>
  3914. </select>
  3915. </td>
  3916. </tr>
  3917. <tr>
  3918. <td>
  3919. <input id="access_allow_edit" name="access_allow_edit" type="text" />
  3920. <a href="javascript:void(0);" onClick="javascript:accessListEdit('access_allow'); return false;"><img src="images/approve.gif" alt="Approve" /></a>
  3921. <a href="javascript:void(0);" onClick="javascript:accessListDelete('access_allow'); return false;"><img src="images/decline.gif" alt="Delete" /></a>
  3922. </td>
  3923. <td>
  3924. <input id="access_deny_edit" name="access_deny_edit" type="text" />
  3925. <a href="javascript:void(0);" onClick="javascript:accessListEdit('access_deny'); return false;"><img src="images/approve.gif" alt="Approve" /></a>
  3926. <a href="javascript:void(0);" onClick="javascript:accessListDelete('access_deny'); return false;"><img src="images/decline.gif" alt="Delete" /></a>
  3927. </td>
  3928. </tr>
  3929. </table>
  3930. </div>
  3931. </fieldset>
  3932. <script type="text/javascript" language="javascript">
  3933. <?php
  3934. $allowRecs = $am->getAccessRuleByType('accessfile', 'allow');
  3935. if (is_array($allowRecs)) {
  3936. foreach ($allowRecs as $k=>$v) {
  3937. echo '$(\'access_allow\').options[ $(\'access_allow\').options.length ] = ';
  3938. echo ' new Option( "' . addslashes($v) . '", "' . addslashes($v) . '", false );';
  3939. }
  3940. }
  3941. $denyRecs = $am->getAccessRuleByType('accessfile', 'deny');
  3942. if (is_array($denyRecs)) {
  3943. foreach ($denyRecs as $k=>$v) {
  3944. echo '$(\'access_deny\').options[ $(\'access_deny\').options.length ] = ';
  3945. echo ' new Option( "' . addslashes($v) . '", "' . addslashes($v) . '", false );';
  3946. }
  3947. }
  3948. ?>
  3949. </script>
  3950. <!-- 401 handler -->
  3951. <fieldset>
  3952. <legend><?php echo $am->M('LEGEND_HANDLER401') ?></legend>
  3953. <?php
  3954. // ErrorDocument 401 <path>
  3955. $deferrordocument401 = $am->getUrlByType('errordocument401');
  3956. $errordocument401 = htmlEncode($am->getAccessRuleByType('accessfile', 'errordocument401'));
  3957. if ($noaccessfile) {
  3958. $errordocument401 = $deferrordocument401;
  3959. }
  3960. ?>
  3961. <div>
  3962. <label for="enableerrordocument401" class=""><?php echo $am->M('FIELD_HANDLER401') ?></label>
  3963. <input type="checkbox" id="enableerrordocument401" name="enableerrordocument401" value="1"
  3964. <?php if ($errordocument401!='') { echo " checked=\"checked\" "; } ?>
  3965. onClick="javascript:accessOnEnableErrorDocument401('edit_form');" /> <?php echo $am->M('ENABLE') ?>
  3966. </div>
  3967. <div id="editErrordocument401" style="display:<?php echo ($errordocument401=='' ?'none' : 'block') ?>;">
  3968. <?php
  3969. if ($errordocument401 == '') {
  3970. $errordocument401 = $deferrordocument401;
  3971. }
  3972. ?>
  3973. <label for="errordocument401" class=""><?php echo $am->M('FIELD_LOCATION401') ?></label>
  3974. <input type="text" id="errordocument401" name="errordocument401" size="40" maxlength="255" class=""
  3975. <?php if ($deferrordocument401==$errordocument401) { echo " disabled "; } ?>
  3976. value="<?php echo $errordocument401 ?>" />
  3977. <nobr>
  3978. <input type="checkbox" id="deferrordocument401" name="deferrordocument401" value="1"
  3979. <?php if ($deferrordocument401==$errordocument401) { echo " checked=\"checked\" "; } ?>
  3980. onClick="javascript:accessOnDefErrorDocument401('edit_form');" /> <?php echo $am->M('USEDEFAULT') ?>
  3981. </nobr>
  3982. </div>
  3983. </fieldset>
  3984. <div class="buttonrow">
  3985. <div id="edit_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('SAVING') ?></span></div>
  3986. <input type="hidden" name="page" value="access" />
  3987. <input type="hidden" name="action" value="updateaccess" />
  3988. <?php echo htmlSubmit('submit') ?>
  3989. <?php echo htmlReset('reset') ?>
  3990. </div>
  3991. </form>
  3992. <div class="spacer30"></div>
  3993. <?php
  3994. echo '</div>'; // righty
  3995. web_footer();
  3996. }
  3997. /* the end of 'access' module */
  3998. /**
  3999. * Output support information
  4000. *
  4001. * @return void
  4002. */
  4003. function showPage_support()
  4004. {
  4005. global $am;
  4006. // check access rights
  4007. if (!$am->isAuthenticated()) {
  4008. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  4009. showPage_401( true );
  4010. exit;
  4011. }
  4012. $message = $error = null;
  4013. $action = getParam('action', null, 'attribute');
  4014. // ------------- Ajax Actions ----------------
  4015. // Ajax Action: send email to administrator
  4016. if ($action == 'supportrequest' && !$am->isAdmin()) {
  4017. $userData = $am->getAuthenticatedUser();
  4018. $userData['requestsubject'] = getParam('subject', null, 'subject');
  4019. $userData['requestbody'] = getParam('body', null, array('htmlcode','max4k'));
  4020. // sending email to adminitrator
  4021. if (!$am->sendMail('memberreq', $userData)) {
  4022. $error = $am->getError();
  4023. }
  4024. if (isset($error)) {
  4025. echo '<div class="warning">' . fmt_message($error) . "</div>\n";
  4026. } else {
  4027. $message = $am->M('INFO_EMAILSENT');
  4028. echo '<div class="message">' . fmt_message($message) . "</div>\n";
  4029. }
  4030. exit;
  4031. }
  4032. web_header( $am->M('SUBTITLE_SUPPORT') );
  4033. web_menu();
  4034. echo '<div id="righty">'; // righty
  4035. // ------------- Information ----------------
  4036. echo '<div class="pagenotes">';
  4037. echo '<h4>' . $am->M('SUBTITLE_SUPPORT') . '</h4>';
  4038. echo '<div><div class="name">'.$am->M('PROJECTHOMEPAGE').'</div>';
  4039. echo '<div class="value"><a target="_blank" href="http://www.authman.com/">www.authman.com</a></div></div>';
  4040. echo '<div><div class="name">'.$am->M('VERSION').'</div>';
  4041. echo '<div class="value">' . $am->getVersion() . '</div></div>';
  4042. echo '</div>';
  4043. // ------------- Message ----------------
  4044. web_message( $message, $error );
  4045. // ------------- AccessFile ----------------
  4046. $filepath = $am->getPathByType('accessfile');
  4047. print '<div id="accessfile_message">';
  4048. if (!is_file($filepath)) {
  4049. print '<div class="block">';
  4050. print $am->E('NOSUCHFILE', $filepath);
  4051. print '</div>';
  4052. }
  4053. print '</div>';
  4054. ?>
  4055. <?php if ($am->isAuthenticated() && !$am->isAdmin()) { ?>
  4056. <!-- Support FORM: contact request -->
  4057. <div id="supportRequest_container" style="display: block;">
  4058. <h1><?php echo $am->M('SUBTITLE_SUPPORTREQUEST') ?></h1>
  4059. <p id="supportRequest_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  4060. <form id="supportRequest" name="supportRequest" onSubmit="javascript:return supportOnSubmitForm(this);">
  4061. <fieldset>
  4062. <legend><?php echo $am->M('LEGEND_SUPPORTREQUEST') ?></legend>
  4063. <div>
  4064. <label for="subject" class="required"><?php echo $am->M('FIELD_MAILSUBJECT') ?></label>
  4065. <input name="subject" type="text" maxlength="255" class="required" />
  4066. </div>
  4067. <div>
  4068. <label for="body" class="required"><?php echo $am->M('FIELD_MAILBODY') ?></label>
  4069. </div>
  4070. <div><textarea name="body" class="filecontent required" wrap="off"></textarea>
  4071. </div>
  4072. </fieldset>
  4073. <div class="buttonrow">
  4074. <div id="supportRequest_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" />
  4075. <span><?php echo $am->M('SAVING') ?></span>
  4076. </div>
  4077. <input type="hidden" name="page" value="support" />
  4078. <input type="hidden" name="action" value="supportrequest" />
  4079. <?php echo htmlInput('submit', 'supportRequest_submit', $am->M('SUBMIT')) ?>
  4080. <?php echo htmlReset('supportRequest_reset', 'onclick="javascript:supportResetForm(\'supportRequest\');"') ?>
  4081. </div>
  4082. </form>
  4083. <div class="spacer30"></div>
  4084. </div>
  4085. <!-- end of contact form -->
  4086. <?php } // authenticated and not admin ?>
  4087. <?php if ($am->isAdmin()) { ?>
  4088. <h1><?php echo $am->M('SUBTITLE_SOFTWARESUPPORT') ?></h1>
  4089. <?php echo $am->M('ADMIN_SUPPORT_TEXT') ?>
  4090. <div class="spacer30"></div>
  4091. <div class="block">
  4092. <a href="http://www.authman.com/bugtrack" target="_blank"><?php echo $am->M('ADMIN_SUPPORT_SUBMITBUG') ?></a>
  4093. </div>
  4094. <div class="spacer30"></div>
  4095. <?php } ?>
  4096. </div>
  4097. <?php
  4098. web_footer();
  4099. }
  4100. /* the end of 'support' module */
  4101. /**
  4102. * Member Settings
  4103. *
  4104. * @return void
  4105. */
  4106. function showPage_edit()
  4107. {
  4108. global $am;
  4109. // Checking access rights
  4110. if (!$am->isAuthenticated()) {
  4111. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  4112. showPage_401();
  4113. exit;
  4114. }
  4115. // This module is for members only
  4116. if ($am->isAdmin()) {
  4117. showPage_users();
  4118. exit;
  4119. }
  4120. $message = $error = null;
  4121. $action = getParam('action', null, 'attribute');
  4122. // ------------- Ajax Actions ----------------
  4123. // Ajax Action: Update member account
  4124. if ($action == 'update') {
  4125. $userData = $am->getAuthenticatedUser();
  4126. if (!isset($error)) {
  4127. $userData['info'] = getParam('realname', null, 'field');
  4128. $userData['email'] = getParam('email', null, 'email');
  4129. if (hasParam('password')) {
  4130. $rawpass = getParam('password', null, 'password');
  4131. if (isset($rawpass) && $rawpass != '') {
  4132. // we can't set pass_raw because "login as" function will fail
  4133. $userData['pass'] = $am->htcrypt($rawpass);
  4134. }
  4135. }
  4136. # update / insert
  4137. if (!$am->setRecordByType('authuserfile', $userData['name'],
  4138. $userData, true)) {
  4139. $error = $am->E('MEMBERUPDATEFAILED')
  4140. . ': ' . $am->getError();
  4141. }
  4142. }
  4143. if (!isset($error) && hasParam('password')) {
  4144. $am->loginAs($userData['name'], $userData['pass']);
  4145. }
  4146. if (isset($error)) {
  4147. echo '<div class="warning">' . fmt_message($error) . "</div>\n";
  4148. exit;
  4149. }
  4150. $message = $am->M('MEMBERUPDSUCCESS');
  4151. echo '<div class="message">' . fmt_message($message) . "</div>\n";
  4152. exit;
  4153. }
  4154. web_header( $am->M('SUBTITLE_MEMBEREDIT') );
  4155. web_menu();
  4156. $userData = $am->getAuthenticatedUser();
  4157. ?>
  4158. <div id="righty">
  4159. <h1><?php echo $am->M('SUBTITLE_MEMBEREDIT') ?></h1>
  4160. <!-- Page Message -->
  4161. <?php web_message( $message, $error ); ?>
  4162. <!-- Member Settings FORM: EDIT Account -->
  4163. <div id="memberEdit_container" style="display: display;">
  4164. <form id="memberEdit" name="memberEdit" method="post" onSubmit="javascript:return memberOnSubmitForm(this);">
  4165. <p id="memberEdit_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  4166. <fieldset>
  4167. <legend><?php echo $am->M('LEGEND_MEMBEREDIT') ?></legend>
  4168. <div>
  4169. <label for="username" class=""><?php echo $am->M('FIELD_USERNAME') ?></label>
  4170. <?php echo htmlspecialchars($userData['name']) ?>
  4171. </div>
  4172. <div>
  4173. <label for="password"><?php echo $am->M('FIELD_NEWPASSWORD') ?></label>
  4174. <input id="memberEdit_password" type="text" name="password" maxlength="255" />
  4175. <input type="button" value="<?php echo $am->M('GENERATE') ?>" onclick="javascript:mainGeneratePassword2('memberEdit');" />
  4176. </div>
  4177. <div>
  4178. <label for="realname" class="required"><?php echo $am->M('FIELD_REALNAME') ?></label>
  4179. <input id="memberEdit_realname" type="text" name="realname" size="40" maxlength="255" class="required" value="<?php echo htmlspecialchars($userData['info']) ?>" />
  4180. </div>
  4181. <div>
  4182. <label for="email" class="required"><?php echo $am->M('FIELD_EMAIL') ?></label>
  4183. <input id="memberEdit_email" type="text" name="email" size="40" maxlength="255" class="required" value="<?php echo htmlspecialchars($userData['email']) ?>" />
  4184. </div>
  4185. </fieldset>
  4186. <div class="buttonrow">
  4187. <div id="memberEdit_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" />
  4188. <span><?php echo $am->M('SAVING') ?></span>
  4189. </div>
  4190. <input type="hidden" name="page" value="edit" />
  4191. <input type="hidden" name="action" value="update" />
  4192. <?php echo htmlSubmit('submit') ?>
  4193. <?php echo htmlReset('reset') ?>
  4194. </div>
  4195. </form>
  4196. </div>
  4197. <div class="spacer30"></div>
  4198. <!-- end of member edit form -->
  4199. <!-- end of righty -->
  4200. </div>
  4201. <?php
  4202. web_footer();
  4203. }
  4204. /* the end of 'member' module */
  4205. /**
  4206. * Delete Member Account
  4207. *
  4208. * @return void
  4209. */
  4210. function showPage_remove()
  4211. {
  4212. global $am;
  4213. // Checking access rights
  4214. if (!$am->isAuthenticated()) {
  4215. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  4216. showPage_401();
  4217. exit;
  4218. }
  4219. // This module is for members only
  4220. if ($am->isAdmin()) {
  4221. showPage_users();
  4222. exit;
  4223. }
  4224. $message = $error = null;
  4225. $action = getParam('action', null, 'attribute');
  4226. // Member action: delete account
  4227. if ($action == 'remove') {
  4228. $userData = $am->getAuthenticatedUser();
  4229. if (!isset($error)) {
  4230. // removing
  4231. if (!$am->setRecordByType('authuserfile', $userData['name'],
  4232. null, true )) {
  4233. $error = $am->E('USERDELETEFAILED', $userData['name'])
  4234. . ': ' . $am->getError();
  4235. }
  4236. // sending email to adminitrator
  4237. if (!$am->sendMail('memberdel', $userData)) {
  4238. $am->clearError();
  4239. }
  4240. }
  4241. if (!isset($error)) {
  4242. showPage_logout();
  4243. exit;
  4244. }
  4245. }
  4246. web_header( $am->M('SUBTITLE_MEMBERDELETE') );
  4247. web_menu();
  4248. ?>
  4249. <div id="righty">
  4250. <h1><?php echo $am->M('SUBTITLE_MEMBERDELETE') ?></h1>
  4251. <!-- Page Message -->
  4252. <?php web_message( $message, $error ); ?>
  4253. <!-- Member settings FORM: delete -->
  4254. <div id="memberDelete_container" style="display: display;">
  4255. <form id="memberDelete" name="memberDelete" method="post">
  4256. <fieldset>
  4257. <legend><?php echo $am->M('LEGEND_MEMBERDELETE') ?></legend>
  4258. <p id="memberDelete_msg" class="formmessage"><?php echo $am->M('Q_MEMBERDELETE'); ?></p>
  4259. </fieldset>
  4260. <div class="buttonrow">
  4261. <input type="hidden" name="page" value="remove" />
  4262. <input type="hidden" name="action" value="remove" />
  4263. <input type="submit" id="submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  4264. <input type="submit" id="cancel" name="cancel" value="<?php echo $am->M('CANCEL') ?>"
  4265. onClick="javascript:document.location='index.php?page=home'; return false;" />
  4266. </div>
  4267. </form>
  4268. </div>
  4269. <div class="spacer30"></div>
  4270. <!-- end of member delete form -->
  4271. <!-- end of righty -->
  4272. </div>
  4273. <?php
  4274. web_footer();
  4275. }
  4276. /* the end of 'remove' module */
  4277. /**
  4278. * Member Password Recovering (step 1)
  4279. *
  4280. * @return void
  4281. */
  4282. function showPage_forgot()
  4283. {
  4284. global $am;
  4285. $message = $error = null;
  4286. $action = getParam('action', null, 'attribute');
  4287. // Checking access rights
  4288. if ($am->isAuthenticated()) {
  4289. header("Location: index.php?page=home");
  4290. exit;
  4291. }
  4292. // This module is for members only
  4293. if (!$am->hasFeature('phpmailer')) {
  4294. $error = $am->M('PASSRECOVERDISABLED');
  4295. }
  4296. // Member action: recover password
  4297. if ($action == 'recover' && !isset($error)) {
  4298. $username = getParam('username', null, 'username');
  4299. $userData = $am->fetchRecordByType('authuserfile', $username, false);
  4300. if (false == $userData) {
  4301. $error = $am->E('INCORRECTARGS');
  4302. }
  4303. $email = getParam('email', null, 'email');
  4304. if (!isset($error)) {
  4305. if ($email == '') {
  4306. $error = $am->E('INCORRECTARGS');
  4307. } else if (strcasecmp($userData['email'], $email) != 0) {
  4308. $error = $am->E('INCORRECTARGS');
  4309. }
  4310. }
  4311. // sending email request to the user
  4312. if (!isset($error)) {
  4313. // $userData['hashofname'] = md5( $userData['name'] );
  4314. $userData['hashofpass'] = md5( $userData['pass'] );
  4315. if (!$am->sendMail('userfgt', $userData)) {
  4316. $error = $am->getError();
  4317. }
  4318. }
  4319. if (!isset($error)) {
  4320. $message = $am->M('INFO_EMAILSENT');
  4321. }
  4322. }
  4323. web_header( $am->M('SUBTITLE_FORGOT') );
  4324. web_menu();
  4325. ?>
  4326. <div id="righty">
  4327. <h1><?php echo $am->M('SUBTITLE_FORGOT') ?></h1>
  4328. <!-- Page Message -->
  4329. <?php web_message( $message, $error ); ?>
  4330. <!-- Anonymous FORM: recover password -->
  4331. <div id="forgot_container" style="display: <?php echo ($action=='' && !isset($error) && isset($message)) ? 'none' : 'block' ?>;">
  4332. <p id="forgot_msg" class="formmessage"><?php echo $am->M('NOTES_FORGOT'); ?></p>
  4333. <form id="forgot" name="forgot" method="post" nSubmit="javascript:return memberOnSubmitForm(this);">
  4334. <fieldset>
  4335. <legend><?php echo $am->M('LEGEND_FORGOT') ?></legend>
  4336. <div>
  4337. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  4338. <input type="text" name="username" maxlength="255" class="required" value="<?php echo getParam('username',null,'htmlspecialchars') ?>" />
  4339. </div>
  4340. <div>
  4341. <label for="email" class="required"><?php echo $am->M('FIELD_EMAIL') ?></label>
  4342. <input type="text" name="email" maxlength="255" class="required" value="<?php echo getParam('email',null,'htmlspecialchars') ?>" />
  4343. </div>
  4344. </fieldset>
  4345. <div class="buttonrow">
  4346. <input type="hidden" name="page" value="forgot" />
  4347. <input type="hidden" name="action" value="recover" />
  4348. <input type="submit" id="submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  4349. <input type="submit" id="cancel" name="cancel" value="<?php echo $am->M('CANCEL') ?>"
  4350. onClick="javascript:document.location='index.php?page=home'; return false;" />
  4351. </div>
  4352. </form>
  4353. </div>
  4354. <!-- end of recover form -->
  4355. <div class="spacer30"></div>
  4356. <!-- end of righty -->
  4357. </div>
  4358. <?php
  4359. web_footer();
  4360. }
  4361. /* the end of 'forgot' module */
  4362. /**
  4363. * Member Password Recovernig (step 2)
  4364. *
  4365. * @return void
  4366. */
  4367. function showPage_recover()
  4368. {
  4369. global $am;
  4370. $message = $error = null;
  4371. $action = getParam('action', null, 'attribute');
  4372. if ($am->isAuthenticated()) {
  4373. header("Location: index.php?page=home");
  4374. exit;
  4375. }
  4376. if (!$am->hasFeature('phpmailer')) {
  4377. $error = $am->M('PASSRECOVERDISABLED');
  4378. }
  4379. // Member action: recover password
  4380. if (hasParam('username') && hasParam('key')) {
  4381. $username = getParam('username', null, 'username');
  4382. $userData = $am->fetchRecordByType('authuserfile', $username, false);
  4383. if (false == $userData) {
  4384. $error = $am->E('INCORRECTARGS');
  4385. }
  4386. $key = getParam('key');
  4387. if (!isset($key) || $key == '') {
  4388. $error = $am->E('INCORRECTARGS');
  4389. }
  4390. if ($key != md5($userData['pass'])) {
  4391. $error = $am->E('INCORRECTARGS');
  4392. }
  4393. // password generator
  4394. $totalChar = 6; // number of chars in the password
  4395. $salt = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789"; // salt to select chars from
  4396. $password=""; // set the inital variable
  4397. for ($i=0;$i<$totalChar;$i++) {
  4398. $password = $password . substr ($salt, rand() % strlen($salt), 1);
  4399. }
  4400. $pass_enc = $am->htcrypt( $password );
  4401. $userData['pass'] = $pass_enc;
  4402. $userData['pass_raw'] = $password;
  4403. if (!isset($error)) {
  4404. // updating user
  4405. if (!$am->setRecordByType('authuserfile', $username,
  4406. $userData, true )) {
  4407. $error = $am->E('USERUPDATEFAILED', $username)
  4408. . ': ' . $am->getError();
  4409. }
  4410. }
  4411. if (!isset($error)) {
  4412. // sending email to the user
  4413. if (!$am->sendMail('userrcv', $userData)) {
  4414. $error = $am->getError();
  4415. }
  4416. }
  4417. if (!isset($error)) {
  4418. // logging in as $username
  4419. $am->loginAs($username, $pass_enc);
  4420. // redirecting
  4421. unset($_SESSION['durl']);
  4422. redirect_header('index.php?page=home', 2, $am->M('MSG_PASSWORDRECOVERED'));
  4423. exit;
  4424. }
  4425. }
  4426. web_header( $am->M('SUBTITLE_RECOVER') );
  4427. web_menu();
  4428. ?>
  4429. <div id="righty">
  4430. <h1><?php echo $am->M('SUBTITLE_RECOVER') ?></h1>
  4431. <!-- Page Message -->
  4432. <?php web_message( $message, $error ); ?>
  4433. <!-- Anonymous FORM: recover password -->
  4434. <div id="recover_container" style="display: block;">
  4435. <p id="recover_msg" class="formmessage"><?php echo $am->M('NOTES_RECOVER'); ?></p>
  4436. <form id="recover" name="recover" method="post" onSubmit="javascript:return memberOnSubmitForm(this);">
  4437. <fieldset>
  4438. <legend><?php echo $am->M('LEGEND_RECOVER') ?></legend>
  4439. <div>
  4440. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  4441. <input type="text" name="username" maxlength="255" class="required" value="<?php echo getParam('username',null,'htmlspecialchars') ?>" />
  4442. </div>
  4443. <div>
  4444. <label for="key" class="required">Key</label>
  4445. <input type="text" name="key" maxlength="255" class="required" value="<?php echo getParam('key',null,'htmlspecialchars') ?>" />
  4446. </div>
  4447. </fieldset>
  4448. <div class="buttonrow">
  4449. <input type="hidden" name="page" value="recover" />
  4450. <input type="hidden" name="action" value="recover" />
  4451. <input type="submit" name="submit" value="<?php echo $am->M('CONFIRM') ?>" />
  4452. <input type="submit" name="cancel" value="<?php echo $am->M('CANCEL') ?>"
  4453. onClick="javascript:document.location='index.php?page=home'; return false;" />
  4454. </div>
  4455. </form>
  4456. </div>
  4457. <!-- end of recover form -->
  4458. <div class="spacer30"></div>
  4459. <!-- end of righty -->
  4460. </div>
  4461. <?php
  4462. web_footer();
  4463. }
  4464. /* the end of 'recover' module */
  4465. /**
  4466. * Show login form
  4467. *
  4468. * @return void
  4469. */
  4470. function showPage_adminpassword()
  4471. {
  4472. global $am;
  4473. $error = $message = null;
  4474. $action = getParam('action', null, 'attribute');
  4475. if (!$am->isAdmin()) {
  4476. $_SESSION['durl'] = $_SERVER['REQUEST_URI'];
  4477. showPage_401( true );
  4478. exit;
  4479. }
  4480. list($admin) = $am->getRecordsByType('authadminfile', null, 1, 0);
  4481. if ($action == 'skip') {
  4482. if (isset($_SESSION['durl']) && $_SESSION['durl'] != '') {
  4483. $durl = $_SESSION['durl'];
  4484. unset($_SESSION['durl']);
  4485. redirect_header( $durl, 1, $am->M('LOGGINGIN') );
  4486. }
  4487. showPage_home();
  4488. exit;
  4489. }
  4490. if ($action == 'change') {
  4491. $npassword = getParam('npassword', null, 'password');
  4492. $npassword2 = getParam('npassword2', null, 'password');
  4493. if (!isset($error)) {
  4494. if (!isset($npassword) || $npassword=='') {
  4495. $error = $am->E('INVUSERORPASS');
  4496. } else if (strlen($npassword) < 4) {
  4497. $error = $am->E('PASSWORDTOOSHORT', 4);
  4498. } else if (strcmp($npassword, $npassword2)!=0) {
  4499. $error = $am->W('PASSWORDSMISSMATCHED');
  4500. }
  4501. }
  4502. if (!isset($error)) {
  4503. $admin['pass_raw'] = $npassword;
  4504. # update / insert
  4505. if (!$am->setRecordByType('authadminfile', null, $admin, true, true)) {
  4506. $error = $am->E('ADMINUPDATEFAILED', $admin['name'])
  4507. . ': ' . $am->getError();
  4508. }
  4509. }
  4510. if (!isset($error)) {
  4511. $pass_enc = $am->htcrypt( $npassword );
  4512. $am->loginAs($admin['name'], $pass_enc);
  4513. if (isset($_SESSION['durl']) && $_SESSION['durl'] != '') {
  4514. $durl = $_SESSION['durl'];
  4515. unset($_SESSION['durl']);
  4516. redirect_header( $durl, 1, $am->M('ADMINUPDSUCCESS', $data['name']));
  4517. }
  4518. redirect_header( 'index.php?page=home', 1, $am->M('ADMINUPDSUCCESS', $data['name']));
  4519. }
  4520. }
  4521. web_header( $am->M('ADMINCHANGEPASSWORD') );
  4522. // web_menu();
  4523. echo '<div id="righty">'; // righty
  4524. echo '<h3>' . $am->M('ADMINCHANGEPASSWORD') . '</h3>';
  4525. // ------------- Message ----------------
  4526. web_message( $message, $error );
  4527. ?>
  4528. <div class="block">
  4529. <img src="images/icon_warning.gif" width="20" height="20" align="left" />
  4530. <?php echo $am->M('NOTES_ADMINHASDEFAULTPASSWORD') ?>
  4531. </div>
  4532. <form id="adminpassword" name="adminpassword" action="index.php" method="post" onSubmit="javascript:return homeOnSubmitForm(this);">
  4533. <p id="adminpassword_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  4534. <fieldset>
  4535. <legend><?php echo $am->M('ADMINCHANGEPASSWORD') ?></legend>
  4536. <div>
  4537. <label for="npassword" class="required"><?php echo $am->M('FIELD_PASSWORD') ?></label>
  4538. <input id="npassword" type="password" name="npassword" maxlength="255" class="required"
  4539. value="<?php echo getParam('npassword') ?>" />
  4540. </div>
  4541. <div>
  4542. <label for="npassword2" class="required"><?php echo $am->M('FIELD_PASSWORD2') ?></label>
  4543. <input id="npassword2" type="password" name="npassword2" maxlength="255" class="required"
  4544. value="<?php echo getParam('npassword2') ?>" />
  4545. </div>
  4546. </fieldset>
  4547. <div class="buttonrow">
  4548. <input type="hidden" name="action" value="change" />
  4549. <input type="hidden" name="page" value="adminpassword" />
  4550. <?php echo htmlInput('submit', 'submit', $am->M('BTN_CONFIRM')) ?>
  4551. <?php echo htmlInput('reset', 'reset', $am->M('BTN_RESET')) ?>
  4552. </div>
  4553. </form>
  4554. <div class="spacer30"></div>
  4555. <div><a href="index.php?page=adminpassword&action=skip"><?php echo $am->M('CHANGEPASSWORDLATER') ?></a></div>
  4556. <div class="spacer30"></div>
  4557. <?php
  4558. echo '</div>'; // righty
  4559. web_footer();
  4560. }
  4561. /* the end of 'adminpassword' module */
  4562. if (!function_exists("htmlspecialchars_decode")) {
  4563. function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
  4564. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
  4565. }
  4566. }
  4567. /**
  4568. * Ajax module
  4569. *
  4570. * @return void
  4571. */
  4572. function showPage_ajax()
  4573. {
  4574. global $am;
  4575. $action = getParam('action', null, 'attribute');
  4576. if ($action == 'fix') {
  4577. echo 'TODO';
  4578. return;
  4579. }
  4580. if ($action == 'checkupdate') {
  4581. $url = "http://www.authman.com/vc/free";
  4582. $fh = @fopen($url, "r");
  4583. if (false == $fh) {
  4584. echo 'Request failed: ' . $url;
  4585. return;
  4586. }
  4587. $version = fread($fh, 256);
  4588. if (false == $version) {
  4589. echo 'Communication failed';
  4590. return;
  4591. }
  4592. $iversion = version2int( $version );
  4593. if (false == $iversion) {
  4594. echo $version;
  4595. return;
  4596. }
  4597. if ($iversion > version2int($am->getVersion())) {
  4598. $am->setRuntimeValue('updateavailable', $version);
  4599. echo '<div>' . $am->M('MSG_UPDATE_AVAILABLE', $version, 'http://www.authman.com/download/free') . '</div>';
  4600. } else {
  4601. $am->setRuntimeValue('updateavailable', null);
  4602. echo '<div>' . $am->M('MSG_UPDATE_NONEED') . '</div>';
  4603. }
  4604. $am->setRuntimeValue('updatechecked_ts', time(), true);
  4605. return;
  4606. }
  4607. if ($action=='setshowmembernews') {
  4608. $val = (bool)getParam('value', false, 'intval');
  4609. $am->setRuntimeValue('showmembernews', $val, true);
  4610. echo 'DONE';
  4611. return;
  4612. }
  4613. if ($action=='getnews') {
  4614. echo $am->newsFetchAsHTML();
  4615. return;
  4616. }
  4617. }
  4618. function version2int( $version )
  4619. {
  4620. $version = trim($version);
  4621. $matches = array();
  4622. if (!preg_match('/^(\d+)\.(\d+)\.(\d+)$/', $version, $matches)) {
  4623. return false;
  4624. }
  4625. return intval( sprintf('%d%03d%03d',
  4626. isset($matches[1]) ? $matches[1] : 0,
  4627. isset($matches[2]) ? $matches[2] : 0,
  4628. isset($matches[3]) ? $matches[3] : 0));
  4629. }
  4630. ################################################################################
  4631. ### HOME
  4632. ################################################################################
  4633. function showPage_home()
  4634. {
  4635. global $am;
  4636. $message = $error = null;
  4637. if ($am->isAuthenticated()) {
  4638. web_header( $am->M('SUBTITLE_HOME') );
  4639. } else {
  4640. web_header();
  4641. }
  4642. web_menu();
  4643. echo '<div id="righty">';
  4644. // ----- Anonymous -------------------------------------
  4645. if (!$am->isAuthenticated()) {
  4646. echo '<h1>' . $am->M('WELCOME') . '</h1>';
  4647. web_message( $message, $error );
  4648. echo '<div>' . $am->M('WELCOME_DEFAULT') . '</div>';
  4649. if ($am->isDemo()) {
  4650. echo '<br />';
  4651. echo '<div><span id="demonote">' . $am->M('WELCOME_DEFAULT_DEMO') . '</span></div>';
  4652. }
  4653. echo '<div class="spacer30"></div>';
  4654. echo '<div class="block">';
  4655. echo '<ul>';
  4656. echo '<li><a href="index.php?page=login">' . $am->M('CLICKHERE') .'</a> ' . $am->M('TOLOGIN') . '</li>';
  4657. echo '<li><a href="../">' . $am->M('CLICKHERE') . '</a> ' . $am->M('TOPROTECTED') . '</li>';
  4658. echo '</ul>';
  4659. echo '</div>';
  4660. // ----- Member -------------------------------------
  4661. } else if (!$am->isAdmin()) {
  4662. echo '<div class="pagenotes">';
  4663. echo '<h4>' . $am->M('SUBTITLE_HOME') . '</h4>';
  4664. echo '<div><div class="name">' . $am->M('PROTECTEDDIRECTORY') . '</div>';
  4665. echo '<div class="value">' . $am->getUrlByType('protected', true) . '</div></div>';
  4666. echo '</div>';
  4667. echo '<h1>' . $am->M('WELCOME') . '</h1>';
  4668. web_message( $message, $error );
  4669. echo '<div>' . $am->M('WELCOME_MEMBER') . '</div>';
  4670. echo '<div class="spacer30"></div>';
  4671. // ----- Administrator -------------------------------------
  4672. } else {
  4673. // ------------- Information ----------------
  4674. echo '<div class="pagenotes">';
  4675. echo '<h4>' . $am->M('SUBTITLE_HOME') . '</h4>';
  4676. $rtErrors = $am->getRuntimeErrors();
  4677. if (count($rtErrors)) {
  4678. $rtCriticals = $am->getRuntimeErrors( true );
  4679. echo '<div><div class="name">'. $am->M('RUNTIMEWARNINGS') .'</div>';
  4680. echo '<div class="value">';
  4681. print 'Found ';
  4682. if (count($rtCriticals)) {
  4683. print count($rtCriticals) . ' critical errors';
  4684. print ', ';
  4685. }
  4686. print (count($rtErrors)-count($rtCriticals)) . ' warnings';
  4687. echo '</div></div>';
  4688. }
  4689. echo '<div><div class="name">' . $am->M('VERSION') . '</div>';
  4690. echo '<div class="value">' . $am->getVersion();
  4691. $updateavailable = $am->getRuntimeValue('updateavailable');
  4692. if (isset($updateavailable) && $updateavailable != '') {
  4693. echo ' [' . $am->M('UPDATEAVAILABLE', $updateavailable) . ']';
  4694. }
  4695. echo '</div></div>';
  4696. echo '<div><div class="name">' . $am->M('TOTALMEMBERS') . '</div>';
  4697. echo '<div class="value"><a href="index.php?page=users">';
  4698. echo $am->getTotalByType('authuserfile');
  4699. echo '</a>';
  4700. $newcount = $am->getTotalByType('signupfile');
  4701. if ($newcount > 0 || $am->getConfigValue('allowsignup')) {
  4702. echo ' ' . $am->M('AND') . ' ';
  4703. if ($newcount) {
  4704. echo '<a href="index.php?page=signups">' . $newcount . '</a>';
  4705. } else {
  4706. echo '0';
  4707. }
  4708. echo ' ' . $am->M('AWAITINGCONFIRM') . ' ';
  4709. }
  4710. echo '</div></div>';
  4711. echo '<div><div class="name">' . $am->M('LASTLOGGEDIN') . '</div>';
  4712. if ($am->hasRuntimeValue('lastloggedin_ts')) {
  4713. echo '<div class="value">';
  4714. echo gmdate('D, d M Y H:i:s', $am->getRuntimeValue('lastloggedin_ts')) . ' GMT';
  4715. if ($am->hasRuntimeValue('lastloggedin_ip')) {
  4716. echo ' ' . $am->M('FROM') . ' ' . $am->getRuntimeValue('lastloggedin_ip');
  4717. }
  4718. echo '</div></div>';
  4719. } else {
  4720. echo '<div class="value">' . $am->M('NOAVAILABLE') . '</div></div>';
  4721. }
  4722. echo '</div>';
  4723. echo '<h1>' . $am->M('WELCOME') . '</h1>';
  4724. echo '<div>' . $am->M('WELCOME_ADMIN') . '</div>';
  4725. echo '<div class="spacer30"></div>';
  4726. web_message( $message, $error );
  4727. // rss, news and updates
  4728. if ($am->hasFeature('magpierss')) {
  4729. ?>
  4730. <div id="home-news">
  4731. <div id="home-news-caption">Authman.com News</div>
  4732. <div id="home-news-content" style="display:none;">
  4733. <?php echo $am->M('LOADING') ?>
  4734. </div>
  4735. <div id="home-news-action">
  4736. <div id="news_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('LOADING') ?></span></div>
  4737. <div id="home-news-hide" style="display:none;"><a href="javascript:void(0)" onClick="javascript:homeShowNews(false,true);return false;"><?php echo $am->M('BTN_HIDENEWS') ?></a></div>
  4738. <div id="home-news-show" style="display:none;"><a href="javascript:void(0)" onClick="javascript:homeShowNews(true,true);return false;"><?php echo $am->M('BTN_SHOWNEWS') ?></a></div>
  4739. </div>
  4740. </div>
  4741. <div class="spacer30"></div>
  4742. <?php
  4743. }
  4744. // signup requests
  4745. $newcount = $am->getTotalByType('signupfile');
  4746. if ($newcount > 0) {
  4747. echo '<div class="block">';
  4748. echo $am->M('MSG_AWAITINGCONFIRM', $newcount);
  4749. echo '</div>';
  4750. echo '<div class="spacer30"></div>';
  4751. }
  4752. // software update
  4753. ?>
  4754. <form>
  4755. <fieldset>
  4756. <div>
  4757. <?php echo $am->M('NOTES_SOFTUPDATES') ?>
  4758. </div>
  4759. <?php
  4760. $showUpdate = $am->hasRuntimeValue('updateavailable')
  4761. && $am->getRuntimeValue('updateavailable') != '';
  4762. echo '<div id="update_msg" class="block" style="display:';
  4763. echo $showUpdate ? 'block' : 'none';
  4764. echo ';">';
  4765. if ($showUpdate) {
  4766. echo '<div>';
  4767. echo $am->M('UPDATEAVAILABLE',
  4768. $am->getRuntimeValue('updateavailable'));
  4769. echo '</div>';
  4770. if ($am->hasRuntimeValue('updatechecked_ts')) {
  4771. echo '<div>';
  4772. echo $am->M('UPDATECHECKED', date('D dS \of M Y',
  4773. $am->getRuntimeValue('lastloggedin_ts')));
  4774. echo '</div>';
  4775. }
  4776. }
  4777. echo '</div>';
  4778. ?>
  4779. </fieldset>
  4780. <div class="buttonrow">
  4781. <div id="update_loading" class="saving" style="display:none"><img src="images/loadinfo.gif" width="16" height="16" /> <span><?php echo $am->M('CHECKING') ?></span></div>
  4782. <input type="submit" value="Check Update" onClick="javascript:homeCheckUpdate(); return false;"/>
  4783. </div>
  4784. </form>
  4785. <div class="spacer30"></div>
  4786. <?php
  4787. // the end of software update
  4788. $rtCriticals = $am->getRuntimeErrors( true );
  4789. foreach ($rtCriticals as $rtErr) {
  4790. print '<div class="warning">';
  4791. print fmt_message($rtErr['message']);
  4792. print ' [#'.$rtErr['errno'].'] ';
  4793. if (isset($rtErr['recover']) && $rtErr['recover']) {
  4794. $url = 'javascript:fixAction('.$rtErr['errno'].');';
  4795. print '<div id="fixaction_'.$rtErr['errno'].'">';
  4796. print ' <div class="fixit"><a href="' . $url . '">'.$am->M('FIXIT').'</a></div>';
  4797. print '</div>';
  4798. }
  4799. print '</div>';
  4800. }
  4801. } // the end of admin section
  4802. echo '<div class="spacer30"></div>';
  4803. echo '</div>'; // righty
  4804. web_footer();
  4805. // rss, news and updates
  4806. if ($am->hasFeature('magpierss')) {
  4807. // show news if runtime variable shownews isn't set or is equal 1
  4808. $showNews = !$am->hasRuntimeValue('showmembernews') || (bool)$am->getRuntimeValue('showmembernews');
  4809. print '<script type="text/javascript">';
  4810. print 'homeShowNews(' . ($showNews ? 'true' : 'false') . ', false);';
  4811. print '</script>';
  4812. }
  4813. }
  4814. ################################################################################
  4815. ### Other pages
  4816. ################################################################################
  4817. /**
  4818. * Show login form
  4819. *
  4820. * @return void
  4821. */
  4822. function showPage_login()
  4823. {
  4824. global $am;
  4825. $error = $message = null;
  4826. $action = getParam('action', null, 'attribute');
  4827. $username = isset($_SESSION['am_u']) ? base64_decode($_SESSION['am_u']) : '';
  4828. if ($action == 'login' && !$am->isAuthenticated()) {
  4829. $username = getParam('username', null, 'username');
  4830. $password = getParam('password', null, 'password');
  4831. if (!isset($password) || $password=='') {
  4832. $error = $am->E('INVUSERORPASS');
  4833. }
  4834. if (!isset($error)) {
  4835. if ($am->isDemo() && $username=='admin' && $password=='admin') {
  4836. list($user) = $am->getRecordsByType('authadminfile', null, 1, 0);
  4837. } else {
  4838. $user = $am->fetchRecordByType('authuserfile', $username);
  4839. if (false == $user) {
  4840. $user = $am->fetchRecordByType('authadminfile', $username, true);
  4841. }
  4842. }
  4843. if (false == $user) {
  4844. $error = $am->E('INVUSERORPASS');
  4845. }
  4846. }
  4847. // password checking
  4848. if (!isset($error)) {
  4849. if ($am->isDemo() && $username=='admin' && $password=='admin') {
  4850. // it's ok to login as admin / admin
  4851. } else {
  4852. $pass_enc = $am->htcrypt( $password, $user['pass'] );
  4853. if ($user['pass'] != $pass_enc) {
  4854. $error = $am->E('INVUSERORPASS');
  4855. }
  4856. }
  4857. }
  4858. if (!isset($error)) {
  4859. // logging in
  4860. $am->loginAs( $user['name'], $user['pass'] );
  4861. if (!($am->isDemo() && $username=='admin' && $password=='admin')) {
  4862. // check for default password
  4863. if ($am->isAdmin() && strcmp($password, 'admin')==0) {
  4864. showPage_adminpassword();
  4865. exit;
  4866. }
  4867. }
  4868. if (isset($_SESSION['durl']) && $_SESSION['durl'] != '') {
  4869. $durl = $_SESSION['durl'];
  4870. unset($_SESSION['durl']);
  4871. redirect_header( $durl, 1, $am->M('LOGGINGIN') );
  4872. }
  4873. showPage_home();
  4874. exit;
  4875. }
  4876. }
  4877. web_header( $am->M('LOGGINGIN') );
  4878. web_menu();
  4879. echo '<div id="righty">'; // righty
  4880. echo '<h3>' . $am->M('LOGGINGIN') . '</h3>';
  4881. // ------------- Message ----------------
  4882. web_message( $message, $error );
  4883. if ($am->isAuthenticated()) {
  4884. $user = $am->getAuthenticatedUser();
  4885. ?>
  4886. <div class="block">
  4887. <?php echo $am->M('LOGGEDASALREADY', $user['name']) ?>
  4888. </div>
  4889. <div class="spacer30"></div>
  4890. <?php
  4891. } else {
  4892. if ($am->isDemo()) {
  4893. echo '<br />';
  4894. echo '<div><span id="demonote">' . $am->M('WELCOME_DEFAULT_DEMO') . '</span></div>';
  4895. }
  4896. ?>
  4897. <form id="login_form" name="login_form" action="index.php" method="post">
  4898. <p id="login_form_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  4899. <fieldset>
  4900. <legend><?php echo $am->M('LOGGINGIN') ?></legend>
  4901. <?php
  4902. $password = '';
  4903. if ($am->isDemo() && hasParam('demoadmin') && !hasParam('username') && !hasParam('password')) {
  4904. $username = $password = 'admin';
  4905. }
  4906. ?>
  4907. <div>
  4908. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  4909. <input id="username" type="text" name="username" maxlength="255" class="required" value="<?php echo $username ?>" />
  4910. </div>
  4911. <div>
  4912. <label for="password" class="required"><?php echo $am->M('FIELD_PASSWORD') ?></label>
  4913. <input id="password" type="password" name="password" maxlength="255" class="required" value="<?php echo $password ?>" />
  4914. </div>
  4915. </fieldset>
  4916. <div class="buttonrow">
  4917. <input type="hidden" name="action" value="login" />
  4918. <input type="hidden" name="page" value="login" />
  4919. <?php echo htmlInput('submit', 'submit', $am->M('SUBMIT')) ?>
  4920. </div>
  4921. </form>
  4922. <div class="spacer30"></div>
  4923. <div class="block">
  4924. <ul>
  4925. <?php if ($am->getConfigValue('allowsignup')) { ?>
  4926. <li><a href="index.php?page=signup"><?php echo $am->M('SIGNUPLINK') ?></a></li>
  4927. <?php } ?>
  4928. <li><a href="index.php?page=forgot"><?php echo $am->M('FORGOTLINK') ?></a></li>
  4929. </ul>
  4930. </div>
  4931. <div class="spacer30"></div>
  4932. <?php
  4933. } // not isAuthenticated
  4934. echo '</div>'; // righty
  4935. web_footer();
  4936. }
  4937. /**
  4938. * Show signup form
  4939. *
  4940. * @return void
  4941. */
  4942. function showPage_signup()
  4943. {
  4944. global $am;
  4945. $error = $message = null;
  4946. $action = getParam('action', null, 'attribute');
  4947. if (!$am->getConfigValue('allowsignup')) {
  4948. $error = $am->W('SIGNUPDISABLED');
  4949. }
  4950. if ($action == 'signup' && !isset($error) && !$am->isAuthenticated()) {
  4951. $username = getParam('username', null, 'username');
  4952. if (!isset($username) || $username == '') {
  4953. $error = $am->E('INVALIDREQUEST') . ' [username]';
  4954. } else if ($am->isRecordByType('authuserfile', $username)) {
  4955. $error = $am->E('USEREXISTS', $username);
  4956. } else if ($am->isRecordByType('signupfile', $username)) {
  4957. $error = $am->E('USEREXISTS', $username);
  4958. }
  4959. $password = getParam('password', null, 'password');
  4960. if (!isset($error) && $password != '') {
  4961. if (strlen($password) < 4) {
  4962. $error = $am->E('PASSWORDTOOSHORT', 4);
  4963. }
  4964. }
  4965. // auto approve signup
  4966. if (!isset($error) && $am->getConfigValue('autoapprove')) {
  4967. $data = array('name'=>$username,
  4968. 'pass_raw'=>$password,
  4969. 'info'=>getParam('realname', null, 'field'),
  4970. 'email'=>getParam('email', null, 'email'));
  4971. if (!$am->setRecordByType( 'authuserfile', null, $data, true )) {
  4972. $error = $am->E('USERINSERTFAILED', $username) . ': ' . $am->getError();
  4973. }
  4974. // notify administrator
  4975. if (!isset($error) && !$am->sendMail('memberaa', $data )) {
  4976. $error = $am->getError();
  4977. }
  4978. // notify user
  4979. if (!isset($error) && !$am->sendMail('useradd', $data)) {
  4980. $error = $am->getError();
  4981. }
  4982. if (!isset($error)) {
  4983. redirect_header($am->getUrlByType('protected', true), 6, $am->M('NOTES_SIGNUPAUTOAPPROVE'));
  4984. }
  4985. }
  4986. // pre-moderated signup
  4987. if (!isset($error) && !$am->getConfigValue('autoapprove')) {
  4988. $referer = isset($_SERVER['HTTP_REFERER']) ?
  4989. $_SERVER['HTTP_REFERER'] : '';
  4990. $data = array('name'=>$username,
  4991. 'pass'=>$password,
  4992. 'info'=>getParam('realname', null, 'field'),
  4993. 'email'=>getParam('email', null, 'email'),
  4994. 'ts'=>time(),
  4995. 'referer'=>$referer,
  4996. 'remoteaddr'=>$_SERVER['REMOTE_ADDR']);
  4997. if (!$am->setRecordByType('signupfile', null, $data, true)) {
  4998. $error = $am->E('SIGNUPINSERTFAILED', $username)
  4999. . ': ' . $am->getError();
  5000. }
  5001. }
  5002. if (!isset($error)) {
  5003. redirect_header( 'index.php?op=home', 10, $am->M('NOTES_SIGNUPWAITRESPONSE'));
  5004. }
  5005. }
  5006. web_header( $am->M('SUBTITLE_SIGNUP') );
  5007. web_menu( true );
  5008. echo '<div id="righty">'; // righty
  5009. echo '<h3>' . $am->M('SUBTITLE_SIGNUP') . '</h3>';
  5010. // ------------- Message ----------------
  5011. web_message( $message, $error );
  5012. if ($am->isAuthenticated()) {
  5013. $user = $am->getAuthenticatedUser();
  5014. ?>
  5015. <div class="block">
  5016. <?php echo $am->M('LOGGEDASALREADY', $user['name']) ?>
  5017. </div>
  5018. <div class="spacer30"></div>
  5019. <?php
  5020. } else {
  5021. ?>
  5022. <div id="signup_container">
  5023. <form id="signup" name="signup" action="index.php?page=signup" method="post"
  5024. onSubmit="javascript:return homeOnSubmitForm(this);">
  5025. <p id="signup_msg" class="formmessage"><?php echo $am->M('FILLFIELDS'); ?></p>
  5026. <fieldset>
  5027. <legend><?php echo $am->M('LEGEND_SIGNUP') ?></legend>
  5028. <div>
  5029. <label for="username" class="required"><?php echo $am->M('FIELD_USERNAME') ?></label>
  5030. <input id="signup_username" type="text" name="username" maxlength="255" class="required"
  5031. value="<?php echo getParam('username', null, 'htmlspecialchars') ?>"
  5032. </div>
  5033. <div>
  5034. <label for="password" class=""><?php echo $am->M('FIELD_PASSWORD') ?></label>
  5035. <input id="signup_password" type="text" name="password" maxlength="255" class=""
  5036. value="<?php echo getParam('password', null, 'htmlspecialchars') ?>" />
  5037. </div>
  5038. <div>
  5039. <label for="realname" class="required"><?php echo $am->M('FIELD_REALNAME') ?></label>
  5040. <input id="signup_realname" type="text" name="realname" maxlength="255" class="required"
  5041. value="<?php echo getParam('realname', null, 'htmlspecialchars') ?>" />
  5042. </div>
  5043. <div>
  5044. <label for="email" class="required"><?php echo $am->M('FIELD_EMAIL') ?></label>
  5045. <input id="signup_email" type="text" name="email" maxlength="255" class="required"
  5046. value="<?php echo getParam('email', null, 'htmlspecialchars') ?>"
  5047. </div>
  5048. </fieldset>
  5049. <div class="buttonrow">
  5050. <input type="hidden" name="action" value="signup" />
  5051. <input type="hidden" name="page" value="signup" />
  5052. <?php echo htmlInput('submit', 'submit', $am->M('SUBMIT')) ?>
  5053. </div>
  5054. </form>
  5055. </div>
  5056. <div class="spacer30"></div>
  5057. <?php
  5058. } // is not authenticated
  5059. echo '</div>'; // righty
  5060. web_footer();
  5061. }
  5062. /**
  5063. * Logging out
  5064. *
  5065. * @return void
  5066. */
  5067. function showPage_logout()
  5068. {
  5069. if (isset($_SESSION['am_c'])) {
  5070. unset($_SESSION['am_c']);
  5071. }
  5072. global $am;
  5073. if ($am->isAuthenticatedByBasicAuth()) {
  5074. redirect_header('index.php?page=home', 4, $am->M('MSG_NOLOGOUTBASICAUTH'));
  5075. }
  5076. redirect_header('index.php?page=home', 1, $am->M('LOGGEDOUT'));
  5077. exit;
  5078. }
  5079. /**
  5080. * Show 404 error
  5081. *
  5082. * @return void
  5083. */
  5084. function showPage_404()
  5085. {
  5086. global $am;
  5087. web_header( '404 ERROR');
  5088. web_menu();
  5089. echo '<div id="righty">'; // righty
  5090. echo $am->W('PAGENOTFOUND');
  5091. echo '<div class="block">';
  5092. echo '<a href="index.php">' . $am->M('CLICKHERE') . '</a> To Return to Index Page';
  5093. echo '</div>';
  5094. echo '<div class="spacer30"></div>';
  5095. echo '</div>'; // righty
  5096. web_footer();
  5097. }
  5098. /**
  5099. * Show 401 error
  5100. *
  5101. * @return void
  5102. */
  5103. function showPage_401( $showMenu=false )
  5104. {
  5105. global $am;
  5106. // $error = $message = null;
  5107. web_header( $am->M('TITLE_AUTHREQUIRED'), $am->getUrlByType('base',true));
  5108. if ($showMenu) {
  5109. web_menu();
  5110. }
  5111. echo '<div id="righty">'; // righty
  5112. echo '<h1>' . $am->M('TITLE_AUTHREQUIRED') . '</h1>';
  5113. echo '<p>' . $am->M('NOTES_AUTHREQUIRED') . '</p>';
  5114. echo '<div class="block">';
  5115. echo '<ul>';
  5116. echo '<li><a href="index.php?page=login">' . $am->M('CLICKHERE') .'</a> ' . $am->M('TOLOGIN') . '</li>';
  5117. echo '<li><a href="../">' . $am->M('CLICKHERE') . '</a> ' . $am->M('TOPROTECTED') . '</li>';
  5118. echo '</ul>';
  5119. echo '</div>';
  5120. echo '<div class="spacer30"></div>';
  5121. if ($am->getConfigValue('allowsignup')) {
  5122. echo '<div class="block">';
  5123. echo '<ul>';
  5124. echo '<li><a href="index.php?page=signup">' . $am->M('SIGNUPLINK') . '</a></li>';
  5125. echo '<li><a href="index.php?page=forgot">' . $am->M('FORGOTLINK') . '</a></li>';
  5126. echo '</ul>';
  5127. echo '</div>';
  5128. echo '<div class="spacer30"></div>';
  5129. }
  5130. echo '</div>'; // righty
  5131. web_footer();
  5132. }
  5133. /**
  5134. * Shows page header
  5135. *
  5136. * @param string $title
  5137. * @return void
  5138. */
  5139. function web_header( $title=null, $basePath='', $optHeaders=array() )
  5140. {
  5141. global $am;
  5142. ?>
  5143. <html>
  5144. <head>
  5145. <title><?php echo (isset($title) ? $title : $am->M('TITLE')) . ' - ' ?>AuthMan Free</title>
  5146. <?php foreach($optHeaders as $hdr) { print trim($hdr) . "\n"; } ?>
  5147. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5148. <meta http-equiv="pragma" content="no-cache" />
  5149. <meta http-equiv="expires" content="-1" />
  5150. <meta name="keywords" content="htaccess,htpasswd,user accounts,web applications,software,site access,secure password,user authentication,script,subscriptions,website software,authman,subscription software,web application,website security,site administration,authman.com,security authentication,web site management,web site management system,php,ajax,protection,security,password,management,membership,login,htaccess management,htpasswd management,subscription script,apache,registration" />
  5151. <meta name="description" content="AuthMan Free is authentication/password protection and membership management system written in PHP and licensed under the GNU GPL. It uses .htpasswd and .htaccess files to protect any web directory. Installation is easy and programming knowledge does not required." />
  5152. <?php if ($basePath != '') { echo " <base href=\"" . $basePath . "\" />\n"; } ?>
  5153. <link rel="stylesheet" href="<?php echo $basePath ?>authman.css" type="text/css" />
  5154. <link rel="shortcut icon" href="<?php echo $basePath ?>images/favicon.ico" type="image/x-icon" />
  5155. <script type="text/javascript" src="<?php echo $basePath ?>prototype.js" xml:space="preserve"></script>
  5156. <?php
  5157. if ($am->hasFeature('tinymcejs')) {
  5158. $tinymceUri = $am->getUrlByType('tinymcejs');
  5159. echo ' <script type="text/javascript" src="' . $tinymceUri . '" xml:space="preserve"></script>';
  5160. echo "\n";
  5161. }
  5162. ?>
  5163. <script language="Javascript" type="text/javascript" xml:space="preserve">
  5164. //<![CDATA[
  5165. <?php
  5166. /**
  5167. * Get Javascript Code
  5168. *
  5169. * @return string
  5170. *
  5171. */
  5172. function getJavascript()
  5173. {
  5174. global $am;
  5175. list($admin) = $am->getRecordsByType('authadminfile', null, 1, 0);
  5176. ?>// general js
  5177. function mainCleanMessage()
  5178. {
  5179. $('mainmessage').innerHTML = '';
  5180. }
  5181. function mainShowMessage( text )
  5182. {
  5183. $('mainmessage').innerHTML = text;
  5184. setTimeout( 'mainCleanMessage();', 5000 );
  5185. }
  5186. function getRandomNum(lbound, ubound) {
  5187. return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
  5188. }
  5189. function getRandomChar(number, lower) {
  5190. var numberChars = "0123456789";
  5191. var lowerChars = "abcdefghijklmnopqrstuvwxyz";
  5192. var charSet = '';
  5193. if (number == true)
  5194. charSet += numberChars;
  5195. if (lower == true)
  5196. charSet += lowerChars;
  5197. return charSet.charAt(getRandomNum(0, charSet.length));
  5198. }
  5199. function mainGeneratePassword( fname )
  5200. {
  5201. var newPass = getRandomChar(false, true);
  5202. for (var idx = 1; idx < 8; ++idx)
  5203. newPass = newPass + getRandomChar(true, true);
  5204. $($(fname + '_form').password).value = newPass;
  5205. }
  5206. function mainGeneratePassword2( fname )
  5207. {
  5208. var newPass = getRandomChar(false, true);
  5209. for (var idx = 1; idx < 8; ++idx)
  5210. newPass = newPass + getRandomChar(true, true);
  5211. $($(fname).password).value = newPass;
  5212. }
  5213. function fixAction( code ) {
  5214. new Ajax.Updater('fixaction_'+code, 'index.php?page=ajax&action=fix&errno='+code);
  5215. }
  5216. function mainCheckUsername2( fname )
  5217. {
  5218. var uname = $F( $(fname).username );
  5219. if (uname == "") {
  5220. alert("<?php echo $am->W('EMPTYUSERNAME') ?>");
  5221. return;
  5222. }
  5223. var msg = $( fname + '_checkusername' );
  5224. var requrl = 'index.php?page=users&action=checkusername&username='+uname;
  5225. var req = new Ajax.Request( requrl,
  5226. {
  5227. method: 'get',
  5228. onLoading: function()
  5229. {
  5230. $($(fname).check).disable();
  5231. msg.update('<img src="images/loadinfo.gif"> Checking ...').style.color = 'black';
  5232. },
  5233. onSuccess: function( transport )
  5234. {
  5235. var response = transport.responseText || "no response text";
  5236. $($(fname).check).enable();
  5237. if (response == "USERFOUND") {
  5238. msg.update('<?php echo $am->E('USEREXISTS', ''); ?>').style.color = 'red';
  5239. } else {
  5240. msg.update('<?php echo $am->M('USERNAMEFREE'); ?>').style.color = 'green';
  5241. }
  5242. },
  5243. onFailure: function()
  5244. {
  5245. $($(fname).check).enable();
  5246. msg.update('<?php echo $am->E('UPDATEFAILED'); ?>').style.color = 'red';
  5247. }
  5248. }
  5249. );
  5250. return;
  5251. }
  5252. function mainOnChangeSendMail2( fname )
  5253. {
  5254. if ( $($(fname).sendmail).checked ) {
  5255. $(fname + '_showtemplate').show();
  5256. } else {
  5257. $(fname + '_showtemplate').hide();
  5258. }
  5259. }
  5260. function mainInsertAtCursor(myField, myValue) {
  5261. if (myValue == '') {
  5262. return;
  5263. }
  5264. //IE support
  5265. if (document.selection) {
  5266. try {
  5267. myField.focus();
  5268. } catch (e) { }
  5269. sel = document.selection.createRange();
  5270. sel.text = myValue;
  5271. }
  5272. //MOZILLA/NETSCAPE support
  5273. else if (myField.selectionStart || myField.selectionStart == '0') {
  5274. var startPos = myField.selectionStart;
  5275. var endPos = myField.selectionEnd;
  5276. myField.value = myField.value.substring(0, startPos)
  5277. + myValue
  5278. + myField.value.substring(endPos, myField.value.length);
  5279. } else {
  5280. myField.value += myValue;
  5281. }
  5282. }
  5283. // ----------------------------------------------------------------------------
  5284. // HOME
  5285. // ----------------------------------------------------------------------------
  5286. function homeCheckUpdate() {
  5287. var params = 'page=ajax&action=checkupdate';
  5288. var req = new Ajax.Request( 'index.php',
  5289. {
  5290. method: 'post', parameters: params,
  5291. onLoading: function()
  5292. {
  5293. $('update_loading').show();
  5294. },
  5295. onSuccess: function( transport )
  5296. {
  5297. $('update_loading').hide();
  5298. if (transport.responseText == '') {
  5299. mainShowMessage( '<div class="warning">No response</div>' );
  5300. } else {
  5301. $('update_msg').show();
  5302. $('update_msg').update( transport.responseText );
  5303. }
  5304. },
  5305. onFailure: function()
  5306. {
  5307. $('update_loading').hide();
  5308. mainShowMessage( '<div class="warning">checkiung failed</div>' );
  5309. }
  5310. });
  5311. }
  5312. function homeOnSubmitForm(fObj)
  5313. {
  5314. if (typeof fObj == 'string') {
  5315. fObj = $(fObj);
  5316. }
  5317. var fname = fObj.name;
  5318. if (fname == 'signup') {
  5319. var valid = $(fObj.username).present()
  5320. && $(fObj.realname).present()
  5321. && $(fObj.email).present();
  5322. if (!valid) {
  5323. $(fname+'_msg').update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  5324. return false;
  5325. }
  5326. $(fname+'_msg').update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5327. return true;
  5328. }
  5329. if (fname == 'adminpassword') {
  5330. var valid = $($(fname).npassword).present()
  5331. && $($(fname).npassword2).present();
  5332. if (!valid) {
  5333. $(fname+'_msg').update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  5334. return false;
  5335. }
  5336. var pass = $F($(fname).npassword);
  5337. if (pass.length < 4) {
  5338. $(fname+'_msg').update('<?php echo $am->E('PASSWORDTOOSHORT', 4) ?>').style.color = 'red';
  5339. return false;
  5340. }
  5341. var pass2 = $F($(fname).npassword2);
  5342. if (pass != pass2) {
  5343. $(fname+'_msg').update('<?php echo $am->W('PASSWORDSMISSMATCHED') ?>').style.color = 'red';
  5344. return false;
  5345. }
  5346. $(fname+'_msg').update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5347. return true;
  5348. }
  5349. return false;
  5350. }
  5351. <?php if ($am->hasFeature('magpierss')) { ?>
  5352. function homeShowNews( doShow, doSave )
  5353. {
  5354. if (doShow) {
  5355. $('home-news-content').show();
  5356. // $('home-news-hide').show();
  5357. // $('home-news-show').hide();
  5358. new Ajax.Updater('home-news-content', 'index.php?page=ajax&action=getnews');
  5359. } else {
  5360. $('home-news-content').hide();
  5361. // $('home-news-hide').hide();
  5362. // $('home-news-show').show();
  5363. }
  5364. if (!doSave) {
  5365. return false;
  5366. }
  5367. params = 'page=ajax&action=setshowmembernews&value=' + (doShow?1:0);
  5368. new Ajax.Request( 'index.php',
  5369. {
  5370. method: 'post', parameters: params,
  5371. onLoading: function() { $('news_loading').show(); },
  5372. onSuccess: function( transport ) { $('news_loading').hide(); },
  5373. onFailure: function() { $('update_loading').hide(); }
  5374. });
  5375. return false;
  5376. }
  5377. <?php } ?>
  5378. // ----------------------------------------------------------------------------
  5379. // USERS
  5380. // ----------------------------------------------------------------------------
  5381. var usersCheckUsersFlag = false;
  5382. function usersCheckUsers( fields )
  5383. {
  5384. usersCheckUsersFlag = usersCheckUsersFlag ? false : true;
  5385. $('usersList').getInputs("checkbox","usernames[]").find(function(e) {
  5386. if (usersCheckUsersFlag) {
  5387. e.writeAttribute('checked', 'checked');
  5388. } else {
  5389. e.writeAttribute('checked', null);
  5390. }
  5391. });
  5392. return;
  5393. }
  5394. function usersShowForm( fname, opt )
  5395. {
  5396. if (fname == "") {
  5397. return false;
  5398. }
  5399. if (fname == 'usersMailSel') {
  5400. fname = 'userMail';
  5401. opt = 'SELECTED';
  5402. }
  5403. if (opt == '' || opt == 'hide') {
  5404. $(fname).hide();
  5405. } else {
  5406. $(fname).show();
  5407. $(fname + '_form').onsubmit = usersOnSubmitForm;
  5408. var f = $(fname + '_form');
  5409. if (fname == 'userEdit') {
  5410. $(f.oldusername).value = opt;
  5411. } else if (fname == 'userDelete') {
  5412. $(f.username).value = opt;
  5413. } else if (fname == 'userMail') {
  5414. $(f.username).value = opt;
  5415. // set mailto field
  5416. if (opt == 'SELECTED') {
  5417. // to selected users
  5418. $mailtotext = 'Selected Users';
  5419. } else {
  5420. // to one user
  5421. $mailtotext = users[opt]["name"];
  5422. if (users[opt]["info"] != "") {
  5423. $mailtotext = users[opt]["name"];
  5424. }
  5425. $mailtotext = '&quot;' + $mailtotext +'&quot; &lt;'+ users[opt]["email"] +'&gt;';
  5426. }
  5427. $(fname + '_mailto').innerHTML = $mailtotext;
  5428. }
  5429. usersResetForm( fname );
  5430. }
  5431. var els = new Array("userEdit","userAdd","userDelete","usersDelSel","usersDelAll","userMail");
  5432. for (var i=0,len=els.length; i < len; ++i) {
  5433. if (fname != els[i])
  5434. $(els[i]).hide();
  5435. }
  5436. }
  5437. function usersOnSubmitForm()
  5438. {
  5439. var form = this.identify();
  5440. var msg = $(form + '_msg');
  5441. if (form == 'userEdit_form') {
  5442. var valid = $(this.username).present();
  5443. // sendmail -> check email address
  5444. if ( $(this.sendmail).checked ) {
  5445. valid = valid && $(this.email).present() && $F(this.template) != "";
  5446. }
  5447. if (!valid) {
  5448. msg.update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  5449. return false;
  5450. }
  5451. return true;
  5452. } // end of userEdit_form
  5453. if (form == 'userAdd_form') {
  5454. var valid = $(this.username).present() && $(this.password).present();
  5455. // sendmail -> check email address
  5456. if ( $(this.sendmail).checked ) {
  5457. valid = valid && $(this.email).present() && $F(this.template) != "";
  5458. }
  5459. if (!valid) {
  5460. msg.update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  5461. return false;
  5462. }
  5463. return true;
  5464. } // end of userAdd_form
  5465. if (form == 'userDelete_form') {
  5466. return true;
  5467. }
  5468. if (form == 'usersDelSel_form') {
  5469. var count = 0;
  5470. $('usersList').getInputs("checkbox","usernames[]").find(function(e) {
  5471. if (e.checked) {
  5472. count++;
  5473. }
  5474. });
  5475. if (count < 1) {
  5476. alert('<?php echo $am->W('SELUSERSFIRST') ?>');
  5477. return false;
  5478. }
  5479. $($('usersList').action).value = 'deleteselusers';
  5480. $('usersList').submit();
  5481. return false;
  5482. }
  5483. if (form == 'usersDelAll_form') {
  5484. return true;
  5485. }
  5486. // Sending e-mail to the user, ajax
  5487. if (form == 'userMail_form') {
  5488. var valid = $(this.subject).present() && $(this.body).present();
  5489. if (!valid) {
  5490. msg.update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  5491. return false;
  5492. } else {
  5493. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5494. }
  5495. var params = $(form).serialize(false);
  5496. opt = $($(form).username).value;
  5497. if (opt == 'SELECTED') {
  5498. var count = 0;
  5499. $('usersList').getInputs("checkbox","usernames[]").find(function(e) {
  5500. if (e.checked) {
  5501. count++;
  5502. params += '&usernames[]=' + e.value;
  5503. }
  5504. });
  5505. if (count < 1) {
  5506. alert('<?php echo $am->W('SELUSERSFIRST') ?>');
  5507. return false;
  5508. }
  5509. }
  5510. var req = new Ajax.Request( 'index.php',
  5511. {
  5512. method: 'post',
  5513. parameters: params,
  5514. onLoading: function()
  5515. {
  5516. $('userMail_loading').show();
  5517. },
  5518. onSuccess: function( transport )
  5519. {
  5520. $('userMail_loading').hide();
  5521. mainShowMessage( transport.responseText || '<div class="warning">No response received</div>' );
  5522. // usersResetForm( 'userMail' );
  5523. },
  5524. onFailure: function()
  5525. {
  5526. $('userMail_loading').hide();
  5527. mainShowMessage( '<div class="warning">form failed</div>' );
  5528. }
  5529. }
  5530. );
  5531. return false;
  5532. }
  5533. return false;
  5534. }
  5535. function usersResetForm( fname )
  5536. {
  5537. var f = $(fname + '_form');
  5538. if (fname == 'userEdit') {
  5539. var opt = $F(f.oldusername);
  5540. $(f.username).value = opt;
  5541. $(f.realname).value = opt == "" ? "" : users[opt]['info'];
  5542. $(f.password).value = "";
  5543. $(f.email).value = opt == "" ? "" : users[opt]['email'];
  5544. var msg = $(fname + '_form_msg');
  5545. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5546. } else if (fname == 'userAdd') {
  5547. $(f.username).value = "";
  5548. $(f.realname).value = "";
  5549. $(f.email).value = "";
  5550. // auto generate new password
  5551. mainGeneratePassword( fname );
  5552. $(f.check).enable();
  5553. $(fname + '_checkUsername').innerHTML = '';
  5554. var msg = $(fname + '_form_msg');
  5555. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5556. } else if (fname == 'userDelete') {
  5557. // nothing to do
  5558. } else if (fname == 'usersDelSel') {
  5559. // nothing to do
  5560. } else if (fname == 'usersDelAll') {
  5561. // nothing to do
  5562. } else if (fname == 'userMail') {
  5563. // set values (remove controls)
  5564. <?php if ($am->hasFeature('tinymcejs')) { ?>
  5565. if (tinyMCE.getInstanceById(fname+'_body') != null) {
  5566. tinyMCE.execCommand('mceRemoveControl', false, fname+'_body');
  5567. }
  5568. <?php } ?>
  5569. $($(fname+'_form').subject).value = '';
  5570. $($(fname+'_form').body).value = '';
  5571. // set type to plaintext
  5572. $(fname+'_form').getInputs('radio','type').find(function(e)
  5573. {
  5574. if (e.value == 'plaintext') { e.checked = true; }
  5575. });
  5576. var msg = $(fname + '_form_msg');
  5577. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5578. }
  5579. }
  5580. function usersCheckUsername( fname )
  5581. {
  5582. var f = $(fname + '_form');
  5583. if ($F(f.username) == "") {
  5584. alert("<?php echo $am->W('EMPTYUSERNAME') ?>");
  5585. return;
  5586. }
  5587. var msg = $(fname + '_checkUsername');
  5588. var requrl = 'index.php?page=users&action=checkusername&username='+$F(f.username);
  5589. var req = new Ajax.Request( requrl,
  5590. {
  5591. method: 'get',
  5592. onLoading: function()
  5593. {
  5594. $(f.check).disable();
  5595. msg.update('<img src="images/loadinfo.gif"> Checking ...').style.color = 'black';
  5596. },
  5597. onSuccess: function( transport )
  5598. {
  5599. var response = transport.responseText || "no response text";
  5600. $(f.check).enable();
  5601. if (response == "USERFOUND") {
  5602. msg.update('<?php echo $am->E('USEREXISTS', ''); ?>').style.color = 'red';
  5603. } else {
  5604. msg.update('<?php echo $am->M('USERNAMEFREE'); ?>').style.color = 'green';
  5605. }
  5606. },
  5607. onFailure: function()
  5608. {
  5609. $(f.check).enable();
  5610. msg.update('<?php echo $am->E('UPDATEFAILED'); ?>').style.color = 'red';
  5611. }
  5612. }
  5613. );
  5614. return;
  5615. }
  5616. function usersOnDeleteGroup( groupname )
  5617. {
  5618. if (!confirm("<?php echo $am->M('Q_DELETEGROUP') ?>")) {
  5619. return;
  5620. }
  5621. var url = 'index.php?page=users&groupname='+groupname+'&action=deletegroup';
  5622. document.location = url;
  5623. }
  5624. function usersOnChangeSendMail( fname )
  5625. {
  5626. var f = $(fname + '_form');
  5627. if ( $(f.sendmail).checked ) {
  5628. $(fname + '_showtemplate').show();
  5629. } else {
  5630. $(fname + '_showtemplate').hide();
  5631. }
  5632. }
  5633. // Mailing
  5634. function usersOnChangeTemplate( fname, opt )
  5635. {
  5636. var f = $(fname+'_form');
  5637. // reset select
  5638. $(fname + '_default_templateid').selected = true;
  5639. if (opt == '') {
  5640. return false;
  5641. }
  5642. // set values (remove controls)
  5643. <?php if ($am->hasFeature('tinymcejs')) { ?>
  5644. if (tinyMCE.getInstanceById(fname+'_body') != null) {
  5645. tinyMCE.execCommand('mceRemoveControl', false, fname+'_body');
  5646. }
  5647. <?php } ?>
  5648. $(f).getInputs("radio","type").find(function(e)
  5649. {
  5650. if (e.value == emailTemplates[opt]["type"]) {
  5651. e.checked = true;
  5652. }
  5653. });
  5654. $(f.subject).value = emailTemplates[opt]["subject"];
  5655. $(f.body).value = emailTemplates[opt]["contents"];
  5656. usersOnChangeTemplateType( fname );
  5657. return false;
  5658. }
  5659. // Changing html -> plaintext or plaintext -> html
  5660. function usersOnChangeTemplateType( fname )
  5661. {
  5662. <?php if (false == $am->hasFeature('tinymcejs')) { ?>
  5663. // no tiny mce found
  5664. return false;
  5665. <?php }?>
  5666. var res = $(fname+'_form').getInputs('radio','type').find(function(e){return e.checked;});
  5667. if (res == null) {
  5668. alert('No type selected');
  5669. return false;
  5670. }
  5671. var typename = $F(res);
  5672. var id = fname + '_body';
  5673. if (typename == 'html') {
  5674. if (tinyMCE.getInstanceById(id) == null) {
  5675. tinyMCE.execCommand('mceAddControl', false, id);
  5676. }
  5677. } else {
  5678. if (tinyMCE.getInstanceById(id) != null) {
  5679. tinyMCE.execCommand('mceRemoveControl', false, id);
  5680. }
  5681. }
  5682. return true;
  5683. }
  5684. // ----------------------------------------------------------------------------
  5685. // ACCESS RULES
  5686. // ----------------------------------------------------------------------------
  5687. function accessOnSubmit( fname )
  5688. {
  5689. accessListSelect( 'access_allow' );
  5690. accessListSelect( 'access_deny' );
  5691. var params = $(fname).serialize(false);
  5692. accessListDeselect( 'access_allow' );
  5693. accessListDeselect( 'access_deny' );
  5694. var req = new Ajax.Request( 'index.php', { method: 'post', parameters: params,
  5695. onLoading: function() {
  5696. $('edit_loading').show();
  5697. },
  5698. onSuccess: function( transport ) {
  5699. $('edit_loading').hide();
  5700. $('noaccessfile_msg').hide();
  5701. mainShowMessage( transport.responseText || '<div class="warning">No response</div>' );
  5702. },
  5703. onFailure: function() {
  5704. $('edit_loading').hide();
  5705. mainShowMessage( '<div class="warning">ajax updating failed</div>' );
  5706. }
  5707. });
  5708. return false;
  5709. }
  5710. function accessOnEnableErrorDocument401( fname )
  5711. {
  5712. if ($($(fname).enableerrordocument401).checked) {
  5713. $('editErrordocument401').show();
  5714. } else {
  5715. $('editErrordocument401').hide();
  5716. }
  5717. }
  5718. function accessOnDefErrorDocument401( fname )
  5719. {
  5720. if ($($(fname).deferrordocument401).checked) {
  5721. $($(fname).errordocument401).value = '<?php
  5722. echo htmlEncode($am->getUrlByType('errordocument401'),true,true)
  5723. ?>';
  5724. $($(fname).errordocument401).disable();
  5725. } else {
  5726. $($(fname).errordocument401).enable();
  5727. }
  5728. return false;
  5729. }
  5730. function accessOnDefAuthUserFile( fname )
  5731. {
  5732. if ($($(fname).defauthuserfile).checked) {
  5733. $($(fname).authuserfile).value = '<?php
  5734. echo htmlEncode($am->getDefaultFilePathByType('authuserfile'),true,true)
  5735. ?>';
  5736. $($(fname).authuserfile).disable();
  5737. } else {
  5738. $($(fname).authuserfile).enable();
  5739. }
  5740. return false;
  5741. }
  5742. // List operations
  5743. function accessListChoose( listId )
  5744. {
  5745. var editId = listId + '_edit';
  5746. var idx = $(listId).selectedIndex;
  5747. if (idx < 0) {
  5748. // $(editId).disable();
  5749. $(editId).value = '';
  5750. return;
  5751. }
  5752. // $(editId).enable();
  5753. $(editId).value = $(listId).options[idx].value;
  5754. }
  5755. function accessListSelect( listId )
  5756. {
  5757. for (var i = $(listId).options.length; i > 1; --i) {
  5758. $(listId).options[i-1].selected = true;
  5759. }
  5760. }
  5761. function accessListDeselect( listId )
  5762. {
  5763. for (var i = $(listId).options.length; i > 0; --i) {
  5764. if ($(listId).options[i-1].selected) {
  5765. $(listId).options[i-1].selected = false;
  5766. }
  5767. }
  5768. }
  5769. function accessListEdit( listId )
  5770. {
  5771. var editId = listId + '_edit';
  5772. var idx = $(listId).selectedIndex;
  5773. if ($F(editId) == '') {
  5774. alert('Enter data first');
  5775. return accessListChoose( listId );
  5776. }
  5777. if (idx <= 0) {
  5778. // adding new item
  5779. idx = $(listId).options.length;
  5780. }
  5781. $(listId).options[idx] = new Option( $F(editId), $F(editId) );
  5782. $(editId).value = '';
  5783. // $(editId).disable();
  5784. accessListDeselect( listId );
  5785. }
  5786. function accessListDelete( listId )
  5787. {
  5788. var editId = listId + '_edit';
  5789. $(editId).value = '';
  5790. // $(editId).disable();
  5791. // 0 is registered for create new item action
  5792. for (var i = $(listId).options.length; i > 0; --i) {
  5793. if (i > 1 && $(listId).options[i-1].selected) {
  5794. $(listId).options[i-1] = null;
  5795. continue;
  5796. }
  5797. if ($(listId).options[i-1].selected) {
  5798. $(listId).options[i-1].selected = false;
  5799. }
  5800. }
  5801. }
  5802. // ----------------------------------------------------------------------------
  5803. // FILES
  5804. // ----------------------------------------------------------------------------
  5805. function filesUpdateContents( filetype )
  5806. {
  5807. var params = $(filetype+'_form').serialize(false);
  5808. var req = new Ajax.Request( 'index.php', { method: 'post', parameters: params,
  5809. onLoading: function()
  5810. {
  5811. $(filetype + '_loading').show();
  5812. $(filetype + '_submit').disable();
  5813. $(filetype + '_reset').disable();
  5814. $(filetype + '_message').hide();
  5815. },
  5816. onSuccess: function( transport )
  5817. {
  5818. $(filetype + '_submit').enable();
  5819. $(filetype + '_reset').enable();
  5820. $(filetype + '_loading').hide();
  5821. mainShowMessage( transport.responseText || 'No response' );
  5822. },
  5823. onFailure: function()
  5824. {
  5825. mainShowMessage( '<div class="warning">'+filetype+': ajax updating failed</div>' );
  5826. $(filetype + '_submit').enable();
  5827. $(filetype + '_reset').enable();
  5828. $(filetype + '_loading').hide();
  5829. }
  5830. }
  5831. );
  5832. return false;
  5833. }
  5834. function filesOnChangeContents( filetype )
  5835. {
  5836. $(filetype + '_loading').hide();
  5837. $(filetype + '_submit').enable();
  5838. $(filetype + '_reset').enable();
  5839. }
  5840. function filesDownload( filetype )
  5841. {
  5842. // IE way
  5843. //var contents = escape( $(filetype+'_contents').value );
  5844. //mydoc = document.open();
  5845. //mydoc.write(contents);
  5846. //mydoc.execCommand("saveAs", true, filetype+".txt");
  5847. //mydoc.close();
  5848. document.location = 'index.php?page=files&action=downloadfile&filetype='+filetype;
  5849. }
  5850. // ----------------------------------------------------------------------------
  5851. // SETTINGS
  5852. // ----------------------------------------------------------------------------
  5853. function setsShowForm( fname, opt )
  5854. {
  5855. if (opt == '' || opt == 'hide') {
  5856. $(fname).hide();
  5857. } else {
  5858. $(fname).show();
  5859. if (fname=='editAdmin' || fname=='chooseTpl' || fname=='addTpl' || fname=='editTpl') {
  5860. setsResetForm( fname );
  5861. }
  5862. if (fname=='editAdmin' || fname=='resetProtected' || fname=='addTpl' || fname=='editTpl') {
  5863. var f = $(fname + '_form');
  5864. $(f).onsubmit = setsOnSubmitForm;
  5865. }
  5866. }
  5867. var els = new Array("editAdmin", "downFiles", "resetProtected", "prefFiles");
  5868. for (var i=0,len=els.length; i < len; ++i) {
  5869. if (fname != els[i]) {
  5870. $(els[i]).hide();
  5871. }
  5872. }
  5873. if (fname == "chooseTpl" && opt != 'hide' ||
  5874. fname == "addTpl" && opt=='hide' ||
  5875. fname == "editTpl" && opt=='hide') {
  5876. $('chooseTpl').show();
  5877. setsResetForm('chooseTpl');
  5878. } else if (fname == "addTpl" && opt!='hide') {
  5879. $('chooseTpl').show();
  5880. $('addTpl').show();
  5881. $('editTpl').hide();
  5882. } else if (fname == "editTpl" && opt!='' && opt!='hide') {
  5883. $('chooseTpl').show();
  5884. $('addTpl').hide();
  5885. $('editTpl').show();
  5886. } else {
  5887. $('chooseTpl').hide();
  5888. $('addTpl').hide();
  5889. $('editTpl').hide();
  5890. }
  5891. }
  5892. function setsResetForm( fname )
  5893. {
  5894. var f = $(fname + '_form');
  5895. if (fname == 'editAdmin') {
  5896. $(f.username).value = "<?php echo addslashes($admin['name']) ?>";
  5897. $(f.realname).value = "<?php echo addslashes($admin['info']) ?>";
  5898. $(f.password).value = "<?php echo isset($admin['pass_raw']) ? addslashes($admin['pass_raw']) : '' ?>";
  5899. $(f.email).value = "<?php echo addslashes($admin['email']) ?>";
  5900. var msg = $(fname + '_form_msg');
  5901. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5902. }
  5903. if (fname=='chooseTpl' || fname=='addTpl') {
  5904. $('chooseTpl_default').selected = true;
  5905. }
  5906. if (fname=='addTpl') {
  5907. var msg = $(fname + '_form_msg');
  5908. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  5909. setsOnChangeTemplateType( fname ) ;
  5910. }
  5911. if (fname=='editTpl') {
  5912. var cf = $('chooseTpl_form');
  5913. var opt = $(cf.templateid).value.toString();
  5914. if (opt != '') {
  5915. $(f.templateid).value = opt;
  5916. $(f.templatename).value = emailTemplates[opt]["name"];
  5917. $(f.templatesubject).value = emailTemplates[opt]["subject"];
  5918. // type
  5919. $('editTpl_form').getInputs("radio","templatetype").find(function(e)
  5920. {
  5921. if (e.value == emailTemplates[opt]["type"]) {
  5922. // e.writeAttribute('checked', 'checked');
  5923. e.checked = true;
  5924. }
  5925. });
  5926. // enable / disable delete button for system templates
  5927. if (emailTemplates[opt]['role'] == 'undefinied') {
  5928. $(f.delete_submit).enable();
  5929. } else {
  5930. $(f.delete_submit).disable();
  5931. }
  5932. <?php if ($am->hasFeature('tinymcejs')) { ?>
  5933. if (tinyMCE.getInstanceById(fname + '_templatebody') != null) {
  5934. tinyMCE.execCommand('mceRemoveControl', false, fname + '_templatebody');
  5935. }
  5936. <?php } ?>
  5937. $(fname + '_templatebody').value = emailTemplates[opt]["contents"];
  5938. setsOnChangeTemplateType( fname );
  5939. }
  5940. }
  5941. }
  5942. function setsOnSubmitForm()
  5943. {
  5944. var fname = this.identify();
  5945. if (fname == 'editAdmin_form') {
  5946. var valid = $(this.username).present();
  5947. var msg = $(fname + '_msg');
  5948. if (!valid) {
  5949. msg.update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  5950. return false;
  5951. }
  5952. return true;
  5953. }
  5954. if (fname == 'resetProtected_form') {
  5955. var params = $(fname).serialize(false);
  5956. var req = new Ajax.Request( 'index.php',
  5957. {
  5958. method: 'post',
  5959. parameters: params,
  5960. onLoading: function()
  5961. {
  5962. $('resetProtected_loading').show();
  5963. },
  5964. onSuccess: function( transport )
  5965. {
  5966. $('resetProtected_loading').hide();
  5967. mainShowMessage( transport.responseText || '<div class="warning">No response received</div>' );
  5968. },
  5969. onFailure: function()
  5970. {
  5971. $('resetProtected_loading').hide();
  5972. mainShowMessage( '<div class="warning">form updating failed</div>' );
  5973. }
  5974. }
  5975. );
  5976. return false;
  5977. }
  5978. if (fname=='addTpl_form' || fname=='editTpl_form') {
  5979. var valid = $(this.templatename).present();
  5980. var msg = $(fname + '_msg');
  5981. if (!valid) {
  5982. msg.update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  5983. return false;
  5984. }
  5985. return true;
  5986. }
  5987. return false;
  5988. }
  5989. function setsPrefFilesUpdate( filetype )
  5990. {
  5991. var params = $(filetype+'_form').serialize(false);
  5992. var req = new Ajax.Request( 'index.php',
  5993. {
  5994. method: 'post',
  5995. parameters: params,
  5996. onLoading: function()
  5997. {
  5998. $(filetype + '_loading').show();
  5999. $(filetype + '_message').hide();
  6000. },
  6001. onSuccess: function( transport )
  6002. {
  6003. $(filetype + '_loading').hide();
  6004. mainShowMessage( transport.responseText || '<div class="warning">No response received</div>' );
  6005. },
  6006. onFailure: function()
  6007. {
  6008. $(filetype + '_loading').hide();
  6009. mainShowMessage( '<div class="warning">'+filetype+': updating failed</div>' );
  6010. }
  6011. }
  6012. );
  6013. return false;
  6014. }
  6015. function setsPrefFilesDownload( filetype )
  6016. {
  6017. document.location = 'index.php?page=settings&action=downloadfile&filetype='+filetype;
  6018. }
  6019. function setsOnNewTemplate( val )
  6020. {
  6021. setsShowForm('addTpl', 'show');
  6022. }
  6023. function setsOnChangeTemplate( val )
  6024. {
  6025. if (val == '') {
  6026. setsShowForm('editTpl', 'hide');
  6027. setsShowForm('chooseTpl', 'show');
  6028. return;
  6029. }
  6030. setsShowForm('editTpl', val);
  6031. }
  6032. function setsOnChangeTemplateType( fname )
  6033. {
  6034. <?php if (false == $am->hasFeature('tinymcejs')) { ?>
  6035. // no tiny mce found
  6036. return false;
  6037. <?php }?>
  6038. var res = $(fname+'_form').getInputs('radio','templatetype').find(function(e){return e.checked;});
  6039. if (res == null) {
  6040. alert('No type selected');
  6041. return false;
  6042. }
  6043. var typename = $F(res);
  6044. var id = fname + '_templatebody';
  6045. if (typename == 'html') {
  6046. if (tinyMCE.getInstanceById(id) == null) {
  6047. tinyMCE.execCommand('mceAddControl', false, id);
  6048. }
  6049. // $(fname + '_templatevar').hide();
  6050. } else {
  6051. if (tinyMCE.getInstanceById(id) != null) {
  6052. tinyMCE.execCommand('mceRemoveControl', false, id);
  6053. }
  6054. // $(fname + '_templatevar').show();
  6055. }
  6056. return true;
  6057. }
  6058. function setsSetChooseTpl( id )
  6059. {
  6060. var f = $('chooseTpl_form');
  6061. $(f.templateid).select("option").each( function(e) {
  6062. if (e.value == id ) {
  6063. e.selected = true;
  6064. }
  6065. });
  6066. $('chooseTpl').show();
  6067. }
  6068. function setsOnDeleteTemplate()
  6069. {
  6070. if (!confirm("<?php echo $am->M('Q_DELETETEMPLATE'); ?>")) {
  6071. return false;
  6072. }
  6073. var f = $('editTpl_form');
  6074. $(f.action).value = 'deletetemplate';
  6075. return true;
  6076. }
  6077. // ----------------------------------------------------------------------------
  6078. // MEMBER
  6079. // ----------------------------------------------------------------------------
  6080. function memberOnSubmitForm( fObj )
  6081. {
  6082. if (typeof fObj == 'string') {
  6083. fObj = $(fObj);
  6084. }
  6085. var fname = fObj.name;
  6086. if (fname == 'memberEdit') {
  6087. var valid = $(fObj.realname).present() && $(fObj.email).present();
  6088. if (!valid) {
  6089. $(fname+'_msg').update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  6090. return false;
  6091. }
  6092. $(fname+'_msg').update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  6093. var params = $(fname).serialize(false);
  6094. var req = new Ajax.Request( 'index.php',
  6095. {
  6096. method: 'post',
  6097. parameters: params,
  6098. onLoading: function()
  6099. {
  6100. $(fname+'_loading').show();
  6101. },
  6102. onSuccess: function( transport )
  6103. {
  6104. $(fname+'_loading').hide();
  6105. mainShowMessage( transport.responseText || '<div class="warning">No response received</div>' );
  6106. $($(fname).password).value = '';
  6107. },
  6108. onFailure: function()
  6109. {
  6110. $(fname+'_loading').hide();
  6111. mainShowMessage( '<div class="warning">updating failed</div>' );
  6112. }
  6113. }
  6114. );
  6115. return false;
  6116. }
  6117. if (fname == 'forgot') {
  6118. var valid = $(fObj.username).present() && $(fObj.email).present();
  6119. if (!valid) {
  6120. $(fname+'_msg').update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  6121. return false;
  6122. }
  6123. $(fname+'_msg').update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  6124. return true;
  6125. }
  6126. if (fname == 'recover') {
  6127. var valid = $(fObj.username).present() && $(fObj.key).present();
  6128. if (!valid) {
  6129. $(fname+'_msg').update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  6130. return false;
  6131. }
  6132. $(fname+'_msg').update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  6133. return true;
  6134. }
  6135. return false;
  6136. }
  6137. // ----------------------------------------------------------------------------
  6138. // SUPPORT
  6139. // ----------------------------------------------------------------------------
  6140. function supportResetForm( id )
  6141. {
  6142. var fname = typeof(id) == 'object' ? id.name : id;
  6143. if (fname == 'supportRequest') {
  6144. $(fname+'_msg').update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  6145. $($(fname).subject).value = "";
  6146. $($(fname).body).value = "";
  6147. }
  6148. return false;
  6149. }
  6150. function supportOnSubmitForm(fObj)
  6151. {
  6152. if (typeof fObj == 'string') {
  6153. fObj = $(fObj);
  6154. }
  6155. var fname = fObj.name;
  6156. if (fname == 'supportRequest') {
  6157. var valid = $(fObj.subject).present() && $(fObj.body).present();
  6158. var msg = $(fname + '_msg');
  6159. if (!valid) {
  6160. msg.update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  6161. return false;
  6162. }
  6163. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  6164. var params = $(fname).serialize(false);
  6165. var req = new Ajax.Request( 'index.php',
  6166. {
  6167. method: 'post',
  6168. parameters: params,
  6169. onLoading: function()
  6170. {
  6171. $(fname+'_loading').show();
  6172. },
  6173. onSuccess: function( transport )
  6174. {
  6175. $(fname+'_loading').hide();
  6176. mainShowMessage( transport.responseText || '<div class="warning">No response received</div>' );
  6177. supportResetForm( fname );
  6178. },
  6179. onFailure: function()
  6180. {
  6181. $(fname+'_loading').hide();
  6182. mainShowMessage( '<div class="warning">updating failed</div>' );
  6183. }
  6184. }
  6185. );
  6186. return false;
  6187. }
  6188. return false;
  6189. }
  6190. // ----------------------------------------------------------------------------
  6191. // SIGNUPS
  6192. // ----------------------------------------------------------------------------
  6193. function signupsShowForm( fname, opt )
  6194. {
  6195. if (opt == '' || opt == 'hide') {
  6196. $(fname+'_container').hide();
  6197. } else {
  6198. $(fname+'_container').show();
  6199. if (fname == 'approve' || fname == 'delete') {
  6200. $($(fname).username).value = opt;
  6201. }
  6202. signupsResetForm( fname );
  6203. $(fname).onsubmit = signupsOnSubmitForm;
  6204. }
  6205. var els = new Array("approve", "delete", "deleteall", "deleteselected");
  6206. for (var i=0,len=els.length; i < len; ++i) {
  6207. if (fname != els[i]) {
  6208. $(els[i]+'_container').hide();
  6209. }
  6210. }
  6211. }
  6212. function signupsResetForm( fname )
  6213. {
  6214. if (fname == 'approve') {
  6215. var uname = $F($(fname).username);
  6216. $($(fname).realname).value = signups[uname]['info'];
  6217. $($(fname).password).value = signups[uname]['pass'];
  6218. $($(fname).email).value = signups[uname]['email'];
  6219. $(fname+'_datetime').innerHTML = signups[uname]['ts'];
  6220. $(fname+'_remoteaddr').innerHTML = signups[uname]['remoteaddr'];
  6221. $(fname+'_referer').innerHTML = signups[uname]['referer'];
  6222. var msg = $(fname + '_msg');
  6223. msg.update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  6224. }
  6225. return true;
  6226. }
  6227. function signupsOnSubmitForm( event )
  6228. {
  6229. if (typeof event == 'string') {
  6230. fObj = $(fObj);
  6231. } else {
  6232. fObj = this;
  6233. }
  6234. var fname = fObj.identify();
  6235. if (fname == 'delete' || fname == 'deleteall') {
  6236. return true;
  6237. }
  6238. if (fname == 'deleteselected') {
  6239. var count = 0;
  6240. $('usersList').getInputs("checkbox","usernames[]").find(function(e) {
  6241. if (e.checked) {
  6242. count++;
  6243. }
  6244. });
  6245. if (count < 1) {
  6246. alert('<?php echo $am->W('SELUSERSFIRST') ?>');
  6247. return false;
  6248. }
  6249. $($('usersList').action).value = 'deleteselected';
  6250. $('usersList').submit();
  6251. return false;
  6252. }
  6253. if (fname == 'approve') {
  6254. var valid = $($(fname).username).present() && $($(fname).password).present();
  6255. if (!valid) {
  6256. $(fname+'_msg').update('<?php echo $am->W('FILLOUTALL') ?>').style.color = 'red';
  6257. return false;
  6258. }
  6259. $(fname+'_msg').update('<?php echo $am->M('FILLFIELDS'); ?>').style.color = 'black';
  6260. return true;
  6261. }
  6262. return false;
  6263. }
  6264. <?php
  6265. }
  6266. /**
  6267. * Return Javascript Array
  6268. *
  6269. * @param $string $type
  6270. * @return $string
  6271. */
  6272. function getJsArray( $type )
  6273. {
  6274. global $am;
  6275. $s = '// JS code: ' . $type . "\n";
  6276. if ($type == 'emailTemplates') {
  6277. $tplsArray = $am->getTemplates();
  6278. $s .= "var emailTemplates = new Array();\n";
  6279. foreach ($tplsArray as $id=>$tpl) {
  6280. $id = addslashes($id);
  6281. $s .= "emailTemplates[\"$id\"] = new Array();\n";
  6282. foreach ($tpl as $k=>$v) {
  6283. $v = $v != '' ? addslashes($v) : '';
  6284. $v = preg_replace("/(\n|\r\n)/", "\\n", $v);
  6285. $s .= " emailTemplates[\"$id\"][\"$k\"] = \"$v\";\n";
  6286. }
  6287. }
  6288. }
  6289. return $s;
  6290. }
  6291. // end of js
  6292. getJavascript();
  6293. ?>
  6294. //]]>
  6295. </script>
  6296. </head>
  6297. <body>
  6298. <div id="wrapper">
  6299. <?php
  6300. if ($am->isAuthenticated()) {
  6301. $user = $am->getAuthenticatedUser();
  6302. $info = isset($user['info']) && $user['info'] != '' ? $user['info'] : $user['name'];
  6303. echo '<div id="headermember">';
  6304. echo $am->M('LOGGEDAS', $info) . ', ';
  6305. echo '<a href="http://fakeuser:fakepass@roster.biosupport.se/logout/index.php">' . $am->M('CLICKHERE') . '</a> ';
  6306. echo $am->M('TOLOGOUT');
  6307. echo '</div>';
  6308. }
  6309. ?>
  6310. <div id="header">
  6311. <div id="site_logo"> AuthMan <span class="high">Free</span> </div>
  6312. <!-- <div id="languages"><a href="">How to change language</a></div> -->
  6313. </div>
  6314. <div id="content">
  6315. <?php
  6316. if ($am->isDemo()) {
  6317. print '<div id="demomessage">'.$am->M('NOTES_DEMOMODE').'</div>';
  6318. }
  6319. }
  6320. /**
  6321. * Shows footer
  6322. *
  6323. * @return void
  6324. */
  6325. function web_footer()
  6326. {
  6327. ?>
  6328. </div> <!-- end of content div -->
  6329. <div id="footer">Powered by <a href="http://www.authman.com">AuthMan Free</a> &copy; 2008 Authman.com. All rights reserved.</div>
  6330. </body>
  6331. </html>
  6332. <?php
  6333. }
  6334. /**
  6335. * Shows main menu
  6336. *
  6337. * @return void
  6338. */
  6339. function web_menu()
  6340. {
  6341. global $am;
  6342. echo '<div id="lefty"><ul>';
  6343. echo '<li><a href="index.php?page=home">' . $am->M('MENU_HOME') .'</a></li>';
  6344. if (!$am->isAuthenticated()) {
  6345. echo '<li><a href="index.php?page=login">' . $am->M('MENU_LOGIN') .'</a></li>';
  6346. if ($am->getConfigValue('allowsignup')) {
  6347. echo '<li><a href="index.php?page=signup">' . $am->M('MENU_SIGNUP') .'</a></li>'; }
  6348. }
  6349. if ($am->isAuthenticated()) {
  6350. if (!$am->isAdmin()) {
  6351. echo '<li><a href="index.php?page=edit">' . $am->M('MENU_MEMBEREDIT') . '</a></li>';
  6352. echo '<li><a href="index.php?page=remove">' . $am->M('MENU_MEMBERDELETE') . '</a></li>';
  6353. }
  6354. }
  6355. if ($am->isAdmin()) {
  6356. echo '<li><a href="index.php?page=access">' . $am->M('MENU_ACCESS') . '</a></li>';
  6357. echo '<li><a href="index.php?page=users">' . $am->M('MENU_USERS') . '</a></li>';
  6358. echo '<li><a href="index.php?page=files">' . $am->M('MENU_FILES') . '</a></li>';
  6359. // echo '<li><a href="index.php?page=mailing">' . $am->M('MENU_MAILING') . '</a></li>';
  6360. echo '<li><a href="index.php?page=settings">' . $am->M('MENU_SETTINGS') . '</a></li>';
  6361. }
  6362. if ($am->isAuthenticated()) {
  6363. echo '<li><a href="index.php?page=support">' . $am->M('MENU_SUPPORT') . '</a></li>';
  6364. if (!$am->isAdmin()) {
  6365. echo '<li><a href="http://fakeuser:fakepass@roster.biosupport.se/logout/index.php">' . $am->M('MENU_LOGOUT') . '</a></li>';
  6366. }
  6367. }
  6368. echo '</ul></div>';
  6369. }
  6370. function fmt_message( $msg )
  6371. {
  6372. if (!isset($msg)) {
  6373. return false;
  6374. }
  6375. $sout = '';
  6376. foreach (split("[\r\n\t ]+", $msg) as $s) {
  6377. if (strlen($s) > 30) {
  6378. if (substr($s,0,1)=='/') {
  6379. $ss = strstr( substr($s,-40), '/' );
  6380. if ($ss == false || strlen($ss) < 10) {
  6381. $s = '<u>...</u>' . substr($s, -30);
  6382. } else {
  6383. $s = '<u>...</u>' . $ss;
  6384. }
  6385. } else if (substr($s,1,2)==':\\') {
  6386. $ss = strstr( substr($s,-40), '\\' );
  6387. if ($ss == false || strlen($ss) < 10) {
  6388. $s = '<u>...</u>' . substr($s, -30);
  6389. } else {
  6390. $s = '<u>...</u>' . $ss;
  6391. }
  6392. } else {
  6393. $s = substr($s, 0, 30) . '<u>.</u>';
  6394. }
  6395. }
  6396. $sout .= ' ' . $s;
  6397. }
  6398. return $sout;
  6399. }
  6400. function web_message( $msg, $err )
  6401. {
  6402. print '<div id="mainmessage">';
  6403. $count = 0;
  6404. if (isset($msg)) {
  6405. if (!is_array($msg)) {
  6406. $msg = array( $msg );
  6407. }
  6408. foreach($msg as $text) {
  6409. if (isset($text)) {
  6410. print '<div class="message">' . fmt_message($text) . '</div>';
  6411. $count++;
  6412. }
  6413. }
  6414. }
  6415. if (isset($err)) {
  6416. if (!is_array($err)) {
  6417. $err= array( $err);
  6418. }
  6419. foreach($err as $text) {
  6420. if (isset($text)) {
  6421. print '<div class="warning">' . fmt_message($text) . '</div>';
  6422. $count++;
  6423. }
  6424. }
  6425. }
  6426. print '</div>';
  6427. if ($count) {
  6428. print "\n<script type=\"text/javascript\" xml:space=\"preserve\">\n//<![CDATA[\n";
  6429. print "setTimeout(\"mainCleanMessage();\",5000);";
  6430. print "//]]>\n</script>\n";
  6431. }
  6432. }
  6433. ################################################################################
  6434. function web_stepper( $prefixurl, $total, $limit=10, $page=1 )
  6435. {
  6436. global $am;
  6437. if (empty($limit)) {
  6438. $total_pages = 1;
  6439. $page = 1;
  6440. $last = $total;
  6441. $offset = 0;
  6442. } else {
  6443. $total_pages = ceil( $total / $limit );
  6444. if ($total_pages < 1)
  6445. $total_pages = 1;
  6446. if ($page > $total_pages)
  6447. $page = $total_pages;
  6448. $last = $page * $limit;
  6449. if ($last > $total)
  6450. $last = $total;
  6451. $offset = ($page-1) * $limit;
  6452. if ($offset > $last)
  6453. $offset = $last;
  6454. }
  6455. print '<div class="stepper">';
  6456. // Showing N-N of N Records <select> per page
  6457. print '<div class="pageinfo">';
  6458. print $am->M('STEPPER', ($total > 0 ? $offset+1 : 0), $last, $total);
  6459. echo ' ' . $am->M('WITH') . ' ';
  6460. $values = array(10=>10, 20=>20, 50=>50, '< all >'=>999999);
  6461. print "<select id=\"limit\" name=\"limit\" onChange=\"document.location='".$prefixurl."p=1&limit='+\$F($(limit));\">\n";
  6462. foreach($values as $t=>$i) {
  6463. printf(" <option value=\"%d\"%s>%s</option>\n", $i, ($limit == $i ? ' selected=selected' : ''), $t);
  6464. }
  6465. print "</select>" . $am->M('RECORDSPERPAGE');
  6466. print '</div>';
  6467. // 1 2 3 ...
  6468. print '<div class="pages">';
  6469. if ($page > 1)
  6470. printf('<a href="%sp=%d">%s</a>', $prefixurl, $page-1, '&lt;');
  6471. $prev_p = null;
  6472. for ($p = 1; $p <= $total_pages; $p++) {
  6473. if ($p == $page) {
  6474. printf('<a class="active" href="%sp=%d">%d</a>', $prefixurl, $p, $p);
  6475. $prev_p = $p;
  6476. continue;
  6477. }
  6478. if ($p<3 || $p > $total_pages-2 || $p > $page-2 && $p < $page+2) {
  6479. printf('<a href="%sp=%d">%d</a>', $prefixurl, $p, $p);
  6480. $prev_p = $p;
  6481. continue;
  6482. }
  6483. if ($prev_p) // && $prev_p+1 != $p)
  6484. {
  6485. print '<span>...</span>';
  6486. $prev_p = null;
  6487. }
  6488. }
  6489. if ($page < $total_pages)
  6490. printf('<a href="%sp=%d">%s</a>', $prefixurl, $page+1, '&gt;');
  6491. print '</div>';
  6492. print '</div>';
  6493. }
  6494. /**
  6495. * Header redirect wrapper
  6496. *
  6497. * @param string $url
  6498. * @param int $time default 3
  6499. * @param string $message
  6500. * @return void
  6501. */
  6502. function redirect_header($url, $time = 3, $message = '')
  6503. {
  6504. define("_IFNOTRELOAD","If the page does not automatically reload, please click <a href='%s'>here</a>");
  6505. if (!defined("ENT_QUOTES")) {
  6506. define("ENT_QUOTES", 3);
  6507. }
  6508. $url = preg_replace("/&amp;/i", '&', htmlspecialchars($url, ENT_QUOTES));
  6509. $headers = array(
  6510. '<meta http-equiv="Refresh" content="'.$time.'; url='.$url.'" />'
  6511. );
  6512. web_header( 'REDIRECT MESSAGE', null, $headers );
  6513. echo '<div id="righty">'; // righty
  6514. echo '<div align="center">
  6515. <div class="redirect">
  6516. <span>'.$message.'</span>
  6517. <hr />
  6518. <p>'.sprintf(_IFNOTRELOAD, $url).'</p>
  6519. </div>
  6520. </div>';
  6521. echo '</div>'; // righty
  6522. web_footer();
  6523. exit();
  6524. }
  6525. ################################################################################
  6526. function htmlDecode( $val, $addSlashes=false )
  6527. {
  6528. $val = trim($val);
  6529. $val = @html_entity_decode($val, ENT_COMPAT, 'UTF-8');
  6530. if ($addSlashes) {
  6531. $val = addslashes($val);
  6532. }
  6533. return $val;
  6534. }
  6535. function htmlEncode( $val, $addSlashes=false, $quoteBackSlashes=false )
  6536. {
  6537. $val = @htmlentities($val, ENT_COMPAT, 'UTF-8');
  6538. if ($addSlashes) {
  6539. $val = addSlashes($val);
  6540. }
  6541. if ($quoteBackSlashes) {
  6542. $val = preg_replace('/[\\\]/', '\\\\', $val);
  6543. }
  6544. return $val;
  6545. }
  6546. /**
  6547. * Return true if there is variable with given name
  6548. *
  6549. * @param string $name
  6550. * @return bool
  6551. */
  6552. function hasParam( $name )
  6553. {
  6554. if (array_key_exists($name, $_GET)) {
  6555. return true;
  6556. }
  6557. if (array_key_exists($name, $_POST)) {
  6558. return true;
  6559. }
  6560. return false;
  6561. }
  6562. /**
  6563. * Return GET or POST variable.
  6564. *
  6565. * @param string $name
  6566. * @param string $default
  6567. * @param mixed $filters
  6568. * @return mixed
  6569. */
  6570. function getParam( $name, $default=null, $filters=array() )
  6571. {
  6572. global $am;
  6573. $val = null;
  6574. if (array_key_exists($name, $_POST)) {
  6575. $val = $_POST[$name];
  6576. } else if (array_key_exists($name, $_GET)) {
  6577. $val = $_GET[$name];
  6578. }
  6579. if (!isset($val)) {
  6580. return addslashes($default);
  6581. }
  6582. if (is_array($val)) {
  6583. foreach( $val as $k=>$v ) {
  6584. $val[$k] = get_magic_quotes_gpc() ? stripslashes($v) : $v;
  6585. }
  6586. } else {
  6587. $val = get_magic_quotes_gpc() ? stripslashes($val) : $val;
  6588. }
  6589. if (!is_array($filters)) {
  6590. $filters = array($filters);
  6591. }
  6592. $realFilters = array();
  6593. foreach($filters as $f) {
  6594. if ($f == 'field') {
  6595. $realFilters[] = 'trim';
  6596. $realFilters[] = '_htmldecode';
  6597. $realFilters[] = 'strip_tags';
  6598. $realFilters[] = 'not2dots';
  6599. $realFilters[] = 'max255';
  6600. } elseif ($f == 'username') {
  6601. $realFilters[] = 'trim';
  6602. $realFilters[] = '_htmldecode';
  6603. $realFilters[] = 'strip_tags';
  6604. $realFilters[] = 'not2dots';
  6605. $realFilters[] = 'strtolower';
  6606. $realFilters[] = 'max255';
  6607. } elseif ($f == 'password') {
  6608. $realFilters[] = 'trim';
  6609. $realFilters[] = 'max255';
  6610. } elseif ($f == 'email') {
  6611. $realFilters[] = 'trim';
  6612. $realFilters[] = '_htmldecode';
  6613. $realFilters[] = 'strip_tags';
  6614. $realFilters[] = 'not2dots';
  6615. $realFilters[] = 'max255';
  6616. } elseif ($f == 'subject') {
  6617. $realFilters[] = 'trim';
  6618. $realFilters[] = 'strip_tags';
  6619. $realFilters[] = 'htmlspecialchars_decode';
  6620. $realFilters[] = 'max255';
  6621. } elseif ($f == 'attr' || $f == 'attribute') {
  6622. $realFilters[] = 'strtolower';
  6623. } elseif ($f == 'htmlcode') {
  6624. $realFilters[] = 'trim';
  6625. $realFilters[] = '_htmldecode';
  6626. } elseif ($f == 'url') {
  6627. $realFilters[] = 'trim';
  6628. $realFilters[] = '_htmldecode';
  6629. $realFilters[] = 'strip_tags';
  6630. } elseif ($f == 'filepath') {
  6631. $realFilters[] = 'trim';
  6632. $realFilters[] = '_htmldecode';
  6633. $realFilters[] = 'strip_tags';
  6634. $realFilters[] = '_path';
  6635. } else {
  6636. $realFilters[] = $f;
  6637. }
  6638. }
  6639. foreach($realFilters as $fname) {
  6640. if ($fname == 'alpha') {
  6641. $val = preg_replace('/[^a-z\_]+/i', '', $val);
  6642. } else if ($fname == 'alnum') {
  6643. $val = preg_replace('/[^a-z0-9\_]+/i', '', $val);
  6644. } else if ($fname == 'not2dots') {
  6645. $val = preg_replace('/[:]+/i', '', $val);
  6646. } else if ($fname == '_htmldecode') {
  6647. if (is_array($val)) {
  6648. foreach ($val as $k=>$v) {
  6649. $val[$k] = @html_entity_decode($v, ENT_COMPAT, 'UTF-8');
  6650. }
  6651. } else {
  6652. $val = @html_entity_decode($val, ENT_COMPAT, 'UTF-8');
  6653. }
  6654. } else if ($fname == '_path') {
  6655. $val = $am->getNormalizedPath( $val );
  6656. } else if ($fname == 'max255') {
  6657. if (is_array($val)) {
  6658. foreach ($val as $k=>$v) {
  6659. $val[$k] = substr($v, 0, 255);
  6660. }
  6661. } else {
  6662. $val = substr($val, 0, 255);
  6663. }
  6664. } else if ($fname == 'max4k') {
  6665. if (is_array($val)) {
  6666. foreach ($val as $k=>$v) {
  6667. $val[$k] = substr($v, 0, 4096);
  6668. }
  6669. } else {
  6670. $val = substr($val, 0, 4096);
  6671. }
  6672. } else if (function_exists($fname)) {
  6673. if (!is_array($val)) {
  6674. $val = call_user_func($fname, $val);
  6675. } else {
  6676. foreach($val as $k=>$v) {
  6677. $val[$k] = call_user_func($fname, $v);
  6678. }
  6679. }
  6680. }
  6681. }
  6682. return $val;
  6683. }
  6684. ################################################################################
  6685. function htmlSubmit( $id, $opts=null )
  6686. {
  6687. global $am;
  6688. return htmlInput( 'submit', $id, $am->M('SAVECHANGES'), $opts );
  6689. }
  6690. function htmlReset( $id, $opts=null )
  6691. {
  6692. global $am;
  6693. return htmlInput( 'reset', $id, $am->M('RESET'), $opts );
  6694. }
  6695. function htmlInput( $type, $id, $title, $opts=null, $disableInDemo=false )
  6696. {
  6697. global $am;
  6698. $html = '<input type="' . $type . '"';
  6699. if ($am->isDemo() && $disableInDemo) {
  6700. $html .= ' disabled ';
  6701. }
  6702. if (isset($opts)) {
  6703. $html .= ' ' . $opts;
  6704. }
  6705. $html .= " id=\"$id\" value=\"$title\" />";
  6706. return $html;
  6707. }
  6708. function htmlSelectTemplateVar( $dst )
  6709. {
  6710. global $am;
  6711. echo '<select onchange="javascript:mainInsertAtCursor($(\''.$dst.'\'), this.value); $(\''.$dst.'_deftvar\').selected=true;">
  6712. <option id="'.$dst.'_deftvar" value="">' . $am->M('SELECTONE') . '</option>
  6713. <option value="%DATETIME%">Current Date/Time (GMT)</option>
  6714. <option value="%REMOTEADDR%">Remote IP address</option>
  6715. <option value="%PROTECTEDURL%">URL of protected directory</option>
  6716. <option value="%MEMBERURL%">Member URL</option>
  6717. <option value="">-------| User Variables |-------</option>
  6718. <option value="%USERNAME%">Username</option>
  6719. <option value="%USERREALNAME%">Real name</option>
  6720. <option value="%USERPASSWORD%">User\'s password</option>
  6721. <option value="%USERMAIL%">E-mail address of the user</option>
  6722. <option value="">-------| Special variables |-------</option>
  6723. <option value="%USERREQUESTSUBJECT%">Request Subject (contact form)</option>
  6724. <option value="%USERREQUESTBODY%">Request Body (contact form)</option>
  6725. <option value="%USERHASHOFPASS%">Used in password recovery form</option>
  6726. </select>';
  6727. return;
  6728. }
  6729. ################################################################################
  6730. function utils_strip_path( $path, $dirsep = DIRECTORY_SEPARATOR )
  6731. {
  6732. $path = str_replace('\\', '/', $path);
  6733. $path = preg_replace('/\/\.+/', '', $path );
  6734. if ($dirsep != '/') {
  6735. $path = str_replace('/', $dirsep, $path);
  6736. }
  6737. return $path;
  6738. }
  6739. ##############################################################################
  6740. header('Pragma: public');
  6741. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  6742. header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
  6743. header('Cache-Control: no-store, no-cache, must-revalidate');
  6744. header('Cache-Control: pre-check=0, post-check=0, max-age=0');
  6745. header('Pragma: no-cache');
  6746. session_start();
  6747. global $am;
  6748. $am = new Authman();
  6749. $page = getParam('page', 'home', 'attribute');
  6750. $fn = 'showPage_'.$page;
  6751. if (function_exists($fn)) {
  6752. call_user_func( $fn );
  6753. } else {
  6754. showPage_404();
  6755. }
  6756. exit;
  6757. /* the end of the file */