]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Conf/Admin.pm
added version check and comments
[selfforum.git] / selfforum-cgi / shared / Conf / Admin.pm
1 package Conf::Admin;
2
3 ################################################################################
4 # #
5 # File: shared/CheckRFC.pm #
6 # #
7 # Authors: Andre Malo <nd@o3media.de>, 2001-06-16 #
8 # #
9 # Description: read and parse admin default config #
10 # #
11 ################################################################################
12
13 use strict;
14 use vars qw(
15 @EXPORT
16 $VERSION
17 );
18
19 use Lock qw(:READ);
20
21 use XML::DOM;
22
23 ################################################################################
24 #
25 # Version check
26 #
27 $VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
28
29 ################################################################################
30 #
31 # Export
32 #
33 use base qw(Exporter);
34 @EXPORT = qw(read_admin_conf);
35
36 ### get_severance () ###########################################################
37 #
38 # read out severance config (used twice)
39 #
40 # Params: $severance - element node
41 #
42 # Return: hashref
43 #
44 sub get_severance ($) {
45 my $severance = shift;
46
47 my $after_byte = $severance -> getElementsByTagName ('AfterByte', 0) -> item (0);
48 my $after_message = $severance -> getElementsByTagName ('AfterMessage', 0) -> item (0);
49 my $after_thread = $severance -> getElementsByTagName ('AfterThread', 0) -> item (0);
50 my $last_posting = $severance -> getElementsByTagName ('AfterLastPosting', 0) -> item (0);
51
52 my %conf =(
53 exArchiving => $severance -> getAttribute ('executeArchiving'),
54 archiving => $severance
55 -> getElementsByTagName ('Archiving', 0) -> item (0)
56 -> getElementsByTagName ('*', 0) -> item (0) -> getTagName,
57 severance => $severance -> getAttribute ('executeSeverance'),
58 afterByte => (
59 $after_byte
60 ? $after_byte -> getFirstChild -> getData
61 : undef
62 ),
63 afterThread => (
64 $after_thread
65 ? $after_thread -> getFirstChild -> getData
66 : undef
67 ),
68 afterMessage => (
69 $after_message
70 ? $after_message -> getFirstChild -> getData
71 : undef
72 ),
73 lastPosting => (
74 $last_posting
75 ? $last_posting -> getFirstChild -> getData
76 : undef
77 )
78 );
79
80 \%conf;
81 }
82
83 ### read_admin_conf () #########################################################
84 #
85 # read and parse admin config
86 #
87 # Params: $filename - filename
88 #
89 # Return: hashref
90 #
91 sub read_admin_conf ($) {
92 my $filename=shift;
93 my %conf;
94
95 if (-f $filename) {
96 if (lock_file ($filename)) {
97 my $xml = new XML::DOM::Parser -> parsefile ($filename);
98 violent_unlock_file ($filename) unless (unlock_file ($filename));
99
100 # write data into the hash
101 #
102 my $forum = $xml -> getElementsByTagName ('Forum',0) -> item (0);
103
104 # View
105 my $forum_view = $forum -> getElementsByTagName ('ForumView', 0) -> item (0);
106 my $thread_view = $forum_view -> getElementsByTagName ('ThreadView', 0) -> item (0);
107 my $show_thread = $thread_view -> getElementsByTagName ('ShowThread', 0) -> item (0);
108 my $show_how = $show_thread -> getElementsByTagName ('*', 0) -> item (0);
109 my $how_name = $show_how -> getTagName;
110 my $message_view = $forum_view -> getElementsByTagName ('MessageView', 0) -> item (0);
111 my $flags = $forum_view -> getElementsByTagName ('Flags', 0) -> item (0);
112 my $quoting = $forum_view -> getElementsByTagName ('Quoting', 0) -> item (0);
113 my $char = $quoting -> getElementsByTagName ('Chars', 0) -> item (0);
114
115 $conf {View} = {
116 threadOpen => $thread_view -> getAttribute ('threadOpen'),
117 countMessages => $thread_view -> getAttribute ('countMessages'),
118 sortThreads => $thread_view -> getAttribute ('sortThreads'),
119 sortMessages => $thread_view -> getAttribute ('sortMessages'),
120 showThread => (($how_name eq 'ShowAll')
121 ? undef
122 : (($how_name eq 'ShowNone')
123 ? 1
124 : ($show_how -> getFirstChild -> getData))),
125 showPreview => $message_view -> getAttribute ('previewON'),
126 showNA => $flags -> getAttribute ('showNA'),
127 showHQ => $flags -> getAttribute ('showHQ'),
128 quoting => $quoting -> getAttribute ('quotingON'),
129 quoteChars => $char?$char -> getFirstChild -> getData:undef
130 };
131
132 my $voting = $forum -> getElementsByTagName ('Voting', 0) -> item (0);
133 $conf {Voting} = {
134 voteLock => $voting -> getAttribute ('voteLock'),
135 Limit => $voting -> getAttribute ('Limit')
136 };
137
138 # Severance
139 $conf {Severance} = get_severance ($forum -> getElementsByTagName ('Severance', 0) -> item (0));
140
141 # Messaging
142 my $messaging = $forum -> getElementsByTagName ('Messaging', 0) -> item (0);
143 my $call_by_user = $messaging -> getElementsByTagName ('CallByUser', 0) -> item (0);
144
145 $conf {Messaging} = {
146 userAnswer => $messaging -> getAttribute ('callUserAnswer'),
147 thread => $messaging -> getAttribute ('callAdminThread'),
148 na => $messaging -> getAttribute ('callAdminNA'),
149 hq => $messaging -> getAttribute ('callAdminHQ'),
150 voting => $messaging -> getAttribute ('callAdminVoting'),
151 archiving => $messaging -> getAttribute ('callAdminArchiving'),
152 byUser => $messaging -> getAttribute ('callUserAnswer'),
153 callByName => [
154 $call_by_user
155 ? map {$_ -> getFirstChild -> getData} $call_by_user -> getElementsByTagName ('Name', 0)
156 : ()
157 ],
158 callByMail => [
159 $call_by_user
160 ? map {$_ -> getFirstChild -> getData} $call_by_user -> getElementsByTagName ('Email', 0)
161 : ()
162 ],
163 callByIP => [
164 $call_by_user
165 ? map {$_ -> getFirstChild -> getData} $call_by_user -> getElementsByTagName ('IpAddress', 0)
166 : ()
167 ]
168 };
169
170 # Instant
171 my $instant = $forum -> getElementsByTagName ('InstantJob', 0) -> item (0);
172 my $job = $instant -> getElementsByTagName ('*',0) -> item (0);
173 my $job_name = $job -> getTagName;
174 $job_name = $job -> getAttribute ('reason') if ($job_name ne 'Severance');
175
176 $conf {Instant} = {
177 execute => $instant -> getAttribute ('executeJob'),
178 description => $job_name,
179 url => (
180 ($job_name ne 'Severance')
181 ? $job -> getElementsByTagName ('FileUrl', 0) -> item (0) -> getFirstChild -> getData
182 : undef
183 ),
184 Severance => (
185 ($job_name eq 'Severance')
186 ? get_severance ($job)
187 : undef
188 )
189 };
190
191 # User
192 my $user = $forum -> getElementsByTagName ('UserManagement', 0) -> item (0);
193
194 $conf {User} = {
195 deleteAfterDays => $user
196 -> getElementsByTagName ('DeleteUser', 0) -> item (0)
197 -> getElementsByTagName ('AfterDays', 0) -> item (0)
198 -> getFirstChild -> getData
199 };
200 }
201
202 else {
203 violent_unlock_file ($filename);
204 }
205 }
206
207 # return
208 \%conf;
209 }
210
211 # keep 'require' happy
212 1;
213
214 #
215 #
216 ### end of Conf::Admin #########################################################

patrick-canterino.de