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
00082
00083 require_once (PATH_t3lib.'class.t3lib_tsparser.php');
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00115 class t3lib_userAuthGroup extends t3lib_userAuth {
00116 var $usergroup_column = 'usergroup';
00117 var $usergroup_table = 'be_groups';
00118
00119
00120 var $groupData = Array(
00121 'filemounts' => Array()
00122 );
00123
00124 var $userGroups = Array();
00125 var $userGroupsUID = Array();
00126 var $groupList ='';
00127 var $dataLists=array(
00128 'webmount_list'=>'',
00129 'filemount_list'=>'',
00130 'modList'=>'',
00131 'tables_select'=>'',
00132 'tables_modify'=>'',
00133 'pagetypes_select'=>'',
00134 'non_exclude_fields'=>'',
00135 'explicit_allowdeny'=>'',
00136 'allowed_languages' => '',
00137 'custom_options' => '',
00138 );
00139 var $includeHierarchy=array();
00140 var $includeGroupArray=array();
00141
00142 var $OS='';
00143 var $TSdataArray=array();
00144 var $userTS_text = '';
00145 var $userTS = array();
00146 var $userTSUpdated=0;
00147 var $userTS_dontGetCached=0;
00148
00149 var $RTE_errors = array();
00150 var $errorMsg = '';
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00176 function isAdmin() {
00177 return (($this->user['admin']&1) ==1);
00178 }
00179
00188 function isMemberOfGroup($groupId) {
00189 $groupId = intval($groupId);
00190 if ($this->groupList && $groupId) {
00191 return $this->inList($this->groupList, $groupId);
00192 }
00193 }
00194
00210 function doesUserHaveAccess($row,$perms) {
00211 $userPerms = $this->calcPerms($row);
00212 return ($userPerms & $perms)==$perms;
00213 }
00214
00227 function isInWebMount($id,$readPerms='',$exitOnError=0) {
00228 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'] || $this->isAdmin()) return 1;
00229 $id = intval($id);
00230 if (!$readPerms) $readPerms = $this->getPagePermsClause(1);
00231 if ($id>0) {
00232 $wM = $this->returnWebmounts();
00233 $rL = t3lib_BEfunc::BEgetRootLine($id,' AND '.$readPerms);
00234
00235 foreach($rL as $v) {
00236 if ($v['uid'] && in_array($v['uid'],$wM)) {
00237 return $v['uid'];
00238 }
00239 }
00240 }
00241 if ($exitOnError) {
00242 t3lib_BEfunc::typo3PrintError ('Access Error','This page is not within your DB-mounts',0);
00243 exit;
00244 }
00245 }
00246
00254 function modAccess($conf,$exitOnError) {
00255 if (!t3lib_BEfunc::isModuleSetInTBE_MODULES($conf['name'])) {
00256 if ($exitOnError) {
00257 t3lib_BEfunc::typo3PrintError ('Fatal Error','This module "'.$conf['name'].'" is not enabled in TBE_MODULES',0);
00258 exit;
00259 }
00260 return false;
00261 }
00262
00263
00264 if (!$conf['access'] || $this->isAdmin()) return true;
00265
00266
00267 if (!strstr($conf['access'],'admin') && $conf['name']) {
00268 $acs = $this->check('modules',$conf['name']);
00269 }
00270 if (!$acs && $exitOnError) {
00271 t3lib_BEfunc::typo3PrintError ('Access Error','You don\'t have access to this module.',0);
00272 exit;
00273 } else return $acs;
00274 }
00275
00290 function getPagePermsClause($perms) {
00291 if (is_array($this->user)) {
00292 if ($this->isAdmin()) {
00293 return ' 1=1';
00294 }
00295
00296 $perms = intval($perms);
00297 $str= ' ('.
00298 '(pages.perms_everybody & '.$perms.' = '.$perms.')'.
00299 'OR(pages.perms_userid = '.$this->user['uid'].' AND pages.perms_user & '.$perms.' = '.$perms.')';
00300 if ($this->groupList){$str.='OR(pages.perms_groupid in ('.$this->groupList.') AND pages.perms_group & '.$perms.' = '.$perms.')';}
00301 $str.=')';
00302 return $str;
00303 } else {
00304 return ' 1=0';
00305 }
00306 }
00307
00316 function calcPerms($row) {
00317 if ($this->isAdmin()) {return 31;}
00318
00319 $out=0;
00320 if (isset($row['perms_userid']) && isset($row['perms_user']) && isset($row['perms_groupid']) && isset($row['perms_group']) && isset($row['perms_everybody']) && isset($this->groupList)) {
00321 if ($this->user['uid']==$row['perms_userid']) {
00322 $out|=$row['perms_user'];
00323 }
00324 if ($this->isMemberOfGroup($row['perms_groupid'])) {
00325 $out|=$row['perms_group'];
00326 }
00327 $out|=$row['perms_everybody'];
00328 }
00329 return $out;
00330 }
00331
00339 function isRTE() {
00340 global $CLIENT;
00341
00342
00343 $this->RTE_errors = array();
00344 if (!$this->uc['edit_RTE'])
00345 $this->RTE_errors[] = 'RTE is not enabled for user!';
00346 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled'])
00347 $this->RTE_errors[] = 'RTE is not enabled in $TYPO3_CONF_VARS["BE"]["RTEenabled"]';
00348
00349
00350
00351 $RTE = &t3lib_BEfunc::RTEgetObj();
00352 if (!is_object($RTE)) {
00353 $this->RTE_errors = array_merge($this->RTE_errors, $RTE);
00354 }
00355
00356 if (!count($this->RTE_errors)) {
00357 return TRUE;
00358 } else {
00359 return FALSE;
00360 }
00361 }
00362
00373 function check($type,$value) {
00374 if (isset($this->groupData[$type])) {
00375 if ($this->isAdmin() || $this->inList($this->groupData[$type],$value)) {
00376 return 1;
00377 }
00378 }
00379 }
00380
00390 function checkAuthMode($table,$field,$value,$authMode) {
00391 global $TCA;
00392
00393
00394 if ($this->isAdmin()) return TRUE;
00395
00396
00397 if (!strcmp($value,'')) return TRUE;
00398
00399
00400 if (ereg('[:|,]',$value)) {
00401 return FALSE;
00402 }
00403
00404
00405 $testValue = $table.':'.$field.':'.$value;
00406 $out = TRUE;
00407
00408
00409 switch((string)$authMode) {
00410 case 'explicitAllow':
00411 if (!$this->inList($this->groupData['explicit_allowdeny'],$testValue.':ALLOW')) {
00412 $out = FALSE;
00413 }
00414 break;
00415 case 'explicitDeny':
00416 if ($this->inList($this->groupData['explicit_allowdeny'],$testValue.':DENY')) {
00417 $out = FALSE;
00418 }
00419 break;
00420 case 'individual':
00421 t3lib_div::loadTCA($table);
00422 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$field])) {
00423 $items = $TCA[$table]['columns'][$field]['config']['items'];
00424 if (is_array($items)) {
00425 foreach($items as $iCfg) {
00426 if (!strcmp($iCfg[1],$value) && $iCfg[4]) {
00427 switch((string)$iCfg[4]) {
00428 case 'EXPL_ALLOW':
00429 if (!$this->inList($this->groupData['explicit_allowdeny'],$testValue.':ALLOW')) {
00430 $out = FALSE;
00431 }
00432 break;
00433 case 'EXPL_DENY':
00434 if ($this->inList($this->groupData['explicit_allowdeny'],$testValue.':DENY')) {
00435 $out = FALSE;
00436 }
00437 break;
00438 }
00439 break;
00440 }
00441 }
00442 }
00443 }
00444 break;
00445 }
00446
00447 return $out;
00448 }
00449
00456 function checkLanguageAccess($langValue) {
00457 if (strcmp($this->groupData['allowed_languages'],'')) {
00458 $langValue = intval($langValue);
00459 if ($langValue != -1 && !$this->check('allowed_languages',$langValue)) {
00460 return FALSE;
00461 }
00462 }
00463 return TRUE;
00464 }
00465
00476 function recordEditAccessInternals($table,$idOrRow) {
00477 global $TCA;
00478
00479 if (isset($TCA[$table])) {
00480 t3lib_div::loadTCA($table);
00481
00482
00483 if ($this->isAdmin()) return TRUE;
00484
00485
00486 if (!is_array($idOrRow)) {
00487 $idOrRow = t3lib_BEfunc::getRecord($table, $idOrRow);
00488 if (!is_array($idOrRow)) {
00489 $this->errorMsg = 'ERROR: Record could not be fetched.';
00490 return FALSE;
00491 }
00492 }
00493
00494
00495 if ($TCA[$table]['ctrl']['languageField']) {
00496 if (isset($idOrRow[$TCA[$table]['ctrl']['languageField']])) {
00497 if (!$this->checkLanguageAccess($idOrRow[$TCA[$table]['ctrl']['languageField']])) {
00498 $this->errorMsg = 'ERROR: Language was not allowed.';
00499 return FALSE;
00500 }
00501 }
00502 }
00503
00504
00505 if (is_array($TCA[$table]['columns'])) {
00506 foreach($TCA[$table]['columns'] as $fN => $fV) {
00507 if (isset($idOrRow[$fN])) {
00508 if ($fV['config']['type']=='select' && $fV['config']['authMode'] && !strcmp($fV['config']['authMode_enforce'],'strict')) {
00509 if (!$this->checkAuthMode($table,$fN,$idOrRow[$fN],$fV['config']['authMode'])) {
00510 $this->errorMsg = 'ERROR: authMode "'.$fV['config']['authMode'].'" failed for field "'.$fN.'" with value "'.$idOrRow[$fN].'" evaluated';
00511 return FALSE;
00512 }
00513 }
00514 }
00515 }
00516 }
00517
00518
00519 if ($TCA[$table]['ctrl']['editlock'] && $idOrRow[$TCA[$table]['ctrl']['editlock']]) {
00520 $this->errorMsg = 'ERROR: Record was locked for editing. Only admin users can change this state.';
00521 return FALSE;
00522 }
00523
00524
00525
00526
00527
00528 return TRUE;
00529 }
00530 }
00531
00541 function isPSet($lCP,$table,$type='') {
00542 if ($this->isAdmin()) return true;
00543 if ($table=='pages') {
00544 if ($type=='edit') return $lCP & 2;
00545 if ($type=='new') return ($lCP & 8) || ($lCP & 16);
00546 if ($type=='delete') return $lCP & 4;
00547 if ($type=='editcontent') return $lCP & 16;
00548 } else {
00549 return $lCP & 16;
00550 }
00551 }
00552
00558 function mayMakeShortcut() {
00559 return $this->getTSConfigVal('options.shortcutFrame') && !$this->getTSConfigVal('options.mayNotCreateEditShortcuts');
00560 }
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00586 function getTSConfig($objectString,$config='') {
00587 if (!is_array($config)) {
00588 $config=$this->userTS;
00589 }
00590 $TSConf=array();
00591 $parts = explode('.',$objectString,2);
00592 $key = $parts[0];
00593 if (trim($key)) {
00594 if (count($parts)>1 && trim($parts[1])) {
00595
00596 if (is_array($config[$key.'.'])) $TSConf = $this->getTSConfig($parts[1],$config[$key.'.']);
00597 } else {
00598 $TSConf['value']=$config[$key];
00599 $TSConf['properties']=$config[$key.'.'];
00600 }
00601 }
00602 return $TSConf;
00603 }
00604
00612 function getTSConfigVal($objectString) {
00613 $TSConf = $this->getTSConfig($objectString);
00614 return $TSConf['value'];
00615 }
00616
00624 function getTSConfigProp($objectString) {
00625 $TSConf = $this->getTSConfig($objectString);
00626 return $TSConf['properties'];
00627 }
00628
00636 function inList($in_list,$item) {
00637 return strstr(','.$in_list.',', ','.$item.',');
00638 }
00639
00647 function returnWebmounts() {
00648 return (string)($this->groupData['webmounts'])!='' ? explode(',',$this->groupData['webmounts']) : Array();
00649 }
00650
00657 function returnFilemounts() {
00658 return $this->groupData['filemounts'];
00659 }
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00687 function fetchGroupData() {
00688 if ($this->user['uid']) {
00689
00690
00691 $this->dataLists['modList'] = $this->user['userMods'];
00692 $this->dataLists['allowed_languages'] = $this->user['allowed_languages'];
00693 $this->dataLists['webmount_list'] = $this->user['db_mountpoints'];
00694 $this->dataLists['filemount_list'] = $this->user['file_mountpoints'];
00695
00696
00697 $this->TSdataArray[]=$this->addTScomment('From $GLOBALS["TYPO3_CONF_VARS"]["BE"]["defaultUserTSconfig"]:').
00698 $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'];
00699
00700
00701 if ($this->isAdmin()) {
00702 $this->TSdataArray[]=$this->addTScomment('"admin" user presets:').'
00703 admPanel.enable.all = 1
00704 options.shortcutFrame = 1
00705 ';
00706 if (t3lib_extMgm::isLoaded('tt_news')) {
00707 $this->TSdataArray[]='
00708
00709 TCAdefaults.tt_news.author = '.$this->user['realName'].'
00710 TCAdefaults.tt_news.author_email = '.$this->user['email'].'
00711 ';
00712 }
00713 if (t3lib_extMgm::isLoaded('sys_note')) {
00714 $this->TSdataArray[]='
00715
00716 TCAdefaults.sys_note.author = '.$this->user['realName'].'
00717 TCAdefaults.sys_note.email = '.$this->user['email'].'
00718 ';
00719 }
00720 }
00721
00722
00723
00724 if ($this->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) {
00725 $this->addFileMount($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '', PATH_site.$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], 0, '');
00726 }
00727
00728
00729 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath']) {
00730
00731 $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');
00732 if (!$didMount) {
00733
00734 $this->addFileMount($this->user['username'], '', $GLOBALS['TYPO3_CONF_VARS']['BE']['userHomePath'].$this->user['uid'].$GLOBALS['TYPO3_CONF_VARS']['BE']['userUploadDir'], 0, 'user');
00735 }
00736 }
00737
00738
00739
00740 # $grList = t3lib_BEfunc::getSQLselectableList($this->user[$this->usergroup_column],$this->usergroup_table,$this->usergroup_table);
00741 $grList = $GLOBALS['TYPO3_DB']->cleanIntList($this->user[$this->usergroup_column]);
00742 if ($grList) {
00743
00744 $this->fetchGroups($grList);
00745 }
00746
00747
00748 $this->TSdataArray[] = $this->addTScomment('USER TSconfig field').$this->user['TSconfig'];
00749
00750 $this->TSdataArray = t3lib_TSparser::checkIncludeLines_array($this->TSdataArray);
00751
00752
00753 $this->userTS_text = implode(chr(10).'[GLOBAL]'.chr(10),$this->TSdataArray);
00754 $hash = md5('userTS:'.$this->userTS_text);
00755 $cachedContent = t3lib_BEfunc::getHash($hash,0);
00756 if (isset($cachedContent) && !$this->userTS_dontGetCached) {
00757 $this->userTS = unserialize($cachedContent);
00758 } else {
00759 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
00760 $parseObj->parse($this->userTS_text);
00761 $this->userTS = $parseObj->setup;
00762 t3lib_BEfunc::storeHash($hash,serialize($this->userTS),'BE_USER_TSconfig');
00763
00764 $this->userTSUpdated=1;
00765 }
00766
00767
00768 if ($this->isAdmin() && !$this->getTSConfigVal('options.dontMountAdminMounts')) {
00769 $this->dataLists['webmount_list']='0,'.$this->dataLists['webmount_list'];
00770 }
00771
00772
00773 $this->dataLists['filemount_list'] = t3lib_div::uniqueList($this->dataLists['filemount_list']);
00774 if ($this->dataLists['filemount_list']) {
00775 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_filemounts', 'NOT deleted AND NOT hidden AND pid=0 AND uid IN ('.$this->dataLists['filemount_list'].')');
00776 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00777 $this->addFileMount($row['title'], $row['path'], $row['path'], $row['base']?1:0, '');
00778 }
00779 }
00780
00781
00782 $this->groupData['webmounts'] = t3lib_div::uniqueList($this->dataLists['webmount_list']);
00783 $this->groupData['pagetypes_select'] = t3lib_div::uniqueList($this->dataLists['pagetypes_select']);
00784 $this->groupData['tables_select'] = t3lib_div::uniqueList($this->dataLists['tables_modify'].','.$this->dataLists['tables_select']);
00785 $this->groupData['tables_modify'] = t3lib_div::uniqueList($this->dataLists['tables_modify']);
00786 $this->groupData['non_exclude_fields'] = t3lib_div::uniqueList($this->dataLists['non_exclude_fields']);
00787 $this->groupData['explicit_allowdeny'] = t3lib_div::uniqueList($this->dataLists['explicit_allowdeny']);
00788 $this->groupData['allowed_languages'] = t3lib_div::uniqueList($this->dataLists['allowed_languages']);
00789 $this->groupData['custom_options'] = t3lib_div::uniqueList($this->dataLists['custom_options']);
00790 $this->groupData['modules'] = t3lib_div::uniqueList($this->dataLists['modList']);
00791
00792
00793 $this->userGroupsUID = array_reverse(array_unique(array_reverse($this->includeGroupArray)));
00794
00795
00796 $this->groupList = implode(',',$this->userGroupsUID);
00797 $this->setCachedList($this->groupList);
00798 }
00799 }
00800
00810 function fetchGroups($grList,$idList='') {
00811
00812
00813 $lockToDomain_SQL = ' AND (lockToDomain="" OR lockToDomain="'.t3lib_div::getIndpEnv('HTTP_HOST').'")';
00814 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->usergroup_table, 'NOT deleted AND NOT hidden AND pid=0 AND uid IN ('.$grList.')'.$lockToDomain_SQL);
00815
00816
00817 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00818 $this->userGroups[$row['uid']] = $row;
00819 }
00820
00821
00822 $include_staticArr = t3lib_div::intExplode(',',$grList);
00823 reset($include_staticArr);
00824 while(list(,$uid)=each($include_staticArr)) {
00825
00826
00827 $row=$this->userGroups[$uid];
00828 if (is_array($row) && !t3lib_div::inList($idList,$uid)) {
00829
00830
00831 if (trim($row['subgroup'])) {
00832 $theList = implode(',',t3lib_div::intExplode(',',$row['subgroup']));
00833 $this->fetchGroups($theList, $idList.','.$uid);
00834 }
00835
00836 $this->includeGroupArray[]=$uid;
00837 $this->includeHierarchy[]=$idList;
00838 $this->TSdataArray[] = $this->addTScomment('Group "'.$row['title'].'" ['.$row['uid'].'] TSconfig field:').$row['TSconfig'];
00839
00840
00841 if (($this->user['options']&1) == 1) { $this->dataLists['webmount_list'].= ','.$row['db_mountpoints']; }
00842
00843
00844 if (($this->user['options']&2) == 2) { $this->dataLists['filemount_list'].= ','.$row['file_mountpoints']; }
00845
00846
00847 if (($this->user['options']&2) == 2) {
00848
00849 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath']) {
00850 $this->addFileMount($row['title'], '', $GLOBALS['TYPO3_CONF_VARS']['BE']['groupHomePath'].$row['uid'], 0, 'group');
00851 }
00852 }
00853
00854
00855 if ($row['inc_access_lists']==1) {
00856 $this->dataLists['modList'].= ','.$row['groupMods'];
00857 $this->dataLists['tables_select'].= ','.$row['tables_select'];
00858 $this->dataLists['tables_modify'].= ','.$row['tables_modify'];
00859 $this->dataLists['pagetypes_select'].= ','.$row['pagetypes_select'];
00860 $this->dataLists['non_exclude_fields'].= ','.$row['non_exclude_fields'];
00861 $this->dataLists['explicit_allowdeny'].= ','.$row['explicit_allowdeny'];
00862 $this->dataLists['allowed_languages'].= ','.$row['allowed_languages'];
00863 $this->dataLists['custom_options'].= ','.$row['custom_options'];
00864 }
00865
00866 if (!strcmp($idList,'') && !$this->firstMainGroup) {
00867 $this->firstMainGroup=$uid;
00868 }
00869 }
00870 }
00871
00872 }
00873
00882 function setCachedList($cList) {
00883 if ((string)$cList != (string)$this->user['usergroup_cached_list']) {
00884 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_users', 'uid='.intval($this->user['uid']), array('usergroup_cached_list' => $cList));
00885 }
00886 }
00887
00902 function addFileMount($title, $altTitle, $path, $webspace, $type) {
00903
00904 if ($webspace && !$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']) return false;
00905
00906
00907 $path=trim($path);
00908 if ($this->OS=='WIN') {
00909 $path=str_replace('\\','/',$path);
00910 }
00911
00912 if ($path && t3lib_div::validPathStr($path)) {
00913
00914 $path=ereg_replace('^[\/\. ]*','',$path);
00915 $path=trim(ereg_replace('[\/\. ]*$','',$path));
00916
00917
00918 if ($path) {
00919 $fdir=PATH_site.$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
00920 if ($webspace) {
00921 $path=$fdir.$path;
00922 } else {
00923 if ($this->OS!='WIN') {
00924 $path='/'.$path;
00925 }
00926 }
00927 $path.='/';
00928
00929
00930 if (@is_dir($path) &&
00931 (($GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] && t3lib_div::isFirstPartOfStr($path,$GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'])) || t3lib_div::isFirstPartOfStr($path,$fdir))) {
00932
00933 $name = $title ? $title : $altTitle;
00934
00935 $this->groupData['filemounts'][md5($name.'|'.$path.'|'.$type)] = Array('name'=>$name, 'path'=>$path, 'type'=>$type);
00936
00937 return 1;
00938 }
00939 }
00940 }
00941 }
00942
00949 function addTScomment($str) {
00950 $delimiter = '# ***********************************************';
00951
00952 $out = $delimiter.chr(10);
00953 $lines = t3lib_div::trimExplode(chr(10),$str);
00954 foreach($lines as $v) {
00955 $out.= '# '.$v.chr(10);
00956 }
00957 $out.= $delimiter.chr(10);
00958 return $out;
00959 }
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00996 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename='',$recuid='',$recpid='',$event_pid=-1,$NEWid='') {
00997
00998 $fields_values = Array (
00999 'userid' => intval($this->user['uid']),
01000 'type' => intval($type),
01001 'action' => intval($action),
01002 'error' => intval($error),
01003 'details_nr' => intval($details_nr),
01004 'details' => $details,
01005 'log_data' => serialize($data),
01006 'tablename' => $tablename,
01007 'recuid' => intval($recuid),
01008 'recpid' => intval($recpid),
01009 'IP' => t3lib_div::getIndpEnv('REMOTE_ADDR'),
01010 'tstamp' => $GLOBALS['EXEC_TIME'],
01011 'event_pid' => intval($event_pid),
01012 'NEWid' => $NEWid
01013 );
01014
01015 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_log', $fields_values);
01016 return $GLOBALS['TYPO3_DB']->sql_insert_id();
01017 }
01018
01029 function checkLogFailures($email, $secondsBack=3600, $max=3) {
01030 if ($email) {
01031
01032
01033 $theTimeBack = time()-$secondsBack;
01034 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01035 'tstamp',
01036 'sys_log',
01037 'type=255 AND action=4 AND tstamp>'.intval($theTimeBack),
01038 '',
01039 'tstamp DESC',
01040 '1'
01041 );
01042 if ($testRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01043 $theTimeBack = $testRow['tstamp'];
01044 }
01045
01046
01047 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01048 '*',
01049 'sys_log',
01050 'type=255 AND action=3 AND error!=0 AND tstamp>'.intval($theTimeBack),
01051 '',
01052 'tstamp'
01053 );
01054 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > $max) {
01055
01056 $subject = 'TYPO3 Login Failure Warning (at '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].')';
01057 $email_body = '
01058 There has been numerous attempts ('.$GLOBALS['TYPO3_DB']->sql_num_rows($res).') to login at the TYPO3
01059 site "'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].'" ('.t3lib_div::getIndpEnv('HTTP_HOST').').
01060
01061 This is a dump of the failures:
01062
01063 ';
01064 while($testRows = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01065 $theData = unserialize($testRows['log_data']);
01066 $email_body.=date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' H:i',$testRows['tstamp']).': '.@sprintf($testRows['details'],''.$theData[0],''.$theData[1],''.$theData[2]);
01067 $email_body.=chr(10);
01068 }
01069 mail( $email,
01070 $subject,
01071 $email_body,
01072 'From: TYPO3 Login WARNING<>'
01073 );
01074 $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));
01075 }
01076 }
01077 }
01078 }
01079
01080
01081
01082 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauthgroup.php']) {
01083 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauthgroup.php']);
01084 }
01085 ?>