]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/user/fo_posting.pl
3 ################################################################################
5 # File: user/fo_posting.pl #
7 # Authors: André Malo <nd@o3media.de>, 2001-01-25 #
9 # Description: Accept new postings, display "Neue Nachricht" page #
11 ################################################################################
14 use vars
qw($Bin $Shared $Script %subhash $httpurl $flocked);
17 ($Bin) = ($0 =~ /^(.*)\/.*$/)? $1 : '.';
18 $Shared = "$Bin/../shared";
19 ($Script) = ($0 =~ /^.*\/(.*)$/)? $1 : $0;}
21 use CGI::Carp qw(fatalsToBrowser);
25 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
30 use Posting
::_lib
qw(get_all_threads get_message_node get_message_header hr_time);
33 use Template
::Posting
;
35 use CGI
qw(param header);
38 print header
(-type
=> 'text/html');
40 our $conf = read_script_conf
($Bin, $Shared, $Script);
42 our $show_posting = $conf -> {show
} -> {Posting
};
43 our $assign = $show_posting -> {assign
};
44 our $formmust = $show_posting -> {form
} -> {must
};
45 our $formdata = $show_posting -> {form
} -> {data
};
46 our $formact = $show_posting -> {form
} -> {action
};
47 our $template = new Template
"$Bin/".$show_posting -> {templateFile
};
49 our ($failed, %dparam, $threads, $last_thread, $last_message, $ftid, $fmid, $flocked);
51 sub forum_filename
() {$conf -> {wwwRoot
} . $conf -> {files
} -> {forum
};}
52 sub message_path
() {$conf -> {wwwRoot
} . $conf -> {files
} -> {messagePath
};}
54 ################################
56 # Formfelder ausfuellen (Namen)
57 for (qw(posterBody uniqueID followUp quoteChar userID posterName posterEmail posterCategory posterSubject posterURL posterImage)) {
58 $pars -> {$formdata -> {$_} -> {assign
} -> {name
}} = plain
($formdata -> {$_} -> {name
});}
60 my $checked = &check_param
;
62 unless (exists ($subhash {$checked})) {
63 &print_fatal
($assign -> {unknownError
});}
66 unless ($checked eq 'newThread') {
67 $checked = &check_reply_dupe
() || $checked;}
69 unless (exists ($subhash {$checked})) {
70 &print_fatal
($assign -> {unknownError
});}
72 &{$subhash {$checked}};}
75 violent_unlock_file
(forum_filename
) unless (write_unlock_file
(forum_filename
));}}
77 # ====================================================
78 # end of main / Funktionen
79 # ====================================================
82 ### check_reply_dupe () ########################################################
84 # Reply moeglich? Doppelposting?
87 # Return: Dupe check result
88 # 'Dupe' - Posting is a dupe
91 sub check_reply_dupe
() {
94 unless ($stat = write_lock_file
(forum_filename
)) {
97 violent_unlock_file
(forum_filename
);
103 my ($i, %msg, %unids);
107 ($threads, $last_thread, $last_message, my $unids) = get_all_threads
(forum_filename
, 1, 0);
108 ($ftid,$fmid) = split /;/,$dparam{$formdata -> {followUp
} -> {name
}},2;
110 # Thread existiert nicht
111 if (exists($dparam{$formdata -> {followUp
} -> {name
}})) {
112 return 'noReply' unless (exists($threads -> {$ftid}));
114 # nur nicht geloeschte Messages beachten
115 for ($i=0; $i < @
{$threads -> {$ftid}}; $i++) {
116 if ($threads -> {$ftid} -> [$i] -> {deleted
}) {
117 $+=$threads -> {$ftid} -> [$i] -> {answers
};}
120 $msg{$threads -> {$ftid} -> [$i] -> {mid
}}=$i;}}
122 # Message existiert nicht
123 if (exists($dparam{$formdata -> {followUp
} -> {name
}})) {
124 return 'noReply' unless (exists($msg{$fmid}));}
126 %unids = map {$_ => 1} @
{$threads -> {$ftid} -> [$msg{$fmid}] -> {unids
}};
128 %unids = map {$_ => 1} @
$unids;
132 return 'Dupe' if (exists ($unids{$dparam{$formdata -> {uniqueID
} -> {name
}}}));
138 ################################
141 # Eroeffnungsposting speichern
142 ################################
147 my $pars = {author
=> $dparam {$formdata -> {posterName
} -> {name
}},
148 email
=> $dparam {$formdata -> {posterEmail
} -> {name
}},
149 category
=> $dparam {$formdata -> {posterCategory
} -> {name
}},
150 subject
=> $dparam {$formdata -> {posterSubject
} -> {name
}},
151 body
=> $dparam {$formdata -> {posterBody
} -> {name
}},
152 homepage
=> $dparam {$formdata -> {posterURL
} -> {name
}},
153 image
=> $dparam {$formdata -> {posterImage
} -> {name
}},
155 uniqueID
=> $dparam {$formdata -> {uniqueID
} -> {name
}},
156 ip
=> $ENV{REMOTE_ADDR
},
157 forumFile
=> forum_filename
,
158 messagePath
=> message_path
,
159 lastThread
=> $last_thread,
160 lastMessage
=> $last_message,
161 parsedThreads
=> $threads,
163 quoteChars
=> toUTF8
('»» '),
164 messages
=> $conf -> {template
} -> {messages
}};
166 my ($stat, $xml, $mid) = write_posting
($pars);
167 violent_unlock_file
(forum_filename
) unless (write_unlock_file
(forum_filename
));
171 print "Och noe...: $stat";}
174 my $thx = $show_posting -> {thanx
};
176 print ${$template -> scrap
($assign -> {docThx
},
177 {$thx -> {author
} => plain
($dparam {$formdata -> {posterName
} -> {name
}}),
178 $thx -> {email
} => plain
($dparam {$formdata -> {posterEmail
} -> {name
}}),
179 $thx -> {time} => plain
(hr_time
($time)),
180 $thx -> {body
} => message_as_HTML
($xml, $template,
183 $thx -> {category
} => plain
($dparam {$formdata -> {posterCategory
} -> {name
}}),
184 $thx -> {home
} => plain
($dparam {$formdata -> {posterURL
} -> {name
}}),
185 $thx -> {image
} => plain
($dparam {$formdata -> {posterImage
} -> {name
}}),
186 $thx -> {subject
} => plain
($dparam {$formdata -> {posterSubject
} -> {name
}})})};
191 ################################
194 # Antwortposting speichern
195 ################################
201 my $pars = {author
=> $dparam {$formdata -> {posterName
} -> {name
}},
202 email
=> $dparam {$formdata -> {posterEmail
} -> {name
}},
203 category
=> $dparam {$formdata -> {posterCategory
} -> {name
}},
204 subject
=> $dparam {$formdata -> {posterSubject
} -> {name
}},
205 body
=> $dparam {$formdata -> {posterBody
} -> {name
}},
206 homepage
=> $dparam {$formdata -> {posterURL
} -> {name
}},
207 image
=> $dparam {$formdata -> {posterImage
} -> {name
}},
209 uniqueID
=> $dparam {$formdata -> {uniqueID
} -> {name
}},
210 ip
=> $ENV{REMOTE_ADDR
},
211 parentMessage
=> $fmid,
213 forumFile
=> forum_filename
,
214 messagePath
=> message_path
,
215 lastThread
=> $last_thread,
216 lastMessage
=> $last_message,
217 parsedThreads
=> $threads,
219 quoteChars
=> toUTF8
('»» '),
220 messages
=> $conf -> {template
} -> {messages
}};
222 ($stat, my $xml, my $mid) = write_posting
($pars);
223 violent_unlock_file
(forum_filename
) unless (write_unlock_file
(forum_filename
));
227 print "Och noe...: $stat";}
230 my $thx = $show_posting -> {thanx
};
232 print ${$template -> scrap
($assign -> {docThx
},
233 {$thx -> {author
} => plain
($dparam {$formdata -> {posterName
} -> {name
}}),
234 $thx -> {email
} => plain
($dparam {$formdata -> {posterEmail
} -> {name
}}),
235 $thx -> {time} => plain
(hr_time
($time)),
236 $thx -> {body
} => message_as_HTML
($xml, $template,
239 $thx -> {category
} => plain
($dparam {$formdata -> {posterCategory
} -> {name
}}),
240 $thx -> {home
} => plain
($dparam {$formdata -> {posterURL
} -> {name
}}),
241 $thx -> {image
} => plain
($dparam {$formdata -> {posterImage
} -> {name
}}),
242 $thx -> {subject
} => plain
($dparam {$formdata -> {posterSubject
} -> {name
}})})};}
245 ################################
248 # HTML fuer Eroeffnungsposting
249 ################################
252 my $list = [map {{$assign -> {optval
} => plain
($_)}} @
{$formdata -> {posterCategory
} -> {values}}];
254 # spaeter kommen noch userspezifische Daten dazu...
255 print ${$template -> scrap
($assign -> {docNew
},
256 {$formdata->{uniqueID
} ->{assign
}->{value
} => plain
(unique_id
),
257 $formdata->{quoteChar
} ->{assign
}->{value
} => 'ÿ'.plain
(toUTF8
('»» ')),
258 $formact->{post
}->{assign
} => $formact->{post
}->{url
},
259 $formdata->{posterCategory
}->{assign
}->{value
} => $template->list ($assign -> {option
}, $list)
263 ################################
267 ################################
269 sub no_reply
() {&print_fatal
($assign -> {noReply
});}
270 sub dupe_posting
() {&print_fatal
($assign -> {dupe
});}
271 sub missing_key
() {&print_fatal
($assign -> {wrongPar
});}
272 sub unexpected_key
() {&print_fatal
($assign -> {wrongPar
});}
273 sub unknown_encoding
() {&print_fatal
($assign -> {wrongCode
});}
275 if ($formdata -> {$failed} -> {errorType
} eq 'repeat') {
276 &print_error
($formdata -> {$failed} -> {assign
} -> {tooShort
},
277 $formdata -> {$failed} -> {minlength
});}
280 &print_fatal
($formdata -> {$failed} -> {assign
} -> {tooShort
});}
284 if ($formdata -> {$failed} -> {errorType
} eq 'repeat') {
285 &print_error
($formdata -> {$failed} -> {assign
} -> {tooLong
},
286 $formdata -> {$failed} -> {maxlength
});}
289 &print_fatal
($formdata -> {$failed} -> {assign
} -> {tooLong
});}
292 sub wrong_mail
() {print_error
($formdata -> {$failed} -> {assign
} -> {wrong
});}
293 sub occupied
() {print_error
($assign -> {occupied
});}
295 ################################
298 # fatale Fehlerausgabe
299 ################################
301 sub print_fatal
($) {
302 print ${$template -> scrap
($assign -> {docFatal
},
303 {$assign -> {errorMessage
} => $template -> insert
($_[0])
307 ################################
310 # Fehlerausgabe, Moeglichkeit
312 ################################
314 sub print_error
($;$) {
316 print ${$template -> scrap
($assign -> {docError
},
317 {$assign -> {errorMessage
} => $template -> insert
($_[0]),
318 $assign -> {charNum
} => $_[1]
322 ################################
325 # Subject und Category besorgen
326 # (wenn noch nicht vorhanden)
327 ################################
329 sub fetch_subject
() {
330 unless (exists ($dparam{$formdata -> {posterCategory
} -> {name
}}) and
331 exists ($dparam{$formdata -> {posterSubject
} -> {name
}})) {
333 my $filename = message_path
.'t'.$ftid.'.xml';
335 if (lock_file
($filename)) {
336 my $xml = new XML
::DOM
::Parser
-> parsefile
($filename);
337 violent_unlock_file
($filename) unless unlock_file
($filename);
339 my $mnode = get_message_node
($xml, "t$ftid", "m$fmid");
340 my $header = get_message_header
($mnode);
342 $dparam{$formdata -> {posterCategory
} -> {name
}} = $header -> {category
};
343 $dparam{$formdata -> {posterSubject
} -> {name
}} = $header -> {subject
};}}
346 ################################
350 # (bereits vorhandene Formdaten)
351 ################################
356 my $list = [map {{$assign -> {optval
} => plain
($_),
357 (($_ eq $dparam{$formdata -> {posterCategory
} -> {name
}})?
($assign -> {optsel
} => 1):())}}
358 @
{$formdata -> {posterCategory
} -> {values}}];
360 $pars -> {$formdata->{posterCategory
}->{assign
}->{value
}} = $template->list ($assign -> {option
}, $list);
361 $pars -> {$formact ->{post
}->{assign
}} = $formact->{post
}->{url
};
362 $pars -> {$formdata->{quoteChar
}->{assign
}->{value
}} = 'ÿ'.plain
($dparam {$formdata -> {quoteChar
} -> {name
}} or '');
364 # Formfelder ausfuellen (Werte)
365 for (qw(uniqueID userID followUp posterName posterEmail posterSubject posterBody posterURL posterImage)) {
366 $pars -> {$formdata->{$_}->{assign
}->{value
}} = plain
($dparam {$formdata -> {$_} -> {name
}});}
369 ################################
372 # CGI-Parameter decodieren
373 # (rudimentaerer UTF8-support)
374 ################################
376 sub decode_param
() {
377 my $code = param
($formdata -> {quoteChar
} -> {name
});
380 # UTF-8 ([hoechst-]wahrscheinlich)
381 if ($code =~ /^\303\277/) {
387 $dparam{$_} = $array[0];}
390 $dparam{$_} = \
@array;}}}
392 # Latin 1 (hoffentlich - eigentlich ist es gar keine Codierung...)
393 elsif ($code =~ /^\377/) {
398 $dparam{$_} = toUTF8
($array[0]);}
401 $dparam{$_} = [map {toUTF8
($_)} @array];}}}
403 # unbekannte Codierung
407 # ersten beiden Zeichen der Quotechars loeschen (Indikator [ÿ (als UTF8)])
408 $dparam {$formdata -> {quoteChar
} -> {name
}} = ($dparam {$formdata -> {quoteChar
} -> {name
}} =~ /..(.*)/)[0];
410 delete $dparam {$formdata -> {posterURL
} -> {name
}}
411 unless ($dparam {$formdata -> {posterURL
} -> {name
}} =~ /$httpurl/);
413 delete $dparam {$formdata -> {posterImage
} -> {name
}}
414 unless ($dparam {$formdata -> {posterImage
} -> {name
}} =~ /$httpurl/);
416 # Codierung erkannt, alles klar
420 ################################
423 # CGI-Parameter pruefen
424 ################################
427 my %gotKeys = map {($_ => 1)} param
;
428 my $numGotKeys = keys %gotKeys;
430 # Threaderoeffnung, Ersteingabe (leere Seite)
431 return 'newThread' if ($numGotKeys == 0 or
432 (($numGotKeys == 1) and ($gotKeys {$formdata -> {userID
} -> {name
}})));
434 # =======================================================
435 # ab hier steht fest, wir haben ein ausgefuelltes
438 # 1. Umrechnungshash bauen (CGI-Key => Identifier)
439 # 2. alle must-keys vorhanden?
440 # 3. zuviele Parameter uebermittelt?
441 # 4. entsprechen die Daten den Anforderungen?
442 # (alle, nicht nur die must-Daten)
446 my %name = map {($formdata -> {$_} -> {name
} => $_)} keys %$formdata;
451 foreach (@
{$formmust -> {$gotKeys {$formdata -> {followUp
} -> {name
}}?
'reply':'new'}}) {
452 return 'missingKey' unless ($gotKeys {$formdata -> {$_} -> {name
}});
458 $failed = $name {$_};
459 return 'unexpectedKey' unless (exists ($name {$_}));
464 return 'unknownEncoding' unless (decode_param
);
466 foreach (keys %dparam) {
467 $failed = $name {$_};
469 return 'tooLong' if (length($dparam{$_}) > $formdata -> {$name {$_}} -> {maxlength
});
470 return 'tooShort' if (@
{[$dparam{$_} =~ /(\S)/g]} < $formdata -> {$name {$_}} -> {minlength
});
471 return 'wrongMail' if ($formdata -> {$name{$_}} -> {type
} eq 'email' and length ($dparam{$_}) and not is_mail_address
($dparam{$_}));
475 return $gotKeys {$formdata -> {followUp
} -> {name
}}?
'gotReply':'gotNew';
478 # ====================================================
480 # ====================================================
483 %subhash = (newThread
=> \
&new_thread
,
484 missingKey
=> \
&missing_key
,
485 unexpectedKey
=> \
&unexpected_key
,
486 unknownEncoding
=> \
&unknown_encoding
,
487 tooShort
=> \
&too_short
,
488 tooLong
=> \
&too_long
,
489 wrongMail
=> \
&wrong_mail
,
490 Occupied
=> \
&occupied
,
491 Dupe
=> \
&dupe_posting
,
492 noReply
=> \
&no_reply
,
493 gotReply
=> \
&got_reply
,
497 # Die RFC-gerechte URL-Erkennung ist aus dem Forum
498 # (thx2Cheatah - wo auch immer er sie (in der Form) her hat :-)
499 my $lowalpha = '(?:[a-z])';
500 my $hialpha = '(?:[A-Z])';
501 my $alpha = "(?:$lowalpha|$hialpha)";
502 my $digit = '(?:\d)';
503 my $safe = '(?:[$_.+-])';
504 my $hex = '(?:[\dA-Fa-f])';
505 my $escape = "(?:%$hex$hex)";
506 my $digits = '(?:\d+)';
507 my $alphadigit = "(?:$alpha|\\d)";
509 # URL schemeparts for ip based protocols:
510 my $port = "(?:$digits)";
511 my $hostnumber = "(?:$digits\\.$digits\\.$digits\\.$digits)";
512 my $toplabel = "(?:(?:$alpha(?:$alphadigit|-)*$alphadigit)|$alpha)";
513 my $domainlabel = "(?:(?:$alphadigit(?:$alphadigit|-)*$alphadigit)|$alphadigit)";
514 my $hostname = "(?:(?:$domainlabel\\.)*$toplabel)";
515 my $host = "(?:(?:$hostname)|(?:$hostnumber))";
516 my $hostport = "(?:(?:$host)(?::$port)?)";
518 my $httpuchar = "(?:(?:$alpha|$digit|$safe|(?:[!*\',]))|$escape)";
519 my $hsegment = "(?:(?:$httpuchar|[;:\@&=~])*)";
520 my $search = "(?:(?:$httpuchar|[;:\@&=~])*)";
521 my $hpath = "(?:$hsegment(?:/$hsegment)*)";
523 # das alles ergibt eine gueltige URL :-)
524 $httpurl = "^(?:https?://$hostport(?:/$hpath(?:\\?$search)?)?)\$";
527 # ====================================================
528 # end of fo_posting.pl
529 # ====================================================
patrick-canterino.de