3 /* This 'function' updates the gnucomo database to the correct version it will make changes to the
4 * database. It is called within an if-statement when needed.
5 * INPUT : NONE (everything is available within the class)
6 * OUTPUT : Success TRUE/FALSE
10 //Do while statement since all updateshave to be executed starting at the
11 //latest version. It's a walk through.
13 switch ($active_version) {
15 //DROP the rule that prohibits updates (change of spec).
16 $local_sql = "DROP RULE log_update";
17 $dbms->query($local_sql);
20 //In the log table processed should be false by default
21 $local_sql = "UPDATE log SET processed = false";
22 $dbms->query($local_sql);
25 //In the log_adv a column is added that indicates where the detailed
26 //data has been written to
27 $local_sql = "ALTER TABLE log_adv ADD COLUMN detailed_table VARCHAR(75)";
28 $dbms->query($local_sql);
31 //Create a log_adv_kernel_network table that recognizes the log-records
32 //that have come from the kernel-network interface (typically iptables).
33 $local_sql = "CREATE TABLE log_adv_kernel_network (";
34 $local_sql .= "device_in VARCHAR(15), device_out VARCHAR(15), hw_address MACADDR, ";
35 $local_sql .= "source_ip INET, destination_ip INET, packet_length BIGINT, ";
36 $local_sql .= "tos_bit VARCHAR(5), ";
37 $local_sql .= "prec_bit VARCHAR(5), ttl INT, header_id BIGINT, source_port INT, ";
38 $local_sql .= "destination_port INT, body_length INT, protocol VARCHAR(5), ";
39 $local_sql .= "body_len INT";
40 $local_sql .= ") INHERITS (log_adv)";
41 $dbms->query($local_sql);
44 //Add the operating system to the object-table
45 //COLUMN os (VARCHAR - 25)
46 //COLUMN os_version (VARCHAR - 15)
47 $local_sql = "ALTER TABLE object ADD COLUMN os TEXT";
48 $dbms->query($local_sql);
50 $local_sql = "ALTER TABLE object ADD COLUMN os_version TEXT";
51 $dbms->query($local_sql);
53 $local_sql = "CREATE INDEX os ON object (os)";
54 $dbms->query($local_sql);
56 $local_sql = "CREATE INDEX os_version ON object (os, os_version)";
57 $dbms->query($local_sql);
60 //Create a table with supported operating systems. Only after a implementation of a
61 //log-processing application a new OS will be added. This ensures the correctness of
63 $local_sql = "CREATE TABLE supported_os (os_name TEXT, remarks TEXT)";
64 $dbms->query($local_sql);
66 $local_sql = "CREATE UNIQUE INDEX spp_os ON supported_os (os_name)";
67 $dbms->query($local_sql);
70 //Create a column in the log table that indicates if the daemon did recognize the
71 //log-record. This makes it easier to trace which log-records still have to be added
73 $local_sql = "ALTER TABLE log ADD COLUMN recognized BOOLEAN";
74 $dbms->query($local_sql);
76 $local_sql = "ALTER TABLE log ALTER COLUMN recognized SET DEFAULT FALSE";
77 $dbms->query($local_sql);
80 //Set the default value of processed to FALSE
81 $local_sql = "ALTER TABLE log ALTER COLUMN processed SET DEFAULT FALSE";
82 $dbms->query($local_sql);
85 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN window TEXT";
86 $dbms->query($local_sql);
88 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN urgp INT";
89 $dbms->query($local_sql);
91 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN syn BOOLEAN";
92 $dbms->query($local_sql);
94 $local_sql = "ALTER TABLE log_adv_kernel_network ALTER COLUMN syn SET DEFAULT FALSE";
95 $dbms->query($local_sql);
99 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN type INT";
100 $dbms->query($local_sql);
102 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN code INT";
103 $dbms->query($local_sql);
105 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN sequence_number INT";
106 $dbms->query($local_sql);
109 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN res varchar(5)";
110 $dbms->query($local_sql);
112 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN rst BOOLEAN";
113 $dbms->query($local_sql);
115 $local_sql = "ALTER TABLE log_adv_kernel_network ADD COLUMN df BOOLEAN";
116 $dbms->query($local_sql);
119 $local_sql = "INSERT INTO db_value VALUES ('gcm_daemon_version', '1')";
120 $dbms->query($local_sql);
124 $local_sql = "UPDATE db_value SET setting_value = ".$active_version." WHERE setting = 'db_version'";
125 $dbms->query($local_sql);