/[scire]/branches/new-fu/server/scireserver.pl
Gentoo

Diff of /branches/new-fu/server/scireserver.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 283 Revision 284
7 7
8$| = 1; 8$| = 1;
9 9
10my $SCIRE_CONFIG_FILE = '../etc/scireserver.conf'; #will be /etc/scire.conf when released. 10my $SCIRE_CONFIG_FILE = '../etc/scireserver.conf'; #will be /etc/scire.conf when released.
11my %conf; 11my %conf;
12my $LOGFILE;
12 13
13my $conf_file = (defined($conf{config})) ? $conf{config} : $SCIRE_CONFIG_FILE; 14my $conf_file = (defined($conf{config})) ? $conf{config} : $SCIRE_CONFIG_FILE;
14read_config_file($conf_file); 15read_config_file($conf_file);
15Dumper(\%conf); 16Dumper(\%conf);
16 17
17my $identified = 0; #Global variable to determine if already identified or not. 18my $identified = 0; #Global variable to determine if already identified or not.
18# Somehow this feels insecure. 19# Somehow this feels insecure.
19 20
21sub logger {
22 my $line = shift;
23 if(!defined $LOGFILE) {
24 open(*LOGFILE, ">>$conf{logfile}") or die "Cannot open logfile $conf{logfile}";
25 }
26 print LOGFILE localtime() . " " . $line . "\n";
27}
28
20sub debug { 29sub debug {
21 my $line = shift; 30 my $line = shift;
22 if ($conf{debug}) { 31 if ($conf{debug}) {
23 print STDERR "$line\n"; 32 logger("DEBUG: ${line}");
24 } 33 }
25} 34}
26 35
27#Connect to the Database. 36#Connect to the Database.
28my $connect_string = "DBI:$conf{db_type}:$conf{db_name};host=$conf{db_host}"; 37my $connect_string = "DBI:$conf{db_type}:$conf{db_name};host=$conf{db_host}";
100 $ip =~ /^[a-zA-Z0-9\.\:]+$/ or print "ERROR invalid ip $ip!\n"; 109 $ip =~ /^[a-zA-Z0-9\.\:]+$/ or print "ERROR invalid ip $ip!\n";
101 110
102 my ($query, $status_id, $id, $sth); 111 my ($query, $status_id, $id, $sth);
103 eval { 112 eval {
104 $query = 'SELECT statusid FROM client_status WHERE statusname = "Pending"'; 113 $query = 'SELECT statusid FROM client_status WHERE statusname = "Pending"';
105 debug("DEBUG: Query is $query"); 114 debug("Query is $query");
106 $status_id = "4"; #db.conn.GetRow($query) 115 $status_id = "4"; #db.conn.GetRow($query)
107 #$sth = $dbh->prepare($query); 116 #$sth = $dbh->prepare($query);
108 #my @result = $sth->fetchrow_array(); 117 #my @result = $sth->fetchrow_array();
109 #$status_id = $result[0]; 118 #$status_id = $result[0];
110 }; 119 };
111 ($@) and print "ERROR Could not get status id: $DBI::errstr\n"; 120 ($@) and print "ERROR Could not get status id: $DBI::errstr\n";
112 121
113 eval { 122 eval {
114 $query = 'LOCK TABLES `gacl_axo_seq` WRITE'; 123 $query = 'LOCK TABLES `gacl_axo_seq` WRITE';
115 debug("DEBUG: Query is $query"); 124 debug("Query is $query");
116 #execute it 125 #execute it
117 #$dbh->do($query); 126 #$dbh->do($query);
118 $query = 'SELECT id FROM `gacl_axo_seq`'; 127 $query = 'SELECT id FROM `gacl_axo_seq`';
119 debug("DEBUG: Query is $query"); 128 debug("Query is $query");
120 $id = "56"; #execute $query 129 $id = "56"; #execute $query
121 #$sth = $dbh->prepare($query); 130 #$sth = $dbh->prepare($query);
122 #my @result = $sth->fetchrow_array(); 131 #my @result = $sth->fetchrow_array();
123 #$id = $result[0]; 132 #$id = $result[0];
124 133
125 $query = 'UPDATE `gacl_axo_seq` SET id=?'; 134 $query = 'UPDATE `gacl_axo_seq` SET id=?';
126 debug("DEBUG: Query is $query"); 135 debug("Query is $query");
127 #execute with $id 136 #execute with $id
128 #$sth = $dbh->prepare($query); 137 #$sth = $dbh->prepare($query);
129 #$sth->execute($id); 138 #$sth->execute($id);
130 $query = 'UNLOCK TABLES'; 139 $query = 'UNLOCK TABLES';
131 debug("DEBUG: Query is $query"); 140 debug("Query is $query");
132 #$dbh->do($query); 141 #$dbh->do($query);
133 }; 142 };
134 ($@) and print "ERROR during fetching of id sequence: $DBI::errstr\n"; 143 ($@) and print "ERROR during fetching of id sequence: $DBI::errstr\n";
135 144
136 eval { 145 eval {
137 $query = 'INSERT INFO `gacl_axo` (id,section_value,value,order_value,name,hidden VALUES (?,"clients",?,1,?,0)'; 146 $query = 'INSERT INFO `gacl_axo` (id,section_value,value,order_value,name,hidden VALUES (?,"clients",?,1,?,0)';
138 debug("DEBUG: Query is $query"); 147 debug("Query is $query");
139 #$sth = $dbh->prepare($query); 148 #$sth = $dbh->prepare($query);
140 #$sth->execute($id, $hostname, $hostname); 149 #$sth->execute($id, $hostname, $hostname);
141 #execute with $id, $hostname, $hostname 150 #execute with $id, $hostname, $hostname
142 #NOTE: not sure if this query is still valid. may be using id instead of hostname for one of those two now. 151 #NOTE: not sure if this query is still valid. may be using id instead of hostname for one of those two now.
143 152
144 $query = 'INSERT INTO clients (clientid,digest,cert,hostname,mac,ip,status) VALUES (?,?,?,?,?,?,?)'; 153 $query = 'INSERT INTO clients (clientid,digest,cert,hostname,mac,ip,status) VALUES (?,?,?,?,?,?,?)';
145 debug("DEBUG: Query is $query"); 154 debug("Query is $query");
146 #execute with $id, client_cert.digest("sha1"),crypto.dump_certificate(crypto.FILETYPE_PEM,client_cert),$hostname,$mac,$ip,$status_id)) 155 #execute with $id, client_cert.digest("sha1"),crypto.dump_certificate(crypto.FILETYPE_PEM,client_cert),$hostname,$mac,$ip,$status_id))
147 #$sth = $dbh->prepare($query); 156 #$sth = $dbh->prepare($query);
148 #$sth->execute($id,$digest,$hostname,$mac,$ip,$status_id); 157 #$sth->execute($id,$digest,$hostname,$mac,$ip,$status_id);
149 }; 158 };
150 ($@) and print "ERROR Could not insert client with $query: $DBI::errstr\n"; 159 ($@) and print "ERROR Could not insert client with $query: $DBI::errstr\n";
159 #Validate your inputs! 168 #Validate your inputs!
160 $fingerprint =~ s/"//g; #Clear the quotes. 169 $fingerprint =~ s/"//g; #Clear the quotes.
161 $fingerprint =~ /^[A-Za-z0-9]+$/ or print "ERROR invalid fingerprint!\n"; 170 $fingerprint =~ /^[A-Za-z0-9]+$/ or print "ERROR invalid fingerprint!\n";
162 171
163 my $query = 'SELECT client_status.statusname FROM clients JOIN client_status on (clients.status = client_status.statusid) WHERE clients.digest=?'; 172 my $query = 'SELECT client_status.statusname FROM clients JOIN client_status on (clients.status = client_status.statusid) WHERE clients.digest=?';
164 debug("DEBUG: Query is $query"); 173 debug("Query is $query");
165 #$sth = $dbh->prepare($query); 174 #$sth = $dbh->prepare($query);
166 #$sth->execute($fingerprint); 175 #$sth->execute($fingerprint);
167 $identified = 1; 176 $identified = 1;
168 print "OK\n"; 177 print "OK\n";
169} 178}

Legend:
Removed from v.283  
changed lines
  Added in v.284

  ViewVC Help
Powered by ViewVC 1.1.20