⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 save_cache_host.cgi

📁 Unix下基于Web的管理工具
💻 CGI
字号:
#!/usr/local/bin/perl# save_cache_host.cgi# Save, create or delete a cache_host directiverequire './squid-lib.pl';&ReadParse();$conf = &get_config();$cache_host = $squid_version >= 2 ? "cache_peer" : "cache_host";@ch = &find_config($cache_host, $conf);@chd = &find_config($cache_host."_domain", $conf);$dom = $ch[$in{'num'}]->{'values'}->[0];if ($in{'delete'}) {	# delete some directive	splice(@ch, $in{'num'}, 1);	# delete any cache_host directives as well	for($i=0; $i<@chd; $i++) {		if ($chd[$i]->{'values'}->[0] eq $dom) {			splice(@chd, $i--, 1);			}		}	}else {	# validate inputs	$whatfailed = "Failed to save cache";	gethostbyname($in{'host'}) ||		&error("'$in{'host'}' is not a valid cache hostname");	$in{'proxy'} =~ /^\d+$/ ||		&error("'$in{'proxy'}' is not a valid proxy port");	$in{'icp'} =~ /^\d+$/ ||		&error("'$in{'icp'}' is not a valid ICP port");	$in{'ttl'} =~ /^\d*$/ ||		&error("'$in{'ttl'}' is not a valid time-to-live");	$in{'weight'} =~ /^\d*$/ ||		&error("'$in{'weight'}' is not a valid weighting");	@vals = ($in{'host'}, $in{'type'}, $in{'proxy'}, $in{'icp'});	@optlist = ("proxy-only", "weight", "ttl", "no-query", "default",                    "round-robin", "multicast-responder");	push(@optlist, "closest-only", "no-digest",		       "no-netdb-exchange", "no-delay");	foreach $o (@optlist) {		$def = $in{$o."_def"};		if (defined($def)) {			if (!$def) { push(@vals, "$o=$in{$o}"); }			}		elsif ($in{$o}) { push(@vals, $o); }		}	if ($in{'login'}) {		push(@vals, "login=".$in{'login_user'}.":".$in{'login_pass'});		}	$dir = { 'name' => $cache_host, 'values' => \@vals };	@chdl = split(/\s+/, $in{'doq'});	foreach $dontq (split(/\s+/, $in{'dontq'})) { push(@chdl, "!$dontq"); }	if ($in{'new'}) {		# adding a new cache_host and domains		push(@ch, $dir);		if (@chdl) {			push(@chd, { 'name' => $cache_host."_domain",				     'values' => [ $vals[0], @chdl ] });			}		}	else {		# updating existing cache_host and domains		$ch[$in{'num'}] = $dir;		if (@chdl) {			# replace the first cache_host_domain directive			# for this host and remove the rest			$newv = { 'name' => $cache_host."_domain",				  'values' => [ $vals[0], @chdl ] };			for($i=0; $i<@chd; $i++) {				if ($chd[$i]->{'values'}->[0] eq $dom) {					if ($already) {						splice(@chd, $i--, 1);						}					else {						$chd[$i] = $newv;						$already++;						}					}				}			if (!$already) { push(@chd, $newv); }			}		elsif (@chd) {			# remove all the old cache_host_domain directives			# for this host			@chd = grep { $_->{'values'}->[0] ne $dom } @chd;			}		}	}&save_directive($conf, $cache_host, \@ch);&save_directive($conf, $cache_host."_domain", \@chd);&flush_file_lines();&redirect("edit_icp.cgi");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -