Skip to content

Commit

Permalink
Fixes to get non-apache webservers working with the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed Feb 11, 2017
1 parent 325672b commit 732e3b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
6 changes: 6 additions & 0 deletions generate.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require './virtualmin-awstats-lib.pl';
&ReadParse();
&error_setup($text{'generate_err'});
&can_domain($in{'dom'}) || &error($text{'edit_ecannot'});
my $d = &virtual_server::get_domain_by("dom", $in{'dom'});

&ui_print_unbuffered_header(undef, $text{'gen_title'}, "");

Expand All @@ -23,6 +24,11 @@ if ($in{'wipe'} && $data) {
print &text('gen_doing', "<tt>$in{'dom'}</tt>", "<tt>$log</tt>"),"<br>\n";
print "<pre>";
my $ok = &generate_report($in{'dom'}, *STDOUT, 1);
if ($ok && !$d->{'web'}) {
# Also re-generate static HTML
my $outdir = &virtual_server::public_html_dir($d)."/awstats";
&generate_html($in{'dom'}, $outdir);
}
print "</pre>";
print(($ok ? &text('gen_done', "view.cgi?config=$in{'dom'}")
: $text{'gen_failed'}), "<p>\n");
Expand Down
21 changes: 15 additions & 6 deletions virtual_feature.pl
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,28 @@ sub feature_setup
my $outdir = &virtual_server::public_html_dir($d)."/awstats";

# Work out the log format
my ($virt, $vconf) = &virtual_server::get_apache_virtual($d->{'dom'}, $d->{'web_port'});
my $clog = &apache::find_directive("CustomLog", $vconf);
my $fmt = $config{'format'} ? $config{'format'}
: $clog =~ /combined$/i ? 1 : 4;
my $fmt;
if ($d->{'web'}) {
# Get from Apache config
my ($virt, $vconf) = &virtual_server::get_apache_virtual(
$d->{'dom'}, $d->{'web_port'});
my $clog = &apache::find_directive("CustomLog", $vconf);
$fmt = $config{'format'} ? $config{'format'}
: $clog =~ /combined$/i ? 1 : 4;
}
else {
# Assume combined for other webservers
$fmt = 1;
}

# Update settings to match server
&lock_file(&get_config_file($d->{'dom'}));
my $conf = &get_config($d->{'dom'});
&save_directive($conf, $d->{'dom'}, "SiteDomain", "\"$d->{'dom'}\"");
my $qd = quotemeta($d->{'dom'});
my $aliases = &virtual_server::substitute_template($config{'aliases'},$d);
my $aliases = &virtual_server::substitute_template($config{'aliases'}, $d);
&save_directive($conf, $d->{'dom'}, "HostAliases",
"REGEX[$qd\$] $aliases");
"REGEX[$qd\$]".($aliases ? " $aliases" : ""));
&save_directive($conf, $d->{'dom'}, "LogFile",
&virtual_server::get_website_log($d));
&save_directive($conf, $d->{'dom'}, "DirData", $dir);
Expand Down
14 changes: 7 additions & 7 deletions virtualmin-awstats-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ sub generate_report
my @all = $baselog =~ /\|\s*$/ ? ( undef ) : &all_log_files($baselog);

# Find last modified time for each log file
my ($a, %mtime);
foreach my $a (@all) {
my @st = stat($a);
$mtime{$a} = $st[9];
my ($all, %mtime);
foreach my $all (@all) {
my @st = stat($all);
$mtime{$all} = $st[9];
}

# Do each log file that we haven't already done
Expand Down Expand Up @@ -329,9 +329,9 @@ sub generate_report
# Use the data files for some domain to generate a static HTML report
sub generate_html
{
local ($dom, $dir) = @_;
local $user = &get_run_user($dom);
local $cmd = "$config{'awstats'} -config=$dom -output -staticlinks >$dir/index.html";
my ($dom, $dir) = @_;
my $user = &get_run_user($dom);
my $cmd = "$config{'awstats'} -config=$dom -output -staticlinks >$dir/index.html";
$ENV{'GATEWAY_INTERFACE'} = undef;
if ($user ne "root") {
$cmd = &command_as_user($user, 0, $cmd);
Expand Down

0 comments on commit 732e3b6

Please sign in to comment.