define('SMOPT_TYPE_PLUGINS', 11);
define('SMOPT_TYPE_LDAP', 12);
define('SMOPT_TYPE_EXTERNAL', 32);
+define('SMOPT_TYPE_PATH',33);
global $languages;
'type' => SMOPT_TYPE_STRING,
'size' => 40 ),
'$org_logo' => array( 'name' => _("Organization Logo"),
- 'type' => SMOPT_TYPE_STRING,
- 'size' => 40 ),
+ 'type' => SMOPT_TYPE_PATH,
+ 'size' => 40,
+ 'default' => '../images/sm_logo.png'),
'$org_logo_width' => array( 'name' => _("Organization Logo Width"),
'type' => SMOPT_TYPE_INTEGER,
'size' => 5,
'type' => SMOPT_TYPE_STRING,
'size' => 40 ),
'$signout_page' => array( 'name' => _("Signout Page"),
- 'type' => SMOPT_TYPE_STRING,
+ 'type' => SMOPT_TYPE_PATH,
'size' => 40 ),
'$squirrelmail_default_language' => array( 'name' => _("Default Language"),
'type' => SMOPT_TYPE_STRLIST,
'windows-1251' => 'windows-1251',
'ISO-2022-JP' => 'ISO-2022-JP' ) ),
'$data_dir' => array( 'name' => _("Data Directory"),
- 'type' => SMOPT_TYPE_STRING,
+ 'type' => SMOPT_TYPE_PATH,
'size' => 40 ),
'$attachment_dir' => array( 'name' => _("Temp Directory"),
- 'type' => SMOPT_TYPE_STRING,
+ 'type' => SMOPT_TYPE_PATH,
'size' => 40 ),
'$dir_hash_level' => array( 'name' => _("Hash Level"),
'type' => SMOPT_TYPE_NUMLIST,
'Group7' => array( 'name' => _("Themes"),
'type' => SMOPT_TYPE_TITLE ),
'$theme_css' => array( 'name' => _("Style Sheet URL (css)"),
- 'type' => SMOPT_TYPE_STRING,
+ 'type' => SMOPT_TYPE_PATH,
'size' => 40 ),
/* --------------------------------------------------------*/
'$config_use_color' => array( 'name' => '',
}
}
}
+}
+
+/* Change paths containing SM_PATH to admin-friendly paths
+ relative to the config dir, i.e.:
+ '' --> <empty string>
+ SM_PATH . 'images/logo.gif' --> ../images/logo.gif
+ '/absolute/path/logo.gif' --> /absolute/path/logo.gif
+ 'http://whatever/' --> http://whatever
+ Note removal of quotes in returned value
+*/
+function change_to_rel_path($old_path) {
+ $new_path = str_replace("SM_PATH . '", "../", $old_path);
+ $new_path = str_replace("../config/","", $new_path);
+ $new_path = str_replace("'","", $new_path);
+ return $new_path;
+}
+/* Change relative path (relative to config dir) to
+ internal SM_PATH, i.e.:
+ empty_string --> ''
+ ../images/logo.gif --> SM_PATH . 'images/logo.gif'
+ images/logo.gif --> SM_PATH . 'config/images/logo.gif'
+ /absolute/path/logo.gif --> '/absolute/path/logo.gif'
+ http://whatever/ --> 'http://whatever'
+*/
+function change_to_sm_path($old_path) {
+ if ( $old_path === '' || $old_path == "''" ) {
+ return "''";
+ } elseif ( preg_match("/^(\/|http)/", $old_path) ) {
+ return "'" . $old_path . "'";
+ } elseif ( preg_match("/^(\$|SM_PATH)/", $old_path) ) {
+ return $old_path;
+ }
+
+ $new_path = '';
+ $rel_path = explode("../", $old_path);
+ if ( count($rel_path) > 2 ) {
+ // Since we're relative to the config dir,
+ // more than 1 ../ puts us OUTSIDE the SM tree.
+ // get full path to config.php, then pop the filename
+ $abs_path = explode('/', realpath (SM_PATH . 'config/config.php'));
+ array_pop ($abs_path);
+ foreach ( $rel_path as $subdir ) {
+ if ( $subdir === '' ) {
+ array_pop ($abs_path);
+ } else {
+ array_push($abs_path, $subdir);
+ }
+ }
+ foreach ($abs_path as $subdir) {
+ $new_path .= $subdir . '/';
+ }
+ $new_path = "'$new_path'";
+ } elseif ( count($rel_path) > 1 ) {
+ // we're within the SM tree, prepend SM_PATH
+ $new_path = str_replace('../',"SM_PATH . '", $old_path . "'");
+ } else {
+ // Last, if it's a relative path without a .. prefix,
+ // we're somewhere within the config dir, so prepend
+ // SM_PATH . 'config/
+ $new_path = "SM_PATH . 'config/" . $old_path . "'";
+ }
+ return $new_path;
}
+
/* ---------------------- main -------------------------- */
define('SM_PATH','../../');
GLOBAL $data_dir, $username;
if ( !adm_check_user() ) {
- header("Location: ../../src/options.php") ;
+ header('Location: ' . SM_PATH . 'src/options.php') ;
exit;
}
'Group7' => getPref($data_dir, $username, 'adm_Group7', 'on' ),
'Group8' => getPref($data_dir, $username, 'adm_Group8', 'on' ) );
-if ( isset( $switch ) ) {
-
+if ( isset( $_GET['switch'] ) ) {
+ $switch = $_GET['switch'];
if ( $colapse[$switch] == 'on' ) {
$colapse[$switch] = 'off';
} else {
$colapse[$switch] = 'on';
}
setPref($data_dir, $username, "adm_$switch", $colapse[$switch] );
-
}
echo "<form action=options.php method=post name=options>" .
}
echo "</td></tr>\n";
break;
+ case SMOPT_TYPE_PATH:
+ if ( isset( $HTTP_POST_VARS[$e] ) ) {
+ $v = change_to_sm_path($HTTP_POST_VARS[$e]);
+ $newcfg[$k] = $v;
+ }
+ if ( $v == "''" && isset( $defcfg[$k]['default'] ) ) {
+ $v = change_to_sm_path($defcfg[$k]['default']);
+ $newcfg[$k] = $v;
+ }
+ echo "<tr><td>$name</td><td>".
+ "<input size=\"$size\" name=\"adm_$n\" value=\"" . change_to_rel_path($v) . "\">";
+ if ( isset( $defcfg[$k]['comment'] ) ) {
+ echo ' ' . $defcfg[$k]['comment'];
+ }
+ echo "</td></tr>\n";
+ break;
default:
echo "<tr><td>$name</td><td>" .
"<b><i>$v</i></b>";
echo "</td></tr>\n";
}
}
-
}
/* Special Themes Block */
$k2 = "\$theme[$i]['PATH']";
$e2 = "theme_path_$i";
if ( isset( $HTTP_POST_VARS[$e2] ) ) {
- $v2 = '"' . str_replace( '\"', '"', $HTTP_POST_VARS[$e2] ) . '"';
- $v2 = '"' . str_replace( '"', '\"', $v2 ) . '"';
- $newcfg[$k2] = $v2;
+ $v2 = change_to_sm_path($HTTP_POST_VARS[$e2]);
+ $newcfg[$k2] = $v2;
} else {
$v2 = $newcfg[$k2];
}
$name = substr( $v1, 1, strlen( $v1 ) - 2 );
- $path = substr( $v2, 1, strlen( $v2 ) - 2 );
+ $path = change_to_rel_path($v2);
echo '<tr>'.
"<td align=right>$i. <input name=\"$e1\" value=\"$name\" size=30></td>".
"<td><input name=\"$e2\" value=\"$path\" size=40></td>".