Project

General

Profile

Download (1.99 KB) Statistics
| Branch: | Revision:
1
#!/usr/bin/perl
2

    
3
use LWP;
4
#use URI::Escape;
5
#use Socket;
6
use Sys::Syslog qw( :DEFAULT setlogsock);
7
use ConfigReader::Simple;
8

    
9
# Untaint in order to avoid filling Apache error log with warnings
10
$ENV{'PATH'} = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
11

    
12
#my $base = "/var/www/stabile";
13
#$base = `cat /etc/stabile/basedir` if -e "/etc/stabile/basedir";
14
#chomp $base;
15

    
16
my $baseurl = "http://localhost/stabile";
17
#$baseurl = `cat /etc/stabile/baseurl` if -e "/etc/stabile/baseurl";
18
#$baseurl =~ s/https/http/;
19
chomp $baseurl;
20

    
21
#my $line = `cat /etc/resolv.conf`;
22
#$line =~ /nameserver (\S*)/;
23
#my $mainvalve = scalar(gethostbyaddr(inet_aton($1), AF_INET));
24

    
25
#my $config = ConfigReader::Simple->new("/etc/stabile/config.cfg", [qw(DBI_USER DBI_PASSWD)]);
26
#my $dbiuser =  $config->get('DBI_USER') || "irigo";
27
#my $dbipasswd = $config->get('DBI_PASSWD') || "";
28

    
29
my $url = "$baseurl/piston/piston.cgi";
30
$baseurl =~ /http\w*:\/\/(.*)\//;
31
my $mainvalve = $1;
32

    
33
my $browser = LWP::UserAgent->new;
34
$browser->agent('movepiston/1.0b');
35
$browser->protocols_allowed( [ 'http','https'] );
36
$browser->credentials(
37
  "$mainvalve:80",
38
  'Services',
39
  "irigo", "sunshine"
40
);
41

    
42
my $user = $ARGV[0];
43
my $var = $ARGV[1];
44
if (!$user) {print "No user...\n"; exit;}
45

    
46
#`REMOTE_USER=irigo $base/piston/piston.cgi status=permitopen user=$user`;
47
my $content = $browser->get($url . "?status=permitopen&user=$user")->content();
48
print "$content\n";
49
# print $url . "?status=permitopen&user=$user", "\n$content\n$mainvalve / $dbiuser / $dbipasswd\n";
50
if ($var) {
51
    while (1) {
52
        print scalar localtime() . "\n";
53
        sleep 30;
54
    }
55
}
56

    
57

    
58
sub syslogit {
59
	my ($priority, $msg) = @_;
60
	print $priority, ": ", $msg, "\n";
61
#	return 0 unless ($priority =~ /info|err|debug/);
62
	return 0 unless ($priority =~ /info|err/);
63

    
64
	setlogsock('unix');
65
	# $programname is assumed to be a global.  Also log the PID
66
	# and to CONSole if there's a problem.  Use facility 'user'.
67
	openlog($programname, 'pid,cons', 'user');
68
	syslog($priority, $msg);
69
	closelog();
70
	return 1;
71
}
(14-14/27)