* Thijs Kinkhorst <[EMAIL PROTECTED]> [2006-12-25 18:20]:

> On Sat, December 23, 2006 23:04, Fernando M. Maresca wrote:
> > Hi. Here is the function:
> > ###
> > function die_miserable_death ( $error ) {
> > global $TROUBLE_URL; echo "<html><head><title>WebCalendar: Fatal
> > Error</title></head>\n" .
> > "<body><h2>WebCalendar Error</h2>\n" .
> > "</body></html>\n";
> > exit; }
> > ###
> >
> >
> > Now, don't you think that would be nice that this function actually
> > echoes the $error argument somewhere inside the <body>? ;-)
> 
> Hmm, I indeed misread this. The Debian package specifically patches this
> function to change it (I was looking at the source package file); I'm
> quite unsure why. It should be investigated and possibly fixed indeed.

I looked at debian/patches/01_config_patch.dpatch.  The comment in its
header says:

## DP: Fixes a problem with showing error messages (like invalid logins)
## and adds support for reading settings.conf

Most of the patch concerns the second phrase ("adds support for reading
settings.conf").  The first phrase ("problem with showing error messages")
regards this part of the patch:

@@ -49,67 +49,44 @@
 global $TROUBLE_URL;
   echo "<html><head><title>WebCalendar: Fatal Error</title></head>\n" .
     "<body><h2>WebCalendar Error</h2>\n" .
-    "<p>$error</p>\n<hr />" .
-    "<p><a href=\"$TROUBLE_URL\"target=\"_blank\">" .
-    "Troubleshooting Help</a></p></body></html>\n";
+    "</body></html>\n";
   exit;
 }

which is the object of the present bug report.  However, I cannot understand
which problem the changes above are trying to fix.  Later in the same patch,
there is code like this:

 foreach ( array ( "db_type", "db_host", "db_login", "db_password") as $s ) {
   if ( empty ( $settings[$s] ) ) {
     die_miserable_death ( "Could not find <tt>$s</tt> defined in " .
-      "your <tt>settings.php</tt> file.\n");
+      "your <tt>$WC_CONFIG_FILE</tt> file.\n");
   }
 }

If the patch itself is changing the argument of die_miserable_death, why
would it be ignored with the first change set?  That makes no sense and is
probably an unintentional change.  Unfortunately, I could not find a comment
about this patch in debian/changelog.  Is Tim Peeler (the author of the
patch) still active?
 
I would strongly suggest to use the patch attached below instead.  

-- 
Rafael
#! /bin/sh /usr/share/dpatch/dpatch-run
## 01_config_patch.dpatch by  <[EMAIL PROTECTED]>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Fixes a problem with showing error messages (like invalid logins)
## and adds support for reading settings.conf

@DPATCH@
diff -urNad webcalendar-1.0.3~/includes/config.php 
webcalendar-1.0.3/includes/config.php
--- webcalendar-1.0.3~/includes/config.php      2006-05-22 11:51:20.000000000 
-0400
+++ webcalendar-1.0.3/includes/config.php       2006-05-22 12:01:27.000000000 
-0400
@@ -49,58 +49,37 @@
 
 
 // Open settings file to read
-$settings = array ();
-$settings_file = dirname(__FILE__) . "/settings.php";
-//called from send_reminders.php
-if ( ! empty ( $includedir ) ) 
-  $fd = @fopen ( "$includedir/settings.php", "rb", true );
-else
-  $fd = @fopen ( "settings.php", "rb", true );
-if ( ! $fd )
-  $fd = @fopen ( "includes/settings.php", "rb", true );
-if ( ! $fd  && file_exists ( $settings_file ) )
-  $fd = @fopen ( $settings_file, "rb", true );
-if ( empty ( $fd ) ) {
-  // There is no settings.php file.
-  // Redirect user to install page if it exists.
-  if ( file_exists ( "install/index.php" ) ) {
-    Header ( "Location: install/index.php" );
-    exit;
-  } else {
-    die_miserable_death ( "Could not find settings.php file.<br />\n" .
-      "Please copy settings.php.orig to settings.php and modify for your " .
-      "site.\n" );
-  }
-}
 
-// We don't use fgets() since it seems to have problems with Mac-formatted
-// text files.  Instead, we read in the entire file, then split the lines
-// manually.
-$data = '';
-while ( ! feof ( $fd ) ) {
-  $data .= fgets ( $fd, 4096 );
+$WC_CONFIG_FILE = "/etc/webcalendar/settings.conf";
+$WC_ALT_FILE = $_ENV['WEBCALENDAR_CONFIG_FILE'];
+if (!empty($WC_ALT_FILE) && file_exists($WC_ALT_FILE) &&
+        is_readable($WC_ALT_FILE)) {
+    $WC_CONFIG_FILE = $WC_ALT_FILE;
 }
-fclose ( $fd );
 
-// Replace any combination of carriage return (\r) and new line (\n)
-// with a single new line.
-$data = preg_replace ( "/[\r\n]+/", "\n", $data );
+if (file_exists($WC_CONFIG_FILE) && is_readable($WC_CONFIG_FILE)) {
+    $configLines = file($WC_CONFIG_FILE);
+} else {
+    die("Could not read $WC_CONFIG_FILE\n");
+}
 
-// Split the data into lines.
-$configLines = explode ( "\n", $data );
+$settings = array ();
 
 for ( $n = 0; $n < count ( $configLines ); $n++ ) {
   $buffer = $configLines[$n];
-  $buffer = trim ( $buffer, "\r\n " );
-  if ( preg_match ( "/^#/", $buffer ) )
-    continue;
-  if ( preg_match ( "/^<\?/", $buffer ) ) // start php code
-    continue;
-  if ( preg_match ( "/^\?>/", $buffer ) ) // end php code
-    continue;
-  if ( preg_match ( "/(\S+):\s*(\S+)/", $buffer, $matches ) ) {
-    $settings[$matches[1]] = $matches[2];
-    //echo "settings $matches[1] => $matches[2] <br>";
+  $buffer = trim ( $buffer, "\x0b\0\t\r\n " );
+  if ( preg_match ( "/^#|^\s+#/", $buffer ) ) continue;
+  if ( preg_match ( "/(\S+)\s+=\s+(\S+)/", $buffer, $matches ) ) {
+    $key = trim($matches[1]);
+    $val = trim($matches[2]);
+
+    if (preg_match("/(\S+)\.(\S+)/", $key, $index)) {
+        $key  = trim($index[1]);
+        $key2 = trim($index[2]);
+        $settings[$key][$key2] = $val;
+    } else {
+        $settings[$key] = $val;
+    }
   }
 }
 $configLines = $data = '';
@@ -120,36 +97,47 @@
 $db_login = $settings['db_login'];
 $db_password = $settings['db_password'];
 $db_database = $settings['db_database'];
-$db_persistent = preg_match ( "/(1|yes|true|on)/i",
-  $settings['db_persistent'] ) ? '1' : '0';
+$db_persistent = preg_match ( "/(1|yes|true|on|y|t)/i",
+   $settings['db_persistent'] ) ? '1' : '0';
+
 
 foreach ( array ( "db_type", "db_host", "db_login", "db_password" ) as $s ) {
   if ( empty ( $settings[$s] ) ) {
     die_miserable_death ( "Could not find <tt>$s</tt> defined in " .
-      "your <tt>settings.php</tt> file.\n" );
+      "your <tt>$WC_CONFIG_FILE</tt> file.\n" );
   }
 }
 
-$readonly = preg_match ( "/(1|yes|true|on)/i",
-  $settings['readonly'] ) ? 'Y' : 'N';
+$readonly = preg_match ( "/(1|yes|true|on|y|t)/i",
+   $settings['readonly'] ) ? 'Y' : 'N';
+
 
 $single_user = "N";
-$single_user = preg_match ( "/(1|yes|true|on)/i",
-  $settings['single_user'] ) ? 'Y' : 'N';
+$single_user = preg_match ( "/(1|yes|true|on|y|t)/i",
+   $settings['single_user'] ) ? 'Y' : 'N';
 if ( $single_user == 'Y' )
   $single_user_login = $settings['single_user_login'];
 
 if ( $single_user == 'Y' && empty ( $single_user_login ) ) {
   die_miserable_death ( "You must define <tt>single_user_login</tt> in " .
-    "the settings.php file.\n" );
+    "the $WC_CONFIG_FILE file.\n" );
 }
 
 
-$use_http_auth = preg_match ( "/(1|yes|true|on)/i",
+$use_http_auth = preg_match ( "/(1|yes|true|on|y|t)/i",
   $settings['use_http_auth'] ) ? true : false;
 
 // Type of user authentication
 $user_inc = $settings['user_inc'];
+$user_inc = 'user.php';
+switch($settings['auth_mechanism']) {
+    case 'ldap'     : $user_inc = 'user-ldap.php'; break;
+    case 'nis'      : $user_inc = 'user-nis.php'; break;
+    case 'postnuke' : $user_inc = 'user-app-postnuke.php'; break;
+    case 'standard' :
+    default         : $user_inc = 'user.php'; break;
+}
+
 
 // We can add extra 'nonuser' calendars such as a corporate calendar,
 // holiday calendar, departmental calendar, etc.  We need a unique prefix
diff -urNad webcalendar-1.0.3~/includes/user-app-postnuke.php 
webcalendar-1.0.3/includes/user-app-postnuke.php
--- webcalendar-1.0.3~/includes/user-app-postnuke.php   2006-05-22 
11:51:20.000000000 -0400
+++ webcalendar-1.0.3/includes/user-app-postnuke.php    2006-05-22 
12:03:35.000000000 -0400
@@ -25,61 +25,62 @@
 
 /************************* Config ***********************************/
 
+global $settings;
 //------ Postnuke Specific Settings ------//
 // PostNuke session id cookie
-$pn_sid = 'POSTNUKESID';
+$pn_sid = $settings['pn_sid'];
 
 // Name of table containing users
-$pn_user_table = 'nuke_users';
+$pn_user_table = $settings['pn_user_table'];
 
 // Name of table containing sessions
-$pn_session_table = 'nuke_session_info';
+$pn_session_table = $settings['pn_session_table'];
 
 // Name of table containing group memberships
-$pn_group_table = 'nuke_group_membership';
+$pn_group_table = $settings['pn_group_table'];
 
 // Name of table containing settings
-$pn_settings_table = 'nuke_module_vars';
+$pn_settings_table = $settings['pn_settings_table'];
 
 // Set the group id of the postnuke group you want to be webcal admins.
 // Default is set to the postnuke 'Admins' group
-$pn_admin_gid = '2';
+$pn_admin_gid = $settings['pn_admin_gid'];
 
 
 //------ General Application Settings ------//
 // What is the full URL to the login page (including http:// or https://)
-$app_login_page = 
'http://www.mysite.com/postnuke/html/user.php?op=loginscreen&module=NS-User'; 
+$app_login_page = $settings['app_login_page'];
 
 // Is there a parameter we can pass to tell the application to
 // redirect the user back to the calendar after login?
-$app_redir_param = 'url';  // postnuke uses 'url'
+$app_redir_param = $settings['app_redir_param'];  // postnuke uses 'url'
 
 // What is the full URL to the logout page (including http:// or https://)
-$app_logout_page = 
'http://www.mysite.com/postnuke/html/user.php?module=NS-User&op=logout'; 
+$app_logout_page = $settings['app_logout_page'];
 
 // Are the application's tables in the same database as webcalendar's?
-$app_same_db = '0';  // 1 = yes, 0 = no
+$app_same_db = 
+    preg_match("/yes|true|t|y|1/", $settings['app_same_db']) ?  '1' : '0';
  
 // Only need configure the rest if $app_same_db != 1
 
  // Name of database containing the app's tables
-$app_db = 'postnuke';
+$app_db = $settings['app_db'];
 
 // Host that the app's db is on
-$app_host = 'localhost';
+$app_host = $settings['app_host'];
 
 // Login/Password to access the app's database
-$app_login = 'pnuser';
-$app_pass  = 'pnpassword';
+$app_login = $settings['app_login'];
+$app_pass  = $settings['app_pass'];
 
 /*************************** End Config *****************************/
 
 
 // User administration should be done through the aplication's interface
-$user_can_update_password = false;
-$admin_can_add_user = false;
-$admin_can_delete_user = false;
-
+$user_can_update_password = $settings['user_can_update_password'];
+$admin_can_add_user = $settings['admin_can_add_user'];
+$admin_can_delete_user = $settings['admin_can_delete_user'];
 
 // Checks to see if the user is logged into the application
 // returns: login id
diff -urNad webcalendar-1.0.3~/includes/user-ldap.php 
webcalendar-1.0.3/includes/user-ldap.php
--- webcalendar-1.0.3~/includes/user-ldap.php   2006-05-22 11:51:20.000000000 
-0400
+++ webcalendar-1.0.3/includes/user-ldap.php    2006-05-22 12:04:37.000000000 
-0400
@@ -24,73 +24,77 @@
 // webcal_user.
 
 
+global $settings;
 /***************************** Config *******************************/
 // Set some global config variables about your system.
 // Next three are NOT yet implemented for LDAP
-$user_can_update_password = false;
-$admin_can_add_user = false;
-$admin_can_delete_user = false;
+$user_can_update_password = $settings['user_can_update_password'];
+$admin_can_add_user = $settings['admin_can_add_user'];
+$admin_can_delete_user = $settings['admin_can_delete_user'];
 
 
 //------ LDAP General Server Settings ------//
 //
 // Name or address of the LDAP server 
 //  For SSL/TLS use 'ldaps://localhost'
-$ldap_server = 'localhost';          
+$ldap_server = $settings['ldap_server'];
 
 // Port LDAP listens on (default 389)        
-$ldap_port = '389';                   
+$ldap_port = $settings['ldap_port'];
 
 // Use TLS for the connection (not the same as ldaps://)
-$ldap_start_tls = false;
+$ldap_start_tls = 
+    preg_match("/y|yes|t|true|1/", $settings['ldap_start_tls']) ?
+        true : false;
 
 // If you need to set LDAP_OPT_PROTOCOL_VERSION
-$set_ldap_version = false;
-$ldap_version = '3'; // (usually 3)
+$set_ldap_version = 
+    preg_match("/y|yes|t|true|1/", $settings['set_ldap_version']) ?
+        true : false;
+$ldap_version = $settings['ldap_version'];
 
 // base DN to search for users      
-$ldap_base_dn = 'ou=people,dc=company,dc=com';
+$ldap_base_dn = $settings['ldap_base_dn'];
 
 // The ldap attribute used to find a user (login). 
 // E.g., if you use cn,  your login might be "Jane Smith"
 //       if you use uid, your login might be "jsmith"
-$ldap_login_attr = 'uid';
+$ldap_login_attr = $settings['ldap_login_attr'];
 
 // Account used to bind to the server and search for information. 
 // This user must have the correct rights to perform search.
 // If left empty the search will be made in anonymous.
 //
 // *** We do NOT recommend storing the root LDAP account info here ***
-$ldap_admin_dn = '';  // user DN
-$ldap_admin_pwd = ''; // user password
+$ldap_admin_dn = $settings['ldap_admin_dn'];  // user DN
+$ldap_admin_pwd = $settings['ldap_admin_pwd']; // user password
 
 
 //------ Admin Group Settings ------//
 //
 // A group name (complete DN) to find users with admin rights
-$ldap_admin_group_name = 'cn=webcal_admin,ou=group,dc=company,dc=com';
+$ldap_admin_group_name = $settings['ldap_admin_group_name'];
 
 // What type of group do we want (posixgroup, groupofnames, groupofuniquenames)
-$ldap_admin_group_type = 'posixgroup';
+$ldap_admin_group_type = $settings['ldap_admin_group_type'];
 
 // The LDAP attribute used to store member of a group
-$ldap_admin_group_attr = 'memberuid';
+$ldap_admin_group_attr = $settings['ldap_admin_group_attr'];
 
 
 //------ LDAP Search Settings ------//
 //
 // LDAP filter to find a user list.
-$ldap_user_filter = '(objectclass=person)';
+$ldap_user_filter = $settings['ldap_user_filter'];
 
 // Attributes to fetch from LDAP and corresponding user variables in the
 // application. Do change according to your LDAP Schema
 $ldap_user_attr = array( 
-  // LDAP attribute   //WebCalendar variable
-  'uid',              //login
-  'sn',               //lastname
-  'givenname',        //firstname
-  'cn',               //fullname
-  'mail'              //email
+    $settings['ldap_user_attr']['login'],
+    $settings['ldap_user_attr']['lastname'],
+    $settings['ldap_user_attr']['firstname'],
+    $settings['ldap_user_attr']['fullname'],
+    $settings['ldap_user_attr']['email']
 );
 
 /*************************** End Config *****************************/
diff -urNad webcalendar-1.0.3~/includes/user-nis.php 
webcalendar-1.0.3/includes/user-nis.php
--- webcalendar-1.0.3~/includes/user-nis.php    2006-05-22 11:51:20.000000000 
-0400
+++ webcalendar-1.0.3/includes/user-nis.php     2006-05-22 12:05:17.000000000 
-0400
@@ -18,15 +18,17 @@
 // need these functions and you will still need to add users to
 // webcal_user.
 
+global $settings;
+
 // Set some global config variables about your system.
 // For NIS (which is maintained external to WebCalendar), don't let them
 // add/delete users or change passwords.
-$user_can_update_password = false;
-$admin_can_add_user = false;
-$admin_can_delete_user = false;
+$user_can_update_password = $settings['user_can_update_password'];
+$admin_can_add_user = $settings['admin_can_add_user'];
+$admin_can_delete_user = $settings['admin_can_delete_user'];
 
 // $user_external_group = 100;
-$user_external_email = "domain.com";
+$user_external_email = $settings['user_external_email'];
 
 // Check to see if a given login/password is valid.  If invalid,
 // the error message will be placed in $error (a global variable).
diff -urNad webcalendar-1.0.3~/includes/user.php 
webcalendar-1.0.3/includes/user.php
--- webcalendar-1.0.3~/includes/user.php        2006-05-22 11:51:20.000000000 
-0400
+++ webcalendar-1.0.3/includes/user.php 2006-05-22 12:05:42.000000000 -0400
@@ -18,10 +18,11 @@
 // need these functions and you will still need to add users to
 // webcal_user.
 
+global $settings;
 // Set some global config variables about your system.
-$user_can_update_password = true;
-$admin_can_add_user = true;
-$admin_can_delete_user = true;
+$user_can_update_password = $settings['user_can_update_password'];
+$admin_can_add_user = $settings['admin_can_add_user'];
+$admin_can_delete_user = $settings['admin_can_delete_user'];
 
 
 // Check to see if a given login/password is valid.  If invalid,

Reply via email to