openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit a890acf796bb28191d34b0c82f7f2f2108f59297
parent 2ab7d7ad9cc43b59935a40b2f481b823840aff98
Author: Jan Dankert <devnull@localhost>
Date:   Wed, 12 Dec 2018 23:05:08 +0100

die() grundsätzlich nicht verwenden, sondern stattdessen Exceptions werfen.

Diffstat:
modules/cms-core/action/ElementAction.class.php | 2+-
modules/cms-core/action/FileAction.class.php | 6+++---
modules/cms-core/action/FolderAction.class.php | 4++--
modules/cms-core/action/LoginAction.class.php | 15---------------
modules/cms-core/action/ObjectAction.class.php | 2+-
modules/cms-core/action/PageelementAction.class.php | 3++-
modules/cms-core/action/StartAction.class.php | 1-
modules/cms-core/auth/OpenIdAuth.class.php | 18------------------
modules/cms-core/model/BaseObject.class.php | 4++--
modules/cms-core/model/Image.class.php | 4++--
modules/cms-core/model/ObjectFactory.php | 3+--
modules/cms-core/model/User.class.php | 2+-
modules/cms-core/model/Value.class.php | 6+++---
modules/cms-ui/themes/default/html/views/login/login.php | 4++--
modules/cms-ui/themes/default/html/views/user/edit.php | 8++++----
modules/util/Ldap.class.php | 4++--
modules/wikiparser/parser/WikiParser.class.php | 7++-----
17 files changed, 28 insertions(+), 65 deletions(-)

diff --git a/modules/cms-core/action/ElementAction.class.php b/modules/cms-core/action/ElementAction.class.php @@ -54,7 +54,7 @@ class ElementAction extends Action public function init() { if ( $this->getRequestId() == 0 ) - die('no element-id available'); + throw new \ValidationException('no element-id available'); $this->element = new Element( $this->getRequestId() ); $this->element->load(); diff --git a/modules/cms-core/action/FileAction.class.php b/modules/cms-core/action/FileAction.class.php @@ -363,7 +363,7 @@ class FileAction extends ObjectAction break; default: - die( 'cannot uncompress file with extension: '.$this->file->extension ); + throw new \OpenRatException( 'cannot uncompress file with extension: '.$this->file->extension ); } $this->addNotice('file',$this->file->name,'DONE',OR_NOTICE_OK); @@ -442,7 +442,7 @@ class FileAction extends ObjectAction break; default: - die( 'cannot extract file with extension: '.$this->file->extension ); + throw new \OpenRatException( 'cannot extract file with extension: '.$this->file->extension ); } $this->callSubAction('edit'); } @@ -514,7 +514,7 @@ class FileAction extends ObjectAction break; default: - die( 'unknown compress type: '.$format ); + throw new \OpenRatException( 'unknown compress type: '.$format ); } $this->addNotice('file',$this->file->name,'DONE',OR_NOTICE_OK); diff --git a/modules/cms-core/action/FolderAction.class.php b/modules/cms-core/action/FolderAction.class.php @@ -797,7 +797,7 @@ class FolderAction extends ObjectAction break; default: - die('fatal: what type to delete?'); + throw new \LogicException('fatal: what type to delete?'); } $notices[] = lang('COPIED'); break; @@ -1585,7 +1585,7 @@ class FolderAction extends ObjectAction public function pubPost() { if ( !$this->folder->hasRight( ACL_PUBLISH ) ) - die('no rights for publish'); + throw new \SecurityException('no rights for publish'); $subdirs = ( $this->hasRequestVar('subdirs') ); $pages = ( $this->hasRequestVar('pages' ) ); diff --git a/modules/cms-core/action/LoginAction.class.php b/modules/cms-core/action/LoginAction.class.php @@ -638,11 +638,6 @@ class LoginAction extends Action if ( !$openId->checkAuthentication() ) { throw new \SecurityException('OpenId-Login failed' ); - die(); - $this->addNotice('user',$openId->user,'LOGIN_OPENID_FAILED',OR_NOTICE_ERROR,array('name'=>$openId->user),array($openId->error) ); - $this->addValidationError('openid_url',''); - $this->callSubAction('showlogin'); - return; } //Html::debug($openId); @@ -657,11 +652,6 @@ class LoginAction extends Action { // Es konnte kein Benutzername ermittelt werden. throw new \SecurityException('no username supplied by openid provider' ); - die(); - $this->addNotice('user',$username,'LOGIN_OPENID_FAILED','error',array('name'=>$username) ); - $this->addValidationError('openid_url',''); - $this->callSubAction('showlogin'); - return; } $user = User::loadWithName( $username ); @@ -683,11 +673,6 @@ class LoginAction extends Action Logger::debug("OpenId-Login failed for $username"); // Benutzer ist nicht in Benutzertabelle vorhanden (und angelegt werden soll er auch nicht). throw new \SecurityException('user',$username,'LOGIN_OPENID_FAILED','error',array('name'=>$username) ); - die(); - - $this->addNotice('user',$username,'LOGIN_OPENID_FAILED','error',array('name'=>$username) ); - $this->addValidationError('openid_url',''); - return; } } else diff --git a/modules/cms-core/action/ObjectAction.class.php b/modules/cms-core/action/ObjectAction.class.php @@ -249,7 +249,7 @@ class ObjectAction extends Action $o = new BaseObject( $acl->objectid ); if ( !$o->hasRight( ACL_GRANT ) ) - die('uh?'); // Scheiss Hacker. + throw new \SecurityException('uh?'); // Scheiss Hacker. // Handelt es sich um eine Benutzer- oder Gruppen ACL? switch( $this->getRequestVar('type') ) diff --git a/modules/cms-core/action/PageelementAction.class.php b/modules/cms-core/action/PageelementAction.class.php @@ -13,6 +13,7 @@ use cms\model\BaseObject; use cms\publish\PublishPreview; use Html; use Http; +use LogicException; use Session; use Transformer; use \Text; @@ -776,7 +777,7 @@ class PageelementAction extends Action $this->value->loadWithId(); if ( $this->value->pageid != $this->page->pageid ) - die( 'cannot release, bad page' ); + throw new LogicException( 'cannot release, bad page' ); // Pruefen, ob Berechtigung zum Freigeben besteht if ( !$this->page->hasRight(ACL_RELEASE) ) diff --git a/modules/cms-core/action/StartAction.class.php b/modules/cms-core/action/StartAction.class.php @@ -591,7 +591,6 @@ class StartAction extends Action Session::set('openid',$openId); $openId->redirect(); - die('Unreachable Code'); } diff --git a/modules/cms-core/auth/OpenIdAuth.class.php b/modules/cms-core/auth/OpenIdAuth.class.php @@ -375,27 +375,16 @@ class OpenIdAuth implements Auth if ( $queryVars['openid.invalidate_handle'] != $this->handle ) { throw new \SecurityException('Association-Handle mismatch.'); - die(); - $this->error = 'Association-Handle mismatch.'; - return false; } if ( $queryVars['openid.mode'] != 'id_res' ) { throw new \SecurityException('Open-Id: Unknown mode:'.$queryVars['openid.mode']); - die(); - - $this->error ='Open-Id: Unknown mode:'.$queryVars['openid.mode']; - return false; } if ( $this->provider=='identity' && $queryVars['openid.identity'] != $this->identity ) { throw new \SecurityException('Open-Id: Identity mismatch. Wrong identity:'.$queryVars['openid.identity']); - die(); - - $this->error ='Open-Id: Identity mismatch. Wrong identity:'.$queryVars['openid.identity']; - return false; } @@ -453,10 +442,6 @@ class OpenIdAuth implements Auth { // Zeile nicht gefunden. throw new \SecurityException('Undefined Open-Id response: "is_valid" expected, but not found'); - die(); - - $this->error = 'Undefined Open-Id response: "is_valid" expected, but not found'; - return false; } elseif ( $result['is_valid'] == 'true' ) { @@ -467,9 +452,6 @@ class OpenIdAuth implements Auth { // Bestaetigung wurde durch den OpenId-Provider abgelehnt. throw new \SecurityException('Server refused login.'); - die(); - $this->error = 'Server refused login.'; - return false; } } diff --git a/modules/cms-core/model/BaseObject.class.php b/modules/cms-core/model/BaseObject.class.php @@ -543,7 +543,7 @@ SQL $row = $sql->getRow(); if (count($row) == 0) - die('fatal: Object::objectLoadRaw(): objectid not found: '.$this->objectid.', SQL='.$sql->raw); + throw new \ObjectNotFoundException('objectid not found: '.$this->objectid); $this->parentid = $row['parentid' ]; $this->filename = $row['filename' ]; @@ -580,7 +580,7 @@ SQL public function setDatabaseRow( $row ) { if ( count($row)==0 ) - die('setDatabaseRow() got empty array, oid='.$this->objectid); + throw new \LogicException('setDatabaseRow() got empty array, oid='.$this->objectid); $this->parentid = $row['parentid' ]; $this->projectid = $row['projectid']; diff --git a/modules/cms-core/model/Image.class.php b/modules/cms-core/model/Image.class.php @@ -151,7 +151,7 @@ class Image extends File break; default: - die('unsupported image format "'.$this->extension.'", cannot load image. resize failed'); + throw new \LogicException('unsupported image format "'.$this->extension.'", cannot load image. resize failed'); } // Ab Version 2 der GD-Bibliothek sind TrueColor-Umwandlungen moeglich. @@ -234,7 +234,7 @@ class Image extends File break; default: - die('unsupported image format "'.$newformat.'", cannot resize'); + throw new \LogicException('unsupported image format "'.$newformat.'", cannot resize'); } $f = fopen( $this->tmpfile(), "r" ); diff --git a/modules/cms-core/model/ObjectFactory.php b/modules/cms-core/model/ObjectFactory.php @@ -42,8 +42,7 @@ class ObjectFactory break; default: - die( "Unknown Object-Typ: ".$o->getType() ); - debug_backtrace(); + throw new \LogicException( "Unknown Object-Typ: ".$o->getType() ); } $x->load(); diff --git a/modules/cms-core/model/User.class.php b/modules/cms-core/model/User.class.php @@ -750,7 +750,7 @@ SQL */ function getRights() { - die('User.class::getRights()'); + throw new \DomainException('User.class::getRights()'); // $db = db_connection(); // $var = array(); diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php @@ -662,10 +662,10 @@ SQL $inhalt = '?'.$this->element->subtype.'?'; } } - else die('FATAL: recursion detected'); + else throw new \LogicException('FATAL: recursion detected'); } } - else die('FATAL: recursion detected'); + else throw new LogicException('FATAL: recursion detected'); } } elseif ( $object->isPage ) @@ -706,7 +706,7 @@ SQL break; } } - else die('FATAL: recursion detected'); + else throw new LogicException('FATAL: recursion detected'); } } diff --git a/modules/cms-ui/themes/default/html/views/login/login.php b/modules/cms-ui/themes/default/html/views/login/login.php @@ -6,13 +6,13 @@ <?php $if3=(config('login','logo','enabled')); if($if3){?> <?php $if4=!((config('login','logo','url'))==FALSE); if($if4){?> <a target="_self" data-url="<?php echo config('login','logo','url') ?>" data-action="" data-method="login" data-id="<?php echo OR_ID ?>" data-extra="[]" href="<?php echo Html::url('','','',array()) ?>"> - <img class="" title="" src="<?php echo config('login','logo','image') ?>" /> + <img src="<?php echo config('login','logo','image') ?>" /> </a> <?php } ?> <?php if(!$if4){?> - <img class="" title="" src="<?php echo config('login','logo','image') ?>" /> + <img src="<?php echo config('login','logo','image') ?>" /> <?php } ?> <?php } ?> diff --git a/modules/cms-ui/themes/default/html/views/user/edit.php b/modules/cms-ui/themes/default/html/views/user/edit.php @@ -33,7 +33,7 @@ <div class="input"> <div class="inputholder"><input id="<?php echo REQUEST_ID ?>_mail" name="<?php if ('') echo ''.'_' ?>mail<?php if ('') echo '_disabled' ?>" type="text" maxlength="255" class="" value="<?php echo Text::encodeHtml(@$mail) ?>" /><?php if ('') { ?><input type="hidden" name="mail" value="<?php $mail ?>"/><?php } ?></div> - <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo 'mailto:'.$mail.'' ?>" title="?QRCODE_SHOW?"></i> + <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo 'mailto:'.$mail.'' ?>" title="QR-Code anzeigen"></i> </div> </div> @@ -56,7 +56,7 @@ <div class="input"> <div class="inputholder"><input id="<?php echo REQUEST_ID ?>_tel" name="<?php if ('') echo ''.'_' ?>tel<?php if ('') echo '_disabled' ?>" type="text" maxlength="128" class="" value="<?php echo Text::encodeHtml(@$tel) ?>" /><?php if ('') { ?><input type="hidden" name="tel" value="<?php $tel ?>"/><?php } ?></div> - <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo 'tel:'.$tel.'' ?>" title="?QRCODE_SHOW?"></i> + <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo 'tel:'.$tel.'' ?>" title="QR-Code anzeigen"></i> </div> </div> @@ -184,7 +184,7 @@ </label> <span><?php echo nl2br(encodeHtml(htmlentities($otpSecret))); ?></span> - <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo $totpSecretUrl ?>" title="?QRCODE_SHOW?"></i> + <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo $totpSecretUrl ?>" title="QR-Code anzeigen"></i> </div> </div> @@ -210,7 +210,7 @@ <label for="<?php echo REQUEST_ID ?>_hotp" class="label"><?php echo lang('user_hotp') ?> </label> - <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo $hotpSecretUrl ?>" title="?QRCODE_SHOW?"></i> + <i class="image-icon image-icon--menu-qrcode qrcode" data-qrcode="<?php echo $hotpSecretUrl ?>" title="QR-Code anzeigen"></i> </div> </div> diff --git a/modules/util/Ldap.class.php b/modules/util/Ldap.class.php @@ -67,13 +67,13 @@ class Ldap { Logger::error( "connect to ldap server '$ldapHost:$ldapPort' failed" ); // Abbruch, wenn LDAP-Server nicht erreichbar - die( "Connection failed to $ldapHost:$ldapPort (".ldap_errno().'/'.ldap_error().'). Please contact your administrator.' ); + throw new RuntimeException( "Connection failed to $ldapHost:$ldapPort (".ldap_errno().'/'.ldap_error().'). Please contact your administrator.' ); } // Protokollversion setzen. $j = ldap_set_option( $this->connection, LDAP_OPT_PROTOCOL_VERSION,intval($conf['ldap']['protocol']) ); if ( ! $j ) - die( 'LDAP error while setting protocol version'.ldap_errno().'/'.ldap_error().')' ); + throw new LogicException( 'LDAP error while setting protocol version'.ldap_errno().'/'.ldap_error().')' ); } diff --git a/modules/wikiparser/parser/WikiParser.class.php b/modules/wikiparser/parser/WikiParser.class.php @@ -154,7 +154,6 @@ class WikiParser $zeilenAuszug = $this->getListenAuszug( $zeilen,$zeileNr,$bisZeileNr); // Html::debug($zeilenAuszug,"Auszug"); -// die(); $quote->children = $this->parseMultiLineText($zeilenAuszug); $zeileNr = $bisZeileNr; $children[] = $quote; @@ -176,7 +175,6 @@ class WikiParser $zeilenAuszug = $this->getListenAuszug( $zeilen,$zeileNr,$bisZeileNr); // Html::debug($zeilenAuszug,"Auszug"); -// die(); foreach( $zeilenAuszug as $zeile ) { $sep = $conf['editor']['text-markup']['definition-sep']; @@ -281,8 +279,7 @@ class WikiParser $bisZeileNr--; // Html::debug($zeileNr,"Zeile"); // Html::debug($bisZeileNr,"bisZeile-P"); -// die(); - + $para = new ParagraphElement(); for( $zn=$zeileNr;$zn<=$bisZeileNr;$zn++) { @@ -305,7 +302,7 @@ class WikiParser continue; } - die( 'unknown line: '.$dieseZeile ); + throw new LogicException( 'unknown line: '.$dieseZeile ); } return $children;