diff options
author | Gunnar Wrobel <wrobel@pardus.de> | 2010-09-13 12:30:56 (GMT) |
---|---|---|
committer | Gunnar Wrobel <wrobel@pardus.de> | 2010-09-13 12:30:56 (GMT) |
commit | 42235552b8c245a9d5723909f719ff56c3c343ed (patch) | |
tree | bb7a47fca8a136447f17684724c226b214f63c66 /lib | |
parent | c7f24760d5043330a97d682db412f9f3155ac6be (diff) | |
download | kolab-webadmin-42235552b8c245a9d5723909f719ff56c3c343ed.tar.gz |
Avoid the use of two include directories.
This is the major change in order to get rid of the dist_conf approach for the web admin:
This moves all includes into the KolabAdmin/include directory. The top directory
KolabAdmin needs to be in the include path. Should be a sane setup for all distributions.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/KolabAdmin/include/Sieve.php | 1168 | ||||
-rw-r--r-- | lib/KolabAdmin/include/auth.class.php | 176 | ||||
-rw-r--r-- | lib/KolabAdmin/include/authenticate.php | 35 | ||||
-rw-r--r-- | lib/KolabAdmin/include/debug.php | 79 | ||||
-rw-r--r-- | lib/KolabAdmin/include/form.class.php | 489 | ||||
-rw-r--r-- | lib/KolabAdmin/include/headers.php | 36 | ||||
-rw-r--r-- | lib/KolabAdmin/include/ldap.class.php | 54 | ||||
-rw-r--r-- | lib/KolabAdmin/include/locale.php | 124 | ||||
-rw-r--r-- | lib/KolabAdmin/include/menu.php | 140 | ||||
-rw-r--r-- | lib/KolabAdmin/include/mysmarty.php | 92 | ||||
-rw-r--r-- | lib/KolabAdmin/include/passwd.php | 47 |
11 files changed, 2440 insertions, 0 deletions
diff --git a/lib/KolabAdmin/include/Sieve.php b/lib/KolabAdmin/include/Sieve.php new file mode 100644 index 0000000..eec1c81 --- /dev/null +++ b/lib/KolabAdmin/include/Sieve.php @@ -0,0 +1,1168 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Copyright (c) 2002-2003, Richard Heyes | +// | All rights reserved. | +// | | +// | Redistribution and use in source and binary forms, with or without | +// | modification, are permitted provided that the following conditions | +// | are met: | +// | | +// | o Redistributions of source code must retain the above copyright | +// | notice, this list of conditions and the following disclaimer. | +// | o Redistributions in binary form must reproduce the above copyright | +// | notice, this list of conditions and the following disclaimer in the | +// | documentation and/or other materials provided with the distribution.| +// | o The names of the authors may not be used to endorse or promote | +// | products derived from this software without specific prior written | +// | permission. | +// | | +// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | +// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | +// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | +// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | +// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | +// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | +// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | +// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | +// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | +// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | +// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | +// | | +// +-----------------------------------------------------------------------+ +// | Author: Richard Heyes <richard@phpguru.org> | +// | Co-Author: Damian Fernandez Sosa <damlists@cnba.uba.ar> | +// +-----------------------------------------------------------------------+ + +// Warning: This is a patched version of Net_Sieve 1.0.1 + +require_once('Net/Socket.php'); + +/** +* TODO +* +* o supportsAuthMech() +*/ + +/** +* Disconnected state +* @const NET_SIEVE_STATE_DISCONNECTED +*/ +define('NET_SIEVE_STATE_DISCONNECTED', 1, true); + +/** +* Authorisation state +* @const NET_SIEVE_STATE_AUTHORISATION +*/ +define('NET_SIEVE_STATE_AUTHORISATION', 2, true); + +/** +* Transaction state +* @const NET_SIEVE_STATE_TRANSACTION +*/ +define('NET_SIEVE_STATE_TRANSACTION', 3, true); + +/** +* A class for talking to the timsieved server which +* comes with Cyrus IMAP. the HAVESPACE +* command which appears to be broken (Cyrus 2.0.16). +* +* @author Richard Heyes <richard@php.net> +* @author Damian Fernandez Sosa <damlists@cnba.uba.ar> +* @access public +* @version 0.9.1 +* @package Net_Sieve +*/ + +class Net_Sieve +{ + /** + * The socket object + * @var object + */ + var $_sock; + + /** + * Info about the connect + * @var array + */ + var $_data; + + /** + * Current state of the connection + * @var integer + */ + var $_state; + + /** + * Constructor error is any + * @var object + */ + var $_error; + + + /** + * To allow class debuging + * @var boolean + */ + var $_debug = false; + + + /** + * The auth methods this class support + * @var array + */ + + var $supportedAuthMethods=array('DIGEST-MD5', 'CRAM-MD5', 'PLAIN' , 'LOGIN'); + //if you have problems using DIGEST-MD5 authentication please commente the line above and discomment the following line + //var $supportedAuthMethods=array( 'CRAM-MD5', 'PLAIN' , 'LOGIN'); + + //var $supportedAuthMethods=array( 'PLAIN' , 'LOGIN'); + + + /** + * The auth methods this class support + * @var array + */ + var $supportedSASLAuthMethods=array('DIGEST-MD5', 'CRAM-MD5'); + + + + /** + * Handles posible referral loops + * @var array + */ + var $_maxReferralCount = 15; + + /** + * Constructor + * Sets up the object, connects to the server and logs in. stores + * any generated error in $this->_error, which can be retrieved + * using the getError() method. + * + * @access public + * @param string $user Login username + * @param string $pass Login password + * @param string $host Hostname of server + * @param string $port Port of server + * @param string $logintype Type of login to perform + * @param string $euser Effective User (if $user=admin, login as $euser) + */ + function Net_Sieve($user = null , $pass = null , $host = 'localhost', $port = 2000, $logintype = '', $euser = '', $debug = false) + { + $this->_state = NET_SIEVE_STATE_DISCONNECTED; + $this->_data['user'] = $user; + $this->_data['pass'] = $pass; + $this->_data['host'] = $host; + $this->_data['port'] = $port; + $this->_data['logintype'] = $logintype; + $this->_data['euser'] = $euser; + $this->_sock = &new Net_Socket(); + $this->_debug = $debug; + /* + * Include the Auth_SASL package. If the package is not available, + * we disable the authentication methods that depend upon it. + */ + if ((@include_once 'Auth/SASL.php') === false) { + if($this->_debug){ + echo "AUTH_SASL NOT PRESENT!\n"; + } + foreach($this->supportedSASLAuthMethods as $SASLMethod){ + $pos = array_search( $SASLMethod, $this->supportedAuthMethods ); + if($this->_debug){ + echo "DISABLING METHOD $SASLMethod\n"; + } + unset($this->supportedAuthMethods[$pos]); + } + } + if( ($user != null) && ($pass != null) ){ + $this->_error = $this->_handleConnectAndLogin(); + } + } + + + + /** + * Handles the errors the class can find + * on the server + * + * @access private + * @return PEAR_Error + */ + + function _raiseError($msg, $code) + { + include_once 'PEAR.php'; + return PEAR::raiseError($msg, $code); + } + + + + + + /** + * Handles connect and login. + * on the server + * + * @access private + * @return mixed Indexed array of scriptnames or PEAR_Error on failure + */ + function _handleConnectAndLogin(){ + if (PEAR::isError($res = $this->connect($this->_data['host'] , $this->_data['port'] ))) { + return $res; + } + if (PEAR::isError($res = $this->login($this->_data['user'], $this->_data['pass'], $this->_data['logintype'] , $this->_data['euser'] ) ) ) { + return $res; + } + return true; + + } + + + + + /** + * Returns an indexed array of scripts currently + * on the server + * + * @access public + * @return mixed Indexed array of scriptnames or PEAR_Error on failure + */ + function listScripts() + { + if (is_array($scripts = $this->_cmdListScripts())) { + $this->_active = $scripts[1]; + return $scripts[0]; + } else { + return $scripts; + } + } + + /** + * Returns the active script + * + * @access public + * @return mixed The active scriptname or PEAR_Error on failure + */ + function getActive() + { + if (!empty($this->_active)) { + return $this->_active; + + } elseif (is_array($scripts = $this->_cmdListScripts())) { + $this->_active = $scripts[1]; + return $scripts[1]; + } + } + + /** + * Sets the active script + * + * @access public + * @param string $scriptname The name of the script to be set as active + * @return mixed true on success, PEAR_Error on failure + */ + function setActive($scriptname) + { + return $this->_cmdSetActive($scriptname); + } + + /** + * Retrieves a script + * + * @access public + * @param string $scriptname The name of the script to be retrieved + * @return mixed The script on success, PEAR_Error on failure + */ + function getScript($scriptname) + { + return $this->_cmdGetScript($scriptname); + } + + /** + * Adds a script to the server + * + * @access public + * @param string $scriptname Name of the script + * @param string $script The script + * @param bool $makeactive Whether to make this the active script + * @return mixed true on success, PEAR_Error on failure + */ + function installScript($scriptname, $script, $makeactive = false) + { + if (PEAR::isError($res = $this->_cmdPutScript($scriptname, $script))) { + return $res; + + } elseif ($makeactive) { + return $this->_cmdSetActive($scriptname); + + } else { + return true; + } + } + + /** + * Removes a script from the server + * + * @access public + * @param string $scriptname Name of the script + * @return mixed True on success, PEAR_Error on failure + */ + function removeScript($scriptname) + { + return $this->_cmdDeleteScript($scriptname); + } + + /** + * Returns any error that may have been generated in the + * constructor + * + * @access public + * @return mixed False if no error, PEAR_Error otherwise + */ + function getError() + { + return PEAR::isError($this->_error) ? $this->_error : false; + } + + /** + * Handles connecting to the server and checking the + * response is valid. + * + * @access private + * @param string $host Hostname of server + * @param string $port Port of server + * @return mixed True on success, PEAR_Error otherwise + */ + function connect($host, $port) + { + if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) { + $msg='Not currently in DISCONNECTED state'; + $code=1; + return $this->_raiseError($msg,$code); + } + + if (PEAR::isError($res = $this->_sock->connect($host, $port, null, 5))) { + return $res; + } + + if(PEAR::isError($res = $this->_doCmd() )) { + $msg='Failed to connect, server said: ' . $res->getMessage(); + $code=2; + return $this->_raiseError($msg,$code); + } + // Get logon greeting/capability and parse + $this->_parseCapability($res); + $this->_state = NET_SIEVE_STATE_AUTHORISATION; + return true; + } + + /** + * Logs into server. + * + * @access public + * @param string $user Login username + * @param string $pass Login password + * @param string $logintype Type of login method to use + * @param string $euser Effective UID (perform on behalf of $euser) + * @return mixed True on success, PEAR_Error otherwise + */ + function login($user, $pass, $logintype = null , $euser = '') + { + if (NET_SIEVE_STATE_AUTHORISATION != $this->_state) { + $msg='Not currently in AUTHORISATION state'; + $code=1; + return $this->_raiseError($msg,$code); +// return PEAR::raiseError('Not currently in AUTHORISATION state'); + } + + if(PEAR::isError($res=$this->_cmdAuthenticate($user , $pass , $logintype, $euser ) ) ){ + return $res; + } +/* + if (PEAR::isError($res = $this->_doCmd() )) { + return $res; + } +*/ + $this->_state = NET_SIEVE_STATE_TRANSACTION; + return true; + } + + + + /* Handles the authentication using any known method + * + * @param string The userid to authenticate as. + * @param string The password to authenticate with. + * @param string The method to use ( if $usermethod == '' then the class chooses the best method (the stronger is the best ) ) + * @param string The effective uid to authenticate as. + * + * @return mixed string or PEAR_Error + * + * @access private + * @since 1.0 + */ + function _cmdAuthenticate($uid , $pwd , $userMethod = null , $euser = '' ) + { + + + if ( PEAR::isError( $method = $this->_getBestAuthMethod($userMethod) ) ) { + return $method; + } + switch ($method) { + case 'DIGEST-MD5': + $result = $this->_authDigest_MD5( $uid , $pwd , $euser ); + return $result; + break; + case 'CRAM-MD5': + $result = $this->_authCRAM_MD5( $uid , $pwd, $euser); + break; + case 'LOGIN': + $result = $this->_authLOGIN( $uid , $pwd , $euser ); + break; + case 'PLAIN': + $result = $this->_authPLAIN( $uid , $pwd , $euser ); + break; + default : + $result = new PEAR_Error( "$method is not a supported authentication method" ); + break; + } + + + if (PEAR::isError($res = $this->_doCmd() )) { + return $res; + } + return $res; + } + + + + + + + + + + /* Authenticates the user using the PLAIN method. + * + * @param string The userid to authenticate as. + * @param string The password to authenticate with. + * @param string The effective uid to authenticate as. + * + * @return array Returns an array containing the response + * + * @access private + * @since 1.0 + */ + function _authPLAIN($user, $pass , $euser ) + { + + if ($euser != '') { + $cmd=sprintf('AUTHENTICATE "PLAIN" "%s"', base64_encode($euser . chr(0) . $user . chr(0) . $pass ) ) ; + } else { + $cmd=sprintf('AUTHENTICATE "PLAIN" "%s"', base64_encode( chr(0) . $user . chr(0) . $pass ) ); + } + return $this->_sendCmd( $cmd ) ; + + } + + + + /* Authenticates the user using the PLAIN method. + * + * @param string The userid to authenticate as. + * @param string The password to authenticate with. + * @param string The effective uid to authenticate as. + * + * @return array Returns an array containing the response + * + * @access private + * @since 1.0 + */ + function _authLOGIN($user, $pass , $euser ) + { + $this->_sendCmd('AUTHENTICATE "LOGIN"'); + $this->_doCmd(sprintf('"%s"', base64_encode($user))); + $this->_doCmd(sprintf('"%s"', base64_encode($pass))); + + } + + + + + /* Authenticates the user using the CRAM-MD5 method. + * + * @param string The userid to authenticate as. + * @param string The password to authenticate with. + * @param string The cmdID. + * + * @return array Returns an array containing the response + * + * @access private + * @since 1.0 + */ + function _authCRAM_MD5($uid, $pwd, $euser) + { + /* + if ( PEAR::isError($error = $this->_sendCmd( 'AUTHENTICATE "CRAM-MD5"' ) ) ) { + $this->_error=$error; + return $error; + } + */ + + if ( PEAR::isError( $challenge = $this->_doCmd( 'AUTHENTICATE "CRAM-MD5"' ) ) ) { + $this->_error=challenge ; + return challenge ; + } + $challenge = base64_decode( $challenge ); + $cram = &Auth_SASL::factory('crammd5'); + $auth_str = base64_encode( $cram->getResponse( $uid , $pwd , $challenge ) ); + if ( PEAR::isError($error = $this->_sendStringResponse( $auth_str ) ) ) { + $this->_error=$error; + return $error; + } + + } + + + + /* Authenticates the user using the DIGEST-MD5 method. + * + * @param string The userid to authenticate as. + * @param string The password to authenticate with. + * @param string The efective user + * + * @return array Returns an array containing the response + * + * @access private + * @since 1.0 + */ + function _authDigest_MD5($uid, $pwd, $euser) + { + /* + if ( PEAR::isError($error = $this->_sendCmd( 'AUTHENTICATE "DIGEST-MD5"' ) ) ) { + $this->_error=$error; + return $error; + } + */ + + if ( PEAR::isError( $challenge = $this->_doCmd('AUTHENTICATE "DIGEST-MD5"') ) ) { + $this->_error=challenge ; + return challenge ; + } + $challenge = base64_decode( $challenge ); + $digest = &Auth_SASL::factory('digestmd5'); + $auth_str = base64_encode($digest->getResponse($uid, $pwd, $challenge, "localhost", "sieve" , $euser)); + + if ( PEAR::isError($error = $this->_sendStringResponse( $auth_str ) ) ) { + $this->_error=$error; + return $error; + } + +///* + + if ( PEAR::isError( $challenge = $this->_doCmd() ) ) { + $this->_error=$challenge ; + return $challenge ; + } + + if( strtoupper(substr($challenge,0,2))== 'OK' ){ + return true; + } + +//echo "CHALL:$challenge\n"; +//*/ + /* + * We don't use the protocol's third step because SIEVE doesn't allow + * subsequent authentication, so we just silently ignore it. + */ + +///* + if ( PEAR::isError($error = $this->_sendStringResponse( '' ) ) ) { + $this->_error=$error; + return $error; + } + + if (PEAR::isError($res = $this->_doCmd() )) { + return $res; + } + +//*/ + } + + + + + /** + * Removes a script from the server + * + * @access private + * @param string $scriptname Name of the script to delete + * @return mixed True on success, PEAR_Error otherwise + */ + function _cmdDeleteScript($scriptname) + { + if (NET_SIEVE_STATE_TRANSACTION != $this->_state) { + $msg='Not currently in AUTHORISATION state'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently in TRANSACTION state'); + } + if (PEAR::isError($res = $this->_doCmd(sprintf('DELETESCRIPT "%s"', $scriptname) ) )) { + return $res; + } + return true; + } + + /** + * Retrieves the contents of the named script + * + * @access private + * @param string $scriptname Name of the script to retrieve + * @return mixed The script if successful, PEAR_Error otherwise + */ + function _cmdGetScript($scriptname) + { + if (NET_SIEVE_STATE_TRANSACTION != $this->_state) { + $msg='Not currently in AUTHORISATION state'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently in TRANSACTION state'); + } + + if (PEAR::isError($res = $this->_doCmd(sprintf('GETSCRIPT "%s"', $scriptname) ) ) ) { + return $res; + } + + return preg_replace('/{[0-9]+}\r\n/', '', $res); + } + + /** + * Sets the ACTIVE script, ie the one that gets run on new mail + * by the server + * + * @access private + * @param string $scriptname The name of the script to mark as active + * @return mixed True on success, PEAR_Error otherwise + */ + function _cmdSetActive($scriptname) + { + if (NET_SIEVE_STATE_TRANSACTION != $this->_state) { + $msg='Not currently in AUTHORISATION state'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently in TRANSACTION state'); + } + + if (PEAR::isError($res = $this->_doCmd(sprintf('SETACTIVE "%s"', $scriptname) ) ) ) { + return $res; + } + + $this->_activeScript = $scriptname; + return true; + } + + /** + * Sends the LISTSCRIPTS command + * + * @access private + * @return mixed Two item array of scripts, and active script on success, + * PEAR_Error otherwise. + */ + function _cmdListScripts() + { + + if (NET_SIEVE_STATE_TRANSACTION != $this->_state) { + $msg='Not currently in AUTHORISATION state'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently in TRANSACTION state'); + } + + $scripts = array(); + $activescript = null; + + if (PEAR::isError($res = $this->_doCmd('LISTSCRIPTS'))) { + return $res; + } + + $res = explode("\r\n", $res); + + foreach ($res as $value) { + if (preg_match('/^"(.*)"( ACTIVE)?$/i', $value, $matches)) { + $scripts[] = $matches[1]; + if (!empty($matches[2])) { + $activescript = $matches[1]; + } + } + } + + return array($scripts, $activescript); + } + + /** + * Sends the PUTSCRIPT command to add a script to + * the server. + * + * @access private + * @param string $scriptname Name of the new script + * @param string $scriptdata The new script + * @return mixed True on success, PEAR_Error otherwise + */ + function _cmdPutScript($scriptname, $scriptdata) + { + if (NET_SIEVE_STATE_TRANSACTION != $this->_state) { + $msg='Not currently in TRANSACTION state'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently in TRANSACTION state'); + } + + if (PEAR::isError($res = $this->_doCmd(sprintf("PUTSCRIPT \"%s\" {%d+}\r\n%s", $scriptname, strlen($scriptdata),$scriptdata ) ))) { + return $res; + } + + return true; + } + + /** + * Sends the LOGOUT command and terminates the connection + * + * @access private + * @return mixed True on success, PEAR_Error otherwise + */ + function _cmdLogout($sendLogoutCMD=true) + { + if (NET_SIEVE_STATE_DISCONNECTED === $this->_state) { + $msg='Not currently connected'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently connected'); + } + + if($sendLogoutCMD){ + if (PEAR::isError($res = $this->_doCmd('LOGOUT'))) { + return $res; + } + } + + $this->_sock->disconnect(); + $this->_state = NET_SIEVE_STATE_DISCONNECTED; + return true; + } + + /** + * Sends the CAPABILITY command + * + * @access private + * @return mixed True on success, PEAR_Error otherwise + */ + function _cmdCapability() + { + if (NET_SIEVE_STATE_TRANSACTION != $this->_state) { + $msg='Not currently in TRANSACTION state'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently in TRANSACTION state'); + } + + if (PEAR::isError($res = $this->_doCmd('CAPABILITY'))) { + return $res; + } + $this->_parseCapability($res); + return true; + } + + + /** + * Checks if the server has space to store the script + * by the server + * + * @access public + * @param string $scriptname The name of the script to mark as active + * @return mixed True on success, PEAR_Error otherwise + */ + function haveSpace($scriptname,$quota) + { + if (NET_SIEVE_STATE_TRANSACTION != $this->_state) { + $msg='Not currently in TRANSACTION state'; + $code=1; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently in TRANSACTION state'); + } + + if (PEAR::isError($res = $this->_doCmd(sprintf('HAVESPACE "%s" %s', $scriptname, $quota) ) ) ) { + //if (PEAR::isError($res = $this->_doCmd(sprintf('HAVESPACE %d "%s"', $quota,$scriptname ) ) ) ) { + return $res; + } + + return true; + } + + + + + /** + * Parses the response from the capability command. Storesq + * the result in $this->_capability + * + * @access private + */ + function _parseCapability($data) + { + $data = preg_split('/\r?\n/', $data, -1, PREG_SPLIT_NO_EMPTY); + + for ($i = 0; $i < count($data); $i++) { + if (preg_match('/^"([a-z]+)" ("(.*)")?$/i', $data[$i], $matches)) { + switch (strtolower($matches[1])) { + case 'implementation': + $this->_capability['implementation'] = $matches[3]; + break; + + case 'sasl': + $this->_capability['sasl'] = preg_split('/\s+/', $matches[3]); + break; + + case 'sieve': + $this->_capability['extensions'] = preg_split('/\s+/', $matches[3]); + break; + + case 'starttls': + $this->_capability['starttls'] = true; + } + } + } + } + + /** + * Sends a command to the server + * + * @access private + * @param string $cmd The command to send + */ + function _sendCmd($cmd) + { + $status = $this->_sock->getStatus(); + if (PEAR::isError($status) || $status['eof']) { + return new PEAR_Error( 'Failed to write to socket: (connection lost!) ' ); + } + if ( PEAR::isError( $error = $this->_sock->write( $cmd . "\r\n" ) ) ) { + return new PEAR_Error( 'Failed to write to socket: ' . $error->getMessage() ); + } + + if( $this->_debug ){ + // C: means this data was sent by the client (this class) + echo "C:$cmd\n"; + } + return true; + + + } + + + + /** + * Sends a string response to the server + * + * @access private + * @param string $cmd The command to send + */ + function _sendStringResponse($str) + { + $response='{' . strlen($str) . "+}\r\n" . $str ; + return $this->_sendCmd($response); + } + + + + + function _recvLn() + { + $lastline=''; + if (PEAR::isError( $lastline = $this->_sock->gets( 8192 ) ) ) { + return new PEAR_Error('Failed to write to socket: ' . $lastline->getMessage() ); + } + $lastline=rtrim($lastline); + if($this->_debug){ + // S: means this data was sent by the IMAP Server + echo "S:$lastline\n" ; + } + +/* if( $lastline === '' ){ + return new PEAR_Error('Failed to receive from the socket: ' ); + } +*/ + return $lastline; + } + + + + + + /** + * Send a command and retrieves a response from the server. + * + * + * @access private + * @param string $cmd The command to send + * @return mixed Reponse string if an OK response, PEAR_Error if a NO response + */ + function _doCmd($cmd = '' ) + { + + $referralCount=0; + while($referralCount < $this->_maxReferralCount ){ + + + if($cmd != '' ){ + if(PEAR::isError($error = $this->_sendCmd($cmd) )) { + return $error; + } + } + $response = ''; + + while (true) { + if(PEAR::isError( $line=$this->_recvLn() )){ + return $line; + } + if ('ok' === strtolower(substr($line, 0, 2))) { + $response .= $line; + return rtrim($response); + + } elseif ('no' === strtolower(substr($line, 0, 2))) { + // Check for string literal error message + if (preg_match('/^no {([0-9]+)\+?}/i', $line, $matches)) { + $line .= str_replace("\r\n", ' ', $this->_sock->read($matches[1] + 2 )); + if($this->_debug){ + echo "S:$line\n"; + } + } + $msg=trim($response . substr($line, 2)); + $code=3; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError(trim($response . substr($line, 2))); + } elseif ('bye' === strtolower(substr($line, 0, 3))) { + + if(PEAR::isError($error = $this->disconnect(false) ) ){ + $msg="Can't handle bye, The error was= " . $error->getMessage() ; + $code=4; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError("Can't handle bye, The error was= " . $error->getMessage() ); + } + if (preg_match('/^bye \(referral "([^"]+)/i', $line, $matches)) { + // Check for referral, then follow it. Otherwise, carp an error. + $this->_data['host'] = $matches[1]; + if (PEAR::isError($error = $this->_handleConnectAndLogin() ) ){ + $msg="Can't follow referral to " . $this->_data['host'] . ", The error was= " . $error->getMessage() ; + $code=5; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError("Can't follow referral to " . $this->_data['host'] . ", The error was= " . $error->getMessage() ); + } + break; + // Retry the command + if(PEAR::isError($error = $this->_sendCmd($cmd) )) { + return $error; + } + continue; + } + $msg=trim($response . $line); + $code=6; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError(trim($response . $line)); + } elseif (preg_match('/^{([0-9]+)\+?}/i', $line, $matches)) { + // Matches String Responses. + $line = $this->_sock->read($matches[1] + 2 ); + if($this->_debug){ + echo "S:$line\n"; + } + return $line; + } + $response .= $line . "\r\n"; + $referralCount++; + } + } + $msg="Max referral count reached ($referralCount times) Cyrus murder loop error?"; + $code=7; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError("Max referral count reached ($referralCount times) Cyrus murder loop error?" ); + } + + + + + /** + * Sets the bebug state + * + * @access public + * @return void + */ + function setDebug($debug=true) + { + $this->_debug=$debug; + } + + /** + * Disconnect from the Sieve server + * + * @access public + * @param string $scriptname The name of the script to be set as active + * @return mixed true on success, PEAR_Error on failure + */ + function disconnect($sendLogoutCMD=true) + { + return $this->_cmdLogout($sendLogoutCMD); + } + + + /** + * Returns the name of the best authentication method that the server + * has advertised. + * + * @param string if !=null,authenticate with this method ($userMethod). + * + * @return mixed Returns a string containing the name of the best + * supported authentication method or a PEAR_Error object + * if a failure condition is encountered. + * @access private + * @since 1.0 + */ + function _getBestAuthMethod($userMethod = null) + { + + if( isset($this->_capability['sasl']) ){ + $serverMethods=$this->_capability['sasl']; + }else{ + // if the server don't send an sasl capability fallback to login auth + //return 'LOGIN'; + return new PEAR_Error("This server don't support any Auth methods SASL problem?"); + } + + if($userMethod != null ){ + $methods = array(); + $methods[] = $userMethod; + }else{ + + $methods = $this->supportedAuthMethods; + } + if( ($methods != null) && ($serverMethods != null)){ + foreach ( $methods as $method ) { + if ( in_array( $method , $serverMethods ) ) { + return $method; + } + } + $serverMethods=implode(',' , $serverMethods ); + $myMethods=implode(',' ,$this->supportedAuthMethods); + return new PEAR_Error("$method NOT supported authentication method!. This server " . + "supports these methods= $serverMethods, but I support $myMethods"); + }else{ + return new PEAR_Error("This server don't support any Auth methods"); + } + } + + + + + + /** + * Return the list of extensions the server supports + * + * @access public + * @return mixed array on success, PEAR_Error on failure + */ + function getExtensions() + { + if (NET_SIEVE_STATE_DISCONNECTED === $this->_state) { + $msg='Not currently connected'; + $code=7; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently connected'); + } + + return $this->_capability['extensions']; + } + + + + + + /** + * Return true if tyhe server has that extension + * + * @access public + * @param string the extension to compare + * @return mixed array on success, PEAR_Error on failure + */ + function hasExtension($extension) + { + if (NET_SIEVE_STATE_DISCONNECTED === $this->_state) { + $msg='Not currently connected'; + $code=7; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently connected'); + } + + if(is_array($this->_capability['extensions'] ) ){ + foreach( $this->_capability['extensions'] as $ext){ + if( trim( strtolower( $ext ) ) === trim( strtolower( $extension ) ) ) + return true; + } + } + return false; + } + + + + /** + * Return the list of auth methods the server supports + * + * @access public + * @return mixed array on success, PEAR_Error on failure + */ + function getAuthMechs() + { + if (NET_SIEVE_STATE_DISCONNECTED === $this->_state) { + $msg='Not currently connected'; + $code=7; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently connected'); + } + if(!isset($this->_capability['sasl']) ){ + $this->_capability['sasl']=array(); + } + return $this->_capability['sasl']; + } + + + + + + /** + * Return true if tyhe server has that extension + * + * @access public + * @param string the extension to compare + * @return mixed array on success, PEAR_Error on failure + */ + function hasAuthMech($method) + { + if (NET_SIEVE_STATE_DISCONNECTED === $this->_state) { + $msg='Not currently connected'; + $code=7; + return $this->_raiseError($msg,$code); + //return PEAR::raiseError('Not currently connected'); + } + + if(is_array($this->_capability['sasl'] ) ){ + foreach( $this->_capability['sasl'] as $ext){ + if( trim( strtolower( $ext ) ) === trim( strtolower( $method ) ) ) + return true; + } + } + return false; + } + + + + + +} +?> diff --git a/lib/KolabAdmin/include/auth.class.php b/lib/KolabAdmin/include/auth.class.php new file mode 100644 index 0000000..c245bfa --- /dev/null +++ b/lib/KolabAdmin/include/auth.class.php @@ -0,0 +1,176 @@ +<?php +/* + * Copyright (c) 2004 Klarälvdalens Datakonsult AB + * + * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +require_once('ldap.class.php'); +require_once('debug.php'); +require_once('mysmarty.php'); +require_once('locale.php'); + +class KolabAuth { + function KolabAuth( $do_auth = true, $params = array() ) { + $this->params = $params; + if( isset( $_GET['logout'] ) || isset( $_POST['logout'] ) ) { + $this->logout(); + } else if( $do_auth ) { + $this->authenticate(); + } + } + + function authenticate() { + global $ldap; + $this->error_string = false; + if( !isset( $ldap ) ) { + $this->error_string = _("Server error, no ldap object!"); + return false; + } + // Anon. bind first + if( !$ldap->bind( $_SESSION['php_dn'], $_SESSION['php_pw'] ) ) { + $this->error_string = _("Could not bind to LDAP server: ").$ldap->error(); + $this->gotoLoginPage(); + } + if( $this->isAuthenticated() ) { + $bind_result = $ldap->bind( $_SESSION['auth_dn'], $_SESSION['auth_pw'] ); + } else { + $bind_result = false; + } + if( !$bind_result ) { + // Anon. bind first + if( !$ldap->bind() ) { + $this->error_string = _("Could not bind to LDAP server"); + $this->gotoLoginPage(); + } + // User not logged in, check login/password + if( isset( $_POST['username'] ) && isset( $_POST['password'] ) ) { + $dn = $ldap->dnForUid( $_POST['username'] ); + if (!$dn) { + $dn = $ldap->dnForMail( $_POST['username'] ); // try mail attribute + } + if( $dn ) { + $auth_user = $ldap->uidForDn( $dn ); + $auth_group = $ldap->groupForUid( $auth_user ); + $tmp_group = ($auth_user=='manager')?'manager':$auth_group; + if( !in_array( $tmp_group, $this->params['allow_user_classes'] ) ) { + $this->error_string = _("User class '$tmp_group' is denied access"); + $this->gotoLoginPage(); + } + $bind_result = $ldap->bind( $dn, $_POST['password'] ); + if( $bind_result ) { + // All OK! + $_SESSION['auth_dn'] = $dn; + $_SESSION['auth_user'] = $auth_user; + $_SESSION['auth_pw'] = $_POST['password']; + $_SESSION['auth_group'] = $auth_group; + $_SESSION['remote_ip'] = $_SERVER['REMOTE_ADDR']; + return true; + } else { + $this->error_string = _("Wrong username or password"); + $this->gotoLoginPage(); + } + } else { + $this->error_string = _("Wrong username or password"); + //$this->error_string = "Dn not found"; + $this->gotoLoginPage(); + } + } else { + //$this->error_string = _('Please log in as a valid user'); + $this->gotoLoginPage(); + // noreturn + } + } else { + // All OK, user already logged in + return true; + } + } + + function logout() { + session_unset(); + session_destroy(); + $this->error_string = false; + //$this->gotoLoginPage(); + Header("Location: $this->params['kolab_wui']/"); + } + + function handleLogin() { + if( isset( $_POST['login'] ) ) { + $this->authenticate(); + } else if( isset( $_POST['logout'] ) ) { + $this->logout(); + } + } + + function gotoLoginPage() { + global $topdir; + $smarty =& new MySmarty(); + $smarty->assign( 'topdir', $topdir ); + $smarty->assign( 'uid', '' ); + $smarty->assign( 'group', '' ); + $smarty->assign( 'page_title', _('Kolab Groupware login') ); + $smarty->assign( 'menuitems', array() ); + if( $this->error() ) $smarty->assign( 'errors', array( $this->error() ) ); + $smarty->assign( 'maincontent', 'login.tpl' ); + $smarty->display('page.tpl'); + exit(); + } + + function isAuthenticated() { + return isset( $_SESSION['auth_dn'] ) && $_SESSION['remote_ip'] == $_SERVER['REMOTE_ADDR']; + } + + function dn() { + if( $this->isAuthenticated() ) return $_SESSION['auth_dn']; + else return false; + } + + function uid() { + if( $this->isAuthenticated() ) return $_SESSION['auth_user']; + else return false; + } + + function group() { + if( $this->isAuthenticated() ) return $_SESSION['auth_group']; + } + + function password() { + if( $this->isAuthenticated() ) { + return $_SESSION['auth_pw']; + } + else return false; + } + + function setDn( $dn ) {$_SESSION['auth_dn'] = $dn;} + function setUid( $uid ) {$_SESSION['auth_user'] = $uid;} + function setPassword( $pw ) {$_SESSION['auth_pw'] = $pw;} + + function error() { + return $this->error_string; + } + + var $error_string = false; + var $params; +}; +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + */ +?> diff --git a/lib/KolabAdmin/include/authenticate.php b/lib/KolabAdmin/include/authenticate.php new file mode 100644 index 0000000..5c5721e --- /dev/null +++ b/lib/KolabAdmin/include/authenticate.php @@ -0,0 +1,35 @@ +<?php +/* + * Copyright (c) 2004 Klarälvdalens Datakonsult AB + * + * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +require_once('auth.class.php'); +global $auth; +global $params; +if( !isset($auth) ) { + $auth =& new KolabAuth(true,$params); +} +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + */ +?>
\ No newline at end of file diff --git a/lib/KolabAdmin/include/debug.php b/lib/KolabAdmin/include/debug.php new file mode 100644 index 0000000..086307f --- /dev/null +++ b/lib/KolabAdmin/include/debug.php @@ -0,0 +1,79 @@ +<?php +/* + * Copyright (c) 2004 Klarälvdalens Datakonsult AB + * + * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +function getmicrotime() { + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); +} +function debug($str) { + #print $str.'<br/>'; +} +function debug_var_dump($var) { + #print '<pre>'; + #var_dump($var); + #print '</pre>'; +} +function backtrace() { + $debug_array = debug_backtrace(); + $counter = count($debug_array); + for($tmp_counter = 0; $tmp_counter != $counter; ++$tmp_counter) { + ?> + <table width="558" height="116" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000"> + <tr> + <td height="38" bgcolor="#D6D7FC"><font color="#000000">function <font color="#FF3300"><? + echo($debug_array[$tmp_counter]["function"]);?>(</font> <font color="#2020F0"> + <?php + //count how many args a there + $args_counter = count($debug_array[$tmp_counter]["args"]); + //print them + for($tmp_args_counter = 0; $tmp_args_counter != $args_counter; ++$tmp_args_counter) { + echo($debug_array[$tmp_counter]["args"][$tmp_args_counter]); + + if(($tmp_args_counter + 1) != $args_counter) { + echo(", "); + } else { + echo(" "); + } + } + ?></font><font color="#FF3300">)</font></font></td></tr><tr> + <td bgcolor="#5F72FA"><font color="#FFFFFF">{</font><br> + <font color="#FFFFFF"> file: + <?php echo($debug_array[$tmp_counter]["file"]);?></font><br> + <font color="#FFFFFF"> line: + <?php echo($debug_array[$tmp_counter]["line"]);?></font><br> + <font color="#FFFFFF">}</font></td></tr></table> + <?php + if(($tmp_counter + 1) != $counter) { + echo("<br>was called by:<br>"); + } + } + //exit(); +} + +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + vim:encoding=utf-8: + */ +?> diff --git a/lib/KolabAdmin/include/form.class.php b/lib/KolabAdmin/include/form.class.php new file mode 100644 index 0000000..7c75fd1 --- /dev/null +++ b/lib/KolabAdmin/include/form.class.php @@ -0,0 +1,489 @@ +<?php +/* + * Copyright (c) 2004 Klarälvdalens Datakonsult AB + * + * Writen by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +require_once('mysmarty.php'); + +function checkuniquealias( $form, $key, $value ) { + global $ldap; + global $action; + global $dn; + $excludedn = false; + if( $action == 'save' ) $excludedn = trim($dn); + $lst = array_unique( array_filter( array_map( 'trim', preg_split( '/\n/', $value ) ), 'strlen') ); + $str = ''; + foreach( $lst as $alias ) { + debug( "looking at $alias, exluding $dn" ); + if( $ldap->countMail( $_SESSION['base_dn'], $alias, $excludedn ) > 0 ) { + $str .= _('Email address ').MySmarty::htmlentities($alias)._(' collides with an address already used for another user, a vCard or a distribution list.<br />'); + } + } + return $str; +} + +// Due to a cyrus imapd bug we can't currently +// support quotas over 4095 MB, see issue1262 +function checkquota( $form, $key, $value ) +{ + if( empty($value) ) return ''; // OK + else if( $value < 0 ) return _('Quota can not be negative'); + else if( !is_numeric($value) ) return _('Quota must be a number'); + else if( (int) $value != $value ) return _('Quota must be an integer'); + else return ''; +} + +function checkphone( $form, $key, $value ) +{ + if( empty($value) ) return ''; // OK + else if( !preg_match('/^[a-zA-Z0-9 ()+\/.=?:-]*$/',$value) ) return _('Phone entries may only contain a-z, numbers, spaces and the characters ()-+/.=?:'); + else return ''; +} + +class KolabForm { + /* + * $entries should be an array of the form: + * array( "fieldname" => array( "name" => "uservisible text", + * "value" => "some value", + * "comment" => "some text", + * "type" => "input/textarea/...", + * "validation" => "notempty/<callbackfnct>" ), + * "fieldname2" => array( ... ) ) + * + * The "callbackfnct" function should be a global function with 3 parameters: + * (form, key, value) + */ + function KolabForm( $name, $template, $entries ) { + $this->name = $name; + $this->template = $template; + $this->entries = $entries; + $this->submittext = _('Submit'); + foreach( $this->entries as $key => $value ) { + if( !isset( $value['type'] ) ) $this->entries[$key]['type'] = ''; + if( !isset( $value['comment'] ) ) $this->entries[$key]['comment'] = ''; + if( !isset( $value['attrs'] ) ) $this->entries[$key]['attrs'] = ''; + } + } + + /* + * this function will be called if an instance of KolabForm will be treated + * as a string + */ + function __toString() { + return sprintf("Debuginformation for class: %s; name: %s; template: %s;", get_class($this), $this->name, $this->template); + } + + /*private*/ + function comment_helper( &$value ) { + $ast = ''; + if( isset($value['validation'])){ + if( is_array( $value['validation'] ) && in_array( 'notempty', $value['validation']) ) { + $ast = '<span class="required_asterisk">*</span> '; + } else if( $value['validation'] == 'notempty' ) { + $ast = '<span class="required_asterisk">*</span> '; + } + } + return $ast.$value['comment']; + } + + function outputForm() { + debug_var_dump($this->entries); + $str = '<div class="contentform">'; + /* + if( count( $this->errors ) > 0 ) { + $str .= '<div class="contenterror">'; + foreach( $this->errors as $err ) { + $str .= $err.'<br/>'; + } + $str .= '</div>'; + }*/ + $str .= '<form name="'.$this->name.'" method="post">'; + $str .= '<table class="contentformtable">'; + $str .= _('<tr><th>Attribute</th><th>Value</th><th>Comment</th></tr>')."\n"; + + $size = 60; + foreach( $this->entries as $key => $value ) { + if( !isset( $value['type'] ) || $value['type']=='' ) $value['type'] = 'text'; + if( !isset( $value['comment'] ) ) $value['comment'] = ''; + if( !isset( $value['attrs'] ) ) $value['attrs'] = ''; + if( !isset( $value['value'] ) ) $value['value'] = ''; + switch( $value['type'] ) { + case 'hidden': continue; + case 'password': + if( ereg( 'readonly', $value['attrs'] ) ) { + // If readonly, skip it -- passwords are at most write-only + break; + } + case 'input': + case 'text': + $str .= '<tr>'; + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><label>'.$value['name'].'</label></td>'; + $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['value']).'</p><input name="' + .$key.'" type="hidden" value="'.MySmarty::htmlentities($value['value']).'" /></td>'; + } else { + $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>'; + $str .= '<td><input name="'.$key.'" id="'.$key.'" type="'.$value['type'].'" value="'.MySmarty::htmlentities($value['value']).'" ' + .MySmarty::htmlentities($value['attrs']).' size="'.$size.'" /></td>'; + } + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + case 'email': + $str .= '<tr>'; + if( strpos($value['value'],'@')===false ) { + $uname = $value['value']; + $domain = ''; + } else { + list($uname,$domain) = split('@',$value['value']); + } + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><label>'.$value['name'].'</label></td>'; + $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['value']).'</p><input name="user_'.$key.'" type="hidden" value="'. + MySmarty::htmlentities($uname).'" /><input name="domain_'.$key.'" type="hidden" value="'. + MySmarty::htmlentities($domain).'" /></td>'; + } else { + $str .= '<td><label for="user_'.$key.'">'.$value['name'].'</label></td>'; + $str .= '<td><input name="user_'.$key.'" id="user_'.$key.'" type="text" value="'.MySmarty::htmlentities($uname).'" ' + .$value['attrs'].' size="'.($size-40).'" />'; + if( count($value['domains']) == 1 ) { + $str .= '<input name="domain_'.$key.'" type="hidden" value="'.MySmarty::htmlentities($value['domains'][0]).'" />'; + $str .= '<span class="ctrl">@'.MySmarty::htmlentities($value['domains'][0]).'</span></td>'; + } else { + $str .= '<label for="domain_'.$key.'">@</label><select name="domain_'.$key.'" id="domain_'.$key.'" '.$value['attrs']." >\n"; + foreach( $value['domains'] as $dom ) { + if( $dom == $domain ) $s = 'selected="selected"'; + else $s = ''; + $str .= '<option value="'.MySmarty::htmlentities($dom).'" '.$s.'>'.MySmarty::htmlentities($dom).'</option>'."\n"; + } + $str .= '</select>'; + $str .= '</td>'; + } + } + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + case 'comment': + $str .= '<tr>'; + $str .= '<td>'.$value['name'].'</td>'; + $str .= '<td>'.$value['value'].'</td>'; + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + case 'textarea': + $str .= '<tr>'; + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><label>'.$value['name'].'</label></td>'; + $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['value']).'</p></td>'; + } else { + $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>'; + $str .= '<td><textarea name="'.$key.'" id="'.$key.'" rows="5" cols="'.$size.'" '.$value['attrs'].' onkeypress="javascript:textareakeypress()">'.MySmarty::htmlentities($value['value']).'</textarea></td>'; + } + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + case 'checkbox': + $str .= '<tr>'; + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><label>'.$value['name'].'</label></td>'; + $str .= '<td><span class="ctrl">'.($value['value']?_('Yes'):_('No')).'</span></td>'; + } else { + $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>'; + $str .= '<td><input name="'.$key.'" id="'.$key.'" type="'.$value['type'].'" value="on" '.($value['value']?'checked':'').' '.$value['attrs'].' /></td>'; + } + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + case 'checklist': + $str .= '<tr>'; + $str .= '<td><label>'.$value['name'].'</label></td>'; + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><div class="ctrl">'.(join('<br/>',$value['options'])).'</div></td>'; + } else { + $str .= '<td><table class="contentform">'; + foreach( $value['options'] as $opt ) { + if( is_array( $value['value'] ) ) $checked = ( in_array($opt ,$value['value'] ))?"checked":""; + else $checked = ""; + //debug("Checking if $opt is in ".join(",",$value['value'])." :$checked"); + $str .= '<tr><td><input name="'.$key.'[]" type="checkbox" value="'.MySmarty::htmlentities($opt).'" '.$value['attrs']." $checked /></td><td>" + .MySmarty::htmlentities($opt).'</td></tr>'; + } + $str .= '</table></td>'; + } + $str .= '<td>'.$value['comment'].'</td>'; + $str .= '</tr>'."\n"; + break; + case 'select': + $str .= '<tr>'; + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><label>'.$value['name'].'</label></td>'; + $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['options'][$value['value']]). + '<input type="hidden" name="'.$key.'" value="'.MySmarty::htmlentities($value['value']).'" /></p></td>'; + } else { + $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>'; + $str .= '<td><select name="'.$key.'" id="'.$key.'" '.$value['attrs'].' >'."\n"; + + for( $i = 0; $i < count($value['options']); ++$i) { + if( $i == $value['value'] ) $s = 'selected="selected"'; + else $s = ''; + $str .= '<option value="'.$i.'" '.$s.'>'.MySmarty::htmlentities($value['options'][$i]).'</option>'."\n"; + } + $str .= '</select>'; + $str .= '</td>'; + } + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + case 'foldertypeselect': + $str .= '<tr>'; + $entries = array ( '' => _('Unspecified'), 'mail' => _('Mails'), 'task' => _('Tasks'), + 'journal' => _('Journals'), 'event' => _('Events'), + 'contact' => _('Contacts'), 'note' => _('Notes')); + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><label>'.$value['name'].'</label></td>'; + $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($entries[$value['value']]). + '<input type="hidden" name="'.$key.'" value="'.MySmarty::htmlentities($value['value']).'" /></p></td>'; + } else { + $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>'; + $str .= '<td><select name="'.$key.'" id="'.$key.'" '.$value['attrs'].' >'."\n"; + foreach ($entries as $id => $title) { + if ( $value['value'] == $id ) + $s = 'selected="selected"'; + else + $s = ''; + + $str .= '<option value="'.$id.'" '.$s.'>'.MySmarty::htmlentities($title).'</option>'."\n"; + } + $str .= '</select>'; + $str .= '</td>'; + } + $str .= '<td>'.$value['comment'].'</td>'; + $str .= '</tr>'."\n"; + break; + case 'aclselect': // Special Kolab entry for ACLs + $str .= '<tr>'; + if( ereg( 'readonly', $value['attrs'] ) ) { + $str .= '<td><label>'.$value['name'].'</label></td>'; + if( $value['user'] ) $str .= '<td><span class="ctrl">'.MySmarty::htmlentities($value['user']).'</span> <span class="ctrl">'.$value['perm'].'</span></td>'; + } else { + $str .= '<td><label for="user_'.$key.'">'.$value['name'].'</label></td>'; + $str .= '<td><input name="user_'.$key.'" id="user_'.$key.'" type="'.$value['type'].'" size="'.($size-15).'" value="' + .MySmarty::htmlentities($value['user']).'" '.$value['attrs'].' />'; + $str .= '<select name="perm_'.$key.'">'."\n"; + if( $value['perm'] ) $selected_perm = $value['perm']; + else $selected_perm = 'all'; + foreach( array( 'none', + 'post', + 'read', 'read/post', + 'append', + 'write', + 'read anon', + 'read anon/post', + 'read hidden', + 'read hidden/post', + 'all' ) as $perm ) { + if( $perm == $selected_perm ) $s = 'selected="selected"'; + else $s = ''; + $str .= '<option value="'.$perm.'"'.$s.' >'.$perm.'</option>'."\n"; + } + $str .= '</select>'; + $str .= '</td>'; + } + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + case 'resourcepolicy': // Special Kolab entry for group/resource policies + debug("resourcepolicy"); + $ro = ereg( 'readonly', $value['attrs'] ); + $str .= '<tr>'; + $str .= '<td><label>'.$value['name'].'</label></td>'; + $str .= '<td>'; + $str .= '<table>'; + $i = 0; + $tmppol = $value['policies']; + unset($tmppol['']); + ksort($tmppol); + $tmppol[''] = 0; + $policies = array( _('Always accept'), + _('Always reject'), + _('Reject if conflicts'), + _('Manual if conflicts'), + _('Manual') ); + foreach( $tmppol as $user => $pol ) { + debug("form: ".$user." => ".$pol); + if( $ro ) { + if( !$user ) continue; + $str .= '<tr><td>'; + if( $user == 'anyone' ) $str .= '<p class="ctrl">'._('Anyone').'</p>'; + else $str .= '<p class="ctrl">'.MySmarty::htmlentities($user).'</p>'; + $str .= '</td><td><p class="ctrl">'.MySmarty::htmlentities($policies[$pol]).'</p></td></tr>'."\n"; + } else { + $str .= '<tr><td>'; + if( $user == 'anyone' ) { + $str .= _('Anyone').'<input type="hidden" name="user_'.$key.'_'.$i.'" value="'.MySmarty::htmlentities($user).'" '.$value['attrs'].' />'; + } else { + $str .= '<input name="user_'.$key.'_'.$i.'" type="text" size="'.($size-20) + .'" value="'.MySmarty::htmlentities($user).'" '.$value['attrs'].' />'; + } + $str .= '</td><td><select name="policy_'.$key.'_'.$i.'">'."\n"; + $j = 0; + foreach( $policies as $p ) { + if( $j == $pol ) { + $str .= '<option value="'.$j++.'" selected="selected">'.$p.'</option>'."\n"; + } else { + $str .= '<option value="'.$j++.'">'.$p.'</option>'."\n"; + } + } + $i++; + $str .= '</select></td></tr>'."\n"; + } + } + $str .= '</table></td>'; + $str .= '<td>'.KolabForm::comment_helper($value).'</td>'; + $str .= '</tr>'."\n"; + break; + } + } + $str .= '<tr><td colspan="3" align="center"><input type="submit" name="submit_'.$this->name.'" value="' + .$this->submittext.'" '.$value['attrs'].' /></td></tr>'; + $str .= '</table>'."\n"; + foreach( $this->entries as $key => $value ) { + if( !isset( $value['type'] ) ) $value['type'] = ''; + if( !isset( $value['comment'] ) ) $value['comment'] = ''; + if( !isset( $value['attrs'] ) ) $value['attrs'] = ''; + if( $value['type'] == 'hidden' ) { + $str .= '<input name="'.$key.'" type="hidden" value="'.MySmarty::htmlentities($value['value']).'" '.$value['attrs'].' />'; + } + } + $str .= '</form>'; + $str .= '<div class="required_asterisk">'._('* Required field.').'</div>'; + $str .= '</div>'; + return $str; + } + + function validate() { + $this->errors = array(); + foreach( $this->entries as $key => $value ) { + if( !empty( $value['validation'] ) && !ereg( 'readonly', $value['attrs'] ) ) { + $vv = $value['validation']; + if( !is_array($vv) ) $va = array($vv); + else $va = $vv; + foreach( $va as $v ) { + //print "validating using $v <br/>"; + if( $v == 'notempty' ) { + debug("checking nonemptiness of $key: ".KolabForm::getRequestVar($key)." len=".strlen(trim(KolabForm::getRequestVar($key)))); + if( $value['type'] == 'aclselect' ) { + // ignore + } else if( $value['type'] == 'email' ) { + debug('Checking '.$value['name'].': '.$_REQUEST['user_'.$key]); + if( strlen(trim($_REQUEST['user_'.$key])) == 0 ) { + $this->errors[] = _('Required field ').$value['name']._(' is empty'); + } + } else if( (!is_array($_REQUEST[$key]) && strlen( trim($_REQUEST[$key]) ) == 0) || empty($_REQUEST[$key]) ) { + $this->errors[] = _('Required field ').$value['name']._(' is empty'); + } + } else { + if( $value['type'] == 'aclselect' ) { + $data = $_REQUEST['user_'.$key].' '.$_REQUEST['perm_'.$key]; + } else if( $value['type'] == 'email' ) { + $data = trim($_REQUEST['user_'.$key]).'@'.trim($_REQUEST['domain_'.$key]); + } else if( $value['type'] == 'resourcepolicy' ) { + $i = 0; + $data = array(); + while( isset($_REQUEST['user_'.$key.'_'.$i] ) ) { + $data[] = $_REQUEST['user_'.$key.'_'.$i++]; + } + } else { + $data = $_REQUEST[$key]; + } + $errstr = $v( $this, $key, $data ); + if( !empty( $errstr ) ) { + $this->errors[] = $errstr; + } + } + } + } + } + //print_r( $this->errors ); + return (count($this->errors) == 0); + } + + function isSubmitted() { + return isset( $_REQUEST['submit_'.$this->name] ); + } + + function value( $key ) { + if( isset( $_REQUEST[$key] ) ) { + return $_REQUEST[$key]; + } else { + return $this->entries[$key]['value']; + } + } + + function setValues() { + foreach( $this->entries as $k => $v ) { + if( $this->entries[$k]['type'] == 'aclselect' ) { + $this->entries[$k]['user'] = trim($this->value('user_'.$k)); + $this->entries[$k]['perm'] = $this->value('perm_'.$k); + } else if( $this->entries[$k]['type'] == 'resourcepolicy' ) { + $i = 0; + $pols = array(); + while( isset($_REQUEST['user_'.$k.'_'.$i]) ) { + $pols[trim($_REQUEST['user_'.$k.'_'.$i])] + = trim($_REQUEST['policy_'.$k.'_'.$i]); + $i++; + } + $this->entries[$k]['policies'] = $pols; + } else if( $this->entries[$k]['type'] == 'checkbox' ) { + $this->entries[$k]['value'] = isset( $_REQUEST[$k] ); + } else if( $this->entries[$k]['type'] == 'checklist' ) { + $this->entries[$k]['value'] = $_REQUEST[$k]; + } else if( $this->entries[$k]['type'] == 'password' ) { + $this->entries[$k]['value'] = $this->value($k); + } else if( $this->entries[$k]['type'] == 'email' ) { + $this->entries[$k]['value'] = trim($this->value('user_'.$k)).'@'.trim($this->value('domain_'.$k)); + } else { + $this->entries[$k]['value'] = trim($this->value($k)); + } + } + } + + /* static */ function getRequestVar($var, $default = false) + { + if( isset($_REQUEST[$var]) ) return $_REQUEST[$var]; + else return $default; + } + + + var $name; + var $template; + var $errors; + var $entries; + var $submittext; +}; + +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + vim:encoding=utf-8: +*/ +?> diff --git a/lib/KolabAdmin/include/headers.php b/lib/KolabAdmin/include/headers.php new file mode 100644 index 0000000..2ddb5bf --- /dev/null +++ b/lib/KolabAdmin/include/headers.php @@ -0,0 +1,36 @@ +<?php +/* + * Copyright (c) 2004 Klaralvdalens Datakonsult AB + * + * Writen by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +header("Content-Type: text/html; charset=UTF-8"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); +header("Cache-Control: no-cache, must-revalidate"); +header("Pragma: no-cache"); + +$topdir = $params['kolab_wui']; +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + vim:encoding=utf-8: + */ +?> diff --git a/lib/KolabAdmin/include/ldap.class.php b/lib/KolabAdmin/include/ldap.class.php new file mode 100644 index 0000000..d2b735c --- /dev/null +++ b/lib/KolabAdmin/include/ldap.class.php @@ -0,0 +1,54 @@ +<?php +/* + * Copyright (c) 2004,2005 Klarälvdalens Datakonsult AB + * + * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +require_once('mysmarty.php'); +require_once('KolabAdmin/Ldap.php'); +require_once('debug.php'); + +/* We dont have any better place to put this right now... */ +function str_rand($length = 8, $seeds = 'abcdefghijklmnopqrstuvwxyz0123456789') { + $str = ''; + $seeds_count = strlen($seeds); + + // Seed + //list($usec, $sec) = explode(' ', microtime()); + //$seed = (float) $sec + ((float) $usec * 100000); + //mt_srand($seed); + + // Generate + for ($i = 0; $length > $i; $i++) { + $str .= $seeds{mt_rand(0, $seeds_count - 1)}; + } + + return $str; + } + +$ldap =& new KolabLDAP; + +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + vim:encoding=utf-8: + */ +?> diff --git a/lib/KolabAdmin/include/locale.php b/lib/KolabAdmin/include/locale.php new file mode 100644 index 0000000..ce7e7fd --- /dev/null +++ b/lib/KolabAdmin/include/locale.php @@ -0,0 +1,124 @@ +<?php +/* + * Copyright (c) 2005 Klarälvdalens Datakonsult AB + * + * Written by Romain Pokrzywka <romain@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + + //require_once("mysmarty.php"); + +// PENDING(romain,steffen): Clean up so this is not a mix of code and global functions + +session_start(); + +function supported_lang($lang) { + + // REMEMBER TO UPDATE THIS WHEN ADDING NEW LANGUAGES + $a = array("de" => "de_DE", + "de_de" => "de_DE", + "fr" => "fr_FR", + "fr_fr" => "fr_FR", + "it" => "it_IT", + "it_it" => "it_IT", + "nl" => "nl_NL", + "nl_nl" => "nl_NL", + "en" => "en_US", + "en_gb" => "en_US", + "en_us" => "en_US", + "es" => "es_ES", + "es_es" => "es_ES"); + + // Locales must be in the format xx_YY to be recognized by xgettext + $lang = strtolower(str_replace('-','_',$lang)); + if( !array_key_exists( $lang, $a ) ) return false; + else return $a[$lang]; +} + +// This function is called in templates my Smarty +function translate($params) +{ + $msg = $params["msg"]; + $domain = $params["domain"]; + if(empty($domain)) { + return gettext($msg); + } else { + return dgettext($domain, $msg); + } +} + +# Returns the currently selected language +function getLanguage() +{ + if(empty($_SESSION["lang"])) + { + $acceptList = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; + if(empty($acceptList)) { + $lang = "en"; + } else { + // In case of multiple accept languages, keep the first one + $acceptList = explode(",", $acceptList); + foreach($acceptList as $l) { + $pos = strpos($l, ';' ); + if( $pos !== false ) { + $l = explode(';',$l); + $l = $l[0]; + } + if( $tmp = supported_lang($l) ) { + $lang = $tmp; + break; + } + } + } + if( !$lang ) $lang = "en"; + setLanguage($lang); + } + return supported_lang($_SESSION["lang"]); +} + +# Allows languages to be set by users +function setLanguage($lang) +{ + $lang = supported_lang($lang); + $_SESSION["lang"] = $lang; +} + +// Check if language was changed +if(!empty($_REQUEST["lang"])) { + setLanguage($_REQUEST["lang"]); +} + +// I18N support information +$language = getLanguage(); +putenv("LANG=$language"); +putenv("LANGUAGE=$language"); +setlocale(LC_ALL, $language); + +$domain = "messages"; +//$tmpSmarty = new MySmarty(); +bindtextdomain($domain, $locale_dir); +bind_textdomain_codeset($domain, "UTF-8"); +textdomain($domain); + +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + vim:encoding=utf-8: + */ +?> diff --git a/lib/KolabAdmin/include/menu.php b/lib/KolabAdmin/include/menu.php new file mode 100644 index 0000000..6954c5b --- /dev/null +++ b/lib/KolabAdmin/include/menu.php @@ -0,0 +1,140 @@ +<?php +/* + * Copyright (c) 2004 Klarälvdalens Datakonsult AB + * + * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +require_once('locale.php'); + +$menuitems = array(); + +if( $auth->group() == "admin" || $auth->group() == "maintainer" || $auth->group() == 'domain-maintainer' ) { + $menuitems['user'] = array( 'name' => _('Users'), + 'url' => $topdir.'/user/', + 'title' => _('Manage Email Users'), + 'submenu' => array( + array( 'name' => _('Create New User'), + 'url' => 'user.php?action=create' ))); +} else { + $menuitems['user'] = array( 'name' => _('My User Settings'), + 'url' => $topdir.'/user/user.php?action=modify', + 'title' => _('My User Settings'), + 'submenu' => array( + array( 'name' => _('Mail Delivery'), + 'url' => 'deliver.php'), + array( 'name' => _('Forward Email'), + 'url' => 'forward.php' ), + array( 'name' => _('Vacation'), + 'url' => 'vacation.php' ))); +} +if( $auth->group() == "admin" || $auth->group() == "maintainer") { + $menuitems['addressbook'] = array( 'name' => _('Addressbook'), + 'url' => $topdir.'/addressbook/', + 'title' => _('Manage Address Book'), + 'submenu' => array( + array( 'name' => _('Create New vCard'), + 'url' => 'addr.php?action=create' ))); + +} +if( $auth->group() == "admin" || $auth->group() == "maintainer" || $auth->group() == 'domain-maintainer') { + $menuitems['sf'] = array( 'name' => _('Shared Folder'), + 'url' => $topdir.'/sharedfolder/', + 'title' => _('Manage Shared Folders'), + 'submenu' => array( + array( 'name' => _('Add Shared Folder'), + 'url' => 'sf.php?action=create' ))); +} +if( $auth->group() == 'admin' || $auth->group() == 'maintainer' || $auth->group() == 'domain-maintainer') { + $menuitems['distlist'] = array( 'name' => _('Distribution Lists'), + 'url' => $topdir.'/distributionlist/', + 'title' => _('Manage Distribution Lists'), + 'submenu' => array( + array( 'name' => _('Create New List'), + 'url' => 'list.php?action=create' ) ) ); +} +if( $auth->group() == 'admin' ) { + $menuitems['administrator'] = array( 'name' => _('Administrators'), + 'url' => $topdir.'/administrator/', + 'title' => _('Manage Administrators'), + 'submenu' => array( + array( 'name' => _('Create New Administrator'), + 'url' => 'admin.php?action=create' ) ) ); + $menuitems['domain-maintainer'] = array( 'name' => _('Domain Maintainers'), + 'url' => $topdir.'/domainmaintainer/', + 'title' => _('Manage Domain Maintainers'), + 'submenu' => array( + array( 'name' => _('Create New Domain Maintainer'), + 'url' => 'domainmaintainer.php?action=create' ) ) ); + $menuitems['maintainer'] = array( 'name' => _('Maintainers'), + 'url' => $topdir.'/maintainer/', + 'title' => _('Manage Maintainers'), + 'submenu' => array( + array( 'name' => _('Create New Maintainer'), + 'url' => 'maintainer.php?action=create' ) ) ); +} else if( $auth->group() == 'maintainer' ) { + $mdn = $auth->dn(); + $menuitems['maintainer'] = array( 'name' => _('Maintainers'), + 'url' => $topdir.'/maintainer/maintainer.php?action=modify&dn='.urlencode($mdn), + 'title' => _('Manage Maintainer') ); + $menuitems['domain-maintainer'] = array( 'name' => _('Domain Maintainers'), + 'url' => $topdir.'/domainmaintainer/', + 'title' => _('Manage Domain Maintainers'), + 'submenu' => array( + array( 'name' => _('Create New Domain Maintainer'), + 'url' => 'domainmaintainer.php?action=create' ) ) ); +} else if( $auth->group() == 'domain-maintainer' ) { + $mdn = $auth->dn(); + $menuitems['domain-maintainer'] = array( 'name' => _('Domain Maintainers'), + 'url' => $topdir.'/domainmaintainer/domainmaintainer.php?action=modify&dn='.urlencode($mdn), + 'title' => _('Manage Domain Maintainer') ); +} +if( $auth->group() == 'admin' ) { + $menuitems['service'] = array( 'name' => _('Settings'), + 'url' => $topdir.'/settings/', + 'title' => _('System Settings') ); +} + +$menuitems['about'] = array( 'name' => _('About Kolab'), + 'url' => $topdir.'/kolab/', + 'title' => _('About Kolab'), + 'submenu' => array( + array( 'name' => _('Erfrakon'), + 'url' => 'erfrakon.php' ), + array( 'name' => _('Intevation'), + 'url' => 'intevation.php' ), + array( 'name' => _('Klarälvdalens Datakonsult'), + 'url' => 'kdab.php' ), + array( 'name' => _('Code Fusion'), + 'url' => 'codefusion.php' ), + array( 'name' => _('KDE'), + 'url' => 'kde.php' ) + )); +if( $auth->group() == 'admin' || $auth->group() == 'maintainer' || $auth->group() == 'domain-maintainer') { + $menuitems['about']['submenu'][] = array( 'name' => _('Versions'), + 'url' => 'versions.php' ); +} + +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + vim:encoding=utf-8: + */ +?> diff --git a/lib/KolabAdmin/include/mysmarty.php b/lib/KolabAdmin/include/mysmarty.php new file mode 100644 index 0000000..0e27fa5 --- /dev/null +++ b/lib/KolabAdmin/include/mysmarty.php @@ -0,0 +1,92 @@ +<?php +/* + * Copyright (c) 2004 Klarälvdalens Datakonsult AB + * + * Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can view the GNU General Public License, online, at the GNU + * Project's homepage; see <http://www.gnu.org/licenses/gpl.html>. + */ + +require_once('config.php'); +require_once('locale.php'); + +// PENDING: Remove this before production(!) +//function count_bytes($tpl_output, &$smarty) { +// return $tpl_output.strlen($tpl_output); +//} + +class MySmarty extends Smarty { + function MySmarty() { + global $topdir; + global $php_dir; + global $language; + global $basedir; + global $smarty_compiledir; + $this->Smarty(); + + $this->config_dir = $basedir.'configs/'; + $this->template_dir = $basedir.'templates/'; + $this->compile_dir = $smarty_compiledir; + + //$this->cache_dir = $basedir.'cache/'; + // Added for i18n management (Romain 05-03-03) + $this->register_function("tr", "translate"); + + //$this->register_outputfilter("count_bytes"); + + $this->assign( 'topdir', $topdir ); + $this->assign( 'self_url', $_SERVER['REQUEST_URI'] ); + + $cleanurl = preg_replace('/(\?|&)lang=(.*)(&|$)/', '', $_SERVER['REQUEST_URI']); + $this->assign( 'lang_url', + strpos($cleanurl,'?')===false? + ($cleanurl.'?lang='): + ($cleanurl.'&lang=') ); + + // If you add a translation, + // add the new language here + $this->assign( 'currentlang', $language ); + $this->assign( 'languages', array( + array( 'name' => 'Deutsch', + 'code' => 'de_DE' ), + array( 'name' => 'English', + 'code' => 'en_US' ), + array( 'name' => 'Français', + 'code' => 'fr_FR' ), + array( 'name' => 'Italiano', + 'code' => 'it_IT' ), + array( 'name' => 'Nederlands', + 'code' => 'nl_NL' ), + array( 'name' => 'Español', + 'code' => 'es_ES' ), + )); + } + + + /** UTF-8 friendly htmlentities() */ + /* static */ function htmlentities( $str ) { + return htmlentities( $str, ENT_QUOTES, "UTF-8"); + } +}; + +/* + Local variables: + mode: php + indent-tabs-mode: t + tab-width: 4 + buffer-file-coding-system: utf-8 + End: + vim:encoding=utf-8: + */ +?> diff --git a/lib/KolabAdmin/include/passwd.php b/lib/KolabAdmin/include/passwd.php new file mode 100644 index 0000000..97846f0 --- /dev/null +++ b/lib/KolabAdmin/include/passwd.php @@ -0,0 +1,47 @@ +<?php +/* ------------------------------------------------------------------- + Copyright (c) 2004 Klaraelvdalens Datakonsult AB + Copyright (C) 2007 by Intevation GmbH + Author(s): + Sascha Wilde <wilde@intevation.de> + Steffen Hansen <steffen@klaralvdalens-datakonsult.se> + + This program is free software under the GNU GPL (>=v2) + Read the file COPYING coming with the software for details. + ------------------------------------------------------------------- */ + +// Generate OpenLDAP style SSHA password strings +function ssha($string, $salt) +{ + return "{SSHA}" . base64_encode(pack("H*", sha1($string . $salt)) . $salt); +} + +// return 4 random bytes +function gensalt() +{ + $salt = ''; + while (strlen($salt) < 4) + $salt = $salt . chr(mt_rand(0,255)); + return $salt; +} + +// Check that passwords from form input match +function checkpw( $form, $key, $value ) { + global $action; + if( $action == 'firstsave' ) { + if( $key == 'password_0' ) { + if( $value == '' ) return _('Password is empty'); + } else if( $key == 'password_1' ) { + if( $value != $_POST['password_0'] ) { + return _('Passwords dont match'); + } + } + } else { + if( $value != $_POST['password_0'] ) { + return _('Passwords dont match'); + } + } + return ''; +} + +?>
\ No newline at end of file |