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

CRON - Excute a php script

Scheduled Pinned Locked Moved pfSense Packages
2 Posts 1 Posters 2.3k 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.
  • L
    Lectrician
    last edited by Apr 28, 2013, 2:11 PM

    I have a small PHP script which opens the captive portal DB, and then kicks all users from it.  This works fine if I place it in the www folder and execute from a web page.

    I thought I could put the php script into the /usr/local/pkg directory, and then use the CRON package to setup a time each day to execute this (just past midnight).

    I have tried to set the cron job up to execute every 2 minutes to test, and it never fires, and I see no system logs?

    Will a PHP script execute from a cron job?

    Thanks.

    1 Reply Last reply Reply Quote 0
    • L
      Lectrician
      last edited by Apr 28, 2013, 4:21 PM Apr 28, 2013, 3:07 PM

      Ah, Ok.

      I think I had the command wrong.  It works if i use this:  /usr/local/bin/php /usr/local/pkg/kickallusers.php 0

      I was originally just calling /usr/local/pkg/kickallusers.php (similar to what squid does in one it's cron jobs).

      This now works fine.

      For interest, kickallusers.php contains this:

      All the echoed HTML could be lost, as there is no need.  I wanted to do this to force all clients to disconnect at the same time, and not after xx amount of hours.

      echo "Opening Captive Portal Database....................";
      require("/etc/inc/captiveportal.inc");
      if (file_exists("/var/db/captiveportal.db")) {
        $captiveportallck = lock('captiveportaldb');
        $cpcontents = file("/var/db/captiveportal.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        unlock($captiveportallck);	
      }
      echo "DONE.";
      
      echo "
      
      ";
      $cnt = 0;
      foreach ($cpcontents as $cpcontent) {
        $cpent = explode(",", $cpcontent);
        $oursid = $cpent[5];
        echo "";
        captiveportal_disconnect_client($oursid);
        echo "";
        $cnt++;
      }
      
      $fh = fopen("/usr/local/pkg/kickallusers.log", 'w');
      if(flock($fh, LOCK_EX)){
        fwrite ($fh, date('l jS \of F Y h:i:s A'));
        flock($fh, LOCK_UN);
        }
      fclose($fh);	
      
      if($cnt != 0){
        echo "
      
      | Disconnecting [ MAC: $cpent[3] ]   |   [ IP: $cpent[2] ]   |   [ ID: $cpent[5] ]..................... | DONE.
       |
      
      Completed successfully, $cnt clients disconnected.";
      }else{
        echo "
      There where no clients to disconnect!";
      }
      exit;
      ?>
      
      I know the echo's will all buffer out together in this script, they were more just to see the finished output, not a 'rolling report'.
      
      My Captive Portal page has some PHP in it which does a time check, preventing the client from passing through the captive portal between midnight and 7am, the captive portal page that appears says the "Internet Access is currently turned off'.  Outside these times, the normal captive portal page appears.
      
      The reason for this kicking script is to kick all clients just after midnight, forcing them to re-visit the captive portal page, which would then show the "Internet Access is currently turned off" page.
      
      
      1 Reply Last reply Reply Quote 0
      2 out of 2
      • First post
        2/2
        Last post
      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
        This community forum collects and processes your personal information.
        consent.not_received