Provide a way for non-admins to authenticate and use the upgrader,

without using our regular code paths.

Signed-off-by:  <unostar@danalan.info>
This commit is contained in:
Bharat Mediratta
2009-06-11 15:51:06 +08:00
committed by
parent 8d4567f4cc
commit 5f2dca7a51
2 changed files with 30 additions and 5 deletions
+14 -5
View File
@@ -19,24 +19,33 @@
*/
class Upgrader_Controller extends Controller {
public function index() {
// Todo: give the admin a chance to log in here
if (!user::active()->admin) {
access::forbidden();
$session = Session::instance();
// Make sure we have an upgrade token
if (!($upgrade_token = $session->get("upgrade_token", null))) {
$session->set("upgrade_token", $upgrade_token = md5(rand()));
}
// If the upgrade token exists, then bless this session
if (file_exists(TMPPATH . $upgrade_token)) {
$session->set("can_upgrade", true);
@unlink(TMPPATH . $upgrade_token);
}
$view = new View("upgrader.html");
$view->can_upgrade = user::active()->admin || $session->get("can_upgrade");
$view->upgrade_token = $upgrade_token;
$view->available = module::available();
$view->done = Input::instance()->get("done");
print $view;
}
public function upgrade() {
// Todo: give the admin a chance to log in here
if (php_sapi_name() == "cli") {
// @todo this may screw up some module installers, but we don't have a better answer at
// this time.
$_SERVER["HTTP_HOST"] = "example.com";
} else if (!user::active()->admin) {
} else if (!user::active()->admin && !Session::instance()->get("can_upgrade", false)) {
access::forbidden();
}