From c8317e4a9402cf848a54ea7837c3a93572306f12 Mon Sep 17 00:00:00 2001 From: Roland Hieber Date: Sun, 7 Mar 2010 03:25:13 +0100 Subject: [PATCH] config migration in source code; config page is not needed anymore --- inc/class_erConfig.inc | 192 +++++-------------------- inc/class_erErrorReport.inc | 30 ++-- inc/class_erErrorReportManager.inc | 30 +--- inc/class_erErrorReportView.inc | 9 +- inc/init.inc | 8 +- nav/79mod_error-reporter.mod | 5 +- nav/admin/99mod_error-reporter-cfg.mod | 30 ---- src/config.php | 144 ------------------- src/detail.php | 10 +- src/index.php | 7 +- 10 files changed, 75 insertions(+), 390 deletions(-) delete mode 100644 nav/admin/99mod_error-reporter-cfg.mod delete mode 100644 src/config.php diff --git a/inc/class_erConfig.inc b/inc/class_erConfig.inc index ee7c6df..d980b4c 100644 --- a/inc/class_erConfig.inc +++ b/inc/class_erConfig.inc @@ -1,22 +1,22 @@ 0; -} - -/** - * Retrieve all groups that have a privilege assigned - * @param $strPriv (string) Privilege to test - * @return array - */ -function erPrivilegedGroups($strPriv) { - $aReturn = array(); - $h = db_query("SELECT act FROM privileges_assign WHERE privilege = $1 ". - "ORDER BY act;", $strPriv); - if(pg_num_rows($h) > 0) { - while($a = pg_fetch_array($h)) { - $aReturn[] = $a["act"]; - } - } - return $aReturn; -} - -define("ER_CONFIGFILE_HEADER", "setMailNotify(true); - $this->setMailNotifyAddr("admins, win-admins"); + public static function privilegeAssigned($sPriv) { + $h = db_query("SELECT act FROM privileges_assign WHERE privilege = $1;", + $sPriv); + return pg_num_rows($h) > 0; } - - /** - * @} - * @name Operations - * @{ - */ - + /** - * Write the current state of this instance to the config file. - * @return (bool) If the function fails, it returns false. Call - * getLastError() to get more information about the error. + * Retrieve all groups that have a privilege assigned + * @param $strPriv (string) Privilege to test + * @return array */ - public function writeConfig() { - // Open config file - $hFile = fopen("mod_error-reporter/config.inc", "w", true); - if(!is_resource($hFile)) { - setLastError(ER_ERROR_OPEN_FILE); - return false; - } - // Try to lock file repeatedly - for($n = 0; !flock($hFile, LOCK_EX); $n++) { - if($n > 10) { - setLastError(ER_ERROR_LOCK_FILE); - return false; // Give up - } else { - sleep(0.1); // Retry after 100 ms + public static function privilegedGroups($strPriv) { + $aReturn = array(); + $h = db_query("SELECT act FROM privileges_assign WHERE privilege = $1 ". + "ORDER BY act;", $strPriv); + if(pg_num_rows($h) > 0) { + while($a = pg_fetch_array($h)) { + $aReturn[] = $a["act"]; } } - - // Create text for config file - $strFile = ER_CONFIGFILE_HEADER; - - // Mail notification - $strFile .= sprintf("\$cfgErrors->setMailNotify(%s);\n", - $this->isMailNotify() ? "true" : "false"); - $strFile .= sprintf("\$cfgErrors->setMailNotifyAddr('%s');\n", - $this->getMailNotifyAddr()); - - $strFile .= "?>"; - - // Write to config file and unlock it - if(fwrite($hFile, $strFile) == false) { - setLastError(ER_ERROR_WRITE_FILE); - return false; - } - if(!flock($hFile, LOCK_UN)) { - setLastError(ER_ERROR_UNLOCK_FILE); - return false; - } - return true; + return $aReturn; } - - public function readConfig() { - global $cfgErrors; - require("error-reporter/config.inc"); - } - - /** - * @} - * @name Setting options - * @{ - */ - - /** - * Enable or disable mail notification - * @param $b (bool) true to enable mail notification, false - * to disable it. - */ - public function setMailNotify($b) { $this->bMailNotify = ($b == true); } - - /** - * Set the mail address(es) for mail notification - * @param $str (string) The adresses to send the notofication mails to, - * comma-separated - */ - public function setMailNotifyAddr($str) { $this->strMailNotifyAddr = $str; } - - /** - * @} - * @name Retrieving options - * @{ - */ - - /** - * Determine if mail notification is enabled - * @return (bool) true if mail notification is enabled, otherwise - * false - */ - public function isMailNotify() { return $this->bMailNotify; } - - /** - * Get the mail adress(es) for mail notification - * @return string - */ - public function getMailNotifyAddr() { return $this->strMailNotifyAddr; } /** * Determine if the current user is allowed to see and report errors. This * function tests if the user is member of a group which has the * mod-errorreporter_access privilege. - * @return bool + * @return bool */ - public function userHasAccess() { - if($this->userIsAdmin() || - !erPrivilegeAssigned("mod_errorreporter_access")) { + public static function userHasAccess() { + if(erConfig::userIsAdmin() || + !erConfig::privilegeAssigned("mod_errorreporter_access")) { // user is admin or privilege is not assigned return true; } else { return secure_privilege("mod_errorreporter_access"); } } - - /* legacy */ - public function userIsAllowed() { return $this->userHasAccess(); } - + /** - * Determine if the current user has admin rights. This function tests if - * the user is member of a group which has the + * Determine if the current user has admin rights. This function tests if + * the user is member of a group which has the * mod-errorreporter_access privilege - * @return bool + * @return bool */ - public function userIsAdmin() { + public static function userIsAdmin() { return secure_privilege("mod_errorreporter_admin"); } - + /** @} */ } ?> diff --git a/inc/class_erErrorReport.inc b/inc/class_erErrorReport.inc index 827dc4d..2b5208f 100644 --- a/inc/class_erErrorReport.inc +++ b/inc/class_erErrorReport.inc @@ -4,19 +4,19 @@ * A container class for an error report * @author Roland Hieber (roland.hieber@wilhelm-gym.net) * @date 18.10.2007 - * + * * Copyright © 2007 Roland Hieber - * + * * Permission is hereby granted, free of charge, to any person obtaining * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -48,7 +48,7 @@ class erErrorReport { var $strCommentOwner; /** (bool) Indicate if the report can be seen by non-administrators */ var $bHidden; - + /** * @publicsection * @name Constructor @@ -64,8 +64,8 @@ class erErrorReport { * non-administrators * @return erError */ - function erErrorReport($tsDate = null, $strOwner = null, $strMachine = null, $strText = null, - $bHidden = false) { + function erErrorReport($tsDate = null, $strOwner = null, $strMachine = null, + $strText = null, $bHidden = false) { $this->nUid = null; $this->tsDate = intval($tsDate); $this->strOwner = $strOwner; @@ -75,15 +75,15 @@ class erErrorReport { $this->strCommentOwner = null; $this->bHidden = ($bHidden == true); } - + ////////////////////////////// SETTER FUNCTIONS ////////////////////////////// - + /** * @} * @name Setter functions * @{ */ - + /** * Set the unique ID * @param $value (int) @@ -125,15 +125,15 @@ class erErrorReport { * administrators */ function setVisibility($value) { $this->bHidden = $value; } - + ////////////////////////////// GETTER FUNCTIONS ////////////////////////////// - + /** * @} * @name Getter functions * @{ */ - + /** * Get the unique ID in the database * @return (int) @@ -145,7 +145,7 @@ class erErrorReport { */ function getDate() { return intval($this->tsDate); } /** - * Get the account name of the creator + * Get the account name of the creator * @return (string) */ function getOwner() { return $this->strOwner; } @@ -174,7 +174,7 @@ class erErrorReport { * @return (bool) */ function isHidden() { return ($this->bHidden == true); } - + /**@}*/ } ?> diff --git a/inc/class_erErrorReportManager.inc b/inc/class_erErrorReportManager.inc index cf15e03..425f26b 100644 --- a/inc/class_erErrorReportManager.inc +++ b/inc/class_erErrorReportManager.inc @@ -28,6 +28,7 @@ require_once("mod_error-reporter/class_erErrorReport.inc"); require_once("mod_error-reporter/class_erConfig.inc"); require_once("mod_error-reporter/functions.inc"); +require_once("cfg.inc"); require_once("db.inc"); require_once("user.inc"); @@ -116,23 +117,6 @@ define("ER_ERM_SORT_DESC", 1); /*< sort descending */ */ class erErrorReportManager { - - - /** - * (object of type erConfig) pointer to the configuration class - */ - protected $objcfg; - - /** - * Constructor - * @param $objcfg (object of type erConfig) Pointer to the configuration - * class for retrieving the - * configuration data - * @return erErrorReportManager - */ - public function __construct(&$objcfg) { - $this->objcfg = &$objcfg; - } /////////////////////////////////// QUERYING ///////////////////////////////// @@ -259,7 +243,7 @@ class erErrorReportManager { // only allow visible reports for non-admins, but all reports for // admins and owners - if($this->objcfg->userIsAdmin()) { + if(erConfig::userIsAdmin()) { $strWhereClause = (trim($strWhere) == "") ? "" : "WHERE $strWhere"; } else { $strWhereClause = "WHERE ".((trim($strWhere) == "") ? "" : @@ -366,8 +350,8 @@ class erErrorReportManager { * @throws Exception */ public function writeErrorReport(erErrorReport $er) { - if(!$this->objcfg->userHasAccess() and (!$this->userIsOwner($er->nUid) or - ($er->getUid() == null and !($this->objcfg->userIsAdmin())))) { + if(!erConfig::userHasAccess() and (!$this->userIsOwner($er->nUid) or + ($er->getUid() == null and !(erConfig::userIsAdmin())))) { throw new Exception(ER_ERROR_ACCESS_DENIED); } @@ -408,7 +392,7 @@ class erErrorReportManager { erInsertLog($strLog); // send notification mail, but only if the message is new - if($this->objcfg->isMailNotify() and $er->getUid() == null) { + if(cfg("errorreportermailnotify") and $er->getUid() == null) { $strMailText = sprintf("\nEin Benutzer hat eine ". "Fehlermeldung mit dem Fehlermeldungs-Assistenten abgeschickt. ". "Nachfolgend finden sich Angaben über den Fehler.\n". @@ -425,7 +409,7 @@ class erErrorReportManager { $strMailHeader = sprintf("From: %s <%s>\n". "Content-Type: text/html; charset=utf-8", q(erGetRealUserName($er->getOwner())), user_mail_addr($er->getOwner())); - mail($this->objcfg->getMailNotifyAddr(), $strMailSubject, $strMailText, + mail(cfg("errorreportermailaddress"), $strMailSubject, $strMailText, $strMailHeader); } @@ -439,7 +423,7 @@ class erErrorReportManager { * information. */ public function deleteErrorReport($nErrorReportID) { - if(!($this->objcfg->userIsAdmin() or $this->userIsOwner($nErrorReportID))) { + if(!(erConfig::userIsAdmin() or $this->userIsOwner($nErrorReportID))) { setLastError(ER_ERROR_ACCESS_DENIED); return -1; } diff --git a/inc/class_erErrorReportView.inc b/inc/class_erErrorReportView.inc index e335881..590205e 100644 --- a/inc/class_erErrorReportView.inc +++ b/inc/class_erErrorReportView.inc @@ -35,8 +35,6 @@ require_once("format.inc"); /** @todo document */ class erErrorReportView { - /** (erConfig) pointer to the configuration class */ - protected $objcfg; /** (erErrorReportManager) pointer to a erErrorReportManager instance */ protected $objManager; /** @@ -54,14 +52,11 @@ class erErrorReportView { /** * Constructor - * @param $objcfg (erConfig) Pointer to an instance of the erConfig class for - * retrieving the configuration data * @param $objemm (erErrorReportManager) Pointer to a instance of the * erErrorReportManager class for retrieving the document data * @return erErrorReportView */ - public function __construct(erConfig &$objcfg, erErrorReportManager &$objemm) { - $this->objcfg = $objcfg; + public function __construct(erErrorReportManager &$objemm) { $this->objManager = $objemm; html_header(""); - -$cfgErrors = new erConfig(); -require_once("mod_error-reporter/config.inc"); - -PageBlue(_c("error-reporter-cfg:Error Report Wizard – Configuration"), - "mod_error-reporter"); - -if(@$_POST["submit"] == _("Save")) { - $bMailNotify = (@$_POST["mailnotify"] == "true"); - $strMailNotifyAddr = @$_POST["mailnotifyaddr"]; - $bLog = (@$_POST["log"] == "true"); - - if($bMailNotify != $cfgErrors->isMailNotify()) { - $cfgErrors->setMailNotify($bMailNotify); - echo sprintf("

%s

\n", _c("error-reporter-cfg:Set mail ". - "notification.")); - } - if($strMailNotifyAddr != $cfgErrors->getMailNotifyAddr()) { - if(!erIsMailAddress($strMailNotifyAddr)) { - echo sprintf("

%s

", _c("error-reporter-cfg:The ". - "specified string is not a valid e-mail address!")); - } else { - $cfgErrors->setMailNotifyAddr($strMailNotifyAddr); - echo sprintf("

%s

\n", _c("error-reporter-cfg:Set mail ". - "notification address.")); - } - } - $cfgErrors->writeConfig(); -} - -// two columns -echo "". - "
\n"; - -// Mail notification -GroupBox(_c("error-reporter-cfg:Mail notification"), "mail"); -echo "
\n"; -echo "\n"; -echo sprintf("", - _c("error-reporter-cfg:Enable mail notification"), - _c("error-reporter-cfg:If this option is enabled, everytime an error report ". - "is submitted, an e-mail with information about the report will be sent to ". - "the address specified below."), $cfgErrors->isMailNotify() ? - " checked='checked'" : ""); -echo sprintf("". - "", - _c("error-reporter-cfg:Mail address to send the notification mail to"), - _c("error-reporter-cfg:If mail notifications are enabled, any notification ". - "mails are sent to the address specified here. You can give more than one ". - "address by separating them with a comma."), - q($cfgErrors->getMailNotifyAddr())); -echo sprintf("\n", _("Save")); -echo "

%s

%s
<$stdbtn name='submit' ". - "value='%s' />
\n
\n"; -_GroupBox(); - -echo "
\n"; - -// Privileges -GroupBox(_("Privileges"), "keys"); -$asAccessGroups = erPrivilegedGroups("mod_errorreporter_access"); -$asAdminGroups = erPrivilegedGroups("mod_errorreporter_admin"); -echo sprintf("

%s

\n

%s

\n

%s

", _c("error-reporter:This is ". - "a short summary of the privileges related to the error report assistant ". - "and the groups which have them assigned."), - sprintf(_c("error-reporter:If one of these privileges is not assigned to ". - "any group, all users on this server are allowed to perform the specified ". - "action. Please use the %sgroup administration%s to assign and revoke ". - "privileges."), "", ""), - _c("error-reporter:Please note that every group with the administration ". - "privilege can also implicitly report errors and see the reported ". - "messages.")); -echo "

\n"; -echo sprintf("\n", icon("keys"), - _("View error reports and report errors").":", $asAccessGroups == array() ? - _c("error-reporter:all users") : icon("act-group") . join(", ", - array_map("erGetGroupName", $asAccessGroups))); -echo "\n"; -echo sprintf("\n", icon("keys"), - _("Administration of the error report wizard"), - $asAdminGroups == array() ? _c("error-reporter:no users") : - icon("act-group") . join(", ", array_map("erGetGroupName", $asAdminGroups))); -echo "
%s%s%s
%s%s%s

\n"; -_GroupBox(); - -echo "
\n"; - -_PageBlue(); -?> diff --git a/src/detail.php b/src/detail.php index a0af8ac..1dfbcf3 100644 --- a/src/detail.php +++ b/src/detail.php @@ -34,7 +34,7 @@ db_user("errorreporter"); PageBlue(_c("error-reporter:Change an error report"), "mod_error-reporter"); -if(!$cfgErrors->userHasAccess()) { +if(!erConfig::userHasAccess()) { printf("

%s

\n", ER_ERROR_ACCESS_DENIED); _PageBlue(); die(); @@ -55,7 +55,7 @@ if(!is_object($doc->getErrorReportByID($getUid))) { } // Only admins or owners can view this page -if(!($cfgErrors->userIsAdmin() or $doc->userIsOwner($getUid))) { +if(!(erConfig::userIsAdmin() or $doc->userIsOwner($getUid))) { echo sprintf("

%s", _c("error-reporter:You are not ". "allowed to edit this report.")); _PageBlue(); @@ -69,7 +69,7 @@ $strOldComment = $er->getComment(); // Probably we have to update an error report if($getAction == "update" and $postSubmit == _("Change")) { - if($cfgErrors->userIsAdmin()) { + if(erConfig::userIsAdmin()) { $postComment = stripslashes(@$_POST["comment"]); $postCommentOld = stripslashes(@$_POST["comment_old"]); } @@ -80,7 +80,7 @@ if($getAction == "update" and $postSubmit == _("Change")) $er->setVisibility(isset($_POST["hidden"]) ? true : false); // Do we have to change the comment and his owner? - if($cfgErrors->userIsAdmin()) { + if(erConfig::userIsAdmin()) { if(@$_POST["comment_old"] != @$_POST["comment"]) { $er->setComment(stripslashes(@$_POST["comment"]), $_SESSION["act"]); } @@ -116,7 +116,7 @@ echo sprintf("". "". "\n", _c("error-reporter:Hidden:"), $er->isHidden() ? " checked='checked'" : ""); -if($cfgErrors->userIsAdmin()) { +if(erConfig::userIsAdmin()) { echo sprintf("%s", _c("error-reporter:Comment:"), $er->getComment()); if($er->getComment() != "") { diff --git a/src/index.php b/src/index.php index 9a9f7d7..0bae2b6 100644 --- a/src/index.php +++ b/src/index.php @@ -51,7 +51,7 @@ $strError = ""; PageBlue(_c("error-reporter:Report an error"), "mod_error-reporter"); -if(!$cfgErrors->userHasAccess()) { +if(!erConfig::userHasAccess()) { printf("

%s

\n", ER_ERROR_ACCESS_DENIED); _PageBlue(); exit(); @@ -75,7 +75,7 @@ if($getAction == "delete" and isset($getUid)) { _c("error-reporter:The specified error report does not exist!")); Option(_("Back"), null, "href='".$_SERVER["PHP_SELF"]."'", "back"); } else { - if($cfgErrors->userIsAdmin() or $doc->userIsOwner($getUid)) { + if(erConfig::userIsAdmin() or $doc->userIsOwner($getUid)) { echo sprintf("
\n", $view->getDeleteURL($getUid)); echo sprintf("

%s

", _c("error-reporter:You are about to delete ". @@ -109,7 +109,8 @@ if(($getAction == "submit" and $postSubmit == _c("error-reporter:Submit"))) } else { // Write to database $nNewUid = null; - $er = new erErrorReport(time(), $_SESSION["act"], $postMachine, $postText, $postHidden == "true"); + $er = new erErrorReport(time(), $_SESSION["act"], $postMachine, $postText, + $postHidden == "true"); try { $nNewUid = $doc->writeErrorReport($er); } catch(Exception $e) { -- 2.20.1