Copyright (C) 2013 Marcello Coutinho All rights reserved. Based on m0n0wall (http://m0n0.ch/wall) Copyright (C) 2003-2006 Manuel Kasper . All rights reserved. */ /* ========================================================================== */ /* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* ========================================================================== */ require_once('config.inc'); require_once('service-utils.inc'); require_once("util.inc"); require_once("functions.inc"); require_once("pkg-utils.inc"); require_once("globals.inc"); require_once("filter.inc"); require_once("services.inc"); // Check pfSense version $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); if ($pfs_version == "2.1" || $pfs_version == "2.2") define('FREERADIUS_BASE', '/usr/pbi/freeradius-' . php_uname("m")); else define('FREERADIUS_BASE', '/usr/local'); $bash_path = FREERADIUS_BASE . "/bin/bash"; if ($pfs_version == "2.2") { define('FREERADIUS_LIB', FREERADIUS_BASE . '/local/lib'); define('FREERADIUS_ETC', FREERADIUS_BASE . '/local/etc'); } else { define('FREERADIUS_LIB', FREERADIUS_BASE . '/lib'); define('FREERADIUS_ETC', FREERADIUS_BASE . '/etc'); } // Check freeradius lib version $frlib=""; if (file_exists(FREERADIUS_LIB)) { $libfiles = scandir(FREERADIUS_LIB); foreach ($libfiles as $libfile){ if (preg_match("/freeradius-/",$libfile)) $frlib=FREERADIUS_LIB . '/' . $libfile; } } if ($frlib == ""){ log_error("freeRADIUS - No freeradius lib found on ".FREERADIUS_LIB); } function freeradius_deinstall_command() { $pidFile = "/var/run/radiusd.pid"; $i = 0; while (isvalidpid($pidFile) && $i < 3) { $sig = ($i == 2 ? SIGKILL : SIGTERM); sigkillbypid($pidFile, $sig); sleep(1); $i++; } return; } function freeradius_install_command() { global $config, $frlib; // We create here different folders for different counters. @mkdir("/var/log/radacct/datacounter/daily", 0755, true); @mkdir("/var/log/radacct/datacounter/weekly", 0755, true); @mkdir("/var/log/radacct/datacounter/monthly", 0755, true); @mkdir("/var/log/radacct/datacounter/forever", 0755, true); @mkdir("/var/log/radacct/timecounter", 0755, true); @mkdir(FREERADIUS_ETC . "/raddb/scripts", 0755, true); unlink_if_exists("/usr/local/etc/raddb"); @symlink(FREERADIUS_ETC . "/raddb", "/usr/local/etc/raddb"); if (!file_exists("/var/log/radutmp")) { exec("touch /var/log/radutmp"); } if (!file_exists("/var/log/radwtmp")) { exec("touch /var/log/radwtmp"); } exec("chown -R root:wheel " . FREERADIUS_ETC . "/raddb /var/log/radacct"); if (file_exists($frlib)) exec("chown -R root:wheel {$frlib}"); // creating a backup file of the original policy.conf no matter if user checked this or not if (!file_exists(FREERADIUS_ETC . "/raddb/policy.conf.backup")) { log_error("FreeRADIUS: Creating backup of the original file to " . FREERADIUS_ETC . "/raddb/policy.conf.backup"); copy(FREERADIUS_ETC . "/raddb/policy.conf", FREERADIUS_ETC . "/raddb/policy.conf.backup"); } // creating a backup file of the original /modules/files no matter if user checked this or not if (!file_exists(FREERADIUS_ETC . "/raddb/files.backup")) { log_error("FreeRADIUS: Creating backup of the original file to " . FREERADIUS_ETC . "/raddb/files.backup"); copy(FREERADIUS_ETC . "/raddb/modules/files", FREERADIUS_ETC . "/raddb/files.backup"); } // Disable virtual-server we do not need by default if (file_exists(FREERADIUS_ETC . "/raddb/sites-enabled/control-socket")) { unlink(FREERADIUS_ETC . "/raddb/sites-enabled/control-socket"); } if (file_exists(FREERADIUS_ETC . "/raddb/sites-enabled/inner-tunnel")) { unlink(FREERADIUS_ETC . "/raddb/sites-enabled/inner-tunnel"); } // We run this here just to suppress some warnings on syslog if file doesn't exist freeradius_authorizedmacs_resync(); // These two functions create the module and the dictionary entry for Mobile-One-Time-Password freeradius_dictionary_resync(); freeradius_modulesmotp_resync(); // Here we create the modules and scripts for the datacounter freeradius_modulesdatacounter_resync(); freeradius_datacounter_acct_resync(); freeradius_datacounter_auth_resync(); // Some initial module configuration freeradius_modulesmschap_resync(); freeradius_modulesrealm_resync(); freeradius_modulescounter_resync(); // Initialize some config files - the functions below call other functions freeradius_sqlconf_resync(); freeradius_eapconf_resync(); freeradius_clients_resync(); $rcfile = array(); $rcfile['file'] = 'radiusd.sh'; $freeradius_etc_dir = FREERADIUS_ETC; $rcfile['start'] = << "\$LOCKFILE") 2> /dev/null; then # make sure lock file is removed even if script is terminated trap 'rm -f "\$LOCKFILE"; exit \$?' INT TERM EXIT {$freeradius_etc_dir}/rc.d/radiusd onestart # try to wait until the service starts if [ ! -f "\$PIDFILE" ]; then echo "\$SERVICENAME.sh: PID file was not found" for i in 1 2 3 4 5; do if [ -f "\$PIDFILE" ]; then echo "\$SERVICENAME.sh: Service started PID: `cat \$PIDFILE`" break else echo "\$SERVICENAME.sh: Waiting 0.5 seconds" sleep 0.5 fi done else echo "\$SERVICENAME.sh: Service running PID: `cat \$PIDFILE`" fi rm -f "\$LOCKFILE" trap - INT TERM EXIT else echo "\$SERVICENAME.sh: Cannot continue at this moment, this script is already trying to start service PID: \$(cat \$LOCKFILE)" fi EOD; $rcfile['stop'] = FREERADIUS_ETC . '/rc.d/radiusd onestop'; write_rcfile($rcfile); start_service("radiusd"); } function freeradius_settings_resync() { global $config; $conf = ''; // put the constant to a variable $varFREERADIUS_BASE = FREERADIUS_BASE; // We do some checks of some folders which will be deleted after reboot on nanobsd systems if (!file_exists("/var/log/radacct/")) { exec("mkdir /var/log/radacct"); } if (!file_exists("/var/log/radacct/datacounter/")) { exec("mkdir /var/log/radacct/datacounter && mkdir /var/log/radacct/datacounter/daily && mkdir /var/log/radacct/datacounter/weekly && mkdir /var/log/radacct/datacounter/monthly && mkdir /var/log/radacct/datacounter/forever"); } if (!file_exists("/var/log/radacct/timecounter/")) { exec("mkdir /var/log/radacct/timecounter"); } if (!file_exists("/var/log/radutmp")) { exec("touch /var/log/radutmp"); } if (!file_exists("/var/log/radwtmp")) { exec("touch /var/log/radwtmp"); } if (!file_exists("/var/log/radacct/")) { exec("chown -R root:wheel /var/log/radacct"); } $varsettings = $config['installedpackages']['freeradiussettings']['config'][0]; // Variables: General configuration $varsettingsmaxrequests = ($varsettings['varsettingsmaxrequests']?$varsettings['varsettingsmaxrequests']:'1024'); $varsettingsmaxrequesttime = ($varsettings['varsettingsmaxrequesttime']?$varsettings['varsettingsmaxrequesttime']:'30'); $varsettingscleanupdelay = ($varsettings['varsettingscleanupdelay']?$varsettings['varsettingscleanupdelay']:'5'); $varsettingshostnamelookups = ($varsettings['varsettingshostnamelookups']?$varsettings['varsettingshostnamelookups']:'no'); $varsettingsallowcoredumps = ($varsettings['varsettingsallowcoredumps']?$varsettings['varsettingsallowcoredumps']:'no'); $varsettingsregularexpressions = ($varsettings['varsettingsregularexpressions']?$varsettings['varsettingsregularexpressions']:'yes'); $varsettingsextendedexpressions = ($varsettings['varsettingsextendedexpressions']?$varsettings['varsettingsextendedexpressions']:'yes'); // Variables: Logging options $varsettingslogdir = ($varsettings['varsettingslogdir']?$varsettings['varsettingslogdir']:'syslog'); $varsettingsauth = ($varsettings['varsettingsauth']?$varsettings['varsettingsauth']:'yes'); $varsettingsauthbadpass = ($varsettings['varsettingsauthbadpass']?$varsettings['varsettingsauthbadpass']:'no'); $varsettingsauthbadpassmessage = ($varsettings['varsettingsauthbadpassmessage']?$varsettings['varsettingsauthbadpassmessage']:''); $varsettingsauthgoodpass = ($varsettings['varsettingsauthgoodpass']?$varsettings['varsettingsauthgoodpass']:'no'); $varsettingsauthgoodpassmessage = ($varsettings['varsettingsauthgoodpassmessage']?$varsettings['varsettingsauthgoodpassmessage']:''); $varsettingsstrippednames = ($varsettings['varsettingsstrippednames']?$varsettings['varsettingsstrippednames']:'no'); // Variables: Security $varsettingsmaxattributes = ($varsettings['varsettingsmaxattributes']?$varsettings['varsettingsmaxattributes']:'200'); $varsettingsrejectdelay = ($varsettings['varsettingsrejectdelay']?$varsettings['varsettingsrejectdelay']:'1'); // Variables: Thread Pool $varsettingsstartservers = ($varsettings['varsettingsstartservers']?$varsettings['varsettingsstartservers']:'5'); $varsettingsmaxservers = ($varsettings['varsettingsmaxservers']?$varsettings['varsettingsmaxservers']:'32'); $varsettingsminspareservers = ($varsettings['varsettingsminspareservers']?$varsettings['varsettingsminspareservers']:'3'); $varsettingsmaxspareservers = ($varsettings['varsettingsmaxspareservers']?$varsettings['varsettingsmaxspareservers']:'10'); $varsettingsmaxqueuesize = ($varsettings['varsettingsmaxqueuesize']?$varsettings['varsettingsmaxqueuesize']:'65536'); $varsettingsmaxrequestsperserver = ($varsettings['varsettingsmaxrequestsperserver']?$varsettings['varsettingsmaxrequestsperserver']:'0'); // For more details look at "freeradius_sqlconf_resync" $sqlconf = $config['installedpackages']['freeradiussqlconf']['config'][0]; // Dis-/Enable SQL in "instatiate" section in "freeradius_settings_resync" and radiusd.conf SQL SERVER 2 if ($sqlconf['varsqlconf2includeenable'] == 'on') { $varsqlconf2instantiate = 'sql2'; } else { $varsqlconf2instantiate = '### sql2 DISABLED ###'; } $varsqlconf2failover = ($varsettings['varsqlconf2failover']?$varsettings['varsqlconf2failover']:'redundant'); // Dis-/Enable SQL in "instatiate" section in "freeradius_settings_resync" and radiusd.conf SQL SERVER 1 if ($sqlconf['varsqlconfincludeenable'] == 'on') { $varsqlconfinclude = '$INCLUDE sql.conf'; $varsqlconfincludecounter = '$INCLUDE sql/mysql/counter.conf'; $varsqlconfinstantiate = "$varsqlconf2failover {" . "\n\t\tsql" . "\n\t\t$varsqlconf2instantiate" . "\n\t}"; } else { $varsqlconfinclude = '#$INCLUDE sql.conf'; $varsqlconfincludecounter = '#$INCLUDE sql/mysql/counter.conf'; $varsqlconf2failover = ''; $varsqlconfinstantiate = '#sql'; } $conf .= <<= '0') && ($users['varusersacctinteriminterval'] < '60')) { $varusersacctinteriminterval = 60; } else { $varusersacctinteriminterval = $users['varusersacctinteriminterval']; } // Clear variables for next user foreach additional options TOP $varuserstopadditionaloptions = ''; $varusersadditionaloptionstop = ''; if(!empty($users['varuserstopadditionaloptions'])) { $varuserstopadditionaloptions = explode("|", ($users['varuserstopadditionaloptions'])); foreach ($varuserstopadditionaloptions as $toptmp) { $varusersadditionaloptionstop .= $toptmp . "\n"; } } // Clear variables for next user foreach additional options: CHECK-ITEMS $varuserscheckitemsadditionaloptions = ''; $varusersadditionaloptionscheckitems = ''; if(!empty($users['varuserscheckitemsadditionaloptions'])) { $varuserscheckitemsadditionaloptions = explode("|", ($users['varuserscheckitemsadditionaloptions'])); $varusersadditionaloptionscheckitems .= ''; foreach ($varuserscheckitemsadditionaloptions as $checkitemtmp) { $varusersadditionaloptionscheckitems .= "$checkitemtmp" . " "; } } // Clear variables for next user foreach additional options: REPLY-ITEMS $varusersreplyitemsadditionaloptions = ''; $varusersadditionaloptionsreplyitems = ''; if(!empty($users['varusersreplyitemsadditionaloptions'])) { $varusersreplyitemsadditionaloptions = explode("|", ($users['varusersreplyitemsadditionaloptions'])); $varusersadditionaloptionsreplyitems .= ''; foreach ($varusersreplyitemsadditionaloptions as $replyitemtmp) { $varusersadditionaloptionsreplyitems .= $replyitemtmp . "\n\t"; } } // Empty variable $varuserscheckitem = ''; $varusersreplyitem = ''; // check if mobile otp is disabled if ($users['varusersmotpenable'] == '') { // If someone does not want to use username/password but entry "DEFAULT" instead then we can disable this if (($users['varusersusername'] == '') && ($users['varuserspassword'] == '')) { $varuserscheckitem = ''; } else { // Add the user attributes to each user. $varuserscheckitem = '"' . $varusersusername . '"' . " $varuserspasswordencryption := " . '"' . $varuserspassword .'"'; } } // end of check if otp is enabled // if otp is enabled we need to set Auth-Type to accept because password will be checked when the otp script gets executed in reply-item list else { $varuserscheckitem = '"' . $varusersusername . '"' . " Auth-Type = motp"; } // Add additional CHECK-ITEMS here. Different formatting in "users" file needed. if ($varuserssimultaneousconnect != '') { $varuserscheckitem .= ", Simultaneous-Use := " . '"' . $varuserssimultaneousconnect . '"'; } if ($varusersexpiration != '') { $varuserscheckitem .= ", Expiration := " . '"' . $varusersexpiration . '"'; } if ($varuserslogintime != '') { $varuserscheckitem .= ", Login-Time := " . '"' . $varuserslogintime . '"'; } if ($varusersamountoftime != '') { $varuserscheckitem .= ", Max-" . "$varuserspointoftime" . "-Session := " . "$varusersamountoftime"; } if ($varusersadditionaloptionscheckitems != '') { $varuserscheckitem .= ", $varusersadditionaloptionscheckitems"; } // this is the part for mobile otp if ($users['varusersmotpenable'] == 'on') { $varusersreplyitem .= "MOTP-Init-Secret = $varusersmotpinitsecret," . "\n\tMOTP-PIN = $varusersmotppin," . "\n\tMOTP-Offset = $varusersmotpoffset"; } else { $varusersreplyitem .= ''; } // Add additional REPLY-ITEMS here. Different formatting in "users" file needed. if ($varusersframedipaddress != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tFramed-IP-Address = $varusersframedipaddress"; } if ($varusersframedipnetmask != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tFramed-IP-Netmask = $varusersframedipnetmask"; } if ($varusersframedroute != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tFramed-Route = " . '"' . $varusersframedroute . '"'; } if ($varuserssessiontimeout != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tSession-Timeout := $varuserssessiontimeout"; } if ($varusersvlanid != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tTunnel-Type = VLAN,\n\tTunnel-Medium-Type = IEEE-802,\n\tTunnel-Private-Group-ID = " . '"' . $varusersvlanid . '"'; } if ($varusersmaxbandwidthup != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tWISPr-Bandwidth-Max-Up := $varusersmaxbandwidthup"; } if ($varusersmaxbandwidthdown != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tWISPr-Bandwidth-Max-Down := $varusersmaxbandwidthdown"; } if ($varusersacctinteriminterval != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tAcct-Interim-Interval := $varusersacctinteriminterval"; } if ($varuserswisprredirectionurl != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\tWISPr-Redirection-URL := $varuserswisprredirectionurl"; } // If an octet limit is set we create the files for the limit and the counter. Further we call an exec script which checks if the limit is reached or not if ($varusersmaxtotaloctets != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } //create exec script $varusersreplyitem .= "\n\tExec-Program-Wait = " . '"/bin/sh ' . FREERADIUS_ETC . '/raddb/scripts/datacounter_auth.sh ' . "$varusersusername $varusersmaxtotaloctetstimerange" . '"'; // create limit file - will be always overwritten so we can increase limit from GUI exec("`echo $varusersmaxtotaloctets > /var/log/radacct/datacounter/$varusersmaxtotaloctetstimerange/max-octets-$varusersusername`"); // if used-octets file exist we do NOT overwrite this file!!! if (!file_exists("/var/log/radacct/datacounter/$varusersmaxtotaloctetstimerange/used-octets-$varusersusername")) { exec("echo 0 > /var/log/radacct/datacounter/$varusersmaxtotaloctetstimerange/used-octets-$varusersusername"); } } // If an octet limit is NOT set we delete the files for the limit and the counter. else { if (file_exists("/var/log/radacct/datacounter/$varusersmaxtotaloctetstimerange/max-octets-$varusersusername")) { unlink("/var/log/radacct/datacounter/$varusersmaxtotaloctetstimerange/max-octets-$varusersusername"); } if (file_exists("/var/log/radacct/datacounter/$varusersmaxtotaloctetstimerange/used-octets-$varusersusername")) { unlink("/var/log/radacct/datacounter/$varusersmaxtotaloctetstimerange/used-octets-$varusersusername"); } } if ($varusersadditionaloptionsreplyitems != '') { if ($varusersreplyitem != '') { $varusersreplyitem .=","; } $varusersreplyitem .= "\n\t$varusersadditionaloptionsreplyitems"; } // Cosmetic fix - This is just to make a blank new line after each user entry $varusersreplyitem .= "\n\n"; $conf .= <<= '0') && ($users['varmacsacctinteriminterval'] < '60')) { $varmacsacctinteriminterval = 60; } else { $varmacsacctinteriminterval = $users['varmacsacctinteriminterval']; } // Clear variables for next mac foreach additional options TOP $varmacstopadditionaloptions = ''; $varmacsadditionaloptionstop = ''; if(!empty($macs['varmacstopadditionaloptions'])) { $varmacstopadditionaloptions = explode("|", ($macs['varmacstopadditionaloptions'])); foreach ($varmacstopadditionaloptions as $toptmp) { $varmacsadditionaloptionstop .= $toptmp . "\n"; } } // Clear variables for next mac foreach additional options: CHECK-ITEMS $varmacscheckitemsadditionaloptions = ''; $varmacsadditionaloptionscheckitems = ''; if(!empty($macs['varmacscheckitemsadditionaloptions'])) { $varmacscheckitemsadditionaloptions = explode("|", ($macs['varmacscheckitemsadditionaloptions'])); $varmacsadditionaloptionscheckitems .= ''; foreach ($varmacscheckitemsadditionaloptions as $checkitemtmp) { $varmacsadditionaloptionscheckitems .= "$checkitemtmp" . " "; } } // Clear variables for next mac foreach additional options: REPLY-ITEMS $varmacsreplyitemsadditionaloptions = ''; $varmacsadditionaloptionsreplyitems = ''; if(!empty($macs['varmacsreplyitemsadditionaloptions'])) { $varmacsreplyitemsadditionaloptions = explode("|", ($macs['varmacsreplyitemsadditionaloptions'])); $varmacsadditionaloptionsreplyitems .= ''; foreach ($varmacsreplyitemsadditionaloptions as $replyitemtmp) { $varmacsadditionaloptionsreplyitems .= $replyitemtmp . "\n\t"; } } // Empty variable $varmacscheckitem = ''; $varmacsreplyitem = ''; // If someone does not want to use MAC address but entry "DEFAULT" instead then we can disable this if ($macs['varmacsaddress'] == '') { $varmacscheckitem = ''; } else { // Add the user attributes to each user. $varmacscheckitem = "$varmacsaddress" . " Cleartext-Password := " . '"' . $varmacspassword . '"'; } // Add additional CHECK-ITEMS here. Different formatting in "authorized_macs" file needed. if ($varmacssimultaneousconnect != '') { $varmacscheckitem .= ", Simultaneous-Use := " . '"' . $varmacssimultaneousconnect . '"'; } if ($varmacsexpiration != '') { $varmacscheckitem .= ", Expiration := " . '"' . $varmacsexpiration . '"'; } if ($varmacslogintime != '') { $varmacscheckitem .= ", Login-Time := " . '"' . $varmacslogintime . '"'; } if ($varmacsamountoftime != '') { $varmacscheckitem .= ", Max-" . "$varmacspointoftime" . "-Session := " . "$varmacsamountoftime"; } if ($varmacsadditionaloptionscheckitems != '') { $varmacscheckitem .= ", $varmacsadditionaloptionscheckitems"; } // Add additional REPLY-ITEMS here. Different formatting in "authorized_macs" file needed. if ($varmacsframedipaddress != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tFramed-IP-Address = $varmacsframedipaddress"; } if ($varmacsframedipnetmask != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tFramed-IP-Netmask = $varmacsframedipnetmask"; } if ($varmacsframedroute != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tFramed-Route = " . '"' . $varmacsframedroute . '"'; } if ($varmacssessiontimeout != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tSession-Timeout := $varmacssessiontimeout"; } if ($varmacsvlanid != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tTunnel-Type = VLAN,\n\tTunnel-Medium-Type = IEEE-802,\n\tTunnel-Private-Group-ID = " . '"' . $varmacsvlanid . '"'; } if ($varmacsmaxbandwidthup != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tWISPr-Bandwidth-Max-Up := $varmacsmaxbandwidthup"; } if ($varmacsmaxbandwidthdown != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tWISPr-Bandwidth-Max-Down := $varmacsmaxbandwidthdown"; } if ($varmacsacctinteriminterval != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tAcct-Interim-Interval := $varmacsacctinteriminterval"; } if ($varmacswisprredirectionurl != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\tWISPr-Redirection-URL := $varmacsswisprredirectionurl"; } // If an octet limit is set we create the files for the limit and the counter. Further we call an exec script which checks if the limit is reached or not if ($varmacsmaxtotaloctets != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } //create exec script $varmacsreplyitem .= "\n\tExec-Program-Wait = " . '"/bin/sh ' . FREERADIUS_ETC . '/raddb/scripts/datacounter_auth.sh ' . "$varmacsaddress $varmacsmaxtotaloctetstimerange" . '"'; // create limit file - will be always overwritten so we can increase limit from GUI exec("`echo $varmacsmaxtotaloctets > /var/log/radacct/datacounter/$varmacsmaxtotaloctetstimerange/max-octets-$varmacsaddress`"); // if used-octets file exist we do NOT overwrite this file!!! if (!file_exists("/var/log/radacct/datacounter/$varmacsmaxtotaloctetstimerange/used-octets-$varmacsaddress")) { exec("echo 0 > /var/log/radacct/datacounter/$varmacsmaxtotaloctetstimerange/used-octets-$varmacsaddress"); } } // If an octet limit is NOT set we delete the files for the limit and the counter. else { if (file_exists("/var/log/radacct/datacounter/$varmacsmaxtotaloctetstimerange/max-octets-$varmacsaddress")) { unlink("/var/log/radacct/datacounter/$varmacsmaxtotaloctetstimerange/max-octets-$varmacsaddress"); } if (file_exists("/var/log/radacct/datacounter/$varmacsmaxtotaloctetstimerange/used-octets-$varmacsaddress")) { unlink("/var/log/radacct/datacounter/$varmacsmaxtotaloctetstimerange/used-octets-$varmacsaddress"); } } if ($varmacsadditionaloptionsreplyitems != '') { if ($varmacsreplyitem != '') { $varmacsreplyitem .=","; } $varmacsreplyitem .= "\n\t$varmacsadditionaloptionsreplyitems"; } // Cosmetic fix - This is just to make a blank new line after each macs entry $varmacsreplyitem .= "\n\n"; $conf .= << 'none', 'descr' => 'none'); foreach ($config['ca'] as $ca) { $ca_arr[] = array('refid' => $ca['refid'], 'descr' => $ca['descr']); } return $ca_arr; } // Gets started from freeradiuseapconf.xml function freeradius_get_ca_crl() { global $config; $crl_arr = array(); $crl_arr[] = array('refid' => 'none', 'descr' => 'none'); foreach ($config['crl'] as $crl) { $crl_arr[] = array('refid' => $crl['refid'], 'descr' => $crl['descr']); } return $crl_arr; } // Gets started from freeradiuseapconf.xml function freeradius_get_server_certs() { global $config; $cert_arr = array(); $cert_arr[] = array('refid' => 'none', 'descr' => 'none'); foreach ($config['cert'] as $cert) { $cert_arr[] = array('refid' => $cert['refid'], 'descr' => $cert['descr']); } return $cert_arr; } function freeradius_sqlconf_resync() { global $config; $conf = ''; $sqlconf = $config['installedpackages']['freeradiussqlconf']['config'][0]; // Variables: SQL DATABASE 1 $varsqlconfdatabase = ($sqlconf['varsqlconfdatabase']?$sqlconf['varsqlconfdatabase']:'mysql'); $varsqlconfserver = ($sqlconf['varsqlconfserver']?$sqlconf['varsqlconfserver']:'localhost'); $varsqlconfport = ($sqlconf['varsqlconfport']?$sqlconf['varsqlconfport']:'3306'); $varsqlconflogin = ($sqlconf['varsqlconflogin']?$sqlconf['varsqlconflogin']:'radius'); $varsqlconfpassword = ($sqlconf['varsqlconfpassword']?$sqlconf['varsqlconfpassword']:'radpass'); $varsqlconfradiusdb = ($sqlconf['varsqlconfradiusdb']?$sqlconf['varsqlconfradiusdb']:'radius'); $varsqlconfaccttable1 = ($sqlconf['varsqlconfaccttable1']?$sqlconf['varsqlconfaccttable1']:'radacct'); $varsqlconfaccttable2 = ($sqlconf['varsqlconfaccttable2']?$sqlconf['varsqlconfaccttable2']:'radacct'); $varsqlconfpostauthtable = ($sqlconf['varsqlconfpostauthtable']?$sqlconf['varsqlconfpostauthtable']:'radpostauth'); $varsqlconfauthchecktable = ($sqlconf['varsqlconfauthchecktable']?$sqlconf['varsqlconfauthchecktable']:'radcheck'); $varsqlconfauthreplytable = ($sqlconf['varsqlconfauthreplytable']?$sqlconf['varsqlconfauthreplytable']:'radreply'); $varsqlconfgroupchecktable = ($sqlconf['varsqlconfgroupchecktable']?$sqlconf['varsqlconfgroupchecktable']:'radgroupcheck'); $varsqlconfgroupreplytable = ($sqlconf['varsqlconfgroupreplytable']?$sqlconf['varsqlconfgroupreplytable']:'radgroupreply'); $varsqlconfusergrouptable = ($sqlconf['varsqlconfusergrouptable']?$sqlconf['varsqlconfusergrouptable']:'radusergroup'); $varsqlconfreadgroups = ($sqlconf['varsqlconfreadgroups']?$sqlconf['varsqlconfreadgroups']:'yes'); $varsqlconfdeletestalesessions = ($sqlconf['varsqlconfdeletestalesessions']?$sqlconf['varsqlconfdeletestalesessions']:'yes'); $varsqlconfsqltrace = ($sqlconf['varsqlconfsqltrace']?$sqlconf['varsqlconfsqltrace']:'no'); $varsqlconfnumsqlsocks = ($sqlconf['varsqlconfnumsqlsocks']?$sqlconf['varsqlconfnumsqlsocks']:'5'); $varsqlconfconnectfailureretrydelay = ($sqlconf['varsqlconfconnectfailureretrydelay']?$sqlconf['varsqlconfconnectfailureretrydelay']:'60'); $varsqlconflifetime = ($sqlconf['varsqlconflifetime']?$sqlconf['varsqlconflifetime']:'0'); $varsqlconfmaxqueries = ($sqlconf['varsqlconfmaxqueries']?$sqlconf['varsqlconfmaxqueries']:'0'); $varsqlconfreadclients = ($sqlconf['varsqlconfreadclients']?$sqlconf['varsqlconfreadclients']:'yes'); $varsqlconfnastable = ($sqlconf['varsqlconfnastable']?$sqlconf['varsqlconfnastable']:'nas'); // Additional changes were made in "freeradius_settings_resync" // Variables: SQL DATABASE 2 $varsqlconf2database = ($sqlconf['varsqlconf2database']?$sqlconf['varsqlconf2database']:'mysql'); $varsqlconf2server = ($sqlconf['varsqlconf2server']?$sqlconf['varsqlconf2server']:'localhost'); $varsqlconf2port = ($sqlconf['varsqlconf2port']?$sqlconf['varsqlconf2port']:'3306'); $varsqlconf2login = ($sqlconf['varsqlconf2login']?$sqlconf['varsqlconf2login']:'radius'); $varsqlconf2password = ($sqlconf['varsqlconf2password']?$sqlconf['varsqlconf2password']:'radpass'); $varsqlconf2radiusdb = ($sqlconf['varsqlconf2radiusdb']?$sqlconf['varsqlconf2radiusdb']:'radius'); $varsqlconf2accttable1 = ($sqlconf['varsqlconf2accttable1']?$sqlconf['varsqlconf2accttable1']:'radacct'); $varsqlconf2accttable2 = ($sqlconf['varsqlconf2accttable2']?$sqlconf['varsqlconf2accttable2']:'radacct'); $varsqlconf2postauthtable = ($sqlconf['varsqlconf2postauthtable']?$sqlconf['varsqlconf2postauthtable']:'radpostauth'); $varsqlconf2authchecktable = ($sqlconf['varsqlconf2authchecktable']?$sqlconf['varsqlconf2authchecktable']:'radcheck'); $varsqlconf2authreplytable = ($sqlconf['varsqlconf2authreplytable']?$sqlconf['varsqlconf2authreplytable']:'radreply'); $varsqlconf2groupchecktable = ($sqlconf['varsqlconf2groupchecktable']?$sqlconf['varsqlconf2groupchecktable']:'radgroupcheck'); $varsqlconf2groupreplytable = ($sqlconf['varsqlconf2groupreplytable']?$sqlconf['varsqlconf2groupreplytable']:'radgroupreply'); $varsqlconf2usergrouptable = ($sqlconf['varsqlconf2usergrouptable']?$sqlconf['varsqlconf2usergrouptable']:'radusergroup'); $varsqlconf2readgroups = ($sqlconf['varsqlconf2readgroups']?$sqlconf['varsqlconf2readgroups']:'yes'); $varsqlconf2deletestalesessions = ($sqlconf['varsqlconf2deletestalesessions']?$sqlconf['varsqlconf2deletestalesessions']:'yes'); $varsqlconf2sqltrace = ($sqlconf['varsqlconf2sqltrace']?$sqlconf['varsqlconf2sqltrace']:'no'); $varsqlconf2numsqlsocks = ($sqlconf['varsqlconf2numsqlsocks']?$sqlconf['varsqlconf2numsqlsocks']:'5'); $varsqlconf2connectfailureretrydelay = ($sqlconf['varsqlconf2connectfailureretrydelay']?$sqlconf['varsqlconf2connectfailureretrydelay']:'60'); $varsqlconf2lifetime = ($sqlconf['varsqlconf2lifetime']?$sqlconf['varsqlconf2lifetime']:'0'); $varsqlconf2maxqueries = ($sqlconf['varsqlconf2maxqueries']?$sqlconf['varsqlconf2maxqueries']:'0'); $varsqlconf2readclients = ($sqlconf['varsqlconf2readclients']?$sqlconf['varsqlconf2readclients']:'yes'); $varsqlconf2nastable = ($sqlconf['varsqlconf2nastable']?$sqlconf['varsqlconf2nastable']:'nas'); // Additional changes were made in "freeradius_settings_resync" $conf .= <<