2004-03-14 02:10:37 +01:00
< ? php
2008-06-07 19:45:33 +02:00
/**
2021-04-13 18:15:10 +02:00
* EGroupware - simple / non - CalDAV freebusy URL eg . exported as FBURL in vCard of users
*
* Usage :
* - https :// egw . example . org / egroupware / calendar / freebusy . php ? user =% NAME %
* - https :// egw . example . org / egroupware / calendar / freebusy . php ? email =% NAME %@% SERVER %
* Authentication is required unless explicitly switched off in calendar preferences of the requested user :
* + EGroupware " sessionid " cookie
* + basic auth credentials of an EGroupware user
* + " password " GET parameter with a configured password from the requested user ' s preferences
* + " cred " GET parameter with base64 encoded " <username>:<password> " of an EGroupware user
2008-06-07 19:45:33 +02:00
*
* @ link http :// www . egroupware . org
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ package calendar
* @ subpackage export
*/
2004-03-14 02:10:37 +01:00
2016-05-01 19:47:59 +02:00
use EGroupware\Api ;
2008-06-07 19:45:33 +02:00
$GLOBALS [ 'egw_info' ] = array (
'flags' => array (
'currentapp' => 'calendar' ,
'noheader' => True ,
'nofooter' => True ,
2023-06-16 09:38:19 +02:00
'no_exception_handler' => 'basic_auth' , // we use a basic auth exception handler (sends exception message as basic auth realm)
2008-06-07 19:45:33 +02:00
),
);
2021-04-13 15:55:18 +02:00
// check if we are already logged in
require_once __DIR__ . '/../api/src/autoload.php' ;
if ( ! ( $logged_in = ! empty ( Api\Session :: get_sessionid ())))
2008-06-07 19:45:33 +02:00
{
2021-04-13 15:55:18 +02:00
// support basic auth for regular user-credentials
if ( ! empty ( $_SERVER [ 'PHP_AUTH_PW' ]) || ! empty ( $_SERVER [ 'REDIRECT_HTTP_AUTHORIZATION' ]))
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'autocreate_session_callback' ] = Api\Header\Authenticate :: class . '::autocreate_session_callback' ;
$logged_in = true ; // header sends 401, if not authenticated
}
else
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] = 'login' ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noapi' ] = True ;
}
2008-06-07 19:45:33 +02:00
}
include ( '../header.inc.php' );
2004-03-14 02:10:37 +01:00
2021-04-13 15:55:18 +02:00
if ( ! $logged_in )
2008-06-07 19:45:33 +02:00
{
2019-11-05 10:56:00 +01:00
include ( '../api/src/loader.php' );
2008-06-07 19:45:33 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] = 'calendar' ;
}
// fix for SOGo connector, which does not decode the = in our f/b url
if ( strpos ( $_SERVER [ 'QUERY_STRING' ], '=3D' ) !== false && substr ( $_GET [ 'user' ], 0 , 2 ) == '3D' )
{
2021-04-13 18:15:10 +02:00
foreach ([ 'user' , 'email' , 'password' , 'cred' ] as $name )
{
if ( isset ( $_GET [ $name ])) $_GET [ $name ] = substr ( $_GET [ $name ], 2 );
}
2008-06-07 19:45:33 +02:00
}
2021-04-13 18:15:10 +02:00
if ( isset ( $_GET [ 'user' ]) && ! is_numeric ( $user = $_GET [ 'user' ]))
2008-10-18 10:22:28 +02:00
{
// check if user contains the current domain --> remove it
2021-04-13 18:15:10 +02:00
list (, $domain ) = explode ( '@' , $user );
2008-10-18 10:22:28 +02:00
if ( $domain === $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ])
2021-04-13 18:15:10 +02:00
{
list ( $user ) = explode ( '@' , $user );
}
$user = $GLOBALS [ 'egw' ] -> accounts -> name2id ( $user , 'account_lid' , 'u' );
}
elseif ( isset ( $_GET [ 'email' ]))
{
$user = $GLOBALS [ 'egw' ] -> accounts -> name2id ( $_GET [ 'email' ], 'account_email' , 'u' );
2008-10-18 10:22:28 +02:00
}
if ( $user === false || ! ( $username = $GLOBALS [ 'egw' ] -> accounts -> id2name ( $user )))
2008-06-07 19:45:33 +02:00
{
2023-06-16 09:38:19 +02:00
throw new Api\Exception\NoPermission\AuthenticationRequired ( lang ( " freebusy: unknown user '%1', wrong password or not available to not logged in users !!! " . " $username ( $user ) " , $_GET [ 'user' ]));
2008-06-07 19:45:33 +02:00
}
2021-04-13 15:55:18 +02:00
if ( ! $logged_in )
2008-06-07 19:45:33 +02:00
{
2010-06-26 13:35:11 +02:00
if ( empty ( $_GET [ 'cred' ]))
{
$GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ] = $user ;
$GLOBALS [ 'egw_info' ][ 'user' ][ 'account_lid' ] = $username ;
$GLOBALS [ 'egw' ] -> preferences -> account_id = $user ;
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ] = $GLOBALS [ 'egw' ] -> preferences -> read_repository ();
$cal_prefs = & $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'calendar' ];
2021-04-13 15:55:18 +02:00
$logged_in = ! empty ( $cal_prefs [ 'freebusy' ]) &&
2010-06-26 13:35:11 +02:00
( empty ( $cal_prefs [ 'freebusy_pw' ]) || $cal_prefs [ 'freebusy_pw' ] == $_GET [ 'password' ]);
}
else
{
$credentials = base64_decode ( $_GET [ 'cred' ]);
list ( $authuser , $password ) = explode ( ':' , $credentials , 2 );
if ( strpos ( $authuser , '@' ) === false )
{
$domain = $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ];
$authuser .= '@' . $domain ;
}
else
{
list (, $domain ) = explode ( '@' , $authuser , 2 );
}
if ( array_key_exists ( $domain , $GLOBALS [ 'egw_domain' ]))
{
2021-04-13 15:55:18 +02:00
$_POST [ 'login' ] = $authuser ;
2010-06-26 13:35:11 +02:00
$_REQUEST [ 'domain' ] = $domain ;
$GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ] = $domain ;
$GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ] = $domain ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] = 'login' ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noapi' ] = false ;
2021-04-13 15:55:18 +02:00
$logged_in = $GLOBALS [ 'egw' ] -> session -> create ( $authuser , $password , 'text' );
2010-06-26 13:35:11 +02:00
session_unset ();
session_destroy ();
}
}
2021-04-13 15:55:18 +02:00
if ( ! $logged_in )
2006-07-15 01:24:56 +02:00
{
2023-06-16 09:38:19 +02:00
throw new Api\Exception\NoPermission\AuthenticationRequired ( lang ( " freebusy: unknown user '%1', or not available for unauthenticated users! " , $_GET [ 'user' ]));
2006-07-15 01:24:56 +02:00
}
2008-06-07 19:45:33 +02:00
}
if ( $_GET [ 'debug' ])
{
echo " <pre> " ;
}
else
{
2016-05-01 19:47:59 +02:00
Api\Header\Content :: type ( 'freebusy.ifb' , 'text/calendar' );
2008-06-07 19:45:33 +02:00
}
2016-05-01 19:47:59 +02:00
$ical = new calendar_ical ();
2023-06-16 09:38:19 +02:00
echo $ical -> freebusy ( $user , $_GET [ 'end' ]);