Move two sub-routers into one main router using the advanced routing features in the new CPHP version

feature/node-rewrite
Sven Slootweg 12 years ago
parent d6b6e297f9
commit eaae42365c

@ -0,0 +1,32 @@
<?php
/*
* CVM is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_CVM)) { die("Unauthorized."); }
$router->uVariables['display_menu'] = true;
try
{
$sUser->RequireAccessLevel(20);
$sRouterAuthenticated = true;
}
catch (InsufficientAccessLevelException $e)
{
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, $locale->strings['error-unauthorized-title'], $locale->strings['error-unauthorized-text']);
$sMainContents .= $err->Render();
$sRouterAuthenticated = false;
$router->uVariables['display_menu'] = false;
}

@ -13,37 +13,18 @@
if(!isset($_CVM)) { die("Unauthorized."); }
$router->uVariables['display_menu'] = true;
try
{
$sContainer = new Container($mainrouter->uParameters[1]);
$sContainer = new Container($router->uParameters[1]);
if($sContainer->sUserId != $sUser->sId && $sUser->sAccessLevel < 20)
{
throw new UnauthorizedException("You are not authorized to control this container.");
}
$sError = "";
$sPageContents = "";
$sMainClass = "shift";
$router = new CPHPRouter();
$router->ignore_query = true;
$router->routes = array(
0 => array(
'^/([0-9]+)/?$' => "module.vps.overview.php",
'^/([0-9]+)/(start)/?$' => "module.vps.overview.php",
'^/([0-9]+)/(stop)/?$' => "module.vps.overview.php",
'^/([0-9]+)/(restart)/?$' => "module.vps.overview.php",
'^/([0-9]+)/reinstall/?$' => "module.vps.reinstall.php",
'^/([0-9]+)/password/?$' => "module.vps.password.php",
'^/([0-9]+)/console/?$' => "module.vps.console.php"
)
);
$router->RouteRequest();
$sRouterAuthenticated = true;
try
{
@ -59,14 +40,16 @@ try
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_WARNING, $locale->strings['warning-terminated-title'], $locale->strings['warning-terminated-text']);
$sMainContents .= $err->Render();
}
$sMainContents .= Templater::AdvancedParse("main.vps", $locale->strings, array(
'error' => $sError,
'contents' => $sPageContents,
'id' => $sContainer->sId
));
}
catch(NotFoundException $e)
{
$sMainContents = Templater::AdvancedParse("error.vps.notfound");
$router->uVariables['display_menu'] = false;
$sMainContents = Templater::AdvancedParse("error.vps.notfound", $locale->strings, array());
$sRouterAuthenticated = false;
}
catch(UnauthorizedException $e)
{
$router->uVariables['display_menu'] = false;
$sRouterAuthenticated = false;
}

@ -0,0 +1,16 @@
<?php
/*
* CVM is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_CVM)) { die("Unauthorized."); }
throw new UnauthorizedException("You are not allowed to access this page.");

@ -1,51 +0,0 @@
<?php
/*
* CVM is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_CVM)) { die("Unauthorized."); }
try
{
$sUser->RequireAccessLevel(20);
$sError = "";
$sPageContents = "";
$sMainClass = "shift";
$router = new CPHPRouter();
$router->ignore_query = true;
$router->routes = array(
0 => array(
'^/admin/?$' => "module.admin.overview.php",
'^/admin/users/?$' => "module.admin.users.php",
'^/admin/containers/?$' => "module.admin.containers.php",
'^/admin/user/([0-9]+)/?$' => "module.admin.user.php",
'^/admin/container/([0-9]+)/suspend/?$' => "module.admin.container.suspend.php",
'^/admin/container/([0-9]+)/transfer/?$' => "module.admin.container.transfer.php",
'^/admin/container/([0-9]+)/terminate/?$' => "module.admin.container.terminate.php"
)
);
$router->RouteRequest();
$sMainContents .= Templater::AdvancedParse("main.admin", $locale->strings, array(
'contents' => $sPageContents
));
}
catch (InsufficientAccessLevelException $e)
{
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, $locale->strings['error-unauthorized-title'], $locale->strings['error-unauthorized-text']);
$sMainContents .= $err->Render();
}

@ -85,3 +85,4 @@ catch (SshExitException $e)
$sPageContents = Templater::AdvancedParse("vps.overview", $locale->strings, $sVariables);

@ -47,23 +47,121 @@ $sError = null;
try
{
$mainrouter = new CPHPRouter();
$router = new CPHPRouter();
$mainrouter->ignore_query = true;
$router->ignore_query = true;
$mainrouter->routes = array(
$router->routes = array(
0 => array(
'^/?$' => "module.list.php",
'^/account/?$' => "module.account.php",
'^/login/?$' => "module.login.php",
'^/logout/?$' => "module.logout.php",
'^/admin(/.*)?$' => "module.admin.php",
'^/([0-9]+)(/.*)?$' => "module.vps.php",
'^/([0-9]+)/?$' => array(
'target' => "module.vps.overview.php",
'authenticator' => "authenticator.vps.php",
'auth_error' => "error.access.php",
'_menu' => "vps"
),
'^/([0-9]+)/(start)/?$' => array(
'target' => "module.vps.overview.php",
'authenticator' => "authenticator.vps.php",
'auth_error' => "error.access.php",
'_menu' => "vps"
),
'^/([0-9]+)/(stop)/?$' => array(
'target' => "module.vps.overview.php",
'authenticator' => "authenticator.vps.php",
'auth_error' => "error.access.php",
'_menu' => "vps"
),
'^/([0-9]+)/(restart)/?$' => array(
'target' => "module.vps.overview.php",
'authenticator' => "authenticator.vps.php",
'auth_error' => "error.access.php",
'_menu' => "vps"
),
'^/([0-9]+)/reinstall/?$' => array(
'target' => "module.vps.reinstall.php",
'authenticator' => "authenticator.vps.php",
'auth_error' => "error.access.php",
'_menu' => "vps"
),
'^/([0-9]+)/password/?$' => array(
'target' => "module.vps.password.php",
'authenticator' => "authenticator.vps.php",
'auth_error' => "error.access.php",
'_menu' => "vps"
),
'^/([0-9]+)/console/?$' => array(
'target' => "module.vps.console.php",
'authenticator' => "authenticator.vps.php",
'auth_error' => "error.access.php",
'_menu' => "vps"
),
'^/admin/?$' => array(
'target' => "module.admin.overview.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/admin/users/?$' => array(
'target' => "module.admin.users.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/admin/containers/?$' => array(
'target' => "module.admin.containers.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/admin/user/([0-9]+)/?$' => array(
'target' => "module.admin.user.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/admin/container/([0-9]+)/suspend/?$' => array(
'target' => "module.admin.container.suspend.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/admin/container/([0-9]+)/transfer/?$' => array(
'target' => "module.admin.container.transfer.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/admin/container/([0-9]+)/terminate/?$' => array(
'target' => "module.admin.container.terminate.php",
'authenticator' => "authenticator.admin.php",
'auth_error' => "error.access.php",
'_menu' => "admin"
),
'^/test/?$' => "module.test.php"
)
);
$mainrouter->RouteRequest();
$router->RouteRequest();
if($router->uVariables['menu'] == "vps" && $router->uVariables['display_menu'] === true)
{
$sMainContents .= Templater::AdvancedParse("main.vps", $locale->strings, array(
'error' => $sError,
'contents' => $sPageContents,
'id' => $sContainer->sId
));
}
elseif($router->uVariables['menu'] == "admin" && $router->uVariables['display_menu'] === true)
{
$sMainContents .= Templater::AdvancedParse("main.admin", $locale->strings, array(
'error' => $sError,
'contents' => $sPageContents
));
}
}
catch (UnauthorizedException $e)
{
@ -75,7 +173,7 @@ $sTemplateParameters = array_merge($sTemplateParameters, array(
'logged-in' => $sLoggedIn,
'title' => $sPageTitle,
'main' => $sMainContents,
'main-class' => $sMainClass,
'main-class' => (isset($router->uVariables['menu']) && $router->sAuthenticated === true) ? "shift" : "",
'generation' => "<!-- page generated in " . (round(microtime(true) - $timing_start, 6)) . " seconds. -->"
));

@ -10,6 +10,8 @@
<a class="sidebutton" id="button_api" href="/{%?id}/api/">{%!menu-api}</a> -->
</div>
{%?error}
{%if isset|error}
{%?error}
{%/if}
{%?contents}

Loading…
Cancel
Save