summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/scireserver.conf1
-rwxr-xr-xserver/scireserver.pl27
2 files changed, 19 insertions, 9 deletions
diff --git a/etc/scireserver.conf b/etc/scireserver.conf
index 6755784..298de1e 100644
--- a/etc/scireserver.conf
+++ b/etc/scireserver.conf
@@ -1,6 +1,7 @@
# $Id$
# Scire Server config file.
debug=1
+logfile=/tmp/scireserver.log
#Database stuff.
db_type=mysql
db_host=localhost
diff --git a/server/scireserver.pl b/server/scireserver.pl
index 2d5f11d..3c39b8c 100755
--- a/server/scireserver.pl
+++ b/server/scireserver.pl
@@ -9,6 +9,7 @@ $| = 1;
my $SCIRE_CONFIG_FILE = '../etc/scireserver.conf'; #will be /etc/scire.conf when released.
my %conf;
+my $LOGFILE;
my $conf_file = (defined($conf{config})) ? $conf{config} : $SCIRE_CONFIG_FILE;
read_config_file($conf_file);
@@ -17,10 +18,18 @@ Dumper(\%conf);
my $identified = 0; #Global variable to determine if already identified or not.
# Somehow this feels insecure.
+sub logger {
+ my $line = shift;
+ if(!defined $LOGFILE) {
+ open(*LOGFILE, ">>$conf{logfile}") or die "Cannot open logfile $conf{logfile}";
+ }
+ print LOGFILE localtime() . " " . $line . "\n";
+}
+
sub debug {
my $line = shift;
if ($conf{debug}) {
- print STDERR "$line\n";
+ logger("DEBUG: ${line}");
}
}
@@ -102,7 +111,7 @@ sub register_client {
my ($query, $status_id, $id, $sth);
eval {
$query = 'SELECT statusid FROM client_status WHERE statusname = "Pending"';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
$status_id = "4"; #db.conn.GetRow($query)
#$sth = $dbh->prepare($query);
#my @result = $sth->fetchrow_array();
@@ -112,37 +121,37 @@ sub register_client {
eval {
$query = 'LOCK TABLES `gacl_axo_seq` WRITE';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
#execute it
#$dbh->do($query);
$query = 'SELECT id FROM `gacl_axo_seq`';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
$id = "56"; #execute $query
#$sth = $dbh->prepare($query);
#my @result = $sth->fetchrow_array();
#$id = $result[0];
$query = 'UPDATE `gacl_axo_seq` SET id=?';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
#execute with $id
#$sth = $dbh->prepare($query);
#$sth->execute($id);
$query = 'UNLOCK TABLES';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
#$dbh->do($query);
};
($@) and print "ERROR during fetching of id sequence: $DBI::errstr\n";
eval {
$query = 'INSERT INFO `gacl_axo` (id,section_value,value,order_value,name,hidden VALUES (?,"clients",?,1,?,0)';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
#$sth = $dbh->prepare($query);
#$sth->execute($id, $hostname, $hostname);
#execute with $id, $hostname, $hostname
#NOTE: not sure if this query is still valid. may be using id instead of hostname for one of those two now.
$query = 'INSERT INTO clients (clientid,digest,cert,hostname,mac,ip,status) VALUES (?,?,?,?,?,?,?)';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
#execute with $id, client_cert.digest("sha1"),crypto.dump_certificate(crypto.FILETYPE_PEM,client_cert),$hostname,$mac,$ip,$status_id))
#$sth = $dbh->prepare($query);
#$sth->execute($id,$digest,$hostname,$mac,$ip,$status_id);
@@ -161,7 +170,7 @@ sub identify_client {
$fingerprint =~ /^[A-Za-z0-9]+$/ or print "ERROR invalid fingerprint!\n";
my $query = 'SELECT client_status.statusname FROM clients JOIN client_status on (clients.status = client_status.statusid) WHERE clients.digest=?';
- debug("DEBUG: Query is $query");
+ debug("Query is $query");
#$sth = $dbh->prepare($query);
#$sth->execute($fingerprint);
$identified = 1;