]> err.no Git - varnish/commitdiff
Added the use of config file (at last),which is given as argument to web ui. If not...
authorpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 3 Mar 2009 09:47:49 +0000 (09:47 +0000)
committerpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 3 Mar 2009 09:47:49 +0000 (09:47 +0000)
Added a new config value, 'document_root', which is the root of the web server and contains the templates, images and CSS.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3862 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-tools/webgui/Varnish/RequestHandler.pm
varnish-tools/webgui/Varnish/Util.pm
varnish-tools/webgui/start.pl

index 87d40cd6c7cd88d7cf84e65a8c430fe45c6c8cbf..7bd4d99d93a1debbe889e784f725eaabb039de2f 100644 (file)
@@ -135,10 +135,11 @@ use Socket;
                        defined($use_master_template) ? $use_master_template : 1;
                
                if ($content_template) {
+                       my $document_root = get_config_value('document_root');
                        my %template_options = 
-                               (die_on_bad_params => 0, global_vars => 1, loop_context_vars => 1);
+                               (die_on_bad_params => 0, global_vars => 1, loop_context_vars => 1, path => [$document_root]);
                        if ($use_master_template) {
-                               my $template_text = read_file("templates/master.tmpl");
+                               my $template_text = read_file("$document_root/templates/master.tmpl");
                                $template_text =~ s/CONTENT_TEMPLATE/$content_template/;
 
                                my $template = HTML::Template->new_scalar_ref(  \$template_text,
index 198abec59afe875e3e73182da6ac287dd1f474ff..9941d1dcd5b67d1d086d2d5702f9dab76eaa239a 100644 (file)
@@ -8,7 +8,9 @@ use URI::Escape;
 use Algorithm::Diff;
 
 our @EXPORT = qw(
+                               read_config
                                set_config
+                               print_config
                                get_config_value
                                read_file
                                get_formatted_percentage
@@ -29,6 +31,25 @@ our @EXPORT = qw(
        my $error;
        my $log_handle;
 
+       sub read_config {
+               my ($filename) = @_;
+
+               my $handle;
+               if (!open($handle, "<$filename")) {
+                       die "Could not open config file $filename\n";
+               }
+
+               while (<$handle>) {
+                       if (/^(\w+)\s*=\s*(.*?)$/) {
+                               my $key = lc $1;
+                               my $value = $2;
+                               $config{$key} = $value;
+                       }
+               }
+
+               close($handle); 
+       }
+
        sub set_config {
                my ($config_ref) = @_;
 
@@ -44,6 +65,13 @@ our @EXPORT = qw(
                Varnish::DB->init($config{'db_filename'});
        }
 
+       sub print_config {
+               print "Config:\n";
+               while (my ($k, $v) = each(%config)) {
+                       print "$k: $v\n";
+               }
+       }
+
        sub get_config_value {
                my ($key) = @_;
 
index b48c940916f736364ec072b7781f7989435c0d09..671f556f79d95aca8c5b1c47eaed6a50e2f03c76 100755 (executable)
@@ -14,9 +14,8 @@ use Varnish::Node;
 use Varnish::Statistics;
 use Varnish::DB;
 
-
-# Configuration starts here
-my %config = (
+my $global_config_filename = '/etc/varnish/webui.conf';
+my %default_config = (
 # 'address' is the IP to bind to. If not set, it listens on all.
 #      address                         => localhost,
 
@@ -39,14 +38,27 @@ my %config = (
        large_graph_height      => 500,
 
 # 'log_filename' is the filename to log errors and information about actions done in the GUI
-       log_filename            => "varnish.log",
+       log_filename            => 'varnish.log',
 
 # 'db_filename' is the sqlite3 database created with the SQL outputed from create_db_data.pl
        db_filename                     => 'varnish.db',
+
+# 'document_root' is the root of the templates and css file
+       document_root           => '.',
 );
-# End of configuration
 
-set_config(\%config);
+set_config(\%default_config);
+my $config_filename;
+if (@ARGV == 1 && -f $ARGV[0]) {
+       $config_filename = $ARGV[0];
+}
+elsif (-f $global_config_filename) {
+       $config_filename = $global_config_filename;
+}
+if ($config_filename) {
+       print "Using config file $config_filename\n";
+       read_config($config_filename);
+}
 
 # catch interupt to stop the daemon
 $SIG{'INT'} = sub {
@@ -59,8 +71,8 @@ $SIG{'PIPE'} = sub {
 };
 
 log_info("Starting HTTP daemon");
-my $daemon = HTTP::Daemon->new(        LocalPort => $config{'port'}
-                                                               LocalAddr => $config{'address'},
+my $daemon = HTTP::Daemon->new(        LocalPort => get_config_value('port')
+                                                               LocalAddr => get_config_value('address'),
                                                                ReuseAddr => 1 );
 
 if (!$daemon) {
@@ -72,6 +84,7 @@ print "Web server started with URL: " . $daemon->url, "\n";
 my $running :shared;
 $running = 1;
 my $data_collector_handle = threads->create('data_collector_thread');
+my $document_root = get_config_value('document_root');
 while (my $connection = $daemon->accept) {
        REQUEST:
        while (my $request = $connection->get_request) {
@@ -81,7 +94,7 @@ while (my $connection = $daemon->accept) {
                        $request->uri =~ m{/(.*?\.ico)}) {
                        my $filename = $1;
                        
-                       $connection->send_file_response($filename);
+                       $connection->send_file_response("$document_root/$filename");
                        next REQUEST;
                }
                elsif ($request->uri =~ m{/(.*?\.css)}) {
@@ -115,7 +128,7 @@ $data_collector_handle->join();
 
 sub data_collector_thread {
        my $url = $daemon->url . "collect_data";
-       my $interval = $config{'poll_interval'};
+       my $interval = get_config_value('poll_interval');
        
        log_info("Data collector thread started. Polling URL $url at $interval seconds interval");
        sleep 1; # wait for the server to come up