diff options
author | Preston Cody <codeman@gentoo.org> | 2007-12-30 02:54:46 +0000 |
---|---|---|
committer | Preston Cody <codeman@gentoo.org> | 2007-12-30 02:54:46 +0000 |
commit | d25a3e29ece463e9b79a17e8d0e7cc25969aa144 (patch) | |
tree | e15706612ac4e7de73c582c65c446f3927aa872a /server | |
parent | adding debug. (diff) | |
download | scire-d25a3e29ece463e9b79a17e8d0e7cc25969aa144.tar.gz scire-d25a3e29ece463e9b79a17e8d0e7cc25969aa144.tar.bz2 scire-d25a3e29ece463e9b79a17e8d0e7cc25969aa144.zip |
adding debug() function.
makes things so much cleaner.
svn path=/branches/new-fu/; revision=280
Diffstat (limited to 'server')
-rwxr-xr-x | server/scireserver.pl | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/server/scireserver.pl b/server/scireserver.pl index d7181bd..6ea7543 100755 --- a/server/scireserver.pl +++ b/server/scireserver.pl @@ -17,16 +17,22 @@ Dumper(\%conf); my $identified = 0; #Global variable to determine if already identified or not. # Somehow this feels insecure. +sub debug { + my $line = shift; + if ($conf{debug}) { + print STDERR "$line\n"; + } +} + #Connect to the Database. my $connect_string = "DBI:$conf{db_type}:$conf{db_name};host=$conf{db_host}"; -print STDERR "Connecting to $connect_string\n"; +debug("Connecting to $connect_string"); #my $dbh = DBI->connect($connect_string, $conf{db_user}, $conf{db_passwd}, { RaiseError => 1 } ) # or die "Could not connect to database: $DBI::errstr"; while(<>) { chomp( my $line = $_); - print STDERR "Handling single-line response\n"; - print STDERR "DEBUG: line is: $line\n"; + debug("DEBUG: line is: $line"); if($line =~ /^QUIT$/) { print "OK\n"; exit; @@ -83,6 +89,7 @@ sub read_config_file { # print "Conf file $conf_file read.\n"; } + #New clients must be registered so they can be given a key to use (perhaps for job file transfers?) for authentication. This must be allowed before identifying. sub register_client { my ($mac,$ip) = @_; @@ -93,34 +100,34 @@ sub register_client { my ($query, $status_id, $id); eval { $query = 'SELECT statusid FROM client_status WHERE statusname = "Pending"'; - print STDERR "DEBUG: Query is $query\n"; + debug("DEBUG: Query is $query"); $status_id = "4"; #db.conn.GetRow($query) }; ($@) and print "ERROR Could not get status id: $DBI::errstr"; eval { $query = 'LOCK TABLES `gacl_axo_seq` WRITE'; - print STDERR "DEBUG: Query is $query\n"; + debug("DEBUG: Query is $query"); #execute it $query = 'SELECT id FROM `gacl_axo_seq`'; - print STDERR "DEBUG: Query is $query\n"; + debug("DEBUG: Query is $query"); $id = "56"; #execute $query $query = 'UPDATE `gacl_axo_seq` SET id=%s'; - print STDERR "DEBUG: Query is $query\n"; + debug("DEBUG: Query is $query"); #execute with $id $query = 'UNLOCK TABLES'; - print STDERR "DEBUG: Query is $query\n"; + debug("DEBUG: Query is $query"); }; ($@) and print "ERROR during fetching of id sequence: $DBI::errstr"; eval { $query = 'INSERT INFO `gacl_axo` (id,section_value,value,order_value,name,hidden VALUES (%s,"clients",%s,1,%s,0)'; - print STDERR "DEBUG: Query is $query\n"; + debug("DEBUG: Query is $query"); #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 (%s,%s,%s,%s,%s,%s,%s)'; - print STDERR "DEBUG: Query is $query\n"; + debug("DEBUG: Query is $query"); #execute with $id, client_cert.digest("sha1"),crypto.dump_certificate(crypto.FILETYPE_PEM,client_cert),$hostname,$mac,$ip,$status_id)) }; ($@) and print "ERROR Could not insert client with $query: $DBI::errstr"; @@ -136,7 +143,7 @@ sub identify_client { $fingerprint =~ /^[A-Za-z0-9]+$/ or print "ERROR invalid fingerprint!\n"; #Validate your inputs! my $query = 'SELECT client_status.statusname FROM clients JOIN client_status on (clients.status = client_status.statusid) WHERE clients.digest=%s'; - print STDERR "Query is $query , key is $fingerprint\n"; + debug("DEBUG: Query is $query"); $identified = 1; print "OK\n"; } |