X-Git-Url: https://git.rohieb.name/iserv-mod-error-reporter.git/blobdiff_plain/f6faefbedad2de5c5d4aa915f5a5f180039c055b..dc5b455125820baee8b306e827be5d89aaa6c66d:/inc/class_erConfig.inc 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"); } - + /** @} */ } ?>