Lightsquid için Kullanıcı ve Grup Yönetimi Eklentisi



  • Herkez Lightsquid i ilk kurduğunda kullanıcıları nereye tanımlayacağını bulamaz ve sonuç olarak Realname Kısmında "?" ile karşılaşır (Ldap bağlantısı yapamayanlar için), sonra insanlar hangi ip hangi kullanıcının olduğunu bilemediği için raporu düzgün alamazlar artık buna bi çözüm yapayım dedim ellerimi sıvadım 2 gün çalışmamın sonucunda php-xml-inc-cfg bağlantılarını çözdüm (biraz zor oldu)

    Herkez artık kullanıcı tanımı yaparken zorlanmayacak.
    ve grup tanımında da tabiki.

    Önemli NOT: Daha önceden realname.cfg ve group.cfg dosyalarını kendinize göre yapılandırdıysanız mutlaka dosyaların yedeğini alınız. Mevcut dosyadaki isimleri ve yapılandırmayı senkronize olarak çekmiyor o yüzden üzerine yazdığınız yeni veri eski verilerinizi silecektir.

    lightsquid.inc ve lightsquid.xml dosyalarına aşağıda belirttiğim kodları ekliyoruz.
    bu iki dosyayı /usr/local/pkg/ dizininde bulabilirsiniz.

    lightsquid.xml

    
    				 <field><fielddescr>Realname (manuelly only)</fielddescr>
                <fieldname>lightsquid_realname</fieldname>
    			 <description>Example;
    
    									192.168.1.2	Sergey Erokhin
    
    									192.168.1.1	Jon Doe
    
    									192.168.1.3	Tech Good
    
    									Note:(if u are using squid auth do not use here)]]></description>
    			<type>textarea</type>
    			<cols>70</cols>
    			<rows>10</rows>
    			<encoding>base64</encoding></field> 
    		 <field><fielddescr>Groups (manuelly only)</fielddescr>
                <fieldname>lightsquid_group</fieldname>
    			 <description>Example;
    
    									esl	01	SysAdmin
    
    									karlos	01	SysAdmin
    
    									thy	01	SysAdmin
    
    									Ivanov	02	Developer
    
    									vanov2	02	Developer
    
    									Petrov	03	Commerial
    
    									Petrova	03	Commerial
    
    									vasyav	04	room 312
    
    									petyava	04	room 312
    
    									Note:(if u are using squid auth do not use here)]]></description>
    			<type>textarea</type>
    			<cols>70</cols>
    			<rows>10</rows>
    			<encoding>base64</encoding></field> 
    
    

    lightsquid.inc

    
    function ls_text_area_decode($text){
    	return preg_replace('/\r\n/', "\n",base64_decode($text));	
    }
    		$lsrealname=$config['installedpackages']['lightsquid']['config'][0];
    		if(empty($lsrealname['lightsquid_realname'])){
    		$lightsquid_realname="none";
    		}
    		else{
    		$lightsquid_realname=  LIGHTSQUID_BASE . "/etc/lightsquid/realname.cfg";
    		file_put_contents( LIGHTSQUID_BASE . '/etc/lightsquid/realname.cfg', ls_text_area_decode($lsrealname['lightsquid_realname']),LOCK_EX);
    		}
    
    		$lsgroup=$config['installedpackages']['lightsquid']['config'][0];
    		if(empty($lsgroup['lightsquid_group'])){
    		$lightsquid_group="none";
    		}
    		else{
    		$lightsquid_group=  LIGHTSQUID_BASE . "/etc/lightsquid/group.cfg";
    		file_put_contents( LIGHTSQUID_BASE . '/etc/lightsquid/group.cfg', ls_text_area_decode($lsgroup['lightsquid_group']),LOCK_EX);
    		}
    
    

    Dosyaların ikisinide tamamen ekleyim ki insanlar yapamazlarsa kullansınlar :)

    lightsquid.xml (tam dosya)

    
     <packagegui><copyright>/* $Id$ */
    /* ========================================================================== */
    /*
        authng.xml
        part of pfSense (http://www.pfSense.com)
        Copyright (C) 2007 to whom it may belong
        All rights reserved.
    
        Based on m0n0wall (http://m0n0.ch/wall)
        Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
        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.
                                                                                  */
    /* ========================================================================== */
            ]]>
            </mk@neon1.net></copyright>
    	<description>Describe your package here</description>
    	<requirements>Describe your package requirements here</requirements>
    	<faq>Currently there are no FAQ items provided.</faq>
    	<name>lightsquid</name>
    	<version>1.7.1</version>
    	<title>Services: Proxy Reports (LightSquid, SQStat) -> Settings</title>
    	<category>Status</category>
    	<include_file>/usr/local/pkg/lightsquid.inc</include_file>
    
    <menu>
    		<name>Proxy report</name>
    		<tooltiptext>Proxy server statistic report</tooltiptext>
    		Status
    		<url>/pkg_edit.php?xml=lightsquid.xml&id=0</url>
    	</menu>
    
             <tabs><tab><text>Settings</text>
                            <url>/pkg_edit.php?xml=lightsquid.xml&id=0</url>
                             <active></active></tab>
                     <tab><text>Lightsquid Report</text>
                            <url>/lightsquid/index.cgi</url></tab>
                     <tab><text>Proxy State</text>
                            <url>/sqstat/sqstat.php</url></tab></tabs>
             <additional_files_needed><prefix>/usr/local/pkg/</prefix>
                   <chmod>0755</chmod>
                   http://www.pfsense.org/packages/config/lightsquid/lightsquid.inc</additional_files_needed>
             <additional_files_needed><prefix>/var/tmp/</prefix>
                   <chmod>0755</chmod>
                   http://files.pfsense.org/packages/All/lightsquid_tpl.tbz</additional_files_needed>
             <additional_files_needed><prefix>/usr/local/www/sqstat/</prefix>
                   <chmod>0644</chmod>
                   http://www.pfsense.org/packages/config/lightsquid/sqstat.class.php</additional_files_needed>
             <additional_files_needed><prefix>/usr/local/www/sqstat/</prefix>
                   <chmod>0644</chmod>
                   http://www.pfsense.org/packages/config/lightsquid/sqstat.php</additional_files_needed>
             <additional_files_needed><prefix>/usr/local/www/sqstat/</prefix>
                   <chmod>0644</chmod>
                   http://www.pfsense.org/packages/config/lightsquid/sqstat.css</additional_files_needed>
             <additional_files_needed><prefix>/usr/local/www/sqstat/</prefix>
                   <chmod>0644</chmod>
                   http://www.pfsense.org/packages/config/lightsquid/zhabascript.js</additional_files_needed>
             <fields><field><fielddescr>Language</fielddescr>
                            <fieldname>lightsquid_lang</fieldname>
                            <description>Select report language</description>
                            <type>select</type>
                            <value>eng</value>
                             <options><option><name>Bulgarian</name><value>bg</value></option>
                                     <option><name>Czech</name><value>cz</value></option>
                                     <option><name>English</name><value>eng</value></option>
                                     <option><name>French</name><value>fr</value></option>
                                     <option><name>Hungarian</name><value>hu</value></option>
                                     <option><name>Italian</name><value>it</value></option>
                                     <option><name>Portuguese - Brazil</name><value>pt_br</value></option>
                                     <option><name>Russian</name><value>ru</value></option>
                                     <option><name>Russian KOI-8</name><value>ru-koi8</value></option>
                                     <option><name>Spanish</name><value>sp</value></option>
                                     <option><name>Ukrainian</name><value>ua</value></option></options></field>
                     <field><fielddescr>Bar color</fielddescr>
                            <fieldname>lightsquid_barcolor</fieldname>
                            <description>Select bar color</description>
                            <type>select</type>
                            <value>orange</value>
                             <options><option><name>Orange</name><value>orange</value></option>
                                    <option><name>Blue</name><value>blue</value></option>
                                    <option><name>Green</name><value>green</value></option>
                                    <option><name>Yellow</name><value>yellow</value></option>
                                    <option><name>Brown</name><value>brown</value></option>
                                    <option><name>Red</name><value>red</value></option></options></field>
                     <field><fielddescr>Report scheme</fielddescr>
                            <fieldname>lightsquid_template</fieldname>
                            <description>Select report scheme</description>
                            <type>select</type>
                            <value>base</value>
                             <options><option><name>Base</name><value>base</value></option>
                                    <option><name>Text</name><value>text</value></option>
                                    <option><name>NovoSea</name><value>novosea</value></option>
                                    <option><name>NovoPf</name><value>novopf</value></option></options></field>
                     <field><fielddescr>IP resolve method (future)</fielddescr>
                            <fieldname>lightsquid_ip2name</fieldname>
                             <description><table cellpadding=1 cellspacing=0 style="text-align: left;"> <tbody>
                            <tr><th colspan=2> Select IP to Name resolve method (take effect only on new data): </th><tr>
                            <tr><th> IP         </th><td> - return IP </td><tr>
                            <tr><th> Demo       </th><td> - return AUTHNAME, else DNSNAME, else IP </td><tr>
                            <tr><th> DNS        </th><td> - return DNSNAME </td><tr>
                            <tr><th> Simple     </th><td> - return AUTHNAME else IP </td><tr>
                            <tr><th> SMB        </th><td> - return SMB name of pc </td><tr>
                            <tr><th> Squidauth  </th><td> - return AUTHNAME else IP, allow cyrilyc name </td><tr>
                            </tbody> </table></description>
                            <type>select</type>
                            <value>dns</value>
                             <options><option><name>IP</name><value>ip</value></option>
                                    <option><name>Demo</name><value>demo</value></option>
                                    <option><name>DNS</name><value>dns</value></option>
                                    <option><name>Simple</name><value>simple</value></option>
                                    <option><name>SMB</name><value>smb</value></option>
                                    <option><name>Squidauth</name><value>squidauth</value></option></options></field>
                     <field><fielddescr>Refresh sheduler</fielddescr>
                            <fieldname>lightsquid_refreshsheduler_time</fieldname>
                             <description>Select data refresh period. System will execute task every XX time as from 00:00 hours. <br>
    			For example: if selected 2h - system wil start task at 0-2-4-..-24h. <br>
    			Note:  (!),(*) - use only for powerful system; (+) - recomended. <br><br>
    			<input type="submit" name="Submit" value="Refresh now"><br>
    			<input type="submit" name="Submit" value="Refresh full">
    			<br> Press button for start background refresh (this take some time).
    			<br> <span style="color: rgb(153, 51, 0);"> Note after installation:
    			<br> On the first - enable log in squid package with "/var/squid/log" path.
    			<br> On the second - press Refresh button for create lightsquid reports, else you will have error diagnostic page.</span></description> 
                            <type>select</type>
                            <value>lhp_none</value>
                             <options><option><name>none</name><value>lhp_none</value></option>
                                    <option><name>10min(!)</name><value>lhp_10m</value></option>
                                    <option><name>20min(!)</name><value>lhp_20m</value></option>
                                    <option><name>30min(*)</name><value>lhp_30m</value></option>
                                    <option><name>40min(*)</name><value>lhp_40m</value></option>
                                    <option><name>50min(+)</name><value>lhp_50m</value></option>
                                    <option><name>60min(+)</name><value>lhp_60m</value></option>
                                    <option><name>2h</name><value>lhp_2h</value></option>
                                    <option><name>3h</name><value>lhp_3h</value></option>
                                    <option><name>4h</name><value>lhp_4h</value></option>
                                    <option><name>6h</name><value>lhp_6h</value></option>
                                    <option><name>8h</name><value>lhp_8h</value></option>
                                    <option><name>12h</name><value>lhp_12h</value></option>
                                    <option><name>24(00)h</name><value>lhp_24h</value></option></options></field>
    
    		 <field><fielddescr>Skip url</fielddescr>
                <fieldname>lightsquid_skipurl</fieldname>
    			 <description>If you want skip some sites from stat, example our local www server
                                    Example, if you want skip LOCAL site, put it here
                                    zdd.com|192.168.1.|cnn.com</description> 
    			<type>textarea</type>
    			<cols>60</cols>
    			<rows>5</rows></field> 
    				 <field><fielddescr>Realname (manuelly only)</fielddescr>
                <fieldname>lightsquid_realname</fieldname>
    			 <description>Example;
    
    									192.168.1.2	Sergey Erokhin
    
    									192.168.1.1	Jon Doe
    
    									192.168.1.3	Tech Good
    
    									Note:(if u are using squid auth do not use here)]]></description>
    			<type>textarea</type>
    			<cols>70</cols>
    			<rows>10</rows>
    			<encoding>base64</encoding></field> 
    		 <field><fielddescr>Groups (manuelly only)</fielddescr>
                <fieldname>lightsquid_group</fieldname>
    			 <description>Example;
    
    									esl	01	SysAdmin
    
    									karlos	01	SysAdmin
    
    									thy	01	SysAdmin
    
    									Ivanov	02	Developer
    
    									vanov2	02	Developer
    
    									Petrov	03	Commerial
    
    									Petrova	03	Commerial
    
    									vasyav	04	room 312
    
    									petyava	04	room 312
    
    									Note:(if u are using squid auth do not use here)]]></description>
    			<type>textarea</type>
    			<cols>70</cols>
    			<rows>10</rows>
    			<encoding>base64</encoding></field></fields> 
    	 <custom_php_resync_config_command>lightsquid_resync();</custom_php_resync_config_command> 
    	 <custom_php_install_command>lightsquid_install();
    		lightsquid_resync();</custom_php_install_command> 
    	 <custom_php_deinstall_command>lightsquid_deinstall();</custom_php_deinstall_command></packagegui> 
    
    

    lightsquid.inc (tam dosya)

    
    /*
    	lightsquid.inc
    	Copyright (C) 2006 Serg Dvorianceev
    	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('globals.inc');
    require_once('config.inc');
    require_once('util.inc');
    require_once('pfsense-utils.inc');
    require_once('pkg-utils.inc');
    require_once('filter.inc');
    require_once('service-utils.inc');
    
    if (file_exists('squid.inc')) {
      require_once('squid.inc');
    }
    else update_log("File 'squid.inc' not found.");
    
    $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3);
    switch ($pfs_version) {
    	case "1.2":
    	case "2.0":
    		define('LIGHTSQUID_BASE','/usr/local');
    		break;
    	default:
    		define('LIGHTSQUID_BASE', '/usr/pbi/lightsquid-' . php_uname("m"));
    }
    
    define ('CMD_PKGDELETE', 'pkg_delete lightsquid-1.7.1');
    
    // enable GUI debug
    define('LS_GUI_DEBUG', 'on');
    define('LS_LOG_FILE',  '/tmp/lightsquid_gui.log');
    
    // configuration settings !-- CHECK THIS --!
    define('LS_CONFIGPATH',			LIGHTSQUID_BASE . '/etc/lightsquid');
    define('LS_CONFIGFILE',			'lightsquid.cfg');
    define('LS_CONFIGFILE_DIST',		'lightsquid.cfg.dist');
    define('LS_WWWPATH',			LIGHTSQUID_BASE . '/www/lightsquid');
    define('LS_TEMPLATEPATH',		LIGHTSQUID_BASE . '/www/lightsquid/tpl');
    define('LS_LANGPATH',			LIGHTSQUID_BASE . '/share/lightsquid/lang');
    define('LS_REPORTPATH',			'/var/lightsquid/report');
    
    global $config;
    if (isset($config['installedpackages']['squid']['config'][0])) {
    	if (!empty($config['installedpackages']['squid']['config'][0]['log_dir']))
    		define('LS_SQUIDLOGPATH', $config['installedpackages']['squid']['config'][0]['log_dir']);
    	else
    		define('LS_SQUIDLOGPATH', '/var/squid/logs');
    }
    define('LS_SQUIDLOG',			'access.log');
    define('LS_IP2NAMEPATH',		LIGHTSQUID_BASE . '/libexec/lightsquid');
    
    define('CRONTAB_FILE',			'/var/cron/tabs/root');
    define('CRONTAB_LS_TEMPLATE',		'/usr/bin/perl ' . LIGHTSQUID_BASE . '/www/lightsquid/lightparser.pl');
    define('CRONTAB_LS_JOBKEY',		'/lightparser.pl');
    define('CRONTAB_SQUID_TEMPLATE',	'/usr/local/sbin/squid -k rotate > /dev/null');
    define('CRONTAB_SQUID_JOBKEY',		'/squid -k rotate');
    
    // default values
    define('LS_DEF_IP2NAME',		'dns');
    define('LS_DEF_SQUIDLOGTYPE',		'0');
    define('LS_DEF_SKIPURL',		'zzz\.zzz');
    define('LS_DEF_LANG',			'eng');
    define('LS_DEF_TEMPLATE',		'base');
    define('LS_DEF_BARCOLOR',		'orange');
    
    // variable names
    define('LS_VAR_CFGPATH',		'cfgpath');
    define('LS_VAR_LOGPATH',		'logpath');
    define('LS_VAR_TPLPATH',		'tplpath');
    define('LS_VAR_LANGPATH',		'langpath');
    define('LS_VAR_LANG',			'lang');
    define('LS_VAR_REPORTPATH',		'reportpath');
    define('LS_VAR_SQUIDLOGTYPE',		'squidlogtype');
    define('LS_VAR_SKIPURL',		'skipurl');
    define('LS_VAR_IP2NAMEPATH',		'ip2namepath');
    define('LS_VAR_IP2NAME',		'ip2name');
    define('LS_VAR_TEMPLATE',		'templatename');
    define('LS_VAR_BARCOLOR',		'barcolor');
    
    // xml variables
    define('LS_XML_LANG',			'lightsquid_lang');
    define('LS_XML_SKIPURL',		'lightsquid_skipurl');
    define('LS_XML_IP2NAME',		'lightsquid_ip2name');
    define('LS_XML_TEMPLATE',		'lightsquid_template');
    define('LS_XML_BARCOLOR',		'lightsquid_barcolor');
    define('LS_XML_SHEDULERTIME',		'lightsquid_refreshsheduler_time');
    define('LS_XML_SQUID_SHEDULERTIME',	'lightsquid_squidrotatelog_sheduler_time');
    
    function lightsquid_install() {
    	update_log("lightsquid_install: started");
    
    	// create lightsquid report catalog
    	if (!file_exists(LS_REPORTPATH)) {
    		update_log("lightsquid_install: Create report dir " . LS_REPORTPATH);
    		mwexec("mkdir -p " . LS_REPORTPATH);
    	}
    
    	// install templates
    	$lstpl_file = "/var/tmp/lightsquid_tpl.tbz";
    	if (file_exists($lstpl_file)) {
    		mwexec("tar zxvf $lstpl_file -C " . LS_TEMPLATEPATH);
    		update_log("lightsquid_install: Install templates from $lstpl_file");
    	}
    
    	# check perl
    	if (!file_exists("/usr/bin/perl"))
    		mwexec("ln -s /usr/local/bin/perl /usr/bin/perl");
    
    	update_log("lightsquid_install: stopped");
    }
    
    function lightsquid_deinstall() {
    	update_log("lightsquid_deinstall: started");
    
    	// delete cron task's
    	ls_setup_cron("lightsquid_squid_rotate", "", "", false);
    	ls_setup_cron("lightsquid_parser", "", "", false);
    
    	update_log("lightsquid_deinstall: stopped");
    }
    
    function lightsquid_resync() {
    	global $config;
    	$tm = '';
    	$tm_squid = '';
    
    	# check perl
    	if (!file_exists("/usr/bin/perl"))
    		mwexec("ln -s /usr/local/bin/perl /usr/bin/perl");
    
    	// create lightsquid report catalog
    	if (!file_exists(LS_REPORTPATH)) {
    		update_log("lightsquid_install: Create report dir " . LS_REPORTPATH);
    		mwexec("mkdir -p " . LS_REPORTPATH);
    	}
    
    	mwexec("/bin/chmod -R u+w " . LIGHTSQUID_BASE . "/etc/lightsquid");
    
    	// debug
    	$light_test = array();
    	if (($_POST['Submit'] === 'Save') or !isset($_POST['Submit'])) {
    		$lsconf_var = array();
    
    		// variables for update
    		$lsconf_var[LS_VAR_CFGPATH]	= "\"" . LS_CONFIGPATH . "\"";
    		$lsconf_var[LS_VAR_LOGPATH]	= "\"" . LS_SQUIDLOGPATH . "\"";
    		$lsconf_var[LS_VAR_TPLPATH]	= "\"" . LS_TEMPLATEPATH . "\"";
    		$lsconf_var[LS_VAR_LANGPATH]	= "\"" . LS_LANGPATH . "\"";
    		$lsconf_var[LS_VAR_REPORTPATH]	= "\"" . LS_REPORTPATH . "\"";
    		$lsconf_var[LS_VAR_IP2NAMEPATH]	= "\"" . LS_IP2NAMEPATH . "\"";
    
    		$lsconf_var[LS_VAR_LANG]	= "\"" . LS_DEF_LANG . "\"";
    		$lsconf_var[LS_VAR_TEMPLATE]	= "\"" . LS_DEF_TEMPLATE . "\"";
    		$lsconf_var[LS_VAR_IP2NAME]	= "\"" . LS_DEF_IP2NAME . "\"";
    		$lsconf_var[LS_VAR_SKIPURL]	= "\"" . LS_DEF_SKIPURL . "\"";
    		$lsconf_var[LS_VAR_SQUIDLOGTYPE]= LS_DEF_SQUIDLOGTYPE;
    
    		// update variables from package GUI config
    		if (isset($config['installedpackages']['lightsquid']['config'][0])) {
    			$cfg = $config['installedpackages']['lightsquid']['config'][0];
    
    			$tm = $cfg[LS_XML_SHEDULERTIME];
    			$tm_squid = $cfg[LS_XML_SQUID_SHEDULERTIME];
    
    			if (isset($cfg[LS_XML_LANG]) and !empty($cfg[LS_XML_LANG]))
    				$lsconf_var[LS_VAR_LANG] = "\"" . $cfg[LS_XML_LANG] . "\";";
    
    			if (isset($cfg[LS_XML_SKIPURL]) and !empty($cfg[LS_XML_SKIPURL]))
    				$lsconf_var[LS_VAR_SKIPURL] = "\"" . $cfg[LS_XML_SKIPURL] . "\";";
    
    			if (isset($cfg[LS_XML_IP2NAME]) and !empty($cfg[LS_XML_IP2NAME] ))
    				$lsconf_var[LS_VAR_IP2NAME] = "\"" . $cfg[LS_XML_IP2NAME] . "\";";
    
    			if (isset($cfg[LS_XML_TEMPLATE]) and !empty($cfg[LS_XML_TEMPLATE])) {
    				$tpl_val = $cfg[LS_XML_TEMPLATE];
    				// check template path
    				if (!file_exists(LS_TEMPLATEPATH."/$tpl_val")) $tpl_val = 'base';
    				$lsconf_var[LS_VAR_TEMPLATE] = "\"" . $tpl_val . "\";";
    			}
    
    			if (isset($cfg[LS_XML_BARCOLOR]) and !empty($cfg[LS_XML_BARCOLOR]))
    				$lsconf_var[LS_VAR_BARCOLOR] = "\"" . $cfg[LS_XML_BARCOLOR] . "\";";
    		}
    
    		$lsconf = "";
    		$lsconf_file = LS_CONFIGPATH . "/" . LS_CONFIGFILE;
    		// open lightsquid config
    		if (file_exists($lsconf_file)) {
    			$lsconf = file_get_contents($lsconf_file);
    			update_log("Load config file $lsconf_file");
    		} else {
    			update_log("Error loading config file $lsconf_file");
    			// or open from 'lightsquid.cfg.dist'
    			$lsconf_dist_file = LS_CONFIGPATH . "/" . LS_CONFIGFILE_DIST;
    			if (file_exists($lsconf_dist_file)) {
    				$lsconf = file_get_contents($lsconf_dist_file);
    				update_log("Load config dist. file $lsconf_dist_file");
    			} else update_log("Error loading config dist. file $lsconf_dist_file");
    		}
    
    		// update lightsquid config
    		if (!empty($lsconf)) {
    			$lsconf = explode("\n", $lsconf);
    			foreach ($lsconf_var as $key => $val) {
    				for($i = 0; $i < count($lsconf); $i++) {
    					$s = trim($lsconf[$i]);
    					$e_key = "/^[$]" . $key . "[ ]*[=]+/i";
    #					update_log("Regular: preg_match(\"$e_key," . "'$s')"); // debug regular template
    					if (preg_match($e_key, $s)) {
    #					update_log("Regular PASSED: preg_match(\"$e_key," . "'$s')"); // debug regular template
    						$lsconf[$i] = '$' . "$key = $val;";
    						update_log("Update config: $key=$val");
    					}
    				}
    			}
    
    			$lsconf = implode("\n", $lsconf);
    			$fl = file_put_contents($lsconf_file, $lsconf);
    			update_log("Save config file $lsconf_file ($fl)");
    		}
    
    		// set shedule - refresh data job
    		if ($tm) {
    			$on = false;
    			$opt = array("*", "*", "*", "*", "*", "root", CRONTAB_LS_TEMPLATE . " today");
    			switch($tm) {
    				case 'lhp_none': $on = false; break;
    				case 'lhp_10m':  $on = true; $opt[0]= "*/10"; break;
    				case 'lhp_20m':  $on = true; $opt[0]= "*/20"; break;
    				case 'lhp_30m':  $on = true; $opt[0]= "*/30"; break;
    				case 'lhp_40m':  $on = true; $opt[0]= "*/40"; break;
    				case 'lhp_50m':  $on = true; $opt[0]= "*/50"; break;
    				case 'lhp_60m':  $on = true; $opt[0]= "*/60"; break;
    				case 'lhp_2h':   $on = true; $opt[0]= "0";  $opt[1]= "*/2";  break;
    				case 'lhp_3h':   $on = true; $opt[0]= "0";  $opt[1]= "*/3";  break;
    				case 'lhp_4h':   $on = true; $opt[0]= "0";  $opt[1]= "*/4";  break;
    				case 'lhp_6h':   $on = true; $opt[0]= "0";  $opt[1]= "*/6";  break;
    				case 'lhp_8h':   $on = true; $opt[0]= "0";  $opt[1]= "*/8";  break;
    				case 'lhp_12h':  $on = true; $opt[0]= "0";  $opt[1]= "*/12"; break;
    				case 'lhp_24h':  $on = true; $opt[0]= "45"; $opt[1]= "23";   break; # dayly at 23:45
    			}
    			ls_setup_cron("lightsquid_parser_today", $opt, CRONTAB_LS_JOBKEY, $on);
    
    			# fix possible data lost with 00:00 script start - rescan yesterday
    			$opt = array("15", "0", "*", "*", "*", "root", CRONTAB_LS_TEMPLATE . " yesterday");
    			ls_setup_cron("lightsquid_parser_yesterday", $opt, CRONTAB_LS_JOBKEY, $on);
    
    		}  else {
    			ls_setup_cron("lightsquid_parser_today", "", "", false);
    			ls_setup_cron("lightsquid_parser_yesterday", "", "", false);
    		}
    
    		ls_setup_cron("lightsquid_squid_rotate", "", "", false);
    
    		// update squid conf
    		if (isset($config['installedpackages']['squid']['config'][0])) {
    			$squid_settings = $config['installedpackages']['squid']['config'][0];
    			$squid_settings['log_enabled'] = 'on';
    			if (empty($squid_settings['log_dir']))
    				$squid_settings['log_dir'] = LS_SQUIDLOGPATH;
    
    			# sqstat
                         $ifmgr = "127.0.0.1;";
    			$iface = ($squid_settings['active_interface'] ? $squid_settings['active_interface'] : 'lan');
    			$iface = explode(",", $iface);
    			foreach ($iface as $i => $if) {
    				$realif = ls_get_real_interface_address($if);
                                if ($realif[0]) 
    					$ifmgr = $ifmgr . $realif[0] . ";";
    			}
    
    			/* Only save and resync if we're actually making any changes. */
    			if (strpos($config['installedpackages']['squidnac']['config'][0]['ext_cachemanager'], $ifmgr) === FALSE) {
    				$config['installedpackages']['squidnac']['config'][0]['ext_cachemanager'] = $ifmgr;
    				write_config();
    				if (function_exists('squid_resync'))
    					squid_resync();
    				else
    					update_log("Function 'squid_resync' not found.");
    			}
    		}
    	}
    
    	if ($_POST['Submit'] === 'Refresh now')  refresh_now();
    	if ($_POST['Submit'] === 'Refresh full') refresh_full();
    }
    
    // setup cron tasks
    // original source from '/etc/inc/pfsense-utils.inc' function 'tdr_install_cron'
    // this function safe for other tasks
    // *****************************************************************************
    // - $task_name: cron task name (for config identification) /for searching my cron tasks/
    // - $options:   array=[0:minute][1:hour][2:mday][3:month][4:wday][5:who][6:cmd]
    // - $task_key:  cron command key for searching
    // - $on_off:	true-'on task', false-'off' task
    // required: $task_nameand $on_off
    // *****************************************************************************
    define('FIELD_TASKNAME', 'task_name');
    
    function ls_setup_cron($task_name, $options, $task_key, $on_off) {
    	global $config;
    	update_log("ls_setup_cron: start task_name=$task_name, task_key=$task_key, on_off=$on_off");
    
    	// check input params
    	if(!$task_name) {
    		update_log("ls_setup_cron: exit - uncomplete input params.");
    		return;
    	}
    
    	// delete old task(s)
    	if (is_array($config['cron']['item'])) {
    		foreach ($config['cron']['item'] as $key => $item) {
    		# unset crontask by name
    		if (!empty($task_name) && ($item[FIELD_TASKNAME] == $task_name)) {
    			unset($config['cron']['item'][$key]);
    		} else
    		# unset crontask by cmd
    		if ($options[6] && (strpos($item['command'], $options[6]) !== false)) {
    			unset($config['cron']['item'][$key]);
    		}
    		}
    	}
    
    	# install cron task
    	if ($on_off) {
    		if ($task_key) {
    		if (is_array($options)) {
    			# add new
    			$cron_item = array();
    			$cron_item[FIELD_TASKNAME]	= $task_name;
    			$cron_item['minute']		= $options[0];
    			$cron_item['hour']		= $options[1];
    			$cron_item['mday']		= $options[2];
    			$cron_item['month']		= $options[3];
    			$cron_item['wday']		= $options[4];
    			$cron_item['who']		= $options[5];
    			$cron_item['command']		= $options[6];
    
    			# check options
    			if (!$cron_item['who']) $cron_item['who'] = "nobody";
    
    			$config['cron']['item'][] = $cron_item;
    			update_log("ls_setup_cron: add cron task '{$task_name}'='{$cron_item['command']}'");
    		}
    		} else
    		// log
    		update_log("ls_setup_cron: input prm 'task_key' not defined");
    	}
    
    	write_config("Installed cron task '$task_name' for 'lightsquid' package");
    	configure_cron();
    	update_log("ls_setup_cron: Apply new cron settings.");
    }
    
    function update_log($log) {
    	if (LS_GUI_DEBUG === 'on') {
    		$t_ls_log = '';
    		if (file_exists(LS_LOG_FILE))
    			$t_ls_log = file_get_contents(LS_LOG_FILE);
    		$t_ls_log .= "\n$log";
    		file_put_contents(LS_LOG_FILE, $t_ls_log);
    	}
    }
    
    function refresh_now() {
    	$cmd = CRONTAB_LS_TEMPLATE . " today";
    	update_log("refresh_now: execute command '$cmd'");
    	// create lightsquid report catalog
    	if (!file_exists(LS_REPORTPATH)) {
    		update_log("lightsquid_install: Create report dir " . LS_REPORTPATH);
    		mwexec("mkdir -p " . LS_REPORTPATH);
    	}
    	mwexec_bg($cmd);
    }
    
    function refresh_full() {
    	$cmd = CRONTAB_LS_TEMPLATE;
    	$log_name = LS_SQUIDLOG;
    	update_log("refresh_full: start");
    
    	// create lightsquid report catalog
    	if (!file_exists(LS_REPORTPATH)) {
    		update_log("lightsquid_install: Create report dir " . LS_REPORTPATH);
    		mwexec("mkdir -p " . LS_REPORTPATH);
    	}
    
    	// parse access.log
    	update_log("refresh_full: execute command '$cmd'");
    	mwexec_bg("$cmd $log_name");
    	// parse access.log.x
    	for ($i=0; $i<100; $i++) {
    		$lg = LS_SQUIDLOG . ".$i";
    		if (file_exists(LS_SQUIDLOGPATH . "/$lg")) {
    			update_log("refresh_full: execute command '$cmd $lg'");
    			mwexec_bg("$cmd $lg");
    		} else
    			// really go <= 10 cycles
    			break;
    	}
    	update_log("refresh_full: stop");
    }
    
    function ls_get_real_interface_address($iface)
    {
    	global $config;
    
    	$iface = convert_friendly_interface_to_real_interface_name($iface);
    	$line = trim(shell_exec("ifconfig $iface | grep inet | grep -v inet6"));
    	list($dummy, $ip, $dummy2, $netmask) = explode(" ", $line);
    
    	return array($ip, long2ip(hexdec($netmask)));
    }
    function ls_text_area_decode($text){
    	return preg_replace('/\r\n/', "\n",base64_decode($text));	
    }
    		$lsrealname=$config['installedpackages']['lightsquid']['config'][0];
    		if(empty($lsrealname['lightsquid_realname'])){
    		$lightsquid_realname="none";
    		}
    		else{
    		$lightsquid_realname=  LIGHTSQUID_BASE . "/etc/lightsquid/realname.cfg";
    		file_put_contents( LIGHTSQUID_BASE . '/etc/lightsquid/realname.cfg', ls_text_area_decode($lsrealname['lightsquid_realname']),LOCK_EX);
    		}
    
    		$lsgroup=$config['installedpackages']['lightsquid']['config'][0];
    		if(empty($lsgroup['lightsquid_group'])){
    		$lightsquid_group="none";
    		}
    		else{
    		$lightsquid_group=  LIGHTSQUID_BASE . "/etc/lightsquid/group.cfg";
    		file_put_contents( LIGHTSQUID_BASE . '/etc/lightsquid/group.cfg', ls_text_area_decode($lsgroup['lightsquid_group']),LOCK_EX);
    		}
    
    ?>
    
    

    doğru yaptıysanız resimdeki gibi lightsquid ayar ekranında "skip url" altına eklediğim yerler gelecek :)



Log in to reply