]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/user/fo_posting.pl
91a21a1f5f1124a93e0cf2d9ae77c5168bfece86
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
$show_posting -> {templateFile
};
49 our ($failed, %dparam, $threads, $last_thread, $last_message, $ftid, $fmid, $flocked);
51 sub forum_filename
() {$conf -> {files
} -> {forum
};}
52 sub message_path
() {$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, undef, 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 $i+=$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
() {
331 my %must = map {$_ => 1} @
{$formmust -> {exists $dparam{$formdata -> {followUp
} -> {name
}}?
'reply':'new'}};
333 if ( ($must{posterCategory
} and not exists ($dparam{$formdata -> {posterCategory
} -> {name
}})) or
334 ($must{posterSubject
} and not exists ($dparam{$formdata -> {posterSubject
} -> {name
}})))
336 my $filename = message_path
.'t'.$ftid.'.xml';
338 if (-f
$filename and lock_file
($filename))
340 my $xml = new XML
::DOM
::Parser
-> parsefile
($filename);
341 violent_unlock_file
($filename) unless unlock_file
($filename);
343 my $mnode = get_message_node
($xml, "t$ftid", "m$fmid");
344 my $header = get_message_header
($mnode);
346 $dparam{$formdata -> {posterCategory
} -> {name
}} = $header -> {category
};
347 $dparam{$formdata -> {posterSubject
} -> {name
}} = $header -> {subject
};
352 ################################
356 # (bereits vorhandene Formdaten)
357 ################################
362 my $list = [map {{$assign -> {optval
} => plain
($_),
363 (($_ eq $dparam{$formdata -> {posterCategory
} -> {name
}})?
($assign -> {optsel
} => 1):())}}
364 @
{$formdata -> {posterCategory
} -> {values}}];
366 $pars -> {$formdata->{posterCategory
}->{assign
}->{value
}} = $template->list ($assign -> {option
}, $list);
367 $pars -> {$formact ->{post
}->{assign
}} = $formact->{post
}->{url
};
368 $pars -> {$formdata->{quoteChar
}->{assign
}->{value
}} = 'ÿ'.plain
($dparam {$formdata -> {quoteChar
} -> {name
}} or '');
370 # Formfelder ausfuellen (Werte)
371 for (qw(uniqueID userID followUp posterName posterEmail posterSubject posterBody posterURL posterImage)) {
372 $pars -> {$formdata->{$_}->{assign
}->{value
}} = plain
($dparam {$formdata -> {$_} -> {name
}});}
375 ################################
378 # CGI-Parameter decodieren
379 # (rudimentaerer UTF8-support)
380 ################################
382 sub decode_param
() {
383 my $code = param
($formdata -> {quoteChar
} -> {name
});
386 # UTF-8 ([hoechst-]wahrscheinlich)
387 if ($code =~ /^\303\277/) {
393 $dparam{$_} = $array[0];}
396 $dparam{$_} = \
@array;}}}
398 # Latin 1 (hoffentlich - eigentlich ist es gar keine Codierung...)
399 elsif ($code =~ /^\377/) {
404 $dparam{$_} = toUTF8
($array[0]);}
407 $dparam{$_} = [map {toUTF8
($_)} @array];}}}
409 # unbekannte Codierung
413 # ersten beiden Zeichen der Quotechars loeschen (Indikator [ÿ (als UTF8)])
414 $dparam {$formdata -> {quoteChar
} -> {name
}} = ($dparam {$formdata -> {quoteChar
} -> {name
}} =~ /..(.*)/)[0];
416 delete $dparam {$formdata -> {posterURL
} -> {name
}}
417 unless ($dparam {$formdata -> {posterURL
} -> {name
}} =~ /$httpurl/);
419 delete $dparam {$formdata -> {posterImage
} -> {name
}}
420 unless ($dparam {$formdata -> {posterImage
} -> {name
}} =~ /$httpurl/);
422 # Codierung erkannt, alles klar
426 ################################
429 # CGI-Parameter pruefen
430 ################################
433 my %gotKeys = map {($_ => 1)} param
;
434 my $numGotKeys = keys %gotKeys;
436 # Threaderoeffnung, Ersteingabe (leere Seite)
437 return 'newThread' if ($numGotKeys == 0 or
438 (($numGotKeys == 1) and ($gotKeys {$formdata -> {userID
} -> {name
}})));
440 # =======================================================
441 # ab hier steht fest, wir haben ein ausgefuelltes
444 # 1. Umrechnungshash bauen (CGI-Key => Identifier)
445 # 2. alle must-keys vorhanden?
446 # 3. zuviele Parameter uebermittelt?
447 # 4. entsprechen die Daten den Anforderungen?
448 # (alle, nicht nur die must-Daten)
452 my %name = map {($formdata -> {$_} -> {name
} => $_)} keys %$formdata;
457 foreach (@
{$formmust -> {$gotKeys {$formdata -> {followUp
} -> {name
}}?
'reply':'new'}}) {
458 return 'missingKey' unless ($gotKeys {$formdata -> {$_} -> {name
}});
464 $failed = $name {$_};
465 return 'unexpectedKey' unless (exists ($name {$_}));
470 return 'unknownEncoding' unless (decode_param
);
472 foreach (keys %dparam) {
473 $failed = $name {$_};
475 return 'tooLong' if (length($dparam{$_}) > $formdata -> {$name {$_}} -> {maxlength
});
476 return 'tooShort' if (@
{[$dparam{$_} =~ /(\S)/g]} < $formdata -> {$name {$_}} -> {minlength
});
477 return 'wrongMail' if ($formdata -> {$name{$_}} -> {type
} eq 'email' and length ($dparam{$_}) and not is_mail_address
($dparam{$_}));
481 return $gotKeys {$formdata -> {followUp
} -> {name
}}?
'gotReply':'gotNew';
484 # ====================================================
486 # ====================================================
489 %subhash = (newThread
=> \
&new_thread
,
490 missingKey
=> \
&missing_key
,
491 unexpectedKey
=> \
&unexpected_key
,
492 unknownEncoding
=> \
&unknown_encoding
,
493 tooShort
=> \
&too_short
,
494 tooLong
=> \
&too_long
,
495 wrongMail
=> \
&wrong_mail
,
496 Occupied
=> \
&occupied
,
497 Dupe
=> \
&dupe_posting
,
498 noReply
=> \
&no_reply
,
499 gotReply
=> \
&got_reply
,
503 # Die RFC-gerechte URL-Erkennung ist aus dem Forum
504 # (thx2Cheatah - wo auch immer er sie (in der Form) her hat :-)
505 my $lowalpha = '(?:[a-z])';
506 my $hialpha = '(?:[A-Z])';
507 my $alpha = "(?:$lowalpha|$hialpha)";
508 my $digit = '(?:\d)';
509 my $safe = '(?:[$_.+-])';
510 my $hex = '(?:[\dA-Fa-f])';
511 my $escape = "(?:%$hex$hex)";
512 my $digits = '(?:\d+)';
513 my $alphadigit = "(?:$alpha|\\d)";
515 # URL schemeparts for ip based protocols:
516 my $port = "(?:$digits)";
517 my $hostnumber = "(?:$digits\\.$digits\\.$digits\\.$digits)";
518 my $toplabel = "(?:(?:$alpha(?:$alphadigit|-)*$alphadigit)|$alpha)";
519 my $domainlabel = "(?:(?:$alphadigit(?:$alphadigit|-)*$alphadigit)|$alphadigit)";
520 my $hostname = "(?:(?:$domainlabel\\.)*$toplabel)";
521 my $host = "(?:(?:$hostname)|(?:$hostnumber))";
522 my $hostport = "(?:(?:$host)(?::$port)?)";
524 my $httpuchar = "(?:(?:$alpha|$digit|$safe|(?:[!*\',]))|$escape)";
525 my $hsegment = "(?:(?:$httpuchar|[;:\@&=~])*)";
526 my $search = "(?:(?:$httpuchar|[;:\@&=~])*)";
527 my $hpath = "(?:$hsegment(?:/$hsegment)*)";
529 # das alles ergibt eine gueltige URL :-)
530 $httpurl = "^(?:https?://$hostport(?:/$hpath(?:\\?$search)?)?)\$";
533 # ====================================================
534 # end of fo_posting.pl
535 # ====================================================
patrick-canterino.de