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. */ function global_eval_auth_options(){ conf_mount_rw(); config_lock(); global $config; $auth_method = $config['installedpackages']['squidauth']['config'][0]['auth_method']; switch ($auth_method) { case "none": $filecontents = file('/usr/local/pkg/squid_auth.xml'); $fout = fopen("/usr/local/pkg/squid_auth.xml","w"); foreach($filecontents as $line) { if (stristr($line, "/pkg.php?xml=squid_extauth.xml&id=0")) { fwrite($fout, " /pkg_edit.php?xml=squid_extauth.xml&id=0\n"); } else { fwrite($fout, $line); } } dynamic_no_auth(); break; case "local_auth": dynamic_auth_content(); dynamic_local_auth(); break; case "ldap_bind": $filecontents = file('/usr/local/pkg/squid_auth.xml'); $fout = fopen("/usr/local/pkg/squid_auth.xml","w"); foreach($filecontents as $line) { if (stristr($line, "/pkg.php?xml=squid_extauth.xml&id=0")) { fwrite($fout, " /pkg_edit.php?xml=squid_extauth.xml&id=0\n"); } else { fwrite($fout, $line); } } dynamic_ldap_auth(); break; case "domain_auth": $filecontents = file('/usr/local/pkg/squid_auth.xml'); $fout = fopen("/usr/local/pkg/squid_auth.xml","w"); foreach($filecontents as $line) { if (stristr($line, "/pkg.php?xml=squid_extauth.xml&id=0")) { fwrite($fout, " /pkg_edit.php?xml=squid_extauth.xml&id=0\n"); } else { fwrite($fout, $line); } } dynamic_domain_auth(); break; case "radius_auth": $filecontents = file('/usr/local/pkg/squid_auth.xml'); $fout = fopen("/usr/local/pkg/squid_auth.xml","w"); foreach($filecontents as $line) { if (stristr($line, "/pkg.php?xml=squid_extauth.xml&id=0")) { fwrite($fout, " /pkg_edit.php?xml=squid_extauth.xml&id=0\n"); } else { fwrite($fout, $line); } } dynamic_radius_auth(); break; default: $filecontents = file('/usr/local/pkg/squid_auth.xml'); $fout = fopen("/usr/local/pkg/squid_auth.xml","w"); foreach($filecontents as $line) { if (stristr($line, "/pkg.php?xml=squid_extauth.xml&id=0")) { fwrite($fout, " /pkg_edit.php?xml=squid_extauth.xml&id=0\n"); } else { fwrite($fout, $line); } } dynamic_no_auth(); break; } conf_mount_ro(); config_unlock(); } /* end function global_eval_auth_options */ function dynamic_no_auth() { conf_mount_rw(); config_lock(); global $config; $pkgfile = "/usr/local/pkg/squid_extauth.xml"; $fout = fopen($pkgfile, "w"); fwrite($fout, '' . "\n"); fwrite($fout, "\n"); fwrite($fout, " squidextnoauth\n"); fwrite($fout, " Services: Squid Advanced Proxy -> Extended Authentication Settings\n"); fwrite($fout, " installedpackages->package->squidextnoauth->configuration->settings\n"); fwrite($fout, "\n"); fwrite($fout, " /pkg_edit.php?xml=squid_extauth.xml&id=0\n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " General Settings\n"); fwrite($fout, " /pkg_edit.php?xml=squid_ng.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Upstream Proxy\n"); fwrite($fout, " /pkg_edit.php?xml=squid_upstream.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Cache Mgmt\n"); fwrite($fout, " /pkg_edit.php?xml=squid_cache.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Network Access Control\n"); fwrite($fout, " /pkg_edit.php?xml=squid_nac.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Traffic Mgmt\n"); fwrite($fout, " /pkg_edit.php?xml=squid_traffic.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Auth Settings\n"); fwrite($fout, " /pkg_edit.php?xml=squid_auth.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Extended Auth Settings\n"); fwrite($fout, " /pkg_edit.php?xml=squid_extauth.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " No Authentication Defined\n"); fwrite($fout, " no_auth\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, ' require_once("/usr/local/pkg/squid_ng.inc");' . "\n"); fwrite($fout, "\n"); fwrite($fout, " global_write_squid_config();\n"); fwrite($fout, ' mwexec("/usr/local/sbin/squid -k reconfigure");' . "\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, "\n"); fclose($fout); } function dynamic_local_auth() { conf_mount_rw(); config_lock(); global $config; $pkgfile = "/usr/local/pkg/squid_extauth.xml"; $fout = fopen($pkgfile, "w"); fwrite($fout, '' . "\n"); fwrite($fout, "\n"); fwrite($fout, "\n"); fwrite($fout, " squidextlocalauth\n"); fwrite($fout, " Services: Squid Advanced Proxy -> Extended Authentication Settings\n"); fwrite($fout, " 2.5.10_4\n"); fwrite($fout, " installedpackages->package->squidextlocalauth->configuration->settings\n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " /pkg.php?xml=squid_extauth.xml&id=0\n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " General Settings\n"); fwrite($fout, " /pkg_edit.php?xml=squid_ng.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Upstream Proxy\n"); fwrite($fout, " /pkg_edit.php?xml=squid_upstream.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Cache Mgmt\n"); fwrite($fout, " /pkg_edit.php?xml=squid_cache.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Network Access Control\n"); fwrite($fout, " /pkg_edit.php?xml=squid_nac.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Traffic Mgmt\n"); fwrite($fout, " /pkg_edit.php?xml=squid_traffic.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Auth Settings\n"); fwrite($fout, " /pkg_edit.php?xml=squid_auth.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Extended Auth Settings\n"); fwrite($fout, " /pkg.php?xml=squid_extauth.xml&id=0\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " Username\n"); fwrite($fout, " username\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Description\n"); fwrite($fout, " description\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Restriction Group\n"); fwrite($fout, " group\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " Username\n"); fwrite($fout, " username\n"); fwrite($fout, " input\n"); fwrite($fout, " 15\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Password\n"); fwrite($fout, " password\n"); fwrite($fout, " password\n"); fwrite($fout, " 8\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Description (Optional)\n"); fwrite($fout, " description\n"); fwrite($fout, " input\n"); fwrite($fout, " 30\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, " Restriction Group\n"); fwrite($fout, " group\n"); fwrite($fout, " select\n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, " \n"); fwrite($fout, ' require_once("/usr/local/pkg/squid_ng.inc");' . "\n"); fwrite($fout, "\n"); fwrite($fout, ' if ($password == $confirm_password) { ' . "\n"); fwrite($fout, " mod_htpasswd();\n"); fwrite($fout, " }\n"); fwrite($fout, " global_write_squid_config();\n"); fwrite($fout, ' mwexec("/usr/local/sbin/squid -k reconfigure");' . "\n"); fwrite($fout, " \n"); fwrite($fout, "\n"); fwrite($fout, "\n"); fclose($fout); conf_mount_ro(); config_unlock(); } /* end function dynamic_local_auth */ /* dynamically re-writes all squid xml files to handle adddeletecolumnitems properly */ function dynamic_auth_content() { if ($handle = opendir('/usr/local/pkg')) { while (($file = readdir($handle)) != false) { if (stristr($file, "squid_") && stristr($file, ".xml")) { $filecontents = file("/usr/local/pkg/" . $file); $fout = fopen("/usr/local/pkg/" . $file,"w"); foreach($filecontents as $line) { if (stristr($line, "/pkg_edit.php?xml=squid_extauth.xml&id=0")) { fwrite($fout, " /pkg.php?xml=squid_extauth.xml&id=0\n"); } else { fwrite($fout, $line); } } } } } } /* end function dynamic_auth_content */ ?>