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

    Captive Portal Exp Voucher Code Active After System Backup Restore on Config.XML

    Scheduled Pinned Locked Moved Captive Portal
    15 Posts 5 Posters 4.4k 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.
    • K
      kailrusha
      last edited by

      Hello.

      Good Day.

      I recently Have Harddrive Crash on my System with Pfsense Captive Portal. and i was able to have Backup Copy its System "Config.XML" that contains its configuration and Voucher Code.

      During Success Full Replacement and Reinstallation of the Same Version Pfsense. I was able and to restore the Previous Setting. however i just found out the 1000 Voucher code that has been Used/expired several months Before. Now becomes Available and Active, Instead of Expired/Used Code.

      Is there any Solution to this Problem.

      I was thinking its is a Bug in Pfsense

      Thank You

      1 Reply Last reply Reply Quote 0
      • D
        doktornotor Banned
        last edited by

        Voucher status is not backed up… Or, better said - it is, but there's no code to restore it. Great feature.  ::)  Delete the rolls, generate new ones.

        https://redmine.pfsense.org/issues/3128
        https://forum.pfsense.org/index.php?topic=72418.0

        1 Reply Last reply Reply Quote 0
        • K
          kailrusha
          last edited by

          Voucher Code was Backup. But it doesn't said it is already Expired.

          If you restore your Config.XML with the Voucher Code now all those expired Voucher Code will became Active Again.

          I dont have Problems in Active Voucher and they are working Well. only the Expired one became active again.

          My Problem is i have Hundreds of Code already printed. its a waste of Time if i make a New One.

          IM Using the PF 2.2.1

          I Believe this is a Pfsense Feature that not Yet Available or Missing.

          I Hope Developers Make some Adjustment.

          1 Reply Last reply Reply Quote 0
          • D
            demco
            last edited by

            kailrusha,

            When restoring from backup and reboot the machine, pfsense try to save active & used voucher DB back to config.xml; Since these DB files don't exist in the new machine yet , the config.xml data get overwritten and voucher become unused again.

            One possible solution is to skip saving to config.xml when the DB file doesn't exist.

            Under function voucher_save_db_to_config_zone() in voucher.inc, make sure read from DB
            return non-empty,

            
                // walk all active rolls and save runtime DB's to flash
                $a_roll = &$config['voucher'][$cpzone]['roll'];
                while (list($key, $value) = each($a_roll)) {
                    $rollent = &$a_roll[$key];
                    $roll = $rollent['number'];
                    $bitmask = voucher_read_used_db($roll);
            
                    //** Added this check to make sure used DB exist. **
                    if (!empty($bitmask))
                        $rollent['used'] = base64_encode($bitmask);
            
                    $active_vouchers = voucher_read_active_db($roll);
            
                    //** Added this check to make sure active DB exist. **
                    if (!empty($active_vouchers)) {
                        $db = array();
                        $dbi = 1;
                        foreach($active_vouchers as $voucher => $line) {
                            list($timestamp,$minutes) = explode(",", $line);
                            $activent['voucher'] = $voucher;
                            $activent['timestamp'] = $timestamp;
                            $activent['minutes'] = $minutes;
                            $db["v{$dbi}"] = $activent;
            	        $dbi++;
                        }
                        $rollent['active'] = $db;
                    }
            	unset($active_vouchers);
                }
            
            

            This only consider the case when DB doesn't exist. The modification might break other cases.

            1 Reply Last reply Reply Quote 0
            • D
              doktornotor Banned
              last edited by

              @demco:

              Under function voucher_save_db_to_config_zone() in voucher.inc, make sure read from DB
              return non-empty,
              This only consider the case when DB doesn't exist. The modification might break other cases.

              Can you post… like... a diff? Plus, I frankly don't understand how does this matter in the first place -- where do you see the code to restore the DBs from config.xml? All I can see there is saving those. Now, whether or not those get accidentally emptied does not matter so much, b/c AFAICT the whole backup is just wasting place in config.xml with the code to restore the DBs being MIA.

              1 Reply Last reply Reply Quote 0
              • D
                demco
                last edited by

                @doktornotor:

                Can you post… like... a diff? Plus, I frankly don't understand how does this matter in the first place -- where do you see the code to restore the DBs from config.xml? All I can see there is saving those. Now, whether or not those get accidentally emptied does not matter so much, b/c AFAICT the whole backup is just wasting place in config.xml with the code to restore the DBs being MIA.

                The code to restore the DB from config.xml is in rc.bootup - voucher_configure().

                Attached is the patch for version 2.2.4.

                voucher.diff.txt

                1 Reply Last reply Reply Quote 0
                • I
                  Iahmad
                  last edited by

                  please be more detailed how to use this code…

                  1 Reply Last reply Reply Quote 0
                  • I
                    Iahmad
                    last edited by

                    @demco:

                    @doktornotor:

                    Can you post… like... a diff? Plus, I frankly don't understand how does this matter in the first place -- where do you see the code to restore the DBs from config.xml? All I can see there is saving those. Now, whether or not those get accidentally emptied does not matter so much, b/c AFAICT the whole backup is just wasting place in config.xml with the code to restore the DBs being MIA.

                    The code to restore the DB from config.xml is in rc.bootup - voucher_configure().

                    Attached is the patch for version 2.2.4.

                    where should i upload this patch please tell

                    1 Reply Last reply Reply Quote 0
                    • GertjanG
                      Gertjan
                      last edited by

                      @ishtiaqaj:

                      @demco:

                      @doktornotor:

                      Can you post… like... a diff? Plus, I frankly don't understand how does this matter in the first place -- where do you see the code to restore the DBs from config.xml? All I can see there is saving those. Now, whether or not those get accidentally emptied does not matter so much, b/c AFAICT the whole backup is just wasting place in config.xml with the code to restore the DBs being MIA.

                      The code to restore the DB from config.xml is in rc.bootup - voucher_configure().

                      Attached is the patch for version 2.2.4.

                      where should i upload this patch please tell

                      It's not a question of "uploading and done".
                      The "diff" file has to be merged with the original file - voucher.inc (which you van find it in /etc/inc/ ).
                      But ….

                      The diff was written for pfSense 2.2.4 - is that your version ?

                      The diff could be applied manually - it concerns just a couple of lines - but : even if you find the correct place, the original code could have changed over time. Adding the code can have other - non documented effects.
                      So consider using diff if you can read (easy) and understand (less easy) the entire impact of what you are doing.

                      I looked up /etc/inc/voucher.inc on my system (2.2.6) and I guess you can actually patch manually by editing the file ....

                      No "help me" PM's please. Use the forum, the community will thank you.
                      Edit : and where are the logs ??

                      1 Reply Last reply Reply Quote 0
                      • I
                        Iahmad
                        last edited by

                        @Gertjan:

                        @ishtiaqaj:

                        @demco:

                        @doktornotor:

                        Can you post… like... a diff? Plus, I frankly don't understand how does this matter in the first place -- where do you see the code to restore the DBs from config.xml? All I can see there is saving those. Now, whether or not those get accidentally emptied does not matter so much, b/c AFAICT the whole backup is just wasting place in config.xml with the code to restore the DBs being MIA.

                        The code to restore the DB from config.xml is in rc.bootup - voucher_configure().

                        Attached is the patch for version 2.2.4.

                        where should i upload this patch please tell

                        It's not a question of "uploading and done".
                        The "diff" file has to be merged with the original file - voucher.inc (which you van find it in /etc/inc/ ).
                        But ….

                        The diff was written for pfSense 2.2.4 - is that your version ?

                        The diff could be applied manually - it concerns just a couple of lines - but : even if you find the correct place, the original code could have changed over time. Adding the code can have other - non documented effects.
                        So consider using diff if you can read (easy) and understand (less easy) the entire impact of what you are doing.

                        I looked up /etc/inc/voucher.inc on my system (2.2.6) and I guess you can actually patch manually by editing the file ....

                        now i have upgrade from 2.2.6. to 2.3 and still face the same problem also 2.3 also don't support active voucher restore support.

                        1 Reply Last reply Reply Quote 0
                        • I
                          Iahmad
                          last edited by

                          this is the voucher.inc from version 2.3 please highlight where can i put the code.
                          i find the "voucher_save_db_to_config_zone()" at the end of file.

                          function voucher_save_db_to_config_zone() {
                          global $config, $g, $cpzone;

                          if (!isset($config['voucher'][$cpzone]['enable'])) {
                          return;  // no vouchers or don't want to save DB's
                          }

                          if (!is_array($config['voucher'][$cpzone]['roll'])) {
                          return;
                          }

                          $voucherlck = lock("voucher{$cpzone}", LOCK_EX);

                          // walk all active rolls and save runtime DB's to flash
                          $a_roll = &$config['voucher'][$cpzone]['roll'];
                          while (list($key, $value) = each($a_roll)) {
                          $rollent = &$a_roll[$key];
                          $roll = $rollent['number'];
                          $bitmask = voucher_read_used_db($roll);
                          $rollent['used'] = base64_encode($bitmask);
                          $active_vouchers = voucher_read_active_db($roll);
                          $db = array();
                          $dbi = 1;
                          foreach ($active_vouchers as $voucher => $line) {
                          list($timestamp, $minutes) = explode(",", $line);
                          $activent['voucher'] = $voucher;
                          $activent['timestamp'] = $timestamp;
                          $activent['minutes'] = $minutes;
                          $db["v{$dbi}"] = $activent;
                          $dbi++;
                          }
                          $rollent['active'] = $db;
                          unset($active_vouchers);
                          }

                          unlock($voucherlck);

                          write_config(gettext("Syncing vouchers"));
                          return;
                          }

                          ?>

                          1 Reply Last reply Reply Quote 0
                          • GertjanG
                            Gertjan
                            last edited by

                            @ishtiaqaj:

                            this is the voucher.inc from version 2.3 please highlight where can i put the code.

                            You saw the voucher.diff.txt file ??
                            Yo will find lines like these

                                     $rollent = &$a_roll[$key];
                                     $roll = $rollent['number'];
                                     $bitmask = voucher_read_used_db($roll);
                            

                            You should find exactly ( !! ) the same lines in your actual /etc/inc/voucher.inc
                            You have this in voucher.diff.txt file :
                            -        $rollent['used'] = base64_encode($bitmask);
                            You saw the minus sign ?
                            This is the line to be removed in /etc/inc/voucher.inc.
                            Of course, it should exist in the /etc/inc/voucher.inc file.
                            Replace that line with all these lines :

                            +	if (!empty($bitmask))
                            +	        $rollent['used'] = base64_encode($bitmask);
                            

                            No need to say that you do NOT copy over the leading "+" sign, right ? (It would create a huge PHP error).

                            Then, a new 'sync' is proposed in voucher.diff.txt file :

                                     $active_vouchers = voucher_read_active_db($roll);
                            

                            You should find exactly ( !! ) the same line in your actual /etc/inc/voucher.inc
                            You remove these (which should exist EXACTLY !!) in /etc/inc/voucher.inc :

                            -        $db = array();
                            -		$dbi = 1;
                            -        foreach($active_vouchers as $voucher => $line) {
                            -            list($timestamp,$minutes) = explode(",", $line);
                            -            $activent['voucher'] = $voucher;
                            -            $activent['timestamp'] = $timestamp;
                            -            $activent['minutes'] = $minutes;
                            -            $db["v{$dbi}"] = $activent;
                            -	    $dbi++;
                            -        }
                            -        $rollent['active'] = $db;
                            

                            and put in on that place :

                            +	if (!empty($active_vouchers)) {
                            +	        $db = array();
                            +			$dbi = 1;
                            +	        foreach($active_vouchers as $voucher => $line) {
                            +	            list($timestamp,$minutes) = explode(",", $line);
                            +	            $activent['voucher'] = $voucher;
                            +	            $activent['timestamp'] = $timestamp;
                            +	            $activent['minutes'] = $minutes;
                            +	            $db["v{$dbi}"] = $activent;
                            +		    $dbi++;
                            +	        }
                            +	        $rollent['active'] = $db;
                            +	}
                            

                            (ditch the "+" sign when copying !)

                            The last two line in "voucher.diff.txt" are to re-sync again.

                            Now, a warning :
                            Editing like this, using some lines that were written for software version X, and applying the patch for version Y is NOT a good idea.

                            I'm not saying the patch doesn't work - I didn't test it.
                            Some side effect could exists.
                            Understand that upgrading your pfSense will (maybe = might) blow away your edits … (they have to be redone - the source could have been changed - patch might be more difficult, or completely impossible).

                            The most important one : never ask for "support" when you patch your own pfSense setup. You are on your own. No one will be able to re-create eventual error - because know one has your unique setup ....

                            No "help me" PM's please. Use the forum, the community will thank you.
                            Edit : and where are the logs ??

                            1 Reply Last reply Reply Quote 0
                            • I
                              Iahmad
                              last edited by

                              @Gertjan:

                              @ishtiaqaj:

                              this is the voucher.inc from version 2.3 please highlight where can i put the code.

                              You saw the voucher.diff.txt file ??
                              Yo will find lines like these

                                       $rollent = &$a_roll[$key];
                                       $roll = $rollent['number'];
                                       $bitmask = voucher_read_used_db($roll);
                              

                              You should find exactly ( !! ) the same lines in your actual /etc/inc/voucher.inc
                              You have this in voucher.diff.txt file :
                              -        $rollent['used'] = base64_encode($bitmask);
                              You saw the minus sign ?
                              This is the line to be removed in /etc/inc/voucher.inc.
                              Of course, it should exist in the /etc/inc/voucher.inc file.
                              Replace that line with all these lines :

                              +	if (!empty($bitmask))
                              +	        $rollent['used'] = base64_encode($bitmask);
                              

                              No need to say that you do NOT copy over the leading "+" sign, right ? (It would create a huge PHP error).

                              Then, a new 'sync' is proposed in voucher.diff.txt file :

                                       $active_vouchers = voucher_read_active_db($roll);
                              

                              You should find exactly ( !! ) the same line in your actual /etc/inc/voucher.inc
                              You remove these (which should exist EXACTLY !!) in /etc/inc/voucher.inc :

                              -        $db = array();
                              -		$dbi = 1;
                              -        foreach($active_vouchers as $voucher => $line) {
                              -            list($timestamp,$minutes) = explode(",", $line);
                              -            $activent['voucher'] = $voucher;
                              -            $activent['timestamp'] = $timestamp;
                              -            $activent['minutes'] = $minutes;
                              -            $db["v{$dbi}"] = $activent;
                              -	    $dbi++;
                              -        }
                              -        $rollent['active'] = $db;
                              

                              and put in on that place :

                              +	if (!empty($active_vouchers)) {
                              +	        $db = array();
                              +			$dbi = 1;
                              +	        foreach($active_vouchers as $voucher => $line) {
                              +	            list($timestamp,$minutes) = explode(",", $line);
                              +	            $activent['voucher'] = $voucher;
                              +	            $activent['timestamp'] = $timestamp;
                              +	            $activent['minutes'] = $minutes;
                              +	            $db["v{$dbi}"] = $activent;
                              +		    $dbi++;
                              +	        }
                              +	        $rollent['active'] = $db;
                              +	}
                              

                              (ditch the "+" sign when copying !)

                              The last two line in "voucher.diff.txt" are to re-sync again.

                              Now, a warning :
                              Editing like this, using some lines that were written for software version X, and applying the patch for version Y is NOT a good idea.

                              I'm not saying the patch doesn't work - I didn't test it.
                              Some side effect could exists.
                              Understand that upgrading your pfSense will (maybe = might) blow away your edits … (they have to be redone - the source could have been changed - patch might be more difficult, or completely impossible).

                              The most important one : never ask for "support" when you patch your own pfSense setup. You are on your own. No one will be able to re-create eventual error - because know one has your unique setup ....

                              i made the changes please check once i will try on my stand by system so there is nothing to loose just have look in confirm i made the right placement or not. thanks after that i will give it try,,,,
                              the bold one is replaced with the below of it…

                              // walk all active rolls and save runtime DB's to flash
                              $a_roll = &$config['voucher'][$cpzone]['roll'];
                              while (list($key, $value) = each($a_roll)) {
                              $rollent = &$a_roll[$key];
                              $roll = $rollent['number'];
                              $bitmask = voucher_read_used_db($roll);

                              */*$rollent['used'] = base64_encode($bitmask); /

                              if (!empty($bitmask))
                                      $rollent['used'] = base64_encode($bitmask);

                              $active_vouchers = voucher_read_active_db($roll);

                              / $db = array();
                              $dbi = 1;
                              foreach ($active_vouchers as $voucher => $line) {
                              list($timestamp, $minutes) = explode(",", $line);
                              $activent['voucher'] = $voucher;
                              $activent['timestamp'] = $timestamp;
                              $activent['minutes'] = $minutes;
                              $db["v{$dbi}"] = $activent;
                              $dbi++;
                              }
                              $rollent['active'] = $db; /

                              if (!empty($active_vouchers)) {
                                      $db = array();
                              $dbi = 1;
                                      foreach($active_vouchers as $voucher => $line) {
                                          list($timestamp,$minutes) = explode(",", $line);
                                          $activent['voucher'] = $voucher;
                                          $activent['timestamp'] = $timestamp;
                                          $activent['minutes'] = $minutes;
                                          $db["v{$dbi}"] = $activent;
                                  $dbi++;
                                      }
                                      $rollent['active'] = $db;
                              }

                              unset($active_vouchers);
                              }

                              unlock($voucherlck);

                              1 Reply Last reply Reply Quote 0
                              • GertjanG
                                Gertjan
                                last edited by

                                @ishtiaqaj:

                                i made the changes please check once i will try …..

                                To check code - or just make it readable for others at least, place it in bbcode.

                                If you test-drive on a non-critical system, just run it.
                                It won't explode, neither byte.
                                pfSense will survive a PHP error :)

                                No "help me" PM's please. Use the forum, the community will thank you.
                                Edit : and where are the logs ??

                                1 Reply Last reply Reply Quote 0
                                • I
                                  Iahmad
                                  last edited by

                                  @Gertjan:

                                  @ishtiaqaj:

                                  i made the changes please check once i will try …..

                                  To check code - or just make it readable for others at least, place it in bbcode.

                                  If you test-drive on a non-critical system, just run it.
                                  It won't explode, neither byte.
                                  pfSense will survive a PHP error :)

                                  success.,

                                  i tried the code and its work well with pfsense 2.3 fresh install,

                                  but you can't update on existing install it will show some expired voucher to active state not all but some…(means to say, i last update my system at 22-04-2016 and than last night with new code and it show voucher active that was expire b/w 22-04-2016 to 27-04-2016.

                                  can you provide code that delete the existing db for voucher and than restore...

                                  Even i delete captive portal and reset pfsense to factory default than restore, but again it show some expire voucher to active state.

                                  Gertjan

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