📄 clear.cgi
字号:
#!/usr/local/bin/perl# clear.cgi# Delete the cache, chown the directory to the correct user and re-run squid -zrequire './squid-lib.pl';&ReadParse();$| = 1;$config{'cache_dir'} =~ /^\/\S+/ || &error("Cache directory not set");&header("Clear and Rebuild Cache", "");print "<hr>\n";$conf = &get_config();if (!$in{'confirm'}) { print "<p>Are you sure you want to clear and rebuild your Squid\n"; print "cache? This will delete <b>all</b> the files you have cached\n"; print "and re-start your Squid server. <br>\n"; print "<form action=clear.cgi>\n"; print "<center><input type=submit name=confirm ", "value='Clear and Rebuild Cache'></center></form>\n"; print "<hr>\n"; &footer("", "squid index"); exit; }# Stop squidif ($pidstruct = &find_config("pid_filename", $conf)) { $pidfile = $pidstruct->{'values'}->[0]; }else { $pidfile = $config{'pid_file'}; }if (open(PID, $pidfile)) { <PID> =~ /(\d+)/; $pid = $1; close(PID); }if ($pid && kill(0, $pid)) { print "<p>Stopping squid ...<br>\n"; system("$config{'squid_path'} -f $config{'squid_conf'} ". "-k shutdown >/dev/null 2>&1"); for($i=0; $i<40; $i++) { if (!kill(0, $pid)) { last; } sleep(1); } print ".. Done<br>\n"; $stopped++; }# Get list of cache dirsif (@cachestruct = &find_config("cache_dir", $conf)) { @caches = map { $_->{'values'}->[0] } @cachestruct; }else { @caches = ( $config{'cache_dir'} ); }# Delete old cache files and re-create with same permissions!print "<p>Deleting old cache files ..<br>\n";foreach $c (@caches) { @st = stat($c); if (@st) { system("rm -rf $c >/dev/null 2>&1"); mkdir($c, 0755); chown($st[4], $st[5], $c); chmod($st[2], $c); } }print ".. Done<br>\n";$cmd = "$config{'squid_path'} -z";print "<p>Initializing the Squid cache with the command <tt>$cmd</tt> ..<br>\n";print "<pre>\n";open(INIT, "$cmd 2>&1 |");while(<INIT>) { print; }close(INIT);print "</pre>\n";print ".. Done<br>\n";# Try to re-start squidif ($stopped) { $temp = &tempname(); system("$config{'squid_path'} -sY -f $config{'squid_conf'} >$temp 2>&1 </dev/null &"); sleep(3); $errs = `cat $temp`; unlink($temp); if ($errs) { system("$config{'squid_path'} -k shutdown -f $config{'squid_conf'} >/dev/null 2>&1"); print "Failed to re-start Squid ..<br>\n"; print "<pre>$errs</pre>\n"; } }print "<hr>\n";&footer("", "squid index");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -