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

    Commands to bypass CP at certain times?

    Scheduled Pinned Locked Moved Captive Portal
    28 Posts 4 Posters 5.1k 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.
    • G
      GS850L
      last edited by

      Yes it does  :)

      1 Reply Last reply Reply Quote 0
      • R
        rjcrowder
        last edited by

        OK… think it will be pretty easy. If I can't get to it tonight, it will probably be Sunday or Monday.

        1 Reply Last reply Reply Quote 0
        • R
          rjcrowder
          last edited by

          OK… I'm no PHP guru and I don't have multiple zones setup to test this with, but I think this will work. For rc.captiveportal_disable you would put "rc.captiveportal_disable zone1,zone2,zone3" with no spaces... This is the code for rc.captiveportal_disable (and I'm sure someone could make it more elegant).

          #!/usr/local/bin/php -f
          /* $Id$ */
          /*
              rc.captiveportal_disable
          
              copied and modified from rc.captiveportal_configure
          */
          
          require("config.inc");
          require("functions.inc");
          require_once("filter.inc");
          require("shaper.inc");
          require("captiveportal.inc");
          
          captiveportal_disable();
          
          function captiveportal_disable() {
          	global $config, $cpzone, $argv;
          
          	if (is_array($config['captiveportal'])) {
          		foreach ($config['captiveportal'] as $cpkey => $cp) {
          			$cpzone = $cpkey;
          			if (strpos($argv[1], $cpzone) !== false) {
          				if (isset($cp['enable'])) {
          					unset($cp['enable']);
          				}
          				captiveportal_configure_zone($cp);
          			}
          		}
          	} else
          		mwexec("/sbin/sysctl net.link.ether.ipfw=0");
          }
          
          ?>
          
          

          rc.captiveportal_enable would be the same syntax "rc.captiveportal_enable zone1,zone2,zone3"

          #!/usr/local/bin/php -f
          /* $Id$ */
          /*
              rc.captiveportal_disable
          
              copied and modified from rc.captiveportal_configure
          */
          
          require("config.inc");
          require("functions.inc");
          require_once("filter.inc");
          require("shaper.inc");
          require("captiveportal.inc");
          
          captiveportal_enable();
          
          function captiveportal_enable() {
          	global $config, $cpzone, $argv;
          
          	if (is_array($config['captiveportal'])) {
          		foreach ($config['captiveportal'] as $cpkey => $cp) {
          			$cpzone = $cpkey;
          			if (strpos($argv[1], $cpzone) !== false) {
          				$cp['enable']=true;
          				captiveportal_configure_zone($cp);
          			}
          		}
          	} else
          		mwexec("/sbin/sysctl net.link.ether.ipfw=0");
          }
          
          ?>
          
          
          1 Reply Last reply Reply Quote 0
          • G
            GS850L
            last edited by

            Hello,
              Thank you so much.    To clarify, the zone names are being passed via the command line at runtime? So the file name would always be rc.captiveportal_disable but add  a "space" and then zone name(s) in cron?

            Good day,
            Andy

            1 Reply Last reply Reply Quote 0
            • R
              rjcrowder
              last edited by

              Correct… and list the zone names with a separator such as a comma and no space "zone1,zone2,zone_etc" The code just looks for the zone name in the list that you pass using an "instring" function... not perfect because if you have zones that are named a subset of each other, it won't work correctly. For example, if you have zones "randy" and "randyc" and you you put "randyc" on the command line it would find both "randy"and "randyc" (in what you put on the command line) and shut both down...

              What can I say... it was easy... If I get more time I'll make it better. I just don't know PHP syntax that well so things take me longer than they should :-)

              1 Reply Last reply Reply Quote 0
              • G
                GS850L
                last edited by

                Hi,
                    I ran the disable script at the command line: rc.captiveportal_disable Portal

                The error : "Command not found" was returned…?  Portal is the name of my test CP. I used chmod +x before trying.

                Also in the enable script should "  ...ipfw=0");  " be a =1 instead?

                Good day,
                Andy

                1 Reply Last reply Reply Quote 0
                • R
                  rjcrowder
                  last edited by

                  do "./rc.captiveportal_disable Portal"

                  As far as ipfw=0… I don't think it really matters and I even thought about taking the check out. It is only executed if there is no captive portal section in the config.xml, and, if that doesn't exist in config.xml then ipfw SHOULD be disabled...

                  1 Reply Last reply Reply Quote 0
                  • G
                    GS850L
                    last edited by

                    Hi,
                        I was able to test these on a virtual system. The disable script took the "Portal" command but disabled both of the CP zones. The configure script ran with "Portal" but didn't enable either zone.  I will get a chance to try them on a live system tonight.

                    Thank you,
                    Andy

                    1 Reply Last reply Reply Quote 0
                    • R
                      rjcrowder
                      last edited by

                      BTW… I think the zone name may be lower case in the config... not sure but I think it might save "Portal" as "portal"... Anyway, let me know. I tried it on my system and it worked, but I only have one zone. I can create more if I need to so that I can test it...

                      1 Reply Last reply Reply Quote 0
                      • G
                        GS850L
                        last edited by

                        Awesome, used lower case "portal" and only that one turned on in the test system :D  I'm learning slowly ::)

                        Edit: My meeting got canceled so no live run, but it is working great on my virtual machines.

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