Skip to content

Commit

Permalink
Method unifyEntry argument addDefaults added
Browse files Browse the repository at this point in the history
When Entry is updated, no default values should be added. This behaviour is managed by argument addDefaults. In addition, dependency PHPSpreadsheet version required changed due to security issue of old version.
  • Loading branch information
SourcePot committed Aug 30, 2024
1 parent 082a6a1 commit 45fbf05
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"authors":[{"name":"Carsten Wallenhauer","email":"[email protected]"}],
"require":{
"php":">=8.0",
"phpoffice/phpspreadsheet":"^1.28",
"phpoffice/phpspreadsheet":">=2.2.1",
"michelf/php-markdown":"^2.0.0",
"monolog/monolog":"^3.5.0",
"psr/log":"^3",
Expand Down
8 changes: 4 additions & 4 deletions src/php/Components/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function loginRequest(array $arr)
$this->loginFailed($user,$arr['Email']);
} else if (strcmp($loginEntry['Name'],$arr['Passphrase'])===0){
$this->oc['SourcePot\Datapool\Foundation\Database']->deleteEntries($loginEntry,TRUE);
$this->oc['logger']->log('info','One-time login for {email} at {timestamp} successful.',array('email'=>$arr['Email'],'timestamp'=>time()));
$this->oc['logger']->log('info','One-time login for {email} at {dateTime} was successful.',array('email'=>$arr['Email'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)')));
$this->loginSuccess($user,$arr['Email']);
} else {
$this->loginFailed($user,$arr['Email']);
Expand All @@ -96,13 +96,13 @@ private function resetSession(){
private function loginSuccess($user,$email){
$this->resetSession();
$this->oc['SourcePot\Datapool\Foundation\User']->loginUser($user);
$this->oc['logger']->log('info','Login for {email} at {timestamp} successful.',array('email'=>$email,'timestamp'=>time()));
$this->oc['logger']->log('info','Login for {email} at {dateTime} was successful.',array('email'=>$email,'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)')));
header("Location: ".$this->oc['SourcePot\Datapool\Tools\NetworkTools']->href(array('category'=>'Home')));
}

private function loginFailed($user,$email){
$_SESSION['currentUser']['Privileges']=1;
$this->oc['logger']->log('error','Login failed for {email} at {timestamp}.',array('email'=>$email,'timestamp'=>time()));
$this->oc['logger']->log('notice','Login failed for {email} at {dateTime}.',array('email'=>$email,'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)')));
sleep(30);
header("Location: ".$this->oc['SourcePot\Datapool\Tools\NetworkTools']->href(array('category'=>'Login')));
}
Expand All @@ -126,7 +126,7 @@ private function registerRequest($arr){
}
}
if (empty($err)){
$this->oc['logger']->log('info','You have been registered as new user ({email}).',array('email'=>$arr['Email']));
$this->oc['logger']->log('info','You have been registered as new user ({email}) at {dateTime}.',array('email'=>$arr['Email'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)')));
header("Location: ".$this->oc['SourcePot\Datapool\Tools\NetworkTools']->href(array('category'=>'Admin')));
exit;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/php/Components/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function run(array|bool $arr=TRUE):array{
if ($arr===TRUE){
return array('Category'=>'Logout','Emoji'=>'✖','Label'=>'Logout','Read'=>'ALL_REGISTERED_R','Class'=>__CLASS__);
} else {
$this->oc['logger']->log('info','User logout {user}',array('user'=>$_SESSION['currentUser']['Name']));
$this->oc['logger']->log('info','User logout {user} at {dateTime}',array('user'=>$_SESSION['currentUser']['Name'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)')));
// reset session | keep page state
$_SESSION=array('page state'=>$_SESSION['page state']);
session_regenerate_id(TRUE);
Expand Down
14 changes: 8 additions & 6 deletions src/php/Foundation/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function setTableIndices(string $table)
* This function selects the entry-specific unifyEntry() function based on $entry['Source']
* If the $entry-specific unifyEntry() function is found it will be used to unify the entry.
*/
public function unifyEntry(array $entry):array
public function unifyEntry(array $entry,bool $addDefaults):array
{
if (empty($entry['Source'])){
throw new \ErrorException('Method '.__FUNCTION__.' called with empty entry Source.',0,E_ERROR,__FILE__,__LINE__);
Expand All @@ -236,10 +236,10 @@ public function unifyEntry(array $entry):array
$classWithNamespace=$this->oc['SourcePot\Datapool\Root']->source2class($entry['Source']);
if (isset($this->oc[$classWithNamespace])){
if (method_exists($this->oc[$classWithNamespace],'unifyEntry')){
$entry=$this->oc[$classWithNamespace]->unifyEntry($entry);
$entry=$this->oc[$classWithNamespace]->unifyEntry($entry,$addDefaults);
}
}
$entry=$this->addEntryDefaults($entry);
if ($addDefaults){$entry=$this->addEntryDefaults($entry);}
$entry=$this->oc['SourcePot\Datapool\Root']->substituteWithPlaceholder($entry);
return $entry;
}
Expand Down Expand Up @@ -849,7 +849,7 @@ public function updateEntry(array $entry,bool $isSystemCall=FALSE,bool $noUpdate
$entry=$this->addLog2entry($entry,'Processing log',array('msg'=>'Entry updated','Expires'=>date('Y-m-d H:i:s',time()+604800)),FALSE);
}
// update entry
$entry=$this->unifyEntry($entry);
$entry=$this->unifyEntry($entry,FALSE);
$this->updateEntries($selector,$entry,$isSystemCall,'Write',FALSE,FALSE,FALSE,FALSE,array(),FALSE,$isDebugging=FALSE);
$entry=$this->entryById($selector,$isSystemCall,'Read');
} else {
Expand Down Expand Up @@ -908,9 +908,11 @@ public function hasEntry(array $selector,bool $isSystemCall=TRUE,string $rightTy
*/
public function moveEntryOverwriteTarget($sourceEntry,$targetSelector,$isSystemCall=TRUE,$isTestRun=FALSE,$keepSource=FALSE,$updateSourceFirst=FALSE):array
{
$context=array('class'=>__CLASS__,'function'=>__FUNCTION__);
// test for required keys and set selector
if (empty($sourceEntry['Source']) || empty($sourceEntry['EntryId'])){
throw new \ErrorException('Function '.__FUNCTION__.': Mandatory sourceEntry-key(s) missing, either Source or EntryId',0,E_ERROR,__FILE__,__LINE__);
if (empty($sourceEntry['Source']) || empty($sourceEntry['EntryId']) || empty($targetSelector)){
$this->oc['logger']->log('error','{class} → {function} called with empty sourceEntry[Source], sourceEntry[EntryId] or targetEntry. Source entry was not moved.',$context);
return array();
}
if ($this->oc['SourcePot\Datapool\Foundation\Access']->access($sourceEntry,'Write',FALSE,$isSystemCall)){
// write access
Expand Down
3 changes: 1 addition & 2 deletions src/php/Foundation/Definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ public function entry2form(array $entry=array(),bool $isDebugging=FALSE):string
$debugArr['entry_updated']=$this->oc['SourcePot\Datapool\Foundation\Filespace']->fileUpload2entry($fileArr,$entry);
}
} else {
$entry['skipUpdateCalendarEventEntry']=FALSE;
$debugArr['entry_updated']=$this->oc[$dataStorageClass]->updateEntry($entry);
$debugArr['entry_updated']=$this->oc[$dataStorageClass]->updateEntry($entry,FALSE,FALSE,$addLog=FALSE);
}
$statistics=$this->oc[$dataStorageClass]->getStatistic();
$entryType=(isset($entry['Source']))?strval($entry['Source']):strval($entry['Class']);
Expand Down
10 changes: 6 additions & 4 deletions src/php/Foundation/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function getCurrentUser():array
return $_SESSION['currentUser'];
}

public function unifyEntry(array $entry):array
public function unifyEntry(array $entry,bool $addDefaults=FALSE):array
{
$entry['Source']=$this->entryTable;
if (!isset($entry['Content']['Address'])){$entry['Content']['Address']=array();}
Expand All @@ -164,11 +164,13 @@ public function unifyEntry(array $entry):array
if (empty($entry['Params']['User registration']['Email']) && !empty($entry['Content']['Contact details']['Email'])){
$entry['Params']['User registration']['Email']=$entry['Content']['Contact details']['Email'];
}
$entry=$this->oc['SourcePot\Datapool\Foundation\Access']->addRights($entry,'ADMIN_R','ADMIN_R');
$entry['Group']=$this->oc['SourcePot\Datapool\Foundation\Backbone']->getSettings('pageTitle');
$entry['Folder']=$this->getUserRolsString($entry);
if ($addDefaults){
$entry=$this->oc['SourcePot\Datapool\Foundation\Access']->addRights($entry,'ADMIN_R','ADMIN_R');
$entry=$this->oc['SourcePot\Datapool\Foundation\Definitions']->definition2entry($this->definition,$entry,FALSE);
}
$entry=$this->oc['SourcePot\Datapool\Tools\GeoTools']->address2location($entry);
$entry=$this->oc['SourcePot\Datapool\Foundation\Definitions']->definition2entry($this->definition,$entry,FALSE);
$entry['Name']=$this->userAbstract(array('selector'=>$entry),3);
return $entry;
}
Expand Down Expand Up @@ -311,7 +313,7 @@ public function loginUser(array $user)
{
$_SESSION['currentUser']=$user;
if (strcmp($user['Owner'],'ANONYM')!==0){
$this->oc['logger']->log('info','User login {user}',array('user'=>$_SESSION['currentUser']['Name']));
$this->oc['logger']->log('info','User login {user} at {dateTime}',array('user'=>$_SESSION['currentUser']['Name'],'dateTime'=>$this->oc['SourcePot\Datapool\Tools\MiscTools']->getDateTime('now','','','Y-m-d H:i:s (e)')));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/php/Tools/MiscTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function addEntryId(array $entry,array $relevantKeys=array('Source','Grou
return $entry;
}

public function getDateTime(string $datetime='now',string $addDateInterval='',string $timezone=''):string
public function getDateTime(string $datetime='now',string $addDateInterval='',string $timezone='',string $format='Y-m-d H:i:s'):string
{
if ($datetime[0]==='@'){
$timestamp=intval(trim($datetime,'@'));
Expand All @@ -319,7 +319,7 @@ public function getDateTime(string $datetime='now',string $addDateInterval='',st
}
}
$dateTime->setTimeZone(new \DateTimeZone(\SourcePot\Datapool\Root::DB_TIMEZONE));
return $dateTime->format('Y-m-d H:i:s');
return $dateTime->format($format);
}

public function code2utf(int $code):string
Expand Down

0 comments on commit 45fbf05

Please sign in to comment.