00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 class Gauffr
00018 {
00019
00020
00021
00022
00023
00024
00025
00026 const APP_NAME = "Gauffr";
00027
00028
00029
00030 const APP_VERSION = "0.4";
00031
00032
00033
00034 const CONF_FILE = 'gauffr';
00035
00036
00037
00038 const GAUFFR_DB_INSTANCE = 'gauffr';
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 static private $instance = null;
00049
00050
00051
00052 public $gauffrUserTable;
00053
00054
00055
00056 public $gauffrTables;
00057
00058
00059
00060 public $debugLevel;
00061
00062
00063
00064 static $gauffrPath;
00065
00066
00067
00068 static $gauffrMappingDir;
00069
00070
00071
00072 static $confDir;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 private function __construct ()
00084 {
00085
00086 Gauffr::$gauffrPath = dirname( __FILE__ );
00087 Gauffr::$confDir = Gauffr::$gauffrPath . '/conf';
00088 Gauffr::$gauffrMappingDir = Gauffr::$gauffrPath . '/lib/persistentobjectmapping/';
00089
00090 $this->loadCallback();
00091 $this->loadTableSchema();
00092
00093 $cfg = ezcConfigurationManager::getInstance();
00094 $this->debugLevel = constant( $cfg->getSetting( 'gauffr', 'GauffrSettings', 'LogLevel' ) );
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 public static function getInstance()
00105 {
00106 if ( is_null( self::$instance ) )
00107 {
00108 self::$instance = new Gauffr();
00109 }
00110 return self::$instance;
00111 }
00112
00113
00114
00115
00116
00117
00118 private function loadTableSchema()
00119 {
00120 $cfg = ezcConfigurationManager::getInstance();
00121 $this->gauffrUserTable = $cfg->getSettingsInGroup('gauffr', 'GauffrUserTable');
00122 $this->gauffrTables = $cfg->getSettingsInGroup('gauffr', 'GauffrTables');
00123
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133 private function __clone ()
00134 {
00135 throw new Exception ('Clone is not allowed');
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 public static function log( $message, $source, $severity = GauffrLog::INFO, $attributes=array( "category" => "Gauffr") )
00154 {
00155 $gauffr = self::getInstance();
00156 if ( $gauffr->debugLevel <= $severity )
00157 {
00158 $log = ezcLog::getInstance();
00159 $log->source = $source;
00160 $log->log( $message, $severity, $attributes );
00161 }
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 private function loadCallback()
00174 {
00175 ezcBaseInit::setCallback(
00176 'ezcInitConfigurationManager',
00177 'GauffrLazyConfigurationConfiguration'
00178 );
00179 ezcBaseInit::setCallback(
00180 'ezcInitDatabaseInstance',
00181 'GauffrLazyDatabaseConfiguration'
00182 );
00183 ezcBaseInit::setCallback(
00184 'ezcInitLog',
00185 'GauffrLazyLogConfiguration'
00186 );
00187 ezcBaseInit::setCallback(
00188 'ezcInitPersistentSessionInstance',
00189 'GauffrLazyPersistentSessionConfiguration'
00190 );
00191 }
00192
00193
00194
00195
00196
00197
00198 public static function gauffrInitialization()
00199 {
00200
00201 if ( !defined( 'EZCBASE_ENABLED' ) )
00202 {
00203 $baseEnabled = @include 'ezc/Base/base.php';
00204 if ( !$baseEnabled )
00205 {
00206 $baseEnabled = include 'Base/src/base.php';
00207 }
00208 define( 'EZCBASE_ENABLED', $baseEnabled );
00209 }
00210
00211
00212 if ( !defined('GAUFFR_ENABLED') )
00213 {
00214
00215 spl_autoload_register( array( 'ezcBase', 'autoload' ) );
00216
00217 ezcBase::addClassRepository( dirname( __FILE__ ), dirname( __FILE__ ).'/autoloads' );
00218 define( 'GAUFFR_ENABLED', true );
00219 }
00220
00221
00222 $gauffr = Gauffr::getInstance();
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 public static function info( $as_array = false )
00238 {
00239 $gauffr = Gauffr::getInstance();
00240
00241 $info = array(
00242 'version' => Gauffr::APP_VERSION,
00243 'info' => array(
00244 'Variables' => array(
00245 array(
00246 'Variables' => 'Gauffr::APP_NAME',
00247 'Description' => 'Application name',
00248 'Value' => Gauffr::APP_NAME
00249 ),
00250 array(
00251 'Variables' => 'Gauffr::APP_VERSION',
00252 'Description' => 'Application version',
00253 'Value' => Gauffr::APP_VERSION
00254 ),
00255 array(
00256 'Variables' => 'Gauffr::GAUFFR_DB_INSTANCE',
00257 'Description' => 'Database instance identifier',
00258 'Value' => Gauffr::GAUFFR_DB_INSTANCE
00259 ),
00260 array(
00261 'Variables' => 'Gauffr::$debugLevel',
00262 'Description' => 'Debug level',
00263 'Value' => $gauffr->debugLevel
00264 ),
00265 array(
00266 'Variables' => 'Gauffr::$gauffrPath',
00267 'Description' => 'Gauffr directory',
00268 'Value' => Gauffr::$gauffrPath
00269 ),
00270 array(
00271 'Variables' => 'Gauffr::$confDir',
00272 'Description' => 'Configuration directory',
00273 'Value' => Gauffr::$confDir
00274 ),
00275 array(
00276 'Variables' => 'Gauffr::$gauffrMappingDir',
00277 'Description' => 'Mapping directory',
00278 'Value' => Gauffr::$gauffrMappingDir
00279 ),
00280 ),
00281 'Database info' => array(
00282 array(
00283 'Name' => 'GauffrMaster',
00284 'Table name' => $gauffr->gauffrUserTable['TableName']
00285 ),
00286 array(
00287 'Name' => 'GauffrSlave',
00288 'Information' => $gauffr->gauffrTables['GauffrSlave']
00289 ),
00290 array(
00291 'Name' => 'GauffrLog',
00292 'Information' => $gauffr->gauffrTables['GauffrLog']
00293 ),
00294 ),
00295 'Dependancies' => array(
00296 array(
00297 'Tests' => 'eZC Authentication',
00298 'Result' => (class_exists('ezcAuthentication')) ? 'Pass' : 'Failed'
00299 ),
00300 array(
00301 'Tests' => 'eZC AuthenticationDatabaseTiein',
00302 'Result' => (class_exists('ezcAuthenticationDatabaseInfo')) ? 'Pass' : 'Failed'
00303 ),
00304 array(
00305 'Tests' => 'eZC Configuration',
00306 'Result' => (class_exists('ezcConfiguration')) ? 'Pass' : 'Failed'
00307 ),
00308 array(
00309 'Tests' => 'eZC ConsoleTools',
00310 'Result' => (class_exists('ezcConsoleOption')) ? 'Pass' : 'Failed'
00311 ),
00312 array(
00313 'Tests' => 'eZC Database',
00314 'Result' => (class_exists('ezcDbInstance')) ? 'Pass' : 'Failed'
00315 ),
00316
00317
00318
00319
00320 array(
00321 'Tests' => 'eZC EventLog',
00322 'Result' => (class_exists('ezcLog')) ? 'Pass' : 'Failed'
00323 ),
00324 array(
00325 'Tests' => 'eZC EventLogDatabaseTiein',
00326 'Result' => (class_exists('ezcLogDatabaseWriter')) ? 'Pass' : 'Failed'
00327 ),
00328 array(
00329 'Tests' => 'eZC PersistentObject',
00330 'Result' => (class_exists('ezcPersistentSession')) ? 'Pass' : 'Failed'
00331 )
00332 )
00333 )
00334 );
00335
00336 if( $as_array )
00337 return $info;
00338
00339 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
00340 <html>
00341 <head>
00342 <style type="text/css">
00343 body {background-color: #ffffff; color: #000000;}
00344 body, td, th, h1, h2 {font-family: sans-serif;}
00345 pre {margin: 0px; font-family: monospace;}
00346 a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
00347 a:hover {text-decoration: underline;}
00348 table {border-collapse: collapse;}
00349 .center {text-align: center;}
00350 .center table { margin-left: auto; margin-right: auto; text-align: left;}
00351 .center th { text-align: center !important; }
00352 td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
00353 h1 {font-size: 150%;}
00354 h2 {font-size: 125%;}
00355 .p {text-align: left;}
00356 .e {background-color: #ccccff; font-weight: bold; color: #000000;}
00357 .h {background-color: #9999cc; font-weight: bold; color: #000000;}
00358 .v {background-color: #cccccc; color: #000000;}
00359 .vr {background-color: #cccccc; text-align: right; color: #000000;}
00360 img {float: right; border: 0px;}
00361 hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;}
00362 </style>
00363 <title>Gauffr::info()</title>
00364 <meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE" />
00365 </head>
00366 <body>
00367 <div id="gauffrinfo" class="center">
00368 <table border="0" cellpadding="3" width="600">
00369 <tr class="h">
00370 <td>
00371 <h1 class="p">Gauffr Version ' . Gauffr::APP_VERSION . '</h1>
00372 </td>
00373 </tr>
00374 </table>
00375 <br />';
00376
00377 foreach( $info['info'] as $title => $infos )
00378 {
00379 echo '<h2><a name="' . strtolower($title) . '">' . $title . '</a></h2>
00380 <table width="600" cellpadding="3" border="0">
00381 <thead>
00382 <tr class="h">';
00383 foreach( $infos as $info )
00384 {
00385 foreach( $info as $key => $value )
00386 {
00387 echo '<th>' . $key . '</th>';
00388 }
00389 break;
00390 }
00391 echo '</tr>
00392 </thead>
00393 <tbody>';
00394 foreach( $infos as $info )
00395 {
00396 echo '<tr>';
00397 $is_first = true;
00398 foreach( $info as $key => $value )
00399 {
00400 if( $is_first )
00401 {
00402 $class = 'e';
00403 $is_first = false;
00404 }
00405 else
00406 {
00407 $class = 'v';
00408 }
00409 echo '<td class="' . $class . '">' . $value . '</td>';
00410 }
00411 echo '</tr>';
00412 }
00413 echo '</tbody>
00414 </table>
00415 <br />';
00416 }
00417
00418 echo '
00419 </div>
00420 </body>
00421 </html>';
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 public static function cryptPasswd($password)
00439 {
00440 $gauffr = self::getInstance();
00441 $cryptoMethod = $gauffr->gauffrUserTable['CryptoMethod'];
00442
00443 return $cryptoMethod($password);
00444 }
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 private function authenticationDatabaseFilter( &$authentication, &$filter, $login, $password, $login_is_alt_login = false )
00458 {
00459 $db = ezcDbInstance::get(self::GAUFFR_DB_INSTANCE);
00460
00461 if ( $login_is_alt_login )
00462 {
00463 $user = GauffrUser::fetchUserByAltLogin($login);
00464 if ( $user )
00465 $login = $user->Login;
00466 else
00467 $login = false;
00468 }
00469
00470 $credentials = new ezcAuthenticationPasswordCredentials( $login, self::cryptPasswd($password) );
00471 $database = new ezcAuthenticationDatabaseInfo(
00472 $db,
00473 $this->gauffrUserTable['TableName'],
00474 array( $this->gauffrUserTable['Login'], $this->gauffrUserTable['Password'] )
00475 );
00476
00477 $authentication = new ezcAuthentication( $credentials );
00478 $filter = new ezcAuthenticationDatabaseFilter( $database );
00479 $authentication->addFilter( $filter );
00480
00481 $filter->registerFetchData( array(
00482 $this->gauffrUserTable['ID'],
00483 $this->gauffrUserTable['GroupID'],
00484 $this->gauffrUserTable['Login'],
00485 $this->gauffrUserTable['Mail']
00486 ) );
00487 }
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508 public static function authenticationDatabase( $login, $password, $slave_identifier = false, $login_is_alt_login = false )
00509 {
00510 $gauffr = self::getInstance();
00511 $gauffr->authenticationDatabaseFilter( $authentication, $filter, $login, $password, $login_is_alt_login );
00512
00513 if ( !$authentication->run() )
00514 {
00515 Gauffr::log("Authentification failled for user \"$login\" (".$login_is_alt_login ? "AltLogin" : "Login" . ")", 'gauffr', GauffrLog::DEBUG, array( "category" => "AuthenticationDatabase", "file" => __FILE__, "line" => __LINE__ ) );
00516 return false;
00517 }
00518
00519
00520 $data = $filter->fetchData();
00521 $user = new GauffrUser();
00522 $user->setState( array(
00523 'ID' => reset( $data[$gauffr->gauffrUserTable['ID']] ),
00524 'GroupID' => reset( $data[$gauffr->gauffrUserTable['GroupID']] ),
00525 'Login' => reset( $data[$gauffr->gauffrUserTable['Login']] ),
00526 'Mail' => reset( $data[$gauffr->gauffrUserTable['Mail']] )
00527 ) );
00528
00529
00530 if ( !$slave_identifier )
00531 {
00532 Gauffr::log("Authentification successful for user \"$login\"", 'gauffr', GauffrLog::DEBUG, array( "category" => "AuthenticationDatabase", "file" => __FILE__, "line" => __LINE__ ) );
00533 return $user;
00534 }
00535 else
00536 {
00537 if ( $user->hasCredentialByIdentifier($slave_identifier) )
00538 {
00539 Gauffr::log("Authentification successful on \"$slave_identifier\" for user \"$login\"", 'gauffr', GauffrLog::DEBUG, array( "category" => "AuthenticationDatabase", "file" => __FILE__, "line" => __LINE__ ) );
00540 return $user;
00541 }
00542 else
00543 {
00544 Gauffr::log("User \"$login\" don't have access to \"$slave_identifier\"", 'gauffr', GauffrLog::SYSTEM, array( "category" => "AuthenticationDatabase", "file" => __FILE__, "line" => __LINE__ ) );
00545 return false;
00546 }
00547 }
00548 }
00549 }
00550
00551
00552
00553
00554
00555 if ( !defined('GAUFFR_ENABLED') )
00556 Gauffr::gauffrInitialization();
00557
00558 ?>