Example #1
0
function page()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    if (!isset($_GET["uuid"])) {
        $_GET["uuid"] = $sock->getframework("cmd.php?system-unique-id=yes");
    }
    if (!is_file("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER")) {
        $sock = new sockets();
        $cpunum = intval($sock->getFrameWork("services.php?CPU-NUMBER=yes"));
    } else {
        $cpunum = intval(@file_get_contents("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER"));
    }
    $CPU_NUMBER = $cpunum;
    $DisableAnyCache = $sock->GET_INFO("DisableAnyCache");
    if (!is_numeric($DisableAnyCache)) {
        $DisableAnyCache = 0;
    }
    $SquidCacheLevel = $sock->GET_INFO("SquidCacheLevel");
    if (!is_numeric($SquidCacheLevel)) {
        $SquidCacheLevel = 4;
    }
    if ($SquidCacheLevel == 0) {
        $DisableAnyCache = 1;
    }
    if ($DisableAnyCache == 1) {
        $html = FATAL_ERROR_SHOW_128("{all_cache_method_are_globally_disabled}");
        $html = $html . "<div style='width:100%'>\n\t\t\t\t<div style='margin-top:10px;width:99%' class=form>\n\t\t\t\t\t<a href=\"javascript:blur();\" OnClick=\"Loadjs('squid.caches.disable.php')\"\n\t\t\t\t\tstyle='font-size:16px;text-decoration:underline;font-weight:bold'\n\t\t\t\t\t>{access_to_parameters}</a>\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t";
        echo $tpl->_ENGINE_parse_body($html);
        return;
    }
    $maintoolbar = "\n\t<center id='main-smp-toolbar'>\n\t<table style='width:85%' class=form>\n\t\t<tr>\n\t\t\t<td align='center'>" . imgtootltip("apply-config-44.png", "{apply}", "Loadjs('{$page}?apply-js=yes')", null, time()) . "</td>\n\t\t\t<td align='center'>" . imgtootltip("events-64.png", "{events}", "Loadjs('{$page}?events-js=yes&uuid={$_GET["uuid"]}')", null, time() + 3) . "</td>\t\t\t\t\t\t\t\n\t\t\t<td align='center'>" . imgtootltip("48-refresh.png", "{refresh}", "RefreshTab('squid_main_caches_new')", null, time() + 2) . "</td>\n\t\t\t<td align='center'>" . imgtootltip("48-cancel.png", "{back_to_single_proc}", "Loadjs('{$page}?back-js=yes&uuid={$_GET["uuid"]}')", null, time() + 2) . "</td>\n\t\t</tr>\n\t</table>\n\t</center>";
    $t = time();
    $tpl = new templates();
    $sql = "SELECT * FROM cachestatus WHERE uuid='{$_GET["uuid"]}'";
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL($sql);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $array[trim($ligne["cachedir"])]["CURSIZE"] = FormatBytes($ligne["currentsize"]);
        $array[trim($ligne["cachedir"])]["MAXSIZE"] = trim($ligne["maxsize"]);
        $array[trim($ligne["cachedir"])]["POURC"] = trim($ligne["pourc"]);
    }
    $arraySerialize = urlencode(base64_decode(serialize($array)));
    for ($i = 1; $i < $CPU_NUMBER + 1; $i++) {
        $tr[] = "<div id='section-smp-{$i}'></div>";
        $js[] = "\n\t\t\tfunction SectionSMP{$t}{$i}(){\t\n\t\t\t\tLoadAjax('section-smp-{$i}','{$page}?section-smp&procnum={$i}&uuid={$_GET["uuid"]}&arraySerialize={$arraySerialize}');\n\t\t\n\t\t}";
        $jswait[] = "setTimeout(\"SectionSMP{$t}{$i}()\",1{$i}00);";
    }
    $html = "<center>{$maintoolbar}<div style='width:700px'>" . CompileTr2($tr) . "</div></center>\n\t<script>\n" . @implode("\n", $js) . "\n" . @implode("\n", $jswait) . "</script>\n\t\t\t\n\t";
    echo $tpl->_ENGINE_parse_body($html);
    $sock = new sockets();
    $sock->getFrameWork("squid.php?refresh-caches-infos=yes");
}
function status_squid_left($asroot=false){
	
	if(GET_CACHED(__FILE__, __FUNCTION__,__FUNCTION__)){return;}
	$page=CurrentPageName();
	$tpl=new templates();
	$users=new usersMenus();

	include_once(dirname(__FILE__)."/ressources/class.status.inc");
	$sock=new sockets();
	$SquidBinIpaddr=$sock->GET_INFO("SquidBinIpaddr");
	if($SquidBinIpaddr==null){$SquidBinIpaddr="0.0.0.0";}
	$urgency_mode_img="20-check-grey.png";
	if($SquidBinIpaddr=="0.0.0.0"){$SquidBinIpaddr="{all}";}
	$CacheManagement2=$sock->GET_INFO("CacheManagement2");
	if(!is_numeric($CacheManagement2)){$CacheManagement2=0;}
	$squid=new squidbee();
	$q=new mysql();
	$master_version=$squid->SQUID_VERSION;
	$text_kavicap_error=null;
	$text_script=null;
	$cache_mem=$squid->global_conf_array["cache_mem"];	
	$users=new usersMenus();
	
	$As32=false;
	if(!isset($_GET["uuid"])){$_GET["uuid"]=$sock->getframework("cmd.php?system-unique-id=yes");}
	

	$EnableKavICAPRemote=$sock->GET_INFO("EnableKavICAPRemote");
	$KavICAPRemoteAddr=$sock->GET_INFO("KavICAPRemoteAddr");
	$KavICAPRemotePort=$sock->GET_INFO("KavICAPRemotePort");	
	if(!is_numeric($EnableKavICAPRemote)){$EnableKavICAPRemote=0;}
	$CPU_NUMBER=$sock->getFrameWork("services.php?CPU-NUMBER=yes");
	
	if($EnableKavICAPRemote==1){
		$fp=@fsockopen($KavICAPRemoteAddr, $KavICAPRemotePort, $errno, $errstr, 1);
			if(!$fp){
				$text_kavicap_error="<div>{kavicap_unavailable_text}<br><strong>
				<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.kavicap.php');\" style='font-size:12px;color:#D70707;text-decoration:underline'>$KavICAPRemoteAddr:$KavICAPRemotePort</a><br>$errstr</div>";				
			}
		
		@fclose($fp);			
	}
	
	$q=new mysql_squid_builder();
	
	$text_error_sql="<div id='db-status-infos'></div>
	<script>LoadAjax('db-status-infos','$page?db-status-infos=yes',true);</script>
	";
	
	
	
	$q=new mysql_squid_builder();
	$requests=$q->EVENTS_SUM();
	$requests=numberFormat($requests,0,""," ");
	
	
	$tableblock=date('Ymd')."_blocked";
	$ligneW=$q->COUNT_ROWS($tableblock);
	$blocked_today=numberFormat($ligneW,0,""," ")." {blocked_websites} {this_day}";
	
	$q=new mysql_squid_builder();
	$websitesnums=$q->COUNT_ROWS("dansguardian_sitesinfos","artica_backup");
	$websitesnums=numberFormat($websitesnums,0,""," ");	
	
	$q=new mysql_squid_builder();
	$categories=$q->COUNT_ROWS("dansguardian_community_categories");
	$categories=numberFormat($categories,0,""," ");		
	
	$sock=new sockets();
	$sock->SET_INFO("squidStatsCategoriesNum",$categories);
	$sock->SET_INFO("squidStatsWebSitesNum",$websitesnums);
	$sock->SET_INFO("squidStatsBlockedToday",$blocked_today);
	$sock->SET_INFO("squidStatsRequestNumber",$requests);
	$styleText="font-size:12px;font-weight:bold";
	$migration_pid=unserialize(base64_decode($sock->getFrameWork("squid.php?migration-stats=yes")));
	if(is_array($migration_pid)){
		$text_script="<span style='color:#B80000;font-size:13px'>{migration_script_run_text} PID:{$migration_pid[0]} {since}:{$migration_pid[1]}Mn</span>";
	}	
	
	
	$DisableSquidSNMPModeText="{disabled}";
	$DisableSquidSNMPModeCK="20-check-grey.png";
	$SquidEnableRockStoreCK="20-check-grey.png";
	if(preg_match("#^([0-9]+)\.([0-9]+)#", $master_version,$re)){
		$MAJOR=$re[1];
		$MINOR=$re[2];
		if($MAJOR>2){if($MINOR>1){$As32=true;}}
		$master_version_text="$MAJOR.$MINOR";
	}	
	
	if(preg_match("#^([0-9]+)\.([0-9]+)\.([0-9]+)#", $master_version,$re)){
		$MAJOR=$re[1];
		$MINOR=$re[2];
		$REV=$re[3];
		$master_version_text="$MAJOR.$MINOR.$REV";
	}
	
	
	if($master_version_text==null){$master_version_text="Unknown";}
	
	
	
	if($As32){
		if($CPU_NUMBER>1){
			$SquidEnableRockStore=$sock->GET_INFO("SquidEnableRockStore");
			$SquidRockStoreSize=$sock->GET_INFO("SquidRockStoreSize");
			if(!is_numeric($SquidEnableRockStore)){$SquidEnableRockStore=0;}
			if(!is_numeric($SquidRockStoreSize)){$SquidRockStoreSize=2000;}
			
			
				$DisableSquidSNMPModeText=$CPU_NUMBER." cpu(s)";
				$DisableSquidSNMPModeCK="20-check.png";
			
			
			
			
			if($SquidEnableRockStore==1){
				$SquidRockStoreSize=FormatBytes($SquidRockStoreSize*1024);
				$SquidEnableRockStoreCK="20-check.png";
			}else{
				$SquidRockStoreSize="{disabled}";
			}
			
			$smptr="		
			<tr>
				<td width=1%><img src='img/$DisableSquidSNMPModeCK'></td>
				<td class=legend nowrap style='font-size:12px'>SMP:</td>
				<td style='font-size:14px'>
				<a href=\"javascript:blur();\"
				OnClick=\"javascript:Loadjs('squid.caches32.php?smp-js=yes&uuid={$_GET["uuid"]}');\"
				style='$styleText;text-decoration:underline'>$DisableSquidSNMPModeText</a></span></td>
			</tr>
			<tr>
				<td width=1%><img src='img/$SquidEnableRockStoreCK'></td>
				<td class=legend nowrap style='font-size:12px'>Rock store:</td>
				<td style='font-size:14px'>
				<a href=\"javascript:blur();\"
				OnClick=\"javascript:Loadjs('squid.rockstore.php');\"
				style='$styleText;text-decoration:underline'>$SquidRockStoreSize</a></td>
			</tr>";			
			
		}
	}
	
	
	$qs=new mysql();
	if(!$qs->FIELD_EXISTS("nics","ucarp-enable","artica_backup")){$qs->QUERY_SQL("ALTER TABLE `nics` ADD `ucarp-enable` smallint( 1 ) NULL DEFAULT '0'",'artica_backup'); }
	$sql="SELECT COUNT(*) as tcount FROM nics WHERE `ucarp-enable`=1";
	$ligne2=mysql_fetch_array($qs->QUERY_SQL($sql,"artica_backup"));
	$failover_icon="20-check-grey.png";
	if($ligne2["tcount"]==0){
		$failover_text="{disabled}";
	}else{
		$failover_text="{enabled}";
		$failover_icon="20-check.png";
	}
	if(!$users->UCARP_INSTALLED){
		$failover_text="-";
		$failover_icon="20-check-grey.png";
	}
	
	if($CacheManagement2==1){$smptr=null;}
	$DisableAnyCache=$sock->GET_INFO("DisableAnyCache");
	if(!is_numeric($DisableAnyCache)){$DisableAnyCache=0;}
	$SquidCacheLevel=$sock->GET_INFO("SquidCacheLevel");
	if(!is_numeric($SquidCacheLevel)){$SquidCacheLevel=4;}
	if($SquidCacheLevel==0){$DisableAnyCache=1;}
	
	
	$hasProxyTransparent=$sock->GET_INFO("hasProxyTransparent");
	if(!is_numeric($hasProxyTransparent)){$hasProxyTransparent=0;}
	
	$hasProxyTransparentText="{disabled}";
	$hasProxyTransparentCheck="20-check-grey.png";
	
	$DisableAnyCacheText="{enabled}";
	$DisableAnyCacheCheck="20-check.png";
	
	if($hasProxyTransparent==1){
		$hasProxyTransparentText="{enabled}";
		$hasProxyTransparentCheck="20-check.png";
	}
	
	if($DisableAnyCache==1){
		$DisableAnyCacheText="{disabled}";
		$DisableAnyCacheCheck="20-check-grey.png";
		
	}else{
		$qN=new mysql();
		$ligne=mysql_fetch_array($qN->QUERY_SQL("SELECT SUM(cache_size) as size FROM squid_caches_center WHERE enabled=1","artica_backup"));
		$size=$ligne["size"];
		$DisableAnyCacheText=FormatBytes($size*1024);
	}	
	
	
	
	if(preg_match("#^([0-9]+)\s+#", $cache_mem)){
		$cache_mem2=$re[1];
		$cache_mem2=($cache_mem*1024);
		$cache_mem2=FormatBytes($cache_mem2);
	}
	$EnableCNTLM=$sock->GET_INFO("EnableCNTLM");
	$CNTLMPort=$sock->GET_INFO("CnTLMPORT");
	$EnableRDPProxy=$sock->GET_INFO("EnableRDPProxy");
	$SquidUrgency=$sock->GET_INFO("SquidUrgency");
	if(!is_numeric($SquidUrgency)){$SquidUrgency=0;}
	$urgency_mode_color=null;
	$urgency_text="{disabled}";
	
	if($SquidUrgency==1){
		$urgency_mode_color=";color:#BE0303";
		$urgency_mode_img="20-check-red.png";
		$urgency_text="{enabled}";
	}
	
	
	
	if(!is_numeric($EnableRDPProxy)){$EnableRDPProxy=0;}
	if(!is_numeric($EnableCNTLM)){$EnableCNTLM=0;}
	if(!is_numeric($CNTLMPort)){$CNTLMPort=3155;}
	
	$PP[]=$squid->listen_port;
	
	if(!is_numeric($squid->second_listen_port)){$squid->second_listen_port=0;}
	if($squid->second_listen_port>0){
		$PP[]=$squid->second_listen_port;
	}
	
	if($EnableCNTLM==0){
		if($CNTLMPort>0){
			$PP[]=$CNTLMPort;
		}
	}
	
	$transparent_mode="
		<tr>
			<td width=1%><img src='img/$hasProxyTransparentCheck'></td>
			<td class=legend nowrap style='font-size:12px'>{transparent}:</td>
			<td style='font-size:14px'>
			<a href=\"javascript:blur();\"
			OnClick=\"Loadjs('squid.newbee.php?squid-transparent-js=yes');\"
			style='$styleText;text-decoration:underline'>$hasProxyTransparentText</a></td>
		</tr>";	
	
	$DisableAnyCache="
		<tr>
			<td width=1%><img src='img/$DisableAnyCacheCheck'></td>
			<td class=legend nowrap style='font-size:12px'>{caches} {disk}:</td>
			<td style='font-size:14px'>
			<a href=\"javascript:blur();\"
			
			style='$styleText'>$DisableAnyCacheText</a></td>
		</tr>";	
	
	
	
	
	
	$CacheMemory="<tr>
			<td width=1%><img src='img/20-check.png'></td>
			<td class=legend nowrap style='font-size:12px'>{cache_memory}:</td>
			<td style='font-size:14px'><a href=\"javascript:blur();\" 
			OnClick=\"javascript:Loadjs('squid.cache_mem.php');\" 
			style='$styleText;text-decoration:underline'>{$cache_mem2}</a></td>
		</tr>";
	
	if($CacheManagement2==1){$CacheMemory=null;}
	$squidversion="	
	<center>
	<div class=form style='width:93%'>
	<table style='width:250px;margin-top:10px;' class='TableRemove TableMarged'>
	<tbody>
		<tr>
			<td colspan=3 style='font-size:14px;text-align:center;padding-bottom:10px'><a href=\"javascript:blur();\"
		OnClick=\"javascript:Loadjs('squid.popups.php?script=visible_hostname');\"
		style='font-size:14px;text-decoration:underline;'>$squid->visible_hostname</a>
			</td>
		</tr>	
	
	
		<tr>
			<td width=1%><img src='img/20-check.png'></td>
			<td class=legend nowrap style='font-size:12px'>Proxy {version}:</td>
			<td style='$styleText'><a href=\"javascript:blur();\" 
			OnClick=\"javascript:Loadjs('squid.compilation.status.php');\" 
			style='$styleText;text-decoration:underline'>$master_version_text</a></td>
		</tr>
		<tr>
			<td width=1%><img src='img/20-check.png'></td>
			<td class=legend nowrap style='font-size:12px'>{listen_addr}:</td>
			<td style='font-size:14px'><a href=\"javascript:blur();\" 
			OnClick=\"javascript:Loadjs('squid.nic.php');\" 
			style='$styleText;text-decoration:underline'>$SquidBinIpaddr</a></td>
		</tr>	

		<tr>
			<td width=1%><img src='img/$urgency_mode_img'></td>
			<td class=legend nowrap style='font-size:12px$urgency_mode_color'>{urgency_mode}:</td>
			<td style='$styleText'><a href=\"javascript:blur();\" 
			OnClick=\"javascript:Loadjs('squid.urgency.php');\" 
			style='$styleText;text-decoration:underline$urgency_mode_color'>$urgency_text</a></td>
		</tr>		
		
		$smptr
		$transparent_mode
		$DisableAnyCache
		$CacheMemory

		<tr>
			<td width=1%><img src='img/$failover_icon'></td>
			<td class=legend nowrap style='font-size:12px'>{failover2}:</td>
			<td style='font-size:14px'><a href=\"javascript:blur();\" 
			OnClick=\"javascript:Loadjs('squid.failover.php');\" 
			style='$styleText;text-decoration:underline'>{$failover_text}</a></td>
		</tr>	
		
		
		</tbody>
	</table>
	</div>
	</center>
	";
	
	if($users->WEBSTATS_APPLIANCE){$squidversion=null;}
	
	$design="
	$text_error_sql
	$text_script
	$text_kavicap_error
	$squidversion
	<div id='squid-plugins-activated'></div>
	<div style='width:100%;text-align:right'>". 
	imgtootltip("refresh-24.png","{refresh}",
			"LoadAjax('squid-status','squid.main.quicklinks.php?status=yes');")."
	</div>
	
	";
	
	$classform="class=form";
	$sock=new sockets();
	$EnableRemoteStatisticsAppliance=$sock->GET_INFO("EnableRemoteStatisticsAppliance");
	if(!is_numeric($EnableRemoteStatisticsAppliance)){$EnableRemoteStatisticsAppliance=0;}
	$UnlockWebStats=$sock->GET_INFO("UnlockWebStats");
	if(!is_numeric($UnlockWebStats)){$UnlockWebStats=0;}
	if($UnlockWebStats==1){$EnableRemoteStatisticsAppliance=0;}	
	
	
	if($EnableRemoteStatisticsAppliance==1){$classform=null;}	
	
	$html="
	$design
	<center>
	
		<div id='squid-status-stats' $classform style='width:90%'></div>
	</center>
	
	
	<script>
		LoadAjax('squid-status-stats','squid.traffic.statistics.php?squid-status-stats=yes');	
		LoadAjax('squid-services','$page?squid-services=yes');
		LoadAjax('squid-plugins-activated','dansguardian2.php?dansguardian-status=yes');
	</script>
	";
	

	if($asroot){
		SET_CACHED(__FILE__, __FUNCTION__, __FUNCTION__, $html);
		return;
	}
	
	$html=$tpl->_ENGINE_parse_body($html);
	SET_CACHED(__FILE__, __FUNCTION__, __FUNCTION__, $html);
	echo $html;
	
	
}