diff -r d62212462f9b -r 1b4288399b1f uiconfig.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uiconfig.php Tue Sep 23 23:26:18 2008 -0400 @@ -0,0 +1,176 @@ +header('HTTP/1.1 307 Temporary Redirect'); + $httpd->header('Location: /login'); + + return; + } + + $tried = false; + $success = false; + $needpass = false; + $error = false; + + // if a config password is set, make sure it matches. + $authed = false; + if ( empty($GLOBALS['configpass']) ) + { + $authed = true; + } + else + { + $needpass = true; + if ( isset($_POST['configpass']) && sha1($_POST['configpass']) === $GLOBALS['configpass'] ) + { + $authed = true; + $tried = true; + } + else if ( isset($_POST['configpass']) ) + { + $error = 'You didn\'t enter the right configuration password, so the changes weren\'t saved.'; + $tried = true; + } + } + + if ( $authed && isset($_POST['submit']) ) + { + $need_reboot = ( isset($_POST['public']) !== $GLOBALS['public'] || + isset($_POST['allow_fork']) !== $GLOBALS['allow_fork']); + + // compile the new config file + $public = ( isset($_POST['public']) ) ? 'true' : 'false'; + $allowcontrol = ( isset($_POST['allowcontrol']) ) ? 'true' : 'false'; + $allow_fork = ( isset($_POST['allow_fork']) ) ? 'true' : 'false'; + $use_auth = ( isset($_POST['use_auth']) ) ? 'true' : 'false'; + + // for auth_data, we're going to merge the data from POST with the current auth_data array. + $auth_data = $GLOBALS['auth_data']; + $auth_changed = false; + foreach ( $auth_data as $user => $pass ) + { + if ( !in_array($user, $_POST['users']) ) + { + $auth_changed = true; + unset($auth_data[$user]); + } + } + if ( isset($_POST['users_add']) ) + { + foreach ( $_POST['users_add'] as $user => $pass ) + { + $auth_changed = true; + $auth_data[$user] = $pass; + } + } + $auth_data = var_export_string($auth_data); + + $new_configpass = ( is_string($_POST['newconfigpass']) && $_POST['newconfigpass'] != '____________________' ) ? sha1($_POST['newconfigpass']) : $GLOBALS['configpass']; + + $config_file = <<If you changed your own password, you've been logged out so you'll need to log back in again." : ''; + if ( REBOOT_SUPPORT ) + { + $rebootblurb = $need_reboot ? "\nSince you changed some core configuration values, the Greyhound server has been restarted.\nIf Greyhound doesn't respond, wait 20 seconds and then restart it using Amarok's script manager." : ''; + } + else + { + $rebootblurb = $need_reboot ? "\nPlease restart Greyhound using Amarok's script manager for public IP and multithreading options to take effect." : ''; + } + $success = "Configuration changes successful.{$passblurb}{$rebootblurb}"; + $httpd->threader->ipc_send(array('action' => 'reloadconfig', 'propagate' => true)); + + if ( $need_reboot && REBOOT_SUPPORT ) + { + $addr = $GLOBALS['public'] ? '0.0.0.0' : '127.0.0.1'; + $fork = $GLOBALS['allow_fork']; + $httpd->reboot($addr, null, $fork); + } + } + } + + global $theme; + $iphone = ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || + strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') || + strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') || + isset($_GET['m']) ) + && !isset($_GET['f']) + ); + $theme_id = ( $iphone ) ? 'iphone' : $theme; + $smarty = load_theme($theme_id); + + $smarty->assign('theme', $theme_id); + $smarty->assign('greyhound_version', GREY_VERSION); + $smarty->assign('tried', $tried); + $smarty->assign('success', $success); + $smarty->assign('needpass', $needpass); + $smarty->assign('use_auth', $use_auth); + $smarty->assign('public', $GLOBALS['public']); + $smarty->assign('allowcontrol', $GLOBALS['allowcontrol']); + $smarty->assign('allow_fork', $GLOBALS['allow_fork']); + $smarty->assign('use_auth', $GLOBALS['use_auth']); + $smarty->assign('users', $GLOBALS['auth_data']); + $smarty->assign('error', $error); + $smarty->display('config.tpl'); +}