File: makedb_release.php

package info (click to toggle)
jffnms 0.8.3dfsg.1-2.1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 4,928 kB
  • ctags: 5,050
  • sloc: php: 19,981; sh: 266; makefile: 91; perl: 52
file content (175 lines) | stat: -rw-r--r-- 4,897 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?
/* This file is part of JFFNMS
 * Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com>
 * This program is licensed under the GNU GPL, full terms in the LICENSE file
 */
    //DONT EXECUTE THIS FILE... IS FOR RELEASE CONFIGURATION ONLY

    $no_db=1;
    
    include("../../conf/config.php");

    $db_type="mysql";
    $dbhost="localhost";
    $db="jffnms-release";
    $dbuser="root";
    $dbpass="sun";

    if (!$do) $do = $argv[1];
    $file_output = $argv[2];
    $fp = fopen($file_output,"w+");

    $conexion = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Could not connect - CON1");
    mysql_select_db($db) or die ("Could not select DB - CON2");

//    echo "<PRE>\n";


// -1 save all
// 0 empty
// 1+ leave records with id 1 or +

$tables = Array (
" interface_types  ",-1, 
" interface_types_fields",-1, 
" interface_types_field_types",-1, 
" graph_types      ",-1, 
" alarm_states     ",-1,
" severity         ",-1,
" syslog_types     ",-1,
" trap_receivers   ",-1,
" types            ",-1,
" slas             ",-1,
" slas_cond        ",-1,
" slas_sla_cond    ",-1,
" filters          ",-1,
" filters_fields   ",-1,
" filters_cond     ",-1,
" pollers	   ",-1,
" pollers_groups   ",-1,
" pollers_backend  ",-1,
" pollers_poller_groups",-1,
" autodiscovery    ",-1,
" hosts_config_types",-1,
//" event_tools    ",-1,
" tools          ",-1,

" interfaces_values  ",1, 
" hosts_config     ",1,
" satellites        ",1,
" events_latest    ",0,
" acct             ",0,
" alarms           ",0,
" syslog           ",0,
" traps            ",0,
" traps_varbinds   ",0,
" events           ",0,

" journal	   ",2,
" clients          ",2,
" zones            ",2, //changed to allow more zones //FIXME changed back

" auth             ",1, //changed
" profiles	   ",1, //changed
" profiles_values  ",299,
" profiles_options ",-1,

" hosts            ",1,
" interfaces       ",1,
" maps             ",1,
" maps_interfaces  ",1,

" triggers   	   ",2,
" triggers_rules   ",2,
" triggers_users   ",1,
" actions	   ",-1,

" nad_networks	   ",0,
" nad_ips   	   ",0,
" nad_hosts	   ",0

);


echo "* Tables in list: ".(count ($tables)/2)."\n";
//echo "Do: $do\n";
if ($do!=1) die("No DO Parameter\n");

//$tables=Array(); //disable

  for ($i=0; $i < count($tables); $i = $i+2)
    if ($tables[$i+1] != -1) {
	
	echo "* Deleting all but ".$tables[$i+1]." records from ".trim($tables[$i])."...";
	flush();
	
	$delete="DELETE FROM ".$tables[$i]. " where id > ".$tables[$i+1];
	$result= mysql_query ($delete) or die ("Query failed - T3 - ".mysql_error());

	echo ", fixing...";

	$repair="ALTER TABLE ".$tables[$i]." AUTO_INCREMENT = 1;";
	$result= mysql_query ($repair) or die ("Query failed - T2 - ".mysql_error());

	$repair="OPTIMIZE TABLE ".$tables[$i];
	$result= mysql_query ($repair) or die ("Query failed - T2 - ".mysql_error());

	$repair="REPAIR TABLE ".$tables[$i]." EXTENDED";
	$result= mysql_query ($repair) or die ("Query failed - T2 - ".mysql_error());

	$flush="FLUSH TABLE".$tables[$i];
	$result= mysql_query ($flush) or die ("Query failed - T2 - ".mysql_error());

	echo "done.\n";
    } else { //internal tables
	$tables[$i]=trim($tables[$i]);
	
	echo "* Marking table ".trim($tables[$i])."...";
	flush();
	$repair="ALTER TABLE ".$tables[$i]." AUTO_INCREMENT = 10001;";
	fputs ($fp,"$repair\n");
	//$result= mysql_query ($repair) or die ("Query failed - T2 - ".mysql_error());
	echo "done.\n";
    
    }
    
    if (1==2)
    foreach (users_list() as $user) { //delete all users
	echo "* Deleting UserID ".$user[id]." (".$user[usern].")\n";
	user_del($user[id]);
    }

    echo "* Refixing Users Table\n";
    $result= mysql_query ("ALTER TABLE auth AUTO_INCREMENT = 1") or die ("Query failed - T3 - ".mysql_error());
    $result= mysql_query ("ALTER TABLE profiles AUTO_INCREMENT = 1") or die ("Query failed - T3 - ".mysql_error());

    $repair = "ALTER TABLE profiles_values AUTO_INCREMENT = 300;";
    fputs ($fp,"$repair\n");
    $result= mysql_query ($repair) or die ("Query failed - T3 - ".mysql_error());
    $result= mysql_query ("ALTER TABLE triggers_users AUTO_INCREMENT = 1") or die ("Query failed - T3 - ".mysql_error());

    echo "* Fixing Satellite Table\n";
    $result= mysql_query ("UPDATE satellites set url = '' where id = 1") or die ("Query failed - T3 - ".mysql_error());
    
    $user = "admin";
    //$user = "";
    $pass = crypt("admin","ad");

    if ($user) {
    
	echo "* Creating User $user";
	$id = user_add($user);

	echo ", assigned id: $id, now applying profile.\n";
	user_modify($id,"",$pass,$pass,"Administrator",0);
    
	profile_add_option($id,"ADMIN_ACCESS"); 
        profile_add_option($id,"ADMIN_USERS"); 
	profile_add_option($id,"ADMIN_SYSTEM"); 
	profile_add_option($id,"ADMIN_HOSTS"); 
	profile_add_option($id,"MESSAGES_VIEW_ALL"); 
	profile_add_option($id,"REPORTS_VIEW_ALL_INTERFACES"); 
    }

    fclose($fp);
?>