00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00102
00103 require_once (PATH_t3lib.'class.t3lib_tsparser.php');
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00135 class t3lib_userAuthGroup extends t3lib_userAuth {
00136 var $usergroup_column = 'usergroup';
00137 var $usergroup_table = 'be_groups';
00138
00139
00140 var $groupData = Array(
00141 'filemounts' => Array()
00142 );
00143 var $workspace = -99;
00144 var $workspaceRec = array();
00145
00146 var $userGroups = Array();
00147 var $userGroupsUID = Array();
00148 var $groupList ='';
00149 var $dataLists=array(
00150 'webmount_list'=>'',
00151 'filemount_list'=>'',
00152 'modList'=>'',
00153 'tables_select'=>'',
00154 'tables_modify'=>'',
00155 'pagetypes_select'=>'',
00156 'non_exclude_fields'=>'',
00157 'explicit_allowdeny'=>'',
00158 'allowed_languages' => '',
00159 'workspace_perms' => '',
00160 'custom_options' => '',
00161 );
00162 var $includeHierarchy=array();
00163 var $includeGroupArray=array();
00164
00165 var $OS='';
00166 var $TSdataArray=array();
00167 var $userTS_text = '';
00168 var $userTS = array();
00169 var $userTSUpdated=0;
00170 var $userTS_dontGetCached=0;
00171
00172 var $RTE_errors = array();
00173 var $errorMsg = '';
00174
00175 var $checkWorkspaceCurrent_cache=NULL;
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00199 function isAdmin() {
00200 return (($this->user['admin']&1) ==1);
00201 }
00202
00211 function isMemberOfGroup($groupId) {
00212 $groupId = intval($groupId);
00213 if ($this->groupList && $groupId) {
00214 return $this->inList($this->groupList, $groupId);
00215 }
00216 }
00217
00233 function doesUserHaveAccess($row,$perms) {
00234 $userPerms = $this->calcPerms($row);
00235 return ($userPerms & $perms)==$perms;
00236 }
00237
00250 function isInWebMount($id,$readPerms='',$exitOnError=0) {
00251 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'] || $this->isAdmin()) return 1;
00252 $id = intval($id);
00253 if (!$readPerms) $readPerms = $this->getPagePermsClause(1);
00254 if ($id>0) {
00255 $wM = $this->returnWebmounts();
00256 $rL = t3lib_BEfunc::BEgetRootLine($id,' AND '.$readPerms);
00257
00258 foreach($rL as $v) {
00259 if ($v['uid'] && in_array($v['uid'],$wM)) {
00260 return $v['uid'];
00261 }
00262 }
00263 }
00264 if ($exitOnError) {
00265 t3lib_BEfunc::typo3PrintError ('Access Error','This page is not within your DB-mounts',0);
00266 exit;
00267 }
00268 }
00269
00277 function modAccess($conf,$exitOnError) {
00278 if (!t3lib_BEfunc::isModuleSetInTBE_MODULES($conf['name'])) {
00279 if ($exitOnError) {
00280 t3lib_BEfunc::typo3PrintError ('Fatal Error','This module "'.$conf['name'].'" is not enabled in TBE_MODULES',0);
00281 exit;
00282 }
00283 return FALSE;
00284 }
00285
00286
00287 if ($conf['workspaces']) {
00288 if (($this->workspace===0 && t3lib_div::inList($conf['workspaces'],'online')) ||
00289 ($this->workspace===-1 && t3lib_div::inList($conf['workspaces'],'offline')) ||
00290 ($this->workspace>0 && t3lib_div::inList($conf['workspaces'],'custom'))) {
00291
00292 } else {
00293 if ($exitOnError) {
00294 t3lib_BEfunc::typo3PrintError ('Workspace Error','This module "'.$conf['name'].'" is not available under the current workspace',0);
00295 exit;
00296 }
00297 return FALSE;
00298 }
00299 }
00300
00301
00302 if (!$conf['access'] || $this->isAdmin()) return TRUE;
00303
00304
00305 if (!strstr($conf['access'],'admin') && $conf['name']) {
00306 $acs = $this->check('modules',$conf['name']);
00307 }
00308 if (!$acs && $exitOnError) {
00309 t3lib_BEfunc::typo3PrintError ('Access Error','You don\'t have access to this module.',0);
00310 exit;
00311 } else return $acs;
00312 }
00313
00328 function getPagePermsClause($perms) {
00329 global $TYPO3_CONF_VARS;
00330 if (is_array($this->user)) {
00331 if ($this->isAdmin()) {
00332 return ' 1=1';
00333 }
00334
00335 $perms = intval($perms);
00336 $str= ' ('.
00337 '(pages.perms_everybody & '.$perms.' = '.$perms.')'.
00338 'OR(pages.perms_userid = '.$this->user['uid'].' AND pages.perms_user & '.$perms.' = '.$perms.')';
00339 if ($this->groupList){$str.='OR(pages.perms_groupid in ('.$this->groupList.') AND pages.perms_group & '.$perms.' = '.$perms.')';}
00340 $str.=')';
00341
00342
00343
00344
00345 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getPagePermsClause'])) {
00346
00347 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getPagePermsClause'] as $_funcRef) {
00348 $_params = array('currentClause' => $str, 'perms' => $perms);
00349 $str = t3lib_div::callUserFunction($_funcRef, $_params, $this);
00350 }
00351 }
00352
00353 return $str;
00354 } else {
00355 return ' 1=0';
00356 }
00357 }
00358
00367 function calcPerms($row) {
00368 global $TYPO3_CONF_VARS;
00369 if ($this->isAdmin()) {return 31;}
00370
00371 $out=0;
00372 if (isset($row['perms_userid']) && isset($row['perms_user']) && isset($row['perms_groupid']) && isset($row['perms_group']) && isset($row['perms_everybody']) && isset($this->groupList)) {
00373 if ($this->user['uid']==$row['perms_userid']) {
00374 $out|=$row['perms_user'];
00375 }
00376 if ($this->isMemberOfGroup($row['perms_groupid'])) {
00377 $out|=$row['perms_group'];
00378 }
00379 $out|=$row['perms_everybody'];
00380 }
00381
00382
00383
00384
00385 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['calcPerms'])) {
00386 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['calcPerms'] as $_funcRef) {
00387 $_params = array(
00388 'row' => $row,
00389 'outputPermissions' => $out
00390 );
00391 $out = t3lib_div::callUserFunction($_funcRef, $_params, $this);
00392 }
00393 }
00394
00395 return $out;
00396 }
00397
00405 function isRTE() {
00406 global $CLIENT;
00407
00408
00409 $this->RTE_errors = array();
00410 if (!$this->uc['edit_RTE'])
00411 $this->RTE_errors[] = 'RTE is not enabled for user!';
00412 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled'])
00413 $this->RTE_errors[] = 'RTE is not enabled in $TYPO3_CONF_VARS["BE"]["RTEenabled"]';
00414
00415
00416
00417 $RTE = &t3lib_BEfunc::RTEgetObj();
00418 if (!is_object($RTE)) {
00419 $this->RTE_errors = array_merge($this->RTE_errors, $RTE);
00420 }
00421
00422 if (!count($this->RTE_errors)) {
00423 return TRUE;
00424 } else {
00425 return FALSE;
00426 }
00427 }
00428
00439 function check($type,$value) {
00440 if (isset($this->groupData[$type])) {
00441 if ($this->isAdmin() || $this->inList($this->groupData[$type],$value)) {
00442 return 1;
00443 }
00444 }
00445 }
00446
00456 function checkAuthMode($table,$field,$value,$authMode) {
00457 global $TCA;
00458
00459
00460 if ($this->isAdmin()) return TRUE;
00461
00462
00463 if (!strcmp($value,'')) return TRUE;
00464
00465
00466 if (ereg('[:|,]',$value)) {
00467 return FALSE;
00468 }
00469
00470
00471 $testValue = $table.':'.$field.':'.$value;
00472 $out = TRUE;
00473
00474
00475 switch((string)$authMode) {
00476 case 'explicitAllow':
00477 if (!$this->inList($this->groupData['explicit_allowdeny'],$testValue.':ALLOW')) {
00478 $out = FALSE;
00479 }
00480 break;
00481 case 'explicitDeny':
00482 if ($this->inList($this->groupData['explicit_allowdeny'],$testValue.':DENY')) {
00483 $out = FALSE;
00484 }
00485 break;
00486 case 'individual':
00487 t3lib_div::loadTCA($table);
00488 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$field])) {
00489 $items = $TCA[$table]['columns'][$field]['config']['items'];
00490 if (is_array($items)) {
00491 foreach($items as $iCfg) {
00492 if (!strcmp($iCfg[1],$value) && $iCfg[4]) {
00493 switch((string)$iCfg[4]) {
00494 case 'EXPL_ALLOW':
00495 if (!$this->inList($this->groupData['explicit_allowdeny'],$testValue.':ALLOW')) {
00496 $out = FALSE;
00497 }
00498 break;
00499 case 'EXPL_DENY':
00500 if ($this->inList($this->groupData['explicit_allowdeny'],$testValue.':DENY')) {
00501 $out = FALSE;
00502 }
00503 break;
00504 }
00505 break;
00506 }
00507 }
00508 }
00509 }
00510 break;
00511 }
00512
00513 return $out;
00514 }
00515
00522 function checkLanguageAccess($langValue) {
00523 if (strcmp($this->groupData['allowed_languages'],'')) {
00524 $langValue = intval($langValue);
00525 if ($langValue != -1 && !$this->check('allowed_languages',$langValue)) {
00526 return FALSE;
00527 }
00528 }
00529 return TRUE;
00530 }
00531
00544 function recordEditAccessInternals($table,$idOrRow,$newRecord=FALSE) {
00545 global $TCA;
00546
00547 if (isset($TCA[$table])) {
00548 t3lib_div::loadTCA($table);
00549
00550
00551 if ($this->isAdmin()) return TRUE;
00552
00553
00554 if (!is_array($idOrRow)) {
00555 $idOrRow = t3lib_BEfunc::getRecord($table, $idOrRow);
00556 if (!is_array($idOrRow)) {
00557 $this->errorMsg = 'ERROR: Record could not be fetched.';
00558 return FALSE;
00559 }
00560 }
00561
00562
00563 if ($TCA[$table]['ctrl']['languageField']) {
00564 if (isset($idOrRow[$TCA[$table]['ctrl']['languageField']])) {
00565 if (!$this->checkLanguageAccess($idOrRow[$TCA[$table]['ctrl']['languageField']])) {
00566 $this->errorMsg = 'ERROR: Language was not allowed.';
00567 return FALSE;
00568 }
00569 } else {
00570 $this->errorMsg = 'ERROR: The "languageField" field named "'.$TCA[$table]['ctrl']['languageField'].'" was not found in testing record!';
00571 return FALSE;
00572 }
00573 }
00574
00575
00576 if (is_array($TCA[$table]['columns'])) {
00577 foreach($TCA[$table]['columns'] as $fN => $fV) {
00578 if (isset($idOrRow[$fN])) {
00579 if ($fV['config']['type']=='select' && $fV['config']['authMode'] && !strcmp($fV['config']['authMode_enforce'],'strict')) {
00580 if (!$this->checkAuthMode($table,$fN,$idOrRow[$fN],$fV['config']['authMode'])) {
00581 $this->errorMsg = 'ERROR: authMode "'.$fV['config']['authMode'].'" failed for field "'.$fN.'" with value "'.$idOrRow[$fN].'" evaluated';
00582 return FALSE;
00583 }
00584 }
00585 }
00586 }
00587 }
00588
00589
00590 if (!$newRecord && $TCA[$table]['ctrl']['editlock']) {
00591 if (isset($idOrRow[$TCA[$table]['ctrl']['editlock']])) {
00592 if ($idOrRow[$TCA[$table]['ctrl']['editlock']]) {
00593 $this->errorMsg = 'ERROR: Record was locked for editing. Only admin users can change this state.';
00594 return FALSE;
00595 }
00596 } else {
00597 $this->errorMsg = 'ERROR: The "editLock" field named "'.$TCA[$table]['ctrl']['editlock'].'" was not found in testing record!';
00598 return FALSE;
00599 }
00600 }
00601
00602
00603
00604
00605
00606 return TRUE;
00607 }
00608 }
00609
00619 function isPSet($lCP,$table,$type='') {
00620 if ($this->isAdmin()) return true;
00621 if ($table=='pages') {
00622 if ($type=='edit') return $lCP & 2;
00623 if ($type=='new') return ($lCP & 8) || ($lCP & 16);
00624 if ($type=='delete') return $lCP & 4;
00625 if ($type=='editcontent') return $lCP & 16;
00626 } else {
00627 return $lCP & 16;
00628 }
00629 }
00630
00636 function mayMakeShortcut() {
00637 return $this->getTSConfigVal('options.shortcutFrame') && !$this->getTSConfigVal('options.mayNotCreateEditShortcuts');
00638 }
00639
00650 function workspaceCannotEditRecord($table,$recData) {
00651
00652 if ($this->workspace!==0) {
00653
00654 if (!is_array($recData)) {
00655 $recData = t3lib_BEfunc::getRecord($table,$recData,'pid'.($GLOBALS['TCA'][$table]['ctrl']['versioningWS']?',t3ver_wsid,t3ver_stage':''));
00656 }
00657
00658 if (is_array($recData)) {
00659 if ((int)$recData['pid']===-1) {
00660 if (!$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
00661 return 'Versioning disabled for table';
00662 } elseif ((int)$recData['t3ver_wsid']!==$this->workspace) {
00663 return 'Workspace ID of record didn\'t match current workspace';
00664 } else {
00665 return $this->workspaceCheckStageForCurrent($recData['t3ver_stage']) ? FALSE : 'Record stage "'.$recData['t3ver_stage'].'" and users access level did not allow for editing';
00666 }
00667 } else {
00668 if ($res = $this->workspaceAllowLiveRecordsInPID($recData['pid'], $table)) {
00669
00670 return $res>0 ? FALSE : 'Stage for versioning root point and users access level did not allow for editing';
00671 } else {
00672 return 'Online record was not in versionized branch!';
00673 }
00674 }
00675 } else return 'No record';
00676 } else {
00677 return FALSE;
00678 }
00679 }
00680
00689 function workspaceCannotEditOfflineVersion($table,$recData) {
00690 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
00691
00692 if (!is_array($recData)) {
00693 $recData = t3lib_BEfunc::getRecord($table,$recData,'uid,pid,t3ver_wsid,t3ver_stage');
00694 }
00695 if (is_array($recData)) {
00696 if ((int)$recData['pid']===-1) {
00697 return $this->workspaceCannotEditRecord($table,$recData);
00698 } else return 'Not an offline version';
00699 } else return 'No record';
00700 } else return 'Table does not support versioning.';
00701 }
00702
00712 function workspaceAllowLiveRecordsInPID($pid, $table) {
00713
00714
00715 if ($this->workspace===0 || ($this->workspaceRec['live_edit'] && !$GLOBALS['TCA'][$table]['ctrl']['versioningWS'])) {
00716 return 2;
00717 } elseif (t3lib_BEfunc::isPidInVersionizedBranch($pid, $table)) {
00718
00719 $stage = t3lib_BEfunc::isPidInVersionizedBranch($pid, $table, TRUE);
00720 return $this->workspaceCheckStageForCurrent($stage) ? 1 : -1;
00721 } else {
00722 return FALSE;
00723 }
00724 }
00725
00733 function workspaceCreateNewRecord($pid, $table) {
00734 if ($res = $this->workspaceAllowLiveRecordsInPID($pid,$table)) {
00735 if ($res<0) {
00736 return FALSE;
00737 }
00738 } elseif (!$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
00739 return FALSE;
00740 }
00741 return TRUE;
00742 }
00743
00752 function workspaceAllowAutoCreation($table,$id,$recpid) {
00753
00754 if ($this->workspace!==0
00755 && !$this->workspaceRec['disable_autocreate']
00756 && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']
00757 && $recpid >= 0
00758 && !t3lib_BEfunc::getWorkspaceVersionOfRecord($this->workspace, $table, $id, 'uid')
00759 && !t3lib_BEfunc::isPidInVersionizedBranch($recpid, $table)) {
00760 return TRUE;
00761 }
00762 }
00763
00772 function workspaceCheckStageForCurrent($stage) {
00773 if ($this->isAdmin()) return TRUE;
00774
00775 if ($this->workspace>0) {
00776 $stat = $this->checkWorkspaceCurrent();
00777 if (($stage<=0 && $stat['_ACCESS']==='member') ||
00778 ($stage<=1 && $stat['_ACCESS']==='reviewer') ||
00779 ($stat['_ACCESS']==='owner')) {
00780 return TRUE;
00781 }
00782 } else return TRUE;
00783 }
00784
00795 function workspacePublishAccess($wsid) {
00796 if ($this->isAdmin()) return TRUE;
00797
00798
00799 $retVal = FALSE;
00800
00801 $wsAccess = $this->checkWorkspace($wsid);
00802 if ($wsAccess) {
00803 switch($wsAccess['uid']) {
00804 case 0:
00805 $retVal = TRUE;
00806 break;
00807 case -1:
00808 $retVal = $this->checkWorkspace(0) ? TRUE : FALSE;
00809 break;
00810 default:
00811 $retVal = $wsAccess['_ACCESS'] === 'owner' || ($this->checkWorkspace(0) && !($wsAccess['publish_access']&2));
00812 break;
00813 }
00814 }
00815 return $retVal;
00816 }
00817
00823 function workspaceSwapAccess() {
00824 if ($this->workspace>0 && (int)$this->workspaceRec['swap_modes']===2) {
00825 return FALSE;
00826 } else return TRUE;
00827 }
00828
00835 function workspaceVersioningTypeAccess($type) {
00836 $retVal = FALSE;
00837
00838 if ($this->workspace>0 && !$this->isAdmin()) {
00839 $stat = $this->checkWorkspaceCurrent();
00840 if ($stat['_ACCESS']!=='owner') {
00841
00842 $type = t3lib_div::intInRange($type,-1);
00843 switch((int)$type) {
00844 case -1:
00845 $retVal = $this->workspaceRec['vtypes']&1 ? FALSE : TRUE;
00846 break;
00847 case 0:
00848 $retVal = $this->workspaceRec['vtypes']&2 ? FALSE : TRUE;
00849 break;
00850 default:
00851 $retVal = $this->workspaceRec['vtypes']&4 ? FALSE : TRUE;
00852 break;
00853 }
00854 } else $retVal = TRUE;
00855 } else $retVal = TRUE;
00856
00857 return $retVal;
00858 }
00859
00866 function workspaceVersioningTypeGetClosest($type) {
00867 $type = t3lib_div::intInRange($type,-1);
00868
00869 if ($this->workspace>0) {
00870 switch((int)$type) {
00871 case -1:
00872 $type = -1;
00873 break;
00874 case 0:
00875 $type = $this->workspaceVersioningTypeAccess($type) ? $type : -1;
00876 break;
00877 default:
00878 $type = $this->workspaceVersioningTypeAccess($type) ? $type : ($this->workspaceVersioningTypeAccess(0) ? 0 : -1);
00879 break;
00880 }
00881 }
00882 return $type;
00883 }
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00909 function getTSConfig($objectString,$config='') {
00910 if (!is_array($config)) {
00911 $config=$this->userTS;
00912 }
00913 $TSConf=array();
00914 $parts = explode('.',$objectString,2);
00915 $key = $parts[0];
00916 if (trim($key)) {
00917 if (count($parts)>1 && trim($parts[1])) {
00918
00919 if (is_array($config[$key.'.'])) $TSConf = $this->getTSConfig($parts[1],$config[$key.'.']);
00920 } else {
00921 $TSConf['value']=$config[$key];
00922 $TSConf['properties']=$config[$key.'.'];
00923 }
00924 }
00925 return $TSConf;
00926 }
00927
00935 function getTSConfigVal($objectString) {
00936 $TSConf = $this->getTSConfig($objectString);
00937 return $TSConf['value'];
00938 }
00939
00947 function getTSConfigProp($objectString) {
00948 $TSConf = $this->getTSConfig($objectString);
00949 return $TSConf['properties'];
00950 }
00951
00959 function inList($in_list,$item) {
00960 return strstr(','.$in_list.',', ','.$item.',');
00961 }
00962
00970 function returnWebmounts() {
00971 return (string)($this->groupData['webmounts'])!='' ? explode(',',$this->groupData['webmounts']) : Array();
00972 }
00973
00980 function returnFilemounts() {
00981 return $this->groupData['filemounts'];
00982 }
00983
00997 function jsConfirmation($bitmask) {
00998 $alertPopup = $GLOBALS['BE_USER']->getTSConfig('options.alertPopups');
00999 if (empty($alertPopup['value'])) {
01000 $alertPopup = 255;
01001 } else {
01002 $alertPopup = (int)$alertPopup['value'];
01003 }
01004 if(($alertPopup&$bitmask) == $bitmask) {
01005 return 1;
01006 } else {
01007 return 0;
01008 }
01009 }
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01035 function fetchGroupData() {
01036 if ($this->user['uid']) {
01037
01038
01039 $this->dataLists['modList'] = $this->user['userMods'];
01040 $this->dataLists['allowed_languages'] = $this->user['allowed_languages'];
01041 $this->dataLists['workspace_perms'] = $this->user['workspace_perms'];
01042 $this->dataLists['webmount_list'] = $this->user['db_mountpoints'];
01043 $this->dataLists['filemount_list'] = $this->user['file_mountpoints'];
01044
01045
01046 $this->TSdataArray[]=$this->addTScomment('From $GLOBALS["TYPO3_CONF_VARS"]["BE"]["defaultUserTSconfig"]:').
01047 $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'];
01048
01049
01050 if ($this->isAdmin()) {
01051 $this->TSdataArray[]=$this->addTScomment('"admin" user presets:').'
01052 admPanel.enable.all = 1
01053 options.shortcutFrame = 1
01054 ';
01055 if (t3lib_extMgm::isLoaded('sys_note')) {
01056 $this->TSdataArray[]='
01057
01058 TCAdefaults.sys_note.author = '.$this->user['realName'].'
01059 TCAdefaults.sys_note.email = '.$this->user['email'].'
01060 ';
01061 }
01062 }
01063
01064
01065
01066 if ($this->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) {
01067 $this->addFileMount($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '', PATH_site.$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], 0, '');
01068 }
01069
01070
01071 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath']) {
01072
01073 $didMount=$this->addFileMount($this->user['username'], '',$GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'].$this->user['uid'].'_'.$this->user['username'].$GLOBALS['TYPO3_CONF_VARS']['BE']['userUploadDir'], 0, 'user');
01074 if (!$didMount) {
01075
01076 $this->addFileMount($this->user['username'], '', $GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'].$this->user['uid'].$GLOBALS['TYPO3_CONF_VARS']['BE']['userUploadDir'], 0, 'user');
01077 }
01078 }
01079
01080
01081
01082 # $grList = t3lib_BEfunc::getSQLselectableList($this->user[$this->usergroup_column],$this->usergroup_table,$this->usergroup_table);
01083 $grList = $GLOBALS['TYPO3_DB']->cleanIntList($this->user[$this->usergroup_column]);
01084 if ($grList) {
01085
01086 $this->fetchGroups($grList);
01087 }
01088
01089
01090 $this->TSdataArray[] = $this->addTScomment('USER TSconfig field').$this->user['TSconfig'];
01091
01092 $this->TSdataArray = t3lib_TSparser::checkIncludeLines_array($this->TSdataArray);
01093
01094
01095 $this->userTS_text = implode(chr(10).'[GLOBAL]'.chr(10),$this->TSdataArray);
01096 $hash = md5('userTS:'.$this->userTS_text);
01097 $cachedContent = t3lib_BEfunc::getHash($hash,0);
01098 if (isset($cachedContent) && !$this->userTS_dontGetCached) {
01099 $this->userTS = unserialize($cachedContent);
01100 } else {
01101 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
01102 $parseObj->parse($this->userTS_text);
01103 $this->userTS = $parseObj->setup;
01104 t3lib_BEfunc::storeHash($hash,serialize($this->userTS),'BE_USER_TSconfig');
01105
01106 $this->userTSUpdated=1;
01107 }
01108
01109
01110 if ($this->isAdmin() && !$this->getTSConfigVal('options.dontMountAdminMounts')) {
01111 $this->dataLists['webmount_list']='0,'.$this->dataLists['webmount_list'];
01112 }
01113
01114
01115 $this->dataLists['filemount_list'] = t3lib_div::uniqueList($this->dataLists['filemount_list']);
01116 if ($this->dataLists['filemount_list']) {
01117 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_filemounts', 'deleted=0 AND hidden=0 AND pid=0 AND uid IN ('.$this->dataLists['filemount_list'].')');
01118 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01119 $this->addFileMount($row['title'], $row['path'], $row['path'], $row['base']?1:0, '');
01120 }
01121 }
01122
01123
01124 $this->groupData['webmounts'] = t3lib_div::uniqueList($this->dataLists['webmount_list']);
01125 $this->groupData['pagetypes_select'] = t3lib_div::uniqueList($this->dataLists['pagetypes_select']);
01126 $this->groupData['tables_select'] = t3lib_div::uniqueList($this->dataLists['tables_modify'].','.$this->dataLists['tables_select']);
01127 $this->groupData['tables_modify'] = t3lib_div::uniqueList($this->dataLists['tables_modify']);
01128 $this->groupData['non_exclude_fields'] = t3lib_div::uniqueList($this->dataLists['non_exclude_fields']);
01129 $this->groupData['explicit_allowdeny'] = t3lib_div::uniqueList($this->dataLists['explicit_allowdeny']);
01130 $this->groupData['allowed_languages'] = t3lib_div::uniqueList($this->dataLists['allowed_languages']);
01131 $this->groupData['custom_options'] = t3lib_div::uniqueList($this->dataLists['custom_options']);
01132 $this->groupData['modules'] = t3lib_div::uniqueList($this->dataLists['modList']);
01133 $this->groupData['workspace_perms'] = $this->dataLists['workspace_perms'];
01134
01135
01136 $this->userGroupsUID = array_reverse(array_unique(array_reverse($this->includeGroupArray)));
01137
01138
01139 $this->groupList = implode(',',$this->userGroupsUID);
01140 $this->setCachedList($this->groupList);
01141
01142
01143 if (trim($this->groupData['webmounts'])!=='') {
01144 $webmounts = explode(',',$this->groupData['webmounts']);
01145 $MProws = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND uid IN ('.$this->groupData['webmounts'].') AND '.$this->getPagePermsClause(1),'','','','uid');
01146 foreach($webmounts as $idx => $mountPointUid) {
01147 if ($mountPointUid>0 && !isset($MProws[$mountPointUid])) {
01148 unset($webmounts[$idx]);
01149 }
01150 }
01151 $this->groupData['webmounts'] = implode(',',$webmounts);
01152 }
01153
01154
01155 $this->workspaceInit();
01156 }
01157 }
01158
01168 function fetchGroups($grList,$idList='') {
01169 global $TYPO3_CONF_VARS;
01170
01171
01172 $lockToDomain_SQL = ' AND (lockToDomain=\'\' OR lockToDomain=\''.t3lib_div::getIndpEnv('HTTP_HOST').'\')';
01173 $whereSQL = 'deleted=0 AND hidden=0 AND pid=0 AND uid IN ('.$grList.')'.$lockToDomain_SQL;
01174
01175
01176 if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['fetchGroupQuery'])) {
01177 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['fetchGroupQuery'] as $classRef) {
01178 $hookObj = &t3lib_div::getUserObj($classRef);
01179 if(method_exists($hookObj,'fetchGroupQuery_processQuery')){
01180 $whereSQL = $hookObj->fetchGroupQuery_processQuery($this, $grList, $idList, $whereSQL);
01181 }
01182 }
01183 }
01184
01185 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->usergroup_table, $whereSQL);
01186
01187
01188 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01189 $this->userGroups[$row['uid']] = $row;
01190 }
01191
01192
01193 $include_staticArr = t3lib_div::intExplode(',',$grList);
01194 reset($include_staticArr);
01195 while(list(,$uid)=each($include_staticArr)) {
01196
01197
01198 $row=$this->userGroups[$uid];
01199 if (is_array($row) && !t3lib_div::inList($idList,$uid)) {
01200
01201
01202 if (trim($row['subgroup'])) {
01203 $theList = implode(',',t3lib_div::intExplode(',',$row['subgroup']));
01204 $this->fetchGroups($theList, $idList.','.$uid);
01205 }
01206
01207 $this->includeGroupArray[]=$uid;
01208 $this->includeHierarchy[]=$idList;
01209 $this->TSdataArray[] = $this->addTScomment('Group "'.$row['title'].'" ['.$row['uid'].'] TSconfig field:').$row['TSconfig'];
01210
01211
01212 if (($this->user['options']&1) == 1) { $this->dataLists['webmount_list'].= ','.$row['db_mountpoints']; }
01213
01214
01215 if (($this->user['options']&2) == 2) { $this->dataLists['filemount_list'].= ','.$row['file_mountpoints']; }
01216
01217
01218 if (($this->user['options']&2) == 2) {
01219
01220 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']) {
01221 $this->addFileMount($row['title'], '', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath'].$row['uid'], 0, 'group');
01222 }
01223 }
01224
01225
01226 if ($row['inc_access_lists']==1) {
01227 $this->dataLists['modList'].= ','.$row['groupMods'];
01228 $this->dataLists['tables_select'].= ','.$row['tables_select'];
01229 $this->dataLists['tables_modify'].= ','.$row['tables_modify'];
01230 $this->dataLists['pagetypes_select'].= ','.$row['pagetypes_select'];
01231 $this->dataLists['non_exclude_fields'].= ','.$row['non_exclude_fields'];
01232 $this->dataLists['explicit_allowdeny'].= ','.$row['explicit_allowdeny'];
01233 $this->dataLists['allowed_languages'].= ','.$row['allowed_languages'];
01234 $this->dataLists['custom_options'].= ','.$row['custom_options'];
01235 }
01236
01237
01238 $this->dataLists['workspace_perms'] |= $row['workspace_perms'];
01239
01240
01241 if (!strcmp($idList,'') && !$this->firstMainGroup) {
01242 $this->firstMainGroup=$uid;
01243 }
01244 }
01245 }
01246
01247
01248
01249
01250 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['fetchGroups_postProcessing'])) {
01251 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['fetchGroups_postProcessing'] as $_funcRef) {
01252 $_params = array();
01253 t3lib_div::callUserFunction($_funcRef, $_params, $this);
01254 }
01255 }
01256 }
01257
01266 function setCachedList($cList) {
01267 if ((string)$cList != (string)$this->user['usergroup_cached_list']) {
01268 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_users', 'uid='.intval($this->user['uid']), array('usergroup_cached_list' => $cList));
01269 }
01270 }
01271
01286 function addFileMount($title, $altTitle, $path, $webspace, $type) {
01287
01288 if ($webspace && !$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) return false;
01289
01290
01291 $path=trim($path);
01292 if ($this->OS=='WIN') {
01293 $path=str_replace('\\','/',$path);
01294 }
01295
01296 if ($path && t3lib_div::validPathStr($path)) {
01297
01298 $path=ereg_replace('^[\/\. ]*','',$path);
01299 $path=trim(ereg_replace('[\/\. ]*$','',$path));
01300
01301
01302 if ($path) {
01303 $fdir=PATH_site.$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
01304 if ($webspace) {
01305 $path=$fdir.$path;
01306 } else {
01307 if ($this->OS!='WIN') {
01308 $path='/'.$path;
01309 }
01310 }
01311 $path.='/';
01312
01313
01314 if (@is_dir($path) &&
01315 (($GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] && t3lib_div::isFirstPartOfStr($path,$GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'])) || t3lib_div::isFirstPartOfStr($path,$fdir))) {
01316
01317 $name = $title ? $title : $altTitle;
01318
01319 $this->groupData['filemounts'][md5($name.'|'.$path.'|'.$type)] = Array('name'=>$name, 'path'=>$path, 'type'=>$type);
01320
01321 return 1;
01322 }
01323 }
01324 }
01325 }
01326
01333 function addTScomment($str) {
01334 $delimiter = '# ***********************************************';
01335
01336 $out = $delimiter.chr(10);
01337 $lines = t3lib_div::trimExplode(chr(10),$str);
01338 foreach($lines as $v) {
01339 $out.= '# '.$v.chr(10);
01340 }
01341 $out.= $delimiter.chr(10);
01342 return $out;
01343 }
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01369 function workspaceInit() {
01370
01371
01372 $this->setWorkspace($this->user['workspace_id']);
01373
01374
01375 if ($this->workspace>0 && trim($this->workspaceRec['db_mountpoints'])!=='') {
01376
01377
01378 $newMounts = array();
01379 $readPerms = '1=1';
01380
01381
01382 $mountPoints = t3lib_div::intExplode(',',$this->workspaceRec['db_mountpoints']);
01383 foreach($mountPoints as $mpId) {
01384 if ($this->isInWebMount($mpId,$readPerms)) {
01385 $newMounts[] = $mpId;
01386 }
01387 }
01388
01389
01390 $this->groupData['webmounts'] = implode(',',array_unique($newMounts));
01391 }
01392
01393
01394 if ($this->workspace!==0) $this->groupData['filemounts'] = array();
01395 if ($this->workspace>0 && trim($this->workspaceRec['file_mountpoints'])!=='') {
01396
01397
01398 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_filemounts', 'deleted=0 AND hidden=0 AND pid=0 AND uid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->workspaceRec['file_mountpoints']).')');
01399 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01400 $this->addFileMount($row['title'], $row['path'], $row['path'], $row['base']?1:0, '');
01401 }
01402 }
01403 }
01404
01412 function checkWorkspace($wsRec,$fields='uid,title,adminusers,members,reviewers,publish_access,stagechg_notification') {
01413 $retVal = FALSE;
01414
01415
01416 if (!is_array($wsRec)) {
01417 switch((string)$wsRec) {
01418 case '0':
01419 case '-1':
01420 $wsRec = array('uid' => $wsRec);
01421 break;
01422 default:
01423 list($wsRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
01424 $fields,
01425 'sys_workspace',
01426 'pid=0 AND uid='.intval($wsRec).
01427 t3lib_BEfunc::deleteClause('sys_workspace'),
01428 '',
01429 'title'
01430 );
01431 break;
01432 }
01433 }
01434
01435
01436 if (is_array($wsRec)) {
01437 if ($this->isAdmin()) {
01438 return array_merge($wsRec,array('_ACCESS' => 'admin'));
01439 } else {
01440
01441 switch((string)$wsRec['uid']) {
01442 case '0':
01443 $retVal = ($this->groupData['workspace_perms']&1) ? array_merge($wsRec,array('_ACCESS' => 'online')) : FALSE;
01444 break;
01445 case '-1':
01446 $retVal = ($this->groupData['workspace_perms']&2) ? array_merge($wsRec,array('_ACCESS' => 'offline')) : FALSE;
01447 break;
01448 default:
01449
01450 if (t3lib_div::inList($wsRec['adminusers'],$this->user['uid'])) {
01451 return array_merge($wsRec, array('_ACCESS' => 'owner'));
01452 }
01453
01454 if (t3lib_div::inList($wsRec['reviewers'],'be_users_'.$this->user['uid'])) {
01455 return array_merge($wsRec, array('_ACCESS' => 'reviewer'));
01456 }
01457
01458 foreach($this->userGroupsUID as $groupUid) {
01459 if (t3lib_div::inList($wsRec['reviewers'],'be_groups_'.$groupUid)) {
01460 return array_merge($wsRec, array('_ACCESS' => 'reviewer'));
01461 }
01462 }
01463
01464 if (t3lib_div::inList($wsRec['members'],'be_users_'.$this->user['uid'])) {
01465 return array_merge($wsRec, array('_ACCESS' => 'member'));
01466 }
01467
01468 foreach($this->userGroupsUID as $groupUid) {
01469 if (t3lib_div::inList($wsRec['members'],'be_groups_'.$groupUid)) {
01470 return array_merge($wsRec, array('_ACCESS' => 'member'));
01471 }
01472 }
01473 break;
01474 }
01475 }
01476 }
01477
01478 return $retVal;
01479 }
01480
01487 function checkWorkspaceCurrent() {
01488 if (!isset($this->checkWorkspaceCurrent_cache)) {
01489 $this->checkWorkspaceCurrent_cache = $this->checkWorkspace($this->workspace);
01490 }
01491 return $this->checkWorkspaceCurrent_cache;
01492 }
01493
01500 function setWorkspace($workspaceId) {
01501
01502
01503 if ($this->workspaceRec = $this->checkWorkspace($workspaceId,'*')) {
01504
01505 $this->workspace = (int)$workspaceId;
01506 } else {
01507 $this->workspace = (int)$this->getDefaultWorkspace();
01508 $this->workspaceRec = $this->checkWorkspace($this->workspace,'*');
01509 }
01510
01511
01512 unset($this->checkWorkspaceCurrent_cache);
01513
01514
01515 if (strcmp($this->workspace, $this->user['workspace_id'])) {
01516 $this->user['workspace_id'] = $this->workspace;
01517 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_users','uid='.intval($this->user['uid']),array('workspace_id' => $this->user['workspace_id']));
01518 $this->simplelog('User changed workspace to "'.$this->workspace.'"');
01519 }
01520 }
01521
01528 function setWorkspacePreview($previewState) {
01529 $this->user['workspace_preview'] = $previewState;
01530 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_users','uid='.intval($this->user['uid']),array('workspace_preview' => $this->user['workspace_preview']));
01531 }
01532
01538 function getDefaultWorkspace() {
01539
01540 if ($this->checkWorkspace(0)) {
01541 return 0;
01542 } elseif ($this->checkWorkspace(-1)) {
01543 return -1;
01544 } else {
01545 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
01546 foreach($workspaces as $rec) {
01547 if ($this->checkWorkspace($rec)) {
01548 return $rec['uid'];
01549 }
01550 }
01551 }
01552 return -99;
01553 }
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01589 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename='',$recuid='',$recpid='',$event_pid=-1,$NEWid='',$userId=0) {
01590
01591 $fields_values = Array (
01592 'userid' => $userId ? $userId : intval($this->user['uid']),
01593 'type' => intval($type),
01594 'action' => intval($action),
01595 'error' => intval($error),
01596 'details_nr' => intval($details_nr),
01597 'details' => $details,
01598 'log_data' => serialize($data),
01599 'tablename' => $tablename,
01600 'recuid' => intval($recuid),
01601 # 'recpid' => intval($recpid),
01602 'IP' => t3lib_div::getIndpEnv('REMOTE_ADDR'),
01603 'tstamp' => $GLOBALS['EXEC_TIME'],
01604 'event_pid' => intval($event_pid),
01605 'NEWid' => $NEWid,
01606 'workspace' => $this->workspace
01607 );
01608
01609 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_log', $fields_values);
01610 return $GLOBALS['TYPO3_DB']->sql_insert_id();
01611 }
01612
01621 function simplelog($message, $extKey='', $error=0) {
01622 return $this->writelog(
01623 4,
01624 0,
01625 $error,
01626 0,
01627 ($extKey?'['.$extKey.'] ':'').$message,
01628 array()
01629 );
01630 }
01631
01642 function checkLogFailures($email, $secondsBack=3600, $max=3) {
01643
01644 if ($email) {
01645
01646
01647 $theTimeBack = time()-$secondsBack;
01648 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01649 'tstamp',
01650 'sys_log',
01651 'type=255 AND action=4 AND tstamp>'.intval($theTimeBack),
01652 '',
01653 'tstamp DESC',
01654 '1'
01655 );
01656 if ($testRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01657 $theTimeBack = $testRow['tstamp'];
01658 }
01659
01660
01661 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01662 '*',
01663 'sys_log',
01664 'type=255 AND action=3 AND error!=0 AND tstamp>'.intval($theTimeBack),
01665 '',
01666 'tstamp'
01667 );
01668 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > $max) {
01669
01670 $subject = 'TYPO3 Login Failure Warning (at '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].')';
01671 $email_body = '
01672 There has been numerous attempts ('.$GLOBALS['TYPO3_DB']->sql_num_rows($res).') to login at the TYPO3
01673 site "'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].'" ('.t3lib_div::getIndpEnv('HTTP_HOST').').
01674
01675 This is a dump of the failures:
01676
01677 ';
01678 while($testRows = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01679 $theData = unserialize($testRows['log_data']);
01680 $email_body.=date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' H:i',$testRows['tstamp']).': '.@sprintf($testRows['details'],''.$theData[0],''.$theData[1],''.$theData[2]);
01681 $email_body.=chr(10);
01682 }
01683 mail( $email,
01684 $subject,
01685 $email_body,
01686 'From: TYPO3 Login WARNING<>'
01687 );
01688 $this->writelog(255,4,0,3,'Failure warning (%s failures within %s seconds) sent by email to %s',Array($GLOBALS['TYPO3_DB']->sql_num_rows($res),$secondsBack,$email));
01689 }
01690 }
01691 }
01692 }
01693
01694
01695
01696 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauthgroup.php']) {
01697 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauthgroup.php']);
01698 }
01699 ?>