Advertisement
Nowwhat47

function portal_reply_page (in /etc/inc/captiveportal.inc)

Jan 21st, 2015
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. function portal_reply_page($redirurl, $type = null, $message = null, $clientmac = null, $clientip = null, $username = null, $password = null) {
  2.     global $g, $config, $cpzone;
  3.  
  4.     /* Get captive portal layout */
  5.     if ($type == "redir") {
  6.         header("Location: {$redirurl}");
  7.         return;
  8.     } else if ($type == "login")
  9.         $htmltext = get_include_contents("{$g['varetc_path']}/captiveportal_{$cpzone}.html");
  10.     else if ($type == "already_connected") {
  11.         $sessionid = $_COOKIE['cookie_portal'];
  12.             $htmltext = get_include_contents("{$g['captiveportal_path']}/captiveportal-{$cpzone}-already-connected.html");
  13.         } else
  14.         $htmltext = get_include_contents("{$g['varetc_path']}/captiveportal-{$cpzone}-error.html");
  15.  
  16.     $cpcfg = $config['captiveportal'][$cpzone];
  17.  
  18.     /* substitute the PORTAL_REDIRURL variable */
  19.     if ($cpcfg['preauthurl']) {
  20.         $htmltext = str_replace("\$PORTAL_REDIRURL\$", "{$cpcfg['preauthurl']}", $htmltext);
  21.         $htmltext = str_replace("#PORTAL_REDIRURL#", "{$cpcfg['preauthurl']}", $htmltext);
  22.     }
  23.  
  24.     /* substitute other variables */
  25.     $ourhostname = portal_hostname_from_client_ip($clientip);
  26.     $protocol = (isset($cpcfg['httpslogin'])) ? 'https://' : 'http://';
  27.     $htmltext = str_replace("\$PORTAL_ACTION\$", "{$protocol}{$ourhostname}/", $htmltext);
  28.     $htmltext = str_replace("#PORTAL_ACTION#", "{$protocol}{$ourhostname}/", $htmltext);
  29.  
  30.     $htmltext = str_replace("\$PORTAL_ZONE\$", htmlspecialchars($cpzone), $htmltext);
  31.     $htmltext = str_replace("\$PORTAL_REDIRURL\$", htmlspecialchars($redirurl), $htmltext);
  32.     $htmltext = str_replace("\$PORTAL_MESSAGE\$", htmlspecialchars($message), $htmltext);
  33.     $htmltext = str_replace("\$CLIENT_MAC\$", htmlspecialchars($clientmac), $htmltext);
  34.     $htmltext = str_replace("\$CLIENT_IP\$", htmlspecialchars($clientip), $htmltext);
  35.     $htmltext = str_replace("\$PORTAL_SESSION\$", htmlspecialchars($sessionid), $htmltext);
  36.  
  37.     // Special handling case for captive portal master page so that it can be ran
  38.     // through the PHP interpreter using the include method above.  We convert the
  39.     // $VARIABLE$ case to #VARIABLE# in /etc/inc/captiveportal.inc before writing out.
  40.     $htmltext = str_replace("#PORTAL_ZONE#", htmlspecialchars($cpzone), $htmltext);
  41.     $htmltext = str_replace("#PORTAL_REDIRURL#", htmlspecialchars($redirurl), $htmltext);
  42.     $htmltext = str_replace("#PORTAL_MESSAGE#", htmlspecialchars($message), $htmltext);
  43.     $htmltext = str_replace("#CLIENT_MAC#", htmlspecialchars($clientmac), $htmltext);
  44.     $htmltext = str_replace("#CLIENT_IP#", htmlspecialchars($clientip), $htmltext);
  45.     $htmltext = str_replace("#PORTAL_SESSION#", htmlspecialchars($sessionid), $htmltext);
  46.     $htmltext = str_replace("#USERNAME#", htmlspecialchars($username), $htmltext);
  47.     $htmltext = str_replace("#PASSWORD#", htmlspecialchars($password), $htmltext);
  48.  
  49.     echo $htmltext;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement