12148
|
1 |
--- system-tools-backends-1.4.2.orig/time-conf.in 2006-01-02 23:47:30.000000000 +0800
|
|
2 |
+++ system-tools-backends-1.4.2/time-conf.in 2008-04-17 14:21:37.441179000 +0800
|
|
3 |
@@ -67,6 +67,7 @@
|
7860
|
4 |
"mandrake-7.1", "mandrake-7.2", "mandrake-9.0", "mandrake-9.1", "mandrake-9.2",
|
|
5 |
"mandrake-10.0", "mandrake-10.1",
|
|
6 |
"debian-2.2", "debian-3.0", "debian-sarge",
|
|
7 |
+ "nexenta-1.0", "solaris-2.11",
|
|
8 |
"suse-7.0", "suse-9.0", "suse-9.1", "turbolinux-7.0",
|
|
9 |
"slackware-8.0.0", "slackware-8.1", "slackware-9.0.0", "slackware-9.1.0", "slackware-10.0.0", "slackware-10.1.0", "slackware-10.2.0",
|
|
10 |
"gentoo", "vlos-1.2", "pld-1.0", "pld-1.1", "pld-1.99", "fedora-1", "fedora-2", "fedora-3", "rpath",
|
12148
|
11 |
@@ -79,6 +80,7 @@
|
8612
|
12 |
end_of_description;
|
|
13 |
|
|
14 |
$progress_max = 365;
|
|
15 |
+$profile_file = "profiles.xml";
|
|
16 |
|
|
17 |
|
|
18 |
# --- XML parsing --- #
|
12148
|
19 |
@@ -123,6 +125,8 @@
|
7860
|
20 |
if ($$tree[0] eq "local_time"){ $$hash{"local_time"} = &xml_parse_local_time ($$tree[1]); }
|
|
21 |
elsif ($$tree[0] eq "timezone") { $$hash{"timezone"} = &gst_xml_get_word ($$tree[1]); }
|
|
22 |
elsif ($$tree[0] eq "sync") { $$hash{"sync"} = &xml_parse_sync ($$tree[1], $hash); }
|
|
23 |
+ elsif ($$tree[0] eq "sync_now") { $$hash{"sync_now"} = &xml_parse_sync ($$tree[1], $hash); }
|
8612
|
24 |
+ elsif ($$tree[0] eq "profiledb") { $$hash{"profiledb"} = &xml_parse_profiledb ($tree, $hash); } # zhua
|
7860
|
25 |
|
|
26 |
shift @$tree;
|
|
27 |
shift @$tree;
|
12148
|
28 |
@@ -150,6 +154,23 @@
|
7860
|
29 |
return \@sync;
|
|
30 |
}
|
|
31 |
|
|
32 |
+sub xml_parse_sync_now
|
|
33 |
+{
|
|
34 |
+ my $tree = $_[0];
|
|
35 |
+ my $hash = $_[1];
|
|
36 |
+ my @sync_now;
|
8436
|
37 |
+
|
7860
|
38 |
+ while (@$tree)
|
|
39 |
+ {
|
|
40 |
+ if ($$tree[0] eq "server") { push (@sync_now, &gst_xml_get_word($$tree[1])); }
|
|
41 |
+
|
|
42 |
+ shift @$tree;
|
|
43 |
+ shift @$tree;
|
|
44 |
+ }
|
|
45 |
+
|
|
46 |
+ return \@sync_now;
|
|
47 |
+}
|
|
48 |
+
|
8436
|
49 |
|
7860
|
50 |
sub xml_parse_local_time
|
|
51 |
{
|
12148
|
52 |
@@ -189,7 +210,8 @@
|
8612
|
53 |
|
|
54 |
&gst_xml_print_vspace ();
|
|
55 |
&gst_xml_print_hash ($$h{"local_time"}, "local_time");
|
|
56 |
- &gst_xml_print_vspace ();
|
|
57 |
+
|
|
58 |
+ &xml_print_profiledb($$h{"profiledb"}); #zhua
|
|
59 |
|
|
60 |
&gst_xml_print_vspace ();
|
|
61 |
&gst_xml_print_line ("<sync active='" . &gst_print_boolean_yesno ($$h{'sync_active'}) . "'>\n");
|
12148
|
62 |
@@ -213,7 +235,7 @@
|
8612
|
63 |
# Main operations
|
|
64 |
|
|
65 |
sub get
|
|
66 |
-{
|
|
67 |
+{
|
|
68 |
my $hash;
|
|
69 |
|
|
70 |
$hash = &conf_get ();
|
12148
|
71 |
@@ -225,8 +247,9 @@
|
8612
|
72 |
|
|
73 |
sub set
|
|
74 |
{
|
|
75 |
- my $hash;
|
|
76 |
|
|
77 |
+ my $hash;
|
|
78 |
+
|
|
79 |
$hash = &xml_parse ();
|
|
80 |
|
|
81 |
&conf_set ($hash);
|
12148
|
82 |
@@ -277,6 +300,28 @@
|
7860
|
83 |
return \%h;
|
|
84 |
}
|
|
85 |
|
|
86 |
+sub time_get_sunos_zone
|
|
87 |
+{
|
|
88 |
+ my $zone;
|
|
89 |
+ local *INFILE;
|
|
90 |
+
|
|
91 |
+ *INFILE = &gst_file_open_read_from_names("/etc/default/init");
|
|
92 |
+ if (not *INFILE) { return; }
|
|
93 |
+
|
|
94 |
+ &gst_report ("time_timezone_scan");
|
|
95 |
+
|
|
96 |
+ while (<INFILE>)
|
|
97 |
+ {
|
|
98 |
+ if (/^TZ\s*=\s*(.*)/)
|
|
99 |
+ {
|
|
100 |
+ ($d, $zone) = split /\=/, $_;
|
|
101 |
+ last;
|
|
102 |
+ }
|
|
103 |
+ }
|
|
104 |
+ close (INFILE);
|
|
105 |
+ return $zone;
|
|
106 |
+}
|
|
107 |
+
|
|
108 |
sub time_get_rh62_zone
|
|
109 |
{
|
|
110 |
my ($local_time_file, $zoneinfo_dir) = @_;
|
12148
|
111 |
@@ -318,8 +363,8 @@
|
7860
|
112 |
$zone = "";
|
|
113 |
}
|
|
114 |
|
|
115 |
- return $zone;
|
|
116 |
close (TZLIST);
|
|
117 |
+ return $zone;
|
|
118 |
}
|
|
119 |
|
|
120 |
sub conf_get
|
12148
|
121 |
@@ -342,7 +387,13 @@
|
7860
|
122 |
my ($plat) = $$tool {"system"};
|
|
123 |
my ($command);
|
|
124 |
|
|
125 |
+ my $sunos_table = {
|
|
126 |
+ "nexenta-1.0" => "date %02d%02d%02d%02d%04d.%02d",
|
|
127 |
+ "solaris-2.11" => "date %02d%02d%02d%02d%04d.%02d"
|
|
128 |
+ };
|
|
129 |
+
|
|
130 |
my $plat_table = {
|
|
131 |
+ "SunOS" => $$sunos_table {$$tool {"platform"}},
|
|
132 |
"Linux" => "date %02d%02d%02d%02d%04d.%02d",
|
|
133 |
"FreeBSD" => "date -f %%m%%d%%H%%M%%Y.%%S %02d%02d%02d%02d%04d.%02d"
|
|
134 |
};
|
12148
|
135 |
@@ -356,6 +407,52 @@
|
7860
|
136 |
|
|
137 |
return &gst_file_run ($command);
|
|
138 |
}
|
|
139 |
+# Synchronise time now - moved to backend since it needs root privs.
|
|
140 |
+sub time_set_sync_now
|
|
141 |
+{
|
|
142 |
+ my ($sync_servers) = @_;
|
|
143 |
+ my ($plat) = $$tool{"system"};
|
8436
|
144 |
+
|
7860
|
145 |
+ &gst_report_enter();
|
|
146 |
+
|
|
147 |
+ if ( $plat eq "SunOS" ) {
|
8436
|
148 |
+ if ( $#$sync_servers >= 0 )
|
7860
|
149 |
+ {
|
|
150 |
+ $ntp_service_was_active = &gst_service_smf_get_status( "network/ntp" );
|
|
151 |
+ &gst_service_smf_set_status( "network/ntp", 0 ) if ($ntp_service_was_active);
|
|
152 |
+ $command = "ntpdate -s ";
|
|
153 |
+ foreach $server (@$sync_servers)
|
|
154 |
+ {
|
|
155 |
+ $command .= "$server ";
|
|
156 |
+ }
|
|
157 |
+ &gst_file_run( $command );
|
|
158 |
+ &gst_service_smf_set_status( "network/ntp", 1 ) if ($ntp_service_was_active);
|
|
159 |
+ }
|
|
160 |
+ }
|
|
161 |
+ else {
|
|
162 |
+ &gst_file_run("/etc/init.d/ntpdate restart");
|
|
163 |
+ }
|
|
164 |
+ &gst_report_leave();
|
|
165 |
+}
|
12148
|
166 |
+
|
|
167 |
+sub time_set_sync_period
|
|
168 |
+{
|
|
169 |
+ my ($service, $active) = @_;
|
|
170 |
+ my ($plat) = $$tool{"system"};
|
|
171 |
+
|
|
172 |
+ &gst_report_enter();
|
|
173 |
+
|
|
174 |
+ if ( $plat eq "SunOS" ) {
|
|
175 |
+ $ntp_service_was_active = &gst_service_smf_get_status( $service );
|
|
176 |
+ if ( $active && $ntp_service_was_active )
|
|
177 |
+ {
|
|
178 |
+ &gst_file_run( "svcadm restart $service" );
|
|
179 |
+ } else {
|
|
180 |
+ &gst_service_smf_set_status( $service, $active );
|
|
181 |
+ }
|
|
182 |
+ }
|
|
183 |
+ &gst_report_leave();
|
|
184 |
+}
|
8436
|
185 |
|
7860
|
186 |
sub time_set_local_time
|
|
187 |
{
|
12148
|
188 |
@@ -378,6 +475,49 @@
|
7860
|
189 |
return 0;
|
|
190 |
}
|
|
191 |
|
|
192 |
+sub time_set_sunos_zone
|
|
193 |
+{
|
|
194 |
+ my ($localtime, $zonebase, $timezone) = @_;
|
|
195 |
+ my ($ifh, $ofh);
|
|
196 |
+ local (*INFILE, *OUTFILE);
|
|
197 |
+
|
|
198 |
+ ($ifh, $ofh) = &gst_file_open_filter_write_from_names("/etc/default/init");
|
|
199 |
+ if (not $ofh) { return; } # No point if we can't write.
|
|
200 |
+ *INFILE = $ifh; *OUTFILE = $ofh;
|
|
201 |
+
|
|
202 |
+ &gst_report_enter ();
|
|
203 |
+ &gst_report ("time_timezone_set", $timezone);
|
|
204 |
+
|
|
205 |
+ &gst_file_run ("rtc -z $timezone");
|
|
206 |
+
|
|
207 |
+ while (<INFILE>)
|
|
208 |
+ {
|
|
209 |
+ if (/^TZ\s*=\s*(.*)/) {
|
|
210 |
+ print OUTFILE "TZ=$timezone\n";
|
|
211 |
+ next;
|
|
212 |
+ }
|
|
213 |
+ print OUTFILE $_;
|
|
214 |
+ }
|
|
215 |
+ close OUTFILE;
|
|
216 |
+ close INFILE;
|
|
217 |
+
|
|
218 |
+ # update /etc/localtime too, so unported GNU software will not complain
|
|
219 |
+ my $tz = "$zonebase/$timezone";
|
|
220 |
+ if (stat($tz) ne "")
|
|
221 |
+ {
|
|
222 |
+ unlink $localtime; # Important, since it might be a symlink.
|
|
223 |
+
|
|
224 |
+ &gst_report_enter ();
|
|
225 |
+ $res = copy ($tz, $localtime);
|
|
226 |
+ &gst_report_leave ();
|
|
227 |
+ return -1 unless $res;
|
|
228 |
+ return 0;
|
|
229 |
+ }
|
|
230 |
+
|
|
231 |
+ &gst_report_leave ();
|
|
232 |
+ return -1;
|
|
233 |
+}
|
|
234 |
+
|
|
235 |
sub time_set_archlinux_zone
|
|
236 |
{
|
|
237 |
my ($localtime, $zonebase, $timezone) =@_;
|
12148
|
238 |
@@ -442,7 +582,10 @@
|
7860
|
239 |
|
|
240 |
sub time_sync_hw_from_sys
|
|
241 |
{
|
|
242 |
- &gst_file_run ("hwclock --systohc");
|
|
243 |
+ if ( $$tool{"system"} ne "SunOS" )
|
|
244 |
+ {
|
|
245 |
+ &gst_file_run ("hwclock --systohc");
|
|
246 |
+ }
|
|
247 |
return 0;
|
|
248 |
}
|
|
249 |
|
12148
|
250 |
@@ -560,6 +703,10 @@
|
7860
|
251 |
"debian-3.0" => "debian-3.0",
|
|
252 |
"debian-sarge" => "debian-3.0",
|
|
253 |
|
|
254 |
+ "nexenta-1.0" => "nexenta",
|
|
255 |
+
|
|
256 |
+ "solaris-2.11" => "solaris",
|
|
257 |
+
|
|
258 |
"suse-7.0" => "suse-7.0",
|
|
259 |
"suse-9.0" => "suse-9.0",
|
|
260 |
"suse-9.1" => "suse-9.0",
|
12148
|
261 |
@@ -758,7 +905,24 @@
|
7860
|
262 |
[ "ntpinstalled", \&gst_service_rcng_installed, [ "ntpd", "openntpd" ]],
|
|
263 |
]
|
|
264 |
},
|
|
265 |
-
|
|
266 |
+
|
|
267 |
+ "solaris" =>
|
|
268 |
+ {
|
|
269 |
+ fn =>
|
|
270 |
+ {
|
|
271 |
+ NTP_CONF => "/etc/inet/ntp.conf"
|
|
272 |
+ },
|
|
273 |
+ table =>
|
|
274 |
+ [
|
|
275 |
+ [ "local_time", \&time_get_local_time ],
|
|
276 |
+ [ "timezone", \&time_get_sunos_zone ],
|
|
277 |
+ [ "sync", \&gst_parse_split_all_array_with_pos, NTP_CONF, "server", 0, "[ \t]+", "[ \t]+" ],
|
|
278 |
+ [ "sync_active", \&gst_service_smf_get_status, "network/ntp" ],
|
8612
|
279 |
+ [ "profiledb", \&read_profiledb], #zhua
|
7860
|
280 |
+ [ "ntpinstalled", \&gst_service_installed, "network/ntp" ],
|
|
281 |
+ ]
|
|
282 |
+ },
|
|
283 |
+
|
|
284 |
"freebsd-5" =>
|
|
285 |
{
|
|
286 |
fn =>
|
12148
|
287 |
@@ -813,6 +977,10 @@
|
7860
|
288 |
"debian-3.0" => "debian-3.0",
|
|
289 |
"debian-sarge" => "debian-3.0",
|
|
290 |
|
|
291 |
+ "nexenta-1.0" => "nexenta",
|
|
292 |
+
|
|
293 |
+ "solaris-2.11" => "solaris",
|
|
294 |
+
|
|
295 |
"suse-7.0" => "suse-7.0",
|
|
296 |
"suse-9.0" => "suse-9.0",
|
|
297 |
"suse-9.1" => "suse-9.0",
|
12148
|
298 |
@@ -859,6 +1027,7 @@
|
7860
|
299 |
[
|
|
300 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
301 |
[ "local_time", \&time_set_local_time ],
|
|
302 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
303 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
304 |
[ "sync_active", \&gst_service_sysv_set_status, 90, "xntpd", "%sync_active%" ],
|
|
305 |
]
|
12148
|
306 |
@@ -876,6 +1045,7 @@
|
7860
|
307 |
[
|
|
308 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
309 |
[ "local_time", \&time_set_local_time ],
|
|
310 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
311 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
312 |
[ "sync_active", \&gst_service_sysv_set_status, 90, "ntpd", "%sync_active%" ],
|
|
313 |
]
|
12148
|
314 |
@@ -893,6 +1063,7 @@
|
7860
|
315 |
[
|
|
316 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
317 |
[ "local_time", \&time_set_local_time ],
|
|
318 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
319 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
320 |
[ "sync_active", \&gst_service_sysv_set_status, 23, "ntp", "%sync_active%" ],
|
|
321 |
]
|
12148
|
322 |
@@ -912,6 +1083,7 @@
|
7860
|
323 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
324 |
[ "timezone", \&gst_replace_line_first, TIMEZONE ],
|
|
325 |
[ "local_time", \&time_set_local_time ],
|
|
326 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
327 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
328 |
[ "sync_active", \&gst_service_sysv_set_status, 23, "ntp-server", "%sync_active%" ],
|
|
329 |
]
|
12148
|
330 |
@@ -929,6 +1101,7 @@
|
7860
|
331 |
[
|
|
332 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
333 |
[ "local_time", \&time_set_local_time ],
|
|
334 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
335 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
336 |
[ "sync_active", \&gst_service_sysv_set_status, 90, "xntpd", "%sync_active%" ],
|
|
337 |
]
|
12148
|
338 |
@@ -946,6 +1119,7 @@
|
7860
|
339 |
[
|
|
340 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
341 |
[ "local_time", \&time_set_local_time ],
|
|
342 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
343 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
344 |
[ "sync_active", \&gst_service_suse_set_status, "xntpd" ],
|
|
345 |
]
|
12148
|
346 |
@@ -963,6 +1137,7 @@
|
7860
|
347 |
[
|
|
348 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
349 |
[ "local_time", \&gst_replace_join_all, NTP_CONF, "server", "[ \t]+" ],
|
|
350 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
351 |
[ "sync_active", \&gst_service_sysv_set_status, 90, "ntpd", "%sync_active%" ],
|
|
352 |
]
|
|
353 |
},
|
12148
|
354 |
@@ -979,6 +1154,7 @@
|
7860
|
355 |
[
|
|
356 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
357 |
[ "local_time", \&time_set_local_time ],
|
|
358 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
359 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
360 |
[ "sync_active", \&gst_service_gentoo_set_status, "ntpd", 1, "%sync_active%" ],
|
|
361 |
]
|
12148
|
362 |
@@ -996,10 +1172,49 @@
|
7860
|
363 |
[
|
|
364 |
[ "timezone", \&time_set_archlinux_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
365 |
[ "local_time", \&time_set_local_time ],
|
|
366 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
367 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
368 |
[ "sync_active", \&gst_service_archlinux_set_status, "ntpd", "%sync_active%" ],
|
|
369 |
]
|
|
370 |
},
|
|
371 |
+
|
|
372 |
+ "nexenta" =>
|
|
373 |
+ {
|
|
374 |
+ fn =>
|
|
375 |
+ {
|
|
376 |
+ NTP_CONF => "/etc/inet/ntp.conf",
|
|
377 |
+ ZONEINFO => "/usr/share/lib/zoneinfo",
|
|
378 |
+ LOCAL_TIME => "/etc/localtime"
|
|
379 |
+ },
|
|
380 |
+ table =>
|
|
381 |
+ [
|
|
382 |
+ [ "timezone", \&time_set_sunos_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
383 |
+ [ "local_time", \&time_set_local_time ],
|
|
384 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
385 |
+ [ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
12148
|
386 |
+ [ "sync_active", \&time_set_sync_peroid, "network/ntp", "%sync_active%" ],
|
7860
|
387 |
+ ]
|
|
388 |
+ },
|
|
389 |
+
|
|
390 |
+ "solaris" =>
|
|
391 |
+ {
|
|
392 |
+ fn =>
|
|
393 |
+ {
|
|
394 |
+ NTP_CONF => "/etc/inet/ntp.conf",
|
|
395 |
+ ZONEINFO => "/usr/share/lib/zoneinfo",
|
|
396 |
+ LOCAL_TIME => "/etc/localtime"
|
|
397 |
+ },
|
|
398 |
+ table =>
|
|
399 |
+ [
|
|
400 |
+ [ "timezone", \&time_set_sunos_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
401 |
+ [ "local_time", \&time_set_local_time ],
|
|
402 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
403 |
+ [ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
8612
|
404 |
+ [ "profiledb", \&write_profiledb ], #zhua
|
12148
|
405 |
+ [ "sync_active", \&time_set_sync_period, "network/ntp", "%sync_active%" ],
|
7860
|
406 |
+ ]
|
|
407 |
+ },
|
|
408 |
+
|
|
409 |
|
|
410 |
"freebsd-5" =>
|
|
411 |
{
|
12148
|
412 |
@@ -1013,6 +1228,7 @@
|
7860
|
413 |
[
|
|
414 |
[ "timezone", \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
|
|
415 |
[ "local_time", \&time_set_local_time ],
|
|
416 |
+ [ "sync_now", \&time_set_sync_now ],
|
|
417 |
[ "sync", \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
|
|
418 |
[ "sync_active", \&gst_service_rcng_set_status, "ntpd", "%sync_active%" ],
|
|
419 |
]
|
12148
|
420 |
@@ -1026,3 +1242,140 @@
|
8612
|
421 |
return undef;
|
|
422 |
}
|
|
423 |
|
|
424 |
+# zhua
|
|
425 |
+# add profiledb for ntp server added
|
|
426 |
+sub read_profiledb
|
|
427 |
+{
|
|
428 |
+ my ($hash);
|
|
429 |
+ my $path;
|
|
430 |
+ my $servers;
|
|
431 |
+
|
|
432 |
+
|
|
433 |
+ $path = &gst_file_get_data_path () . "/" . $main::tool->{'name'} . "/" . $profile_file;
|
|
434 |
+ my $tree = &gst_xml_scan ($path, $tool);
|
|
435 |
+
|
|
436 |
+ if ($tree && scalar @$tree)
|
|
437 |
+ {
|
|
438 |
+ $servers = &xml_parse_profiledb ($tree, $hash);
|
|
439 |
+ }
|
|
440 |
+
|
|
441 |
+ return $servers;
|
|
442 |
+}
|
|
443 |
+
|
|
444 |
+sub xml_parse_profiledb
|
|
445 |
+{
|
|
446 |
+ my ($tree, $hash) = @_;
|
|
447 |
+ my (@servers);
|
|
448 |
+
|
|
449 |
+ if ($$tree[0] eq 'profiledb')
|
|
450 |
+ {
|
|
451 |
+ my $svrs = &xml_parse_profile ($$tree[1], $hash);
|
|
452 |
+ push(@servers, @$svrs);
|
|
453 |
+ }
|
|
454 |
+ else
|
|
455 |
+ {
|
|
456 |
+ &gst_report ('xml_unexp_tag', $$tree[0]);
|
|
457 |
+ }
|
|
458 |
+
|
|
459 |
+ return \@servers ;
|
|
460 |
+
|
|
461 |
+}
|
|
462 |
+
|
|
463 |
+sub xml_parse_profile
|
|
464 |
+{
|
|
465 |
+ my ($tree, $hash) = @_;
|
|
466 |
+ my (@servers);
|
|
467 |
+
|
|
468 |
+ shift @$tree; # Skip attributes.
|
|
469 |
+
|
|
470 |
+ while (@$tree)
|
|
471 |
+ {
|
|
472 |
+ my $server;
|
|
473 |
+
|
|
474 |
+ if ($$tree[0] eq "profile") { $server = &xml_parse_server ($$tree[1], $hash); }
|
|
475 |
+ else
|
|
476 |
+ {
|
|
477 |
+ &gst_report ("xml_unexp_tag", $$tree[0]);
|
|
478 |
+ }
|
|
479 |
+
|
|
480 |
+ push(@servers, $server) if ( $server );
|
|
481 |
+
|
|
482 |
+ shift @$tree;
|
|
483 |
+ shift @$tree;
|
|
484 |
+ }
|
|
485 |
+ return \@servers;
|
|
486 |
+}
|
|
487 |
+
|
|
488 |
+sub xml_parse_server
|
|
489 |
+{
|
|
490 |
+ my ($tree, $hash) = @_;
|
|
491 |
+ my ($server);
|
|
492 |
+
|
|
493 |
+ shift @$tree; # Skip attributes.
|
|
494 |
+
|
|
495 |
+ while (@$tree)
|
|
496 |
+ {
|
|
497 |
+ if ($$tree[0] eq "server")
|
|
498 |
+ {
|
|
499 |
+ $server = $$tree[1][2];
|
|
500 |
+ }
|
|
501 |
+ else # files tag is ignored for parsing. # FIXME!
|
|
502 |
+ {
|
|
503 |
+ &gst_report ("xml_unexp_tag", $$tree[0]);
|
|
504 |
+ }
|
|
505 |
+
|
|
506 |
+ shift @$tree;
|
|
507 |
+ shift @$tree;
|
|
508 |
+
|
|
509 |
+ }
|
|
510 |
+ return $server;
|
|
511 |
+}
|
|
512 |
+
|
|
513 |
+sub write_profiledb
|
|
514 |
+{
|
|
515 |
+ my ($profiledb) = @_;
|
|
516 |
+
|
|
517 |
+ unless ($profiledb)
|
|
518 |
+ {
|
|
519 |
+ &gst_report ('users_write_profiledb_fail');
|
|
520 |
+ return;
|
|
521 |
+ }
|
|
522 |
+
|
|
523 |
+ # Write our profiles.
|
|
524 |
+ my $path = &gst_file_get_data_path () . "/" . $main::tool->{'name'} . "/" . $profile_file;
|
|
525 |
+ my $fh = &gst_file_open_write_from_names ($path);
|
|
526 |
+ if ($fh)
|
|
527 |
+ {
|
|
528 |
+ local *STDOUT = $fh;
|
|
529 |
+
|
|
530 |
+ &xml_print_profiledb( $profiledb );
|
|
531 |
+
|
|
532 |
+ close ($fh);
|
|
533 |
+ &gst_report ('users_write_profiledb_success');
|
|
534 |
+ }
|
|
535 |
+ else
|
|
536 |
+ {
|
|
537 |
+ &gst_report ('users_write_profiledb_fail');
|
|
538 |
+ }
|
|
539 |
+}
|
|
540 |
+
|
|
541 |
+sub xml_print_profiledb
|
|
542 |
+{
|
|
543 |
+ my ($profiledb) = @_;
|
|
544 |
+
|
|
545 |
+ return unless (scalar @$profiledb);
|
|
546 |
+
|
|
547 |
+ &gst_xml_container_enter ('profiledb');
|
|
548 |
+
|
|
549 |
+ foreach my $profile (@$profiledb)
|
|
550 |
+ {
|
|
551 |
+ my $key;
|
|
552 |
+ &gst_xml_container_enter ('profile');
|
|
553 |
+ &gst_xml_print_pcdata("server", $profile);
|
|
554 |
+ &gst_xml_container_leave ();
|
|
555 |
+ }
|
|
556 |
+
|
|
557 |
+ &gst_xml_container_leave ();
|
|
558 |
+ &gst_xml_print_vspace ();
|
|
559 |
+}
|
|
560 |
+
|