Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login
    Introducing Netgate Nexus: Multi-Instance Management at Your Fingertips.

    pfsense 2.5.2 can't auto delete pass-through MAC after voucher expired

    Scheduled Pinned Locked Moved Captive Portal
    14 Posts 4 Posters 3.5k Views 4 Watching
    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.
    • M Offline
      maherg
      last edited by maherg

      dear all,

      i want voucher users to be added as pass-through macs and also want them removed after voucher expire automatically

      in 2.4.4 its working but after upgrading to 2.5.2 its not working please anybody now how to fix this.

      T 1 Reply Last reply Reply Quote 0
      • T Offline
        tianakex @maherg
        last edited by

        @maherg hello, did you find any solution?

        M 1 Reply Last reply Reply Quote 0
        • M Offline
          maherg @tianakex
          last edited by

          @tianakex no bro

          nobody is answering and i didn't get any solution.

          T 1 Reply Last reply Reply Quote 0
          • T Offline
            tianakex @maherg
            last edited by

            @maherg did you try rolling back to 2.4.4?

            M 1 Reply Last reply Reply Quote 0
            • M Offline
              maherg @tianakex
              last edited by

              @tianakex no i am still on 2.5.2 because i want to use wireguard vpn but now i am not using auto add pass-through MAC

              T 1 Reply Last reply Reply Quote 0
              • T Offline
                tianakex @maherg
                last edited by tianakex

                @maherg just in case i found the solution, if you still need it

                M 1 Reply Last reply Reply Quote 0
                • M Offline
                  maherg @tianakex
                  last edited by

                  This post is deleted!
                  T 1 Reply Last reply Reply Quote 0
                  • T Offline
                    tianakex @maherg
                    last edited by

                    @maherg I am in 2.6.0 but it should work for you
                    Edit /etc/inc/captiveportal.inc
                    find the captiveportal_prune_old_automac function and add the code below my descirption "/auto delete mac passthrougth at voucher expiration/"

                    function captiveportal_prune_old_automac() {
                    	global $g, $config, $cpzone, $cpzoneid;
                    
                    	if (is_array($config['captiveportal'][$cpzone]['passthrumac']) &&
                    	    isset($config['captiveportal'][$cpzone]['passthrumacadd'])) {
                    		$tmpvoucherdb = array();
                    		$macrules = "";
                    		$writecfg = false;
                    		foreach ($config['captiveportal'][$cpzone]['passthrumac'] as $eid => $emac) {
                    			if ($emac['logintype'] != "voucher") {
                    				continue;
                    			}
                    			if (isset($config['captiveportal'][$cpzone]['noconcurrentlogins'])) {
                    				if (isset($tmpvoucherdb[$emac['username']])) {
                    					$temac = $config['captiveportal'][$cpzone]['passthrumac'][$tmpvoucherdb[$emac['username']]];
                    					$pipeno = captiveportal_get_dn_passthru_ruleno($temac['mac']);
                    					if ($pipeno) {
                    						captiveportal_free_dn_ruleno($pipeno);
                    						$macrules .= "table {$cpzone}_pipe_mac delete any,{$temac['mac']}\n";
                    						$macrules .= "table {$cpzone}_pipe_mac delete {$temac['mac']},any\n";
                    						$macrules .= "pipe delete {$pipeno}\n";
                    						++$pipeno;
                    						$macrules .= "pipe delete {$pipeno}\n";
                    					}
                    					$writecfg = true;
                    					captiveportal_logportalauth($temac['username'], $temac['mac'],
                    					    $temac['ip'], "DUPLICATE {$temac['username']} LOGIN - TERMINATING OLD SESSION");
                    					unset($config['captiveportal'][$cpzone]['passthrumac'][$tmpvoucherdb[$emac['username']]]);
                    				}
                    				$tmpvoucherdb[$emac['username']] = $eid;
                    			}
                    			/*auto delete mac passthrougth at voucher expiration*/
                    			if (voucher_auth($emac['username']) <= 0) {
                    				$pipeno = captiveportal_get_dn_passthru_ruleno($emac['mac']);
                    				if ($pipeno) {
                    					captiveportal_free_dn_ruleno($pipeno);
                    					$macrules .= "table {$cpzone}_pipe_mac delete any,{$emac['mac']}\n";
                    					$macrules .= "table {$cpzone}_pipe_mac delete {$emac['mac']},any\n";
                    					$macrules .= "pipe delete {$pipeno}\n";
                    					++$pipeno;
                    					$macrules .= "pipe delete {$pipeno}\n";
                    				}
                    				$writecfg = true;
                    				captiveportal_logportalauth($emac['username'], $emac['mac'],
                    				    $emac['ip'], "EXPIRED {$emac['username']} LOGIN - TERMINATING SESSION");
                    				unset($config['captiveportal'][$cpzone]['passthrumac'][$eid]);
                    			}
                    			/*end auto delete mac passthrougth at voucher expiration*/
                    		}
                    		unset($tmpvoucherdb);
                    		if (!empty($macrules)) {
                    			@file_put_contents("{$g['tmp_path']}/macentry.prunerules.tmp", $macrules);
                    			unset($macrules);
                    			mwexec("/sbin/ipfw -q {$g['tmp_path']}/macentry.prunerules.tmp");
                    		}
                    		if ($writecfg === true) {
                    			write_config("Prune session for auto-added macs");
                    		}
                    	}
                    }
                    
                    T M LadiesMan217L 4 Replies Last reply Reply Quote 1
                    • T Offline
                      tianakex @tianakex
                      last edited by

                      • restart the CP service
                      • make sure Concurrent user logins is disabled
                      • just dont edit the autoadded mac address because the CP will considere that you added it manually and will not be a voucher associated mac anymore and will not be pruned at the expiration of the code voucher
                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        maherg @tianakex
                        last edited by

                        @tianakex thank you very much i will try this

                        1 Reply Last reply Reply Quote 0
                        • LadiesMan217L Offline
                          LadiesMan217 @tianakex
                          last edited by

                          @tianakex Hi may I know if this patch also works on pfsense 2.6?

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            tianakex
                            last edited by tianakex

                            This post is deleted!
                            GertjanG 1 Reply Last reply Reply Quote 0
                            • GertjanG Offline
                              Gertjan @tianakex
                              last edited by

                              @tianakex

                              Replace de entire function ?
                              Humm ... that's bad.

                              Just for my own curiosity :
                              When :

                              a2bc9abd-def1-4cd4-a31d-76af44826de6-image.png

                              is checked, after login, using voucher or user/password, the MAC get added.

                              If the portal-voucher-user goes off site, comes back again, no need to login, as the MAC let in right in.
                              Up to the admin to delete the MAC from the "MACs" list when the voucher has expired.

                              What bout not checking this option ? 😊
                              True, the voucher user has to re enter the voucher code upon hard-time out.

                              Btw : the 'php script' you've pasted is unreadable.
                              Were are humans here, not PHP interpreters.
                              What about :

                              function captiveportal_prune_old_automac() {
                                    global $g, $cpzone, $cpzoneid;
                                    $cpzone_config = config_get_path("captiveportal/{$cpzone}", []);
                              
                                    if (is_array($cpzone_config['passthrumac']) &&
                                          isset($cpzone_config['passthrumacadd'])) {
                                          $tmpvoucherdb = array();
                                          $writecfg = false;
                                          ....
                              

                              Use this button :

                              cbb53e35-a26d-4914-b535-faff98f2c177-image.png

                              and propose what to add and or remove with exact line numbers using this as a guide line ?

                              No "help me" PM's please. Use the forum, the community will thank you.

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                tianakex @tianakex
                                last edited by

                                This post is deleted!
                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post
                                Copyright 2026 Rubicon Communications LLC (Netgate). All rights reserved.
                                Privacy Policy · Cookie Policy