Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    ¿Variables del portal cautivo?

    Scheduled Pinned Locked Moved Español
    3 Posts 2 Posters 1.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Joseguadalupe
      last edited by

      Buenas a todos

      En la parte de documentación no veo todas las variables que se puede usar en el login del portal cautivo, algunas las he encontrado por aquí, pero quisiera saber dónde puedo encontrar las demás variables que se pueden usar.

      Por ejemplo, variables para mostrar tiempo de conexión, ip del usuario, mac del usuario etc..

      1 Reply Last reply Reply Quote 0
      • J
        javcasta
        last edited by

        Hola

        En el fichero: /etc/inc/captiveportal.inc

        Hay una función php, llamada: portal_reply_page.

        Donde, creo, están algunas de las variables que necesitas sobre el portal cautivo.

        $cpzone
        $redirurl
        $message
        $clientmac
        $clientip
        $username
        $password

        
        function portal_reply_page($redirurl, $type = null, $message = null, $clientmac = null, $clientip = null, $username = null, $password = null) {
        	global $g, $config, $cpzone;
        
        	/* Get captive portal layout */
        	if ($type == "redir") {
        		header("Location: {$redirurl}");
        		return;
        	} else if ($type == "login") {
        		$htmltext = get_include_contents("{$g['varetc_path']}/captiveportal_{$cpzone}.html");
        	} else {
        		$htmltext = get_include_contents("{$g['varetc_path']}/captiveportal-{$cpzone}-error.html");
        	}
        
        	$cpcfg = $config['captiveportal'][$cpzone];
        
        	/* substitute the PORTAL_REDIRURL variable */
        	if ($cpcfg['preauthurl']) {
        		$htmltext = str_replace("\$PORTAL_REDIRURL\$", "{$cpcfg['preauthurl']}", $htmltext);
        		$htmltext = str_replace("#PORTAL_REDIRURL#", "{$cpcfg['preauthurl']}", $htmltext);
        	}
        
        	/* substitute other variables */
        	$ourhostname = portal_hostname_from_client_ip($clientip);
        	$protocol = (isset($cpcfg['httpslogin'])) ? 'https://' : 'http://';
        	$htmltext = str_replace("\$PORTAL_ACTION\$", "{$protocol}{$ourhostname}/index.php?zone={$cpzone}", $htmltext);
        	$htmltext = str_replace("#PORTAL_ACTION#", "{$protocol}{$ourhostname}/index.php?zone={$cpzone}", $htmltext);
        
        	$htmltext = str_replace("\$PORTAL_ZONE\$", htmlspecialchars($cpzone), $htmltext);
        	$htmltext = str_replace("\$PORTAL_REDIRURL\$", htmlspecialchars($redirurl), $htmltext);
        	$htmltext = str_replace("\$PORTAL_MESSAGE\$", htmlspecialchars($message), $htmltext);
        	$htmltext = str_replace("\$CLIENT_MAC\$", htmlspecialchars($clientmac), $htmltext);
        	$htmltext = str_replace("\$CLIENT_IP\$", htmlspecialchars($clientip), $htmltext);
        
        	// Special handling case for captive portal master page so that it can be ran
        	// through the PHP interpreter using the include method above.  We convert the
        	// $VARIABLE$ case to #VARIABLE# in /etc/inc/captiveportal.inc before writing out.
        	$htmltext = str_replace("#PORTAL_ZONE#", htmlspecialchars($cpzone), $htmltext);
        	$htmltext = str_replace("#PORTAL_REDIRURL#", htmlspecialchars($redirurl), $htmltext);
        	$htmltext = str_replace("#PORTAL_MESSAGE#", htmlspecialchars($message), $htmltext);
        	$htmltext = str_replace("#CLIENT_MAC#", htmlspecialchars($clientmac), $htmltext);
        	$htmltext = str_replace("#CLIENT_IP#", htmlspecialchars($clientip), $htmltext);
        	$htmltext = str_replace("#USERNAME#", htmlspecialchars($username), $htmltext);
        	$htmltext = str_replace("#PASSWORD#", htmlspecialchars($password), $htmltext);
        
        	echo $htmltext;
        }
        

        Referencia: https://forum.pfsense.org/index.php?topic=51095.0

        Y en ese mismo fichero, en la función: function portal_allow , hay una variable llamada $remaining_time , que creo se refiere al tiempo de permanecia …

        Bucea un poco en el código de ese fichero y creo que obtendrás la respuestas.

        Salu2

        Javier Castañón
        Técnico de comunicaciones, soporte y sistemas.

        Mi web: https://javcasta.com/

        Soporte scripting/pfSense https://javcasta.com/soporte/

        1 Reply Last reply Reply Quote 0
        • J
          javcasta
          last edited by

          Hola

          Una aclaración

          Las variables que te interesan para tu página del portal cautivo tendrán el formato:

          $CLIENT_IP$ ( se correponderia a la variable en php $clientip )
          $CLIENT_MAC$ ( idem $clientmac )
          …
          etc

          Salu2

          Javier Castañón
          Técnico de comunicaciones, soporte y sistemas.

          Mi web: https://javcasta.com/

          Soporte scripting/pfSense https://javcasta.com/soporte/

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.