debug_history .= "->create_squidguard_object"; $sg_object->set_options(SQUIDGUARD_BINPATH, SQUIDGUARD_WORKDIR, SQUIDGUARD_DBHOME); squidguard_ini_object(&$sg_object); return $sg_object; } function squidguard_ini_object($sg_object) { global $config; $sg_object->debug_history .= "->squidguard_ini_object"; $sg_object->init(); if ($config['installedpackages'][MODULE_GENERAL]['config'][0]['squidguard_enable'] != '') $sg_object->enabled = true; else $sg_object->enabled = false; if ($config['installedpackages'][MODULE_GENERAL]['config'][0]['blacklist'] != '') $sg_object->blacklist_enabled = true; else $sg_object->blacklist_enabled = false; // rewrite's $rewrite = $config['installedpackages'][MODULE_REWRITE]; // ['config']; if (is_array($rewrite)) { foreach($rewrite['config'] as $rew) { // rewrite object $sg_rew =& $sg_object->add_rewrite($rew[FLD_NAME], $rew[FLD_DESCRIPTION], $rew[FLD_ENABLELOG]); if (is_array($rew) and count($rew['row'])) { foreach($rew['row'] as $row) { // rewrite items $sg_rew->add_item($row[FLD_TARGETURL], $row[FLD_REPLACETO]); } } } } // time's $time = $config['installedpackages'][MODULE_TIME]['config']; if (is_array($time)) { foreach($time as $tm) { // time object $sg_time =& $sg_object->add_time($tm[FLD_NAME], $tm[FLD_DESCRIPTION]); foreach($tm['row'] as $row) { // time items if ($row[FLD_TIMETYPE] == 'date') // 0 - "date"$FLD_TIMETYPE $sg_time->add_date ($row[FLD_DATERANGE], $row[FLD_TIMERANGE]); else $sg_time->add_weekly ($row[FLD_TIMEDAYS], /* $row[FLD_DATERANGE], */$row[FLD_TIMERANGE]); } } } // source's $source = $config['installedpackages'][MODULE_SOURCE]['config']; if (is_array($source)) { foreach($source as $src) { // source object $sg_src =& $sg_object->add_src($src[FLD_NAME], $src[FLD_IPLIST], $src[FLD_DESCRIPTION], $src[FLD_ENABLELOG]); } } // destination's $destination = $config['installedpackages'][MODULE_DESTINATION]['config']; if (is_array($destination)) { foreach($destination as $dest) { // destination object $sg_ds =& $sg_object->add_dest($dest[FLD_NAME], $dest[FLD_DOMAINS], $dest[FLD_URLS], $dest[FLD_EXPRESSIONS], $dest[FLD_REDIRECT], $dest[FLD_DESCRIPTION], $dest[FLD_ENABLELOG]); } } // acl's $acl = $config['installedpackages'][MODULE_ACL]['config']; if (is_array($acl)) { foreach($acl as $ac) { $passes = str_replace("]", "", trim($ac[FLD_DESTINATION])); $passes = explode("[", $passes); $pass = ""; $overpass = ""; if (is_array($passes)) { $pass = $passes[0]; $overpass = $passes[1]; } // acl object; log defined only for default acl $sg_acl =& $sg_object->add_acl( $ac[FLD_SOURCE], $ac[FLD_TIME], $ac[FLD_DESCRIPTION], array('pass' => $pass, 'rewrite'=>$ac[FLD_REWRITE], 'redirect'=>$ac[FLD_REDIRECT], 'log'=>''), array('pass' => $overpass, 'rewrite'=>$ac[FLD_REWRITE], 'redirect'=>$ac[FLD_REDIRECT], 'log'=>''), $ac[FLD_DISABLED] ); } } // default acl; log defined only for default acl $acdef = $config['installedpackages'][MODULE_DEFAULT]['config'][0]; if (is_array($acdef)) { $passes = str_replace("]", "", trim($acdef[FLD_DESTINATION])); $passes = explode("[", $passes); $pass = ""; $overpass = ""; if (is_array($passes)) { $pass = $passes[0]; $overpass = $passes[1]; } // default acl object $sg_object->set_default_acl( $acdef[FLD_TIME], $acdef[FLD_DESCRIPTION], array('pass' => $pass, 'rewrite'=>$acdef[FLD_REWRITE], 'redirect'=>$acdef[FLD_REDIRECT], 'log'=>$acdef[FLD_ENABLELOG]), array('pass' => $overpass, 'rewrite'=>$acdef[FLD_REWRITE], 'redirect'=>$acdef[FLD_REDIRECT], 'log'=>$acdef[FLD_ENABLELOG]), $acdef[FLD_DISABLED] ); } // update squidguard object $sg_object->update(); } # --------------------------------------------------------------------------------------------------------------------- # install/deinstall # --------------------------------------------------------------------------------------------------------------------- function squidguard_deinstall() { } # --------------------------------------------------------------------------------------------------------------------- # Upload file to /var/tmp directory # --------------------------------------------------------------------------------------------------------------------- function upload_file($file) { global $squidguard_object; $res = ''; $cat = '/var/tmp/'; $squidguard_object->add_log("FILES: " . count($_FILES)); if (isset($_FILES[$file])) { // if file exists if (move_uploaded_file($_FILES[$file]['tmp_name'], $cat . $_FILES[$file]['name'])) { $res = true; } // else blacklist_add_log('Нифига нет Files=' . count($_FILES)); } return $res; } # --------------------------------------------------------------------------------------------------------------------- # default squidguard blacklist # http://ftp.teledanmark.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz # --------------------------------------------------------------------------------------------------------------------- // upload file and put them to temp catalog function upload_file_from_url($url_file, $destination_file, $proxy) { global $squidguard_object; // open destination file $upload_tmp = '/var/tmp/blacklists.tar.gz'; $result = ''; $squidguard_object->add_log("Begin upload from URL $url_file"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,BLACKLIST_DEFAULT_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); if ($proxy != '') { $ip = ''; $login = ''; $s = trim($proxy); if (strpos($s, ' ')) { $ip = substr($s, 0, strpos($s, ' ')); $login = substr($s, strpos($s, ' ') + 1); } else $ip = $s; if($ip != '') { $s_log = "Host[$ip] "; curl_setopt($ch, CURLOPT_PROXY, $ip); if($login != '') { $s_log .= "Login[$login]"; curl_setopt($ch, CURLOPT_PROXYUSERPWD, $login); } $squidguard_object->add_log("Proxy settings: $s_log"); } } else $squidguard_object->add_log("Proxy: not defined"); $result=curl_exec ($ch); curl_close ($ch); // TODO: check uploaded content for '.gz' file format if (file_put_contents($upload_tmp, $result) > 0) { $squidguard_object->add_log("Uploaded success."); } else $squidguard_object->add_log("Upload error."); return $upload_tmp; } # --------------------------------------------------------------------------------------------------------------------- # Validates # --------------------------------------------------------------------------------------------------------------------- function squidguard_validate_default($post, $input_errors) { squidguard_validate_acl($post, &$input_errors); } function squidguard_validate_acl($post, $input_errors) { global $config; $pass_up = array(); $deny_up = array(); $pass_up_val = ''; $pass_over = array(); $deny_over = array(); $pass_over_val = ''; // ===== store destinations to 'dest' value ===== foreach ($post as $key => $val) { if (substr_count($key, PREFLD_UPTIME) != 0) { $name = str_replace(PREFLD_UPTIME, '', $key); if ($name) $pass_up[$name] = 'on'; } elseif (substr_count($key, PREFLD_UPTIME_DENY) != 0) { $name = str_replace(PREFLD_UPTIME_DENY, '', $key); if ($name) $deny_up[$name] = 'on'; } elseif (substr_count($key, PREFLD_OVERTIME) != 0) { $name = str_replace(PREFLD_OVERTIME, '', $key); if ($name) $pass_over[$name] = 'on'; } elseif (substr_count($key, PREFLD_OVERTIME_DENY) != 0) { $name = str_replace(PREFLD_OVERTIME_DENY, '', $key); if ($name) $deny_over[$name] = 'on'; } } foreach ($pass_up as $key => $val) { if ($deny_up[$key]) $pass_up_val .= " !$key"; else $pass_up_val .= " $key"; } foreach ($pass_over as $key => $val) { if ($deny_over[$key]) $pass_over_val .= " !$key"; else $pass_over_val .= " $key"; } // if not exists key 'all', then add '!all' - default 'deny all' (equiqalence 'none') if ((substr_count($pass_up_val, 'all') == 0)) { $pass_up_val .= ' !all'; } if (!empty($pass_over_val) && (substr_count($pass_over_val, 'all') == 0)) { $pass_over_val .= ' !all'; } if (empty($pass_over_val)) $post[FLD_DEST] = "$pass_up_val"; else $post[FLD_DEST] = "$pass_up_val [$pass_over_val]"; } function squidguard_validate_times($post, $input_errors) { // check name $name = trim($post[FLD_NAME]); if(!empty($name)) { $err = check_name($name); if (!empty($err)) $input_errors[] = $err; } // check unique name if (!check_unique_name(MODULE_TIME, $name)) $input_errors[] = "Name '$name' already exists"; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Format: # date: