3 # Delete the cache, chown the directory to the correct user and re-run squid -z
5 require './squid-lib.pl';
6 $access{'rebuild'} || &error($text{'clear_ecannot'});
8 $config{'cache_dir'} =~ /^\/\S+/ || &error("Cache directory not set");
11 if (!$in{'confirm'}) {
12 # Ask the user if he is sure
13 &ui_print_header(undef, $text{'clear_header'}, "");
14 print $text{'clear_msgclear'},"<br>\n";
15 print $text{'clear_msgclear2'},"<p>\n";
16 print "<form action=clear.cgi>\n";
17 print "<center><input type=submit name=confirm ",
18 "value=\"$text{'clear_buttclear'}\"></center></form>\n";
20 if (&has_command($config{'squidclient'})) {
21 # Show form to clear just one URL
23 print &ui_form_start("purge.cgi");
24 print "<b>$text{'clear_url'}</b>\n";
25 print &ui_textbox("url", undef, 50),"\n";
26 print &ui_submit($text{'clear_ok'}),"\n";
30 &ui_print_footer("", $text{'clear_return'});
34 &ui_print_unbuffered_header(undef, $text{'clear_header'}, "");
36 # Stop squid (if running)
37 if ($pidstruct = &find_config("pid_filename", $conf)) {
38 $pidfile = $pidstruct->{'values'}->[0];
40 else { $pidfile = $config{'pid_file'}; }
41 if (open(PID, $pidfile)) {
42 <PID> =~ /(\d+)/; $pid = $1;
45 if ($pid && kill(0, $pid)) {
46 print "$text{'clear_stop'}<br>\n";
47 &system_logged("$config{'squid_path'} -f $config{'squid_conf'} ".
48 "-k shutdown >/dev/null 2>&1");
49 for($i=0; $i<40; $i++) {
50 if (!kill(0, $pid)) { last; }
53 print "$text{'clear_done'}<p>\n";
57 # Get list of cache dirs
58 if (@cachestruct = &find_config("cache_dir", $conf)) {
59 if ($squid_version >= 2.3) {
60 @caches = map { $_->{'values'}->[1] } @cachestruct;
63 @caches = map { $_->{'values'}->[0] } @cachestruct;
66 else { @caches = ( $config{'cache_dir'} ); }
68 # Delete old cache files and re-create with same permissions!
69 print "$text{'clear_del'}<br>\n";
70 foreach $c (@caches) {
73 &system_logged("rm -rf $c/* >/dev/null 2>&1");
74 #mkdir($c, 0755); # only remove contents
75 #chown($st[4], $st[5], $c);
79 print "$text{'clear_done'}<p>\n";
81 $cmd = "$config{'squid_path'} -f $config{'squid_conf'} -z";
82 print &text('clear_init',$cmd)."<br>\n";
84 &additional_log('exec', undef, $cmd);
85 open(INIT, "$cmd 2>&1 |");
87 print &html_escape($_);
91 print "$text{'clear_done'}<p>\n";
93 # Try to re-start squid
96 &system_logged("$config{'squid_path'} -sY -f $config{'squid_conf'} >$temp 2>&1 </dev/null &");
101 &system_logged("$config{'squid_path'} -k shutdown -f $config{'squid_conf'} >/dev/null 2>&1");
102 print "$text{'clear_failrestart'}<br>\n";
103 print "<pre>$errs</pre>\n";
107 &webmin_log("clear");
108 &ui_print_footer("", $text{'clear_return'});