$lang_avatar
HTML
if ($profile_avatar) { print " "; } else { print ""; }
print <
$lang_contact
HTML
if ($enable_private_messages eq "on") {
print <
<$smallfont>$lang_send_a_private_message_to $profile_name
HTML
}
if ($profile_email and !$profile_hide_email) {
print <
<$smallfont>$lang_email_address :
<$smallfont>$profile_email
HTML
}
if ($profile_icq) {
print <
<$smallfont>$lang_icq_number :
<$smallfont>
$profile_icq
HTML
}
if ($profile_aol) {
print <
<$smallfont>$lang_aol_aim :
<$smallfont>$profile_aol
HTML
}
if ($profile_msn) {
print <
<$smallfont>$lang_msn_messenger :
<$smallfont>$profile_msn
HTML
}
if ($profile_yahoo) {
print <
<$smallfont>$lang_yahoo_messenger :
<$smallfont>$profile_yahoo
HTML
}
print <
$lang_about $profile_name...
$lang_joined :
HTML
print date_time($profile_joindate);
print <
HTML
if ($profile_realname) {
print <
$lang_real_name :
$profile_realname
HTML
}
if ($profile_location) {
print <
$lang_location :
$profile_location
HTML
}
if ($profile_website) {
print <
$lang_website :
$profile_website
HTML
}
if ($profile_occupation) {
print <
$lang_occupation :
$profile_occupation
HTML
}
if ($profile_interests) {
print <
$lang_interests :
$profile_interests
HTML
}
print <
$lang_forum_posts :
$profile_posts
$forumstats
- [ $lang_back ] -
HTML
&page_end;
}
sub post_form {
# check guest access; if read-only the user is not allowed to post
if ($user eq "guest" and $guest_access eq "read-only") {
print " ";
print "";
&login;
return undef;
}
# check the permissions for this forum
open(FORUM_INFO, "< $simpleforum_dir/forum_$forum_id/forum.info") or dienice("Couldn't open forum.info for reading: $!");
$forum_info_content = join '', ;
close FORUM_INFO;
# if this is the post form below a preview of a post, $message and $subject need to be defined
if (param('preview')) {
$subject = param('subject');
$textarea_content = param('message');
$cookie_name = param('name'); # replace the cookie name by the new name
$cookie_email = param('email'); # replace the cookie email by the new one
if (param('subscribe')) { $subscribe_checked = "CHECKED"; }
$attachment = param('attachment');
}
# check if this is a read-only forum and only give access to admins and moderators
if ($forum_info_content =~ /(.*?)<\/forum_perm>/s) {
$forum_perm = $1;
if ($forum_perm eq 'read-only' and !$admin_access and !$moderator_access) {
print "$lang_read_only_forum_not_authorized$lang_back ";
return undef;
}
}
my($type) = @_;
if ($original_topic_title) { $replyto_topic_title = "Re: ".$original_topic_title; }
# print the form
if ($type eq "post" and !param('preview')) {
print " ";
}
if ($msg_id) { #reply to a specific post
open(REPLY, "< $simpleforum_dir/forum_$forum_id/$topic_id.topic") or dienice("Couldn't open topic for reading: $!");
$reply_content = join '', ;
close REPLY;
# check if the user is subscribed to this topic
if ($reply_content =~ /(.*?)<\/subscribe>\n/ and $logged_in) { $subscribe = $1; if ($subscribe =~ /^$user$/ or $subscribe =~ /^$user\|(.*)/ or $subscribe =~ /(.*)\|$user$/) { $user_subscribed = 1; } }
if ($reply_content =~ /(.*)((.*?)$msg_id<\/time>(.*?)<\/post>)(.*)/s) {
$reply_content = $2;
if ($reply_content =~ /(.*?)<\/name>/s) { $reply_name = $1; }
if ($reply_content =~ /(.*?)<\/status>/s) { $reply_status = $1; }
if ($reply_content =~ /(.*?)<\/ip>/s) { $reply_ip = $1; }
if ($reply_content =~ /(.*?)<\/email>/s) { $reply_email = $1; }
if ($reply_content =~ /(.*?)<\/message>/s) { $reply_message = $1; }
if ($reply_content =~ /(.*?)<\/subject>/s) { $reply_subject = $1; }
}
date_time($msg_id);
$reply_message =~ s/\n$//s;
if ($reply_status eq "registered" and -e "$users_dir/$reply_name.prf") {
# known user, get real name and email address
open PRF, "$users_dir/$reply_name.prf";
while () {
if (/(.*?)<\/user_name>/) { $reply_name = $1; }
if (/(.*?)<\/user_email>/) { $reply_email = $1; }
}
close PRF;
}
if ($reply_message =~ /(.*)\[quoted\]..(.*?)\[\/quoted\]/s) {
$former_quote = $2;
$former_quote =~ s/\n/\n> /sg;
$former_quote =~ s/\n> $//sg;
$reply_message =~ s/(.*)\[quoted\]..(.*?)\[\/quoted\]/$1> $former_quote/s;
}
$textarea_content = "\[quoted\]\nAt $hour:$min:$sec $ampm $short_date, $reply_name wrote:\n$reply_message\n\[\/quoted\]\n\n";
$replyto_topic_title = $reply_subject;
if ($mail eq "on" and $reply_email) {
# Set the checkbox for email-reply
$topic_url = $ENV{'HTTP_REFERER'};
$emailreply = "
<$smallfont> $lang_email_to $reply_name
";
}
}
if ($mail eq "on" and $user_email) {
# allow for registered users to subscribe to a topic, set the form in $subscribe
if (!$user_subscribed) { # the user is not subscribed to this topic
$subscribe = "
<$smallfont> $lang_subscribe_to_this_topic
";
} else { # the user is subscribed to this topic, allow him to unsubscribe
$subscribe = " <$smallfont>$lang_unsubscribe ";
}
} else {
$subscribe = "";
}
#if ($admin_access and $type eq "post") {
# # Admins can make this post a sticky post, which means it will stick at the top of the topic list
# $make_sticky = "
#
# <$smallfont> Make this post a Sticky Post
# ";
#}
if ($attachments_uploadmax >= 1024000) {
$max_attachment_size = ($attachments_uploadmax/1024000)."Mb";
} else {
$max_attachment_size = ($attachments_uploadmax/1024)."kb";
}
if (!$topic_url) { $topic_url = url(-path_info=>1,-query=>1); }
# # # # HTML # # # #
print <
HTML
# # # END HTML # # #
}
sub post_preview {
# prints the preview page without the edit preview form, this form can be found in sub post_form
$post_message = add_html(param('message'));
$post_subject = add_html(param('subject'));
$topic_title = param('topic_title');
if ($topic_title) { $menu_topic_title = " » $lang_topic: $topic_title "; }
date_time(time); # set time
if (&random_signature) {
$print_signature = &add_html(&random_signature."\n");
$print_signature = " _________________ $print_signature";
}
if (!$logged_in) { $user_name = param('name'); $user_title = "Guest"; }
print <
HTML
print <
<$smallfont>$lang_posted_on $short_date $hour:$min:$sec$ampm
<$bigfont>$user_name
HTML
# if there's a user title and user titles are turned on print it
if ($user_title and $enable_user_titles eq "on") { print " <$smallfont>$user_title"; }
if ($user_posts) { print " <$smallfont>$lang_posts: $user_posts"; }
print <
<$smallfont> $reply_to_this_post $edit_this_post $quickdel_link $move_topic
HTML
if ($user_avatar) { print " "; }
print <
<$bigfont>$post_subject
$post_message
$print_signature
Edit Preview
HTML
}
sub verify_content {
# check the user input
# check the name field
$name = param('name');
if (!param('name')) {
$error .= "You forgot to enter your name \n";
}
# check the email field on syntax
if (param('email')) {
$mailcheck = param('email');
if ($mailcheck !~ /[\w\-]+\@[\w\-]+\.[\w\-]+/g) {
$error .= "\"$mailcheck\" is not a valid email address \n";
}
}
# check the subject field
if (!param('subject')) {
$error = $error."You forgot to enter a subject \n";
}
# check the message field, message is not required if there's an attachment
if (!param('message') and !param('attachment')) {
$error = $error."You forgot to enter a message \n";
}
# check if a guest's name isn't already used by a registered user
if (!param('logged_in')) {
open_dir($users_dir);
foreach (@files) {
if (/$name\.prf/i) {
$error = $error."The name you specified is already in use by a registered user, please choose a different name \n";
}
}
}
# you can't have an attachment in previews, give an error if this is the case
if (param('attachment') and param('preview')) {
$error .= "You cannot preview attachments, please preview your post without attachments and add it at the end before sending \n";
}
# if any of the above checks results in an error, print the error and abort
if ($error) {
&page_start;
print "Your message has not been posted \n$lang_back ";
&page_end;
exit;
}
# all fields are ok, store them in vars
#[$name = param('name');] this is done above
$subject = param('subject');
$message = param('message');
$email = param('email');
# The part that takes care of the attachment
$file = param("attachment");
if ($file and $allow_attachments eq "yes") {
if ($file =~ /(.*)\/(.*?)$/s) { #unix filesystem
$filename = $2;
} elsif ($file =~ /(.*)\\(.*?)$/s) { #windows filesystem
$filename = $2;
} else {
$filename = $file;
}
#check if the file doesn't already exist
if (-e "$attachments_dir/$filename") {
dienice("$lang_upload_file_exists");
}
if ($ENV{'CONTENT_LENGTH'} > $attachments_uploadmax) {
#file too large
$attachments_uploadmax_kb = $attachments_uploadmax/1024;
dienice("$lang_file_too_large $attachments_uploadmax_kb kb.");
}
$file_size = $ENV{'CONTENT_LENGTH'};
if ($file_size >= 1024000) {
$file_size_kbmb = sprintf("%.1f",($file_size/1024000))."Mb";
} else {
$file_size_kbmb = sprintf("%.2f",($file_size/1024))."kb";
}
# So far so good, now the only thing we need to do is upload the file
#UPLOAD THE FILE
if (!-e "$attachments_dir") {
# attachments dir doesn't exist, so we need to creat this dir first
mkdir("$attachments_dir",0777) or dienice("$! If the above error sais \"Permission Denied\" this means that the attachments directory does not exist or that the script has not got the sufficient previleges to write the attachment to the attachments directory. Please create this directory and set its permissions (hint: chmod 777)");
}
open(OUT,">$attachments_dir/$filename") or dienice("Couldn't write the attachment ($attachments_dir/$filename): $!");
binmode OUT;
flock OUT, 2;
$flen = 0;
while (read($file,$i,1024)) {
print OUT $i;
$flen = $flen + 1024;
if ($flen > $attachments_uploadmax) {
close(OUT);
}
}
close(OUT);
if ($message) { $message .= "\n\n"; }
$ctype = uploadInfo($file)->{'Content-Type'};
if ($ctype eq "image/gif" or $ctype eq "image/jpeg" or $ctype eq "image/pjpeg" or $ctype eq "image/png") {
$attachments_url =~ s/^http:(\/\/(.*?))$/$1/s;
$message .= "\[img:$attachments_url/$filename]";
} else {
$message .= "\[$lang_attachment: \[url=$attachments_url/$filename\]$filename\[/url\] ($file_size_kbmb)\]";
}
}
}
sub quick_delete {
if ($dele_id == '1') {
# delete entire topic
unlink "$simpleforum_dir/forum_$forum_id/$topic_id.topic";
&edit_statistics_file("tpc_amount--");
print redirect("$script_name?fid=$forum_id");
exit;
}
if (!$admin_access and !$moderator_access) { print "$lang_not_authorized \n"; }
if (!param('posted')) {
&page_start;
open (DELE, "< $simpleforum_dir/forum_$forum_id/$topic_id.topic") or dienice("Couldn't open topic for deletion. Refresh the forum and try again.");
$dele_content = join '', ;
close DELE;
if ($dele_content =~ /(.*)((.*?)$dele_id<\/time>(.*?)<\/post>)(.*)/s) {
$dele_content = $2;
if ($dele_content =~ /(.*?)<\/name>/s) { $dele_name = $1; }
if ($dele_content =~ /(.*?)<\/ip>/s) { $dele_ip = $1; }
if ($dele_content =~ /(.*?)<\/email>/s) { $dele_email = $1; }
if ($dele_content =~ /(.*?)<\/message>/s) { $dele_message = $1; }
if ($dele_content =~ /(.*?)<\/subject>/s) { $dele_subject = $1; }
}
&date_time($dele_id);
# # # # HTML # # # #
print <
<$smallfont>$lang_posted_on $short_date $hour:$min:$sec$ampm
HTML
# # # END HTML # # #
$dele_subject = add_html($dele_subject);
$dele_message = add_html($dele_message);
# # # # HTML # # # #
print <
$lang_author:
$dele_name
$lang_subject:
$dele_subject
$lang_message:
$dele_message
$lang_back
HTML
# # # END HTML # # #
&page_end;
} else {
#delete message
open(DELE, "+>> $simpleforum_dir/forum_$forum_id/$topic_id.topic") or dienice("Couldn't open topic for writing: $!");
flock DELE, 2;
seek DELE, 0, 0;
$dele_content = join '', ;
$dele_content =~ s/(.*)((.*?)$dele_id<\/time>(.*?)<\/post>)(.*)/$1$5/s;
seek DELE, 0, 0;
truncate DELE, 0;
print DELE $dele_content;
close DELE;
&edit_statistics_file("msg_amount--");
if ($dele_content !~ //s) {
#the topic is empty, delete the topic file!
unlink "$simpleforum_dir/forum_$forum_id/$topic_id.topic";
&edit_statistics_file("tpc_amount--");
}
print redirect("$script_name?fid=$forum_id");
}
}
sub move_topic {
# move topics from one subforum to another
if (!$admin_access and !$moderator_access) { dienice("$lang_not_authorized"); } # double admin-only protection
rename("$simpleforum_dir/forum_$move_topic_from/$topic_id.topic","$simpleforum_dir/forum_$move_topic_to/$topic_id.topic");
# after moving, go back to the forum you were visiting
print redirect("$script_name?fid=$move_topic_from");
}
sub edit {
if (!param('posted')) {
&page_start;
open (EDIT, "< $simpleforum_dir/forum_$forum_id/$topic_id.topic") or dienice("Couldn't open topic for editing. Refresh the forum and try again.");
$edit_content = join '', ;
close EDIT;
if ($edit_content =~ /(.*)((.*?)$edit_id<\/time>(.*?)<\/post>)(.*)/s) {
$edit_content = $2;
if ($edit_content =~ /(.*?)<\/name>/s) { $edit_name = $1; $edit_user = $1; }
if ($edit_content =~ /(.*?)<\/ip>/s) { $edit_ip = $1; }
if ($edit_content =~ /(.*?)<\/email>/s) { $edit_email = $1; }
if ($edit_content =~ /(.*?)<\/message>/s) { $edit_message = $1; }
if ($edit_content =~ /(.*?)<\/subject>/s) { $edit_subject = $1; }
if ($edit_name eq $user) { # user editing his own post
$edit_name = $user_name;
$edit_posts = $user_posts;
$edit_title = $user_title;
$edit_avatar = $user_avatar;
} else { # administrator/moderator editing someone else's post
if (-e "$users_dir/$edit_name.prf") { # if it's a registered user, get his info
open (PRF, "< $users_dir/$edit_name.prf") or dienice("Couldn't open the user's profile: $!");
flock PRF, 2;
while() {
if (/(.*?)<\/user_name>\n/s) { $edit_name = $1; }
if (/(.*?)<\/user_posts>\n/s) { $edit_posts = $1; }
if (/(.*?)<\/user_avatar>\n/s) { $edit_avatar = $1; }
if (/(.*?)<\/user_title>/s) { $edit_title = $1; }
}
close PRF;
} else { # if it's a guest, just set the title to "Guest"
$edit_title = "Guest";
}
}
if (!$edit_title) { # set the automatic title if no special title is set for this user
if ($edit_posts < $title_lvl2_posts) { $edit_title = $title_lvl1; }
elsif ($edit_posts < $title_lvl3_posts) { $edit_title = $title_lvl2; }
elsif ($edit_posts < $title_lvl4_posts) { $edit_title = $title_lvl3; }
elsif ($edit_posts < $title_lvl5_posts) { $edit_title = $title_lvl4; }
elsif ($edit_posts < $title_lvl6_posts) { $edit_title = $title_lvl5; }
elsif ($edit_posts) { $edit_title = $title_lvl6; }
}
}
&date_time($edit_id);
# # # # HTML # # # #
print " ";
print <$lang_edit
<$smallfont>$lang_posted_on $short_date $hour:$min:$sec$ampm
$lang_back
HTML
# # # END HTML # # #
&page_end;
} elsif ($admin_access or ($user eq param('edit_user') and $author_edit eq "on")) {
#User authorized, edit topic
$message = param('message');
$subject = param('subject');
if (!$message or !$subject) {
&page_start;
print "";
if (!$subject) { print "You have not entered a subject \n"; }
if (!$message) { print "You have not entered a message \n"; }
print "$lang_back ";
&page_end;
exit;
}
open(EDIT, "+>> $simpleforum_dir/forum_$forum_id/$topic_id.topic") or dienice("Couldn't open topic for writing: $!");
flock EDIT, 2;
seek EDIT, 0, 0;
$edit_content = join '', ;
if ($edit_content =~ /(.*)((.*?)$edit_id<\/time>(.*?)<\/post>)(.*)/s) {
$edit_post = $2;
$edit_post =~ s/(.*?)<\/subject>/$subject<\/subject>/s;
$edit_post =~ s/(.*?)<\/message>/$message\n<\/message>/s;
}
$edit_content =~ s/(.*)((.*?)$edit_id<\/time>(.*?)<\/post>)(.*)/$1$edit_post$5/s;
seek EDIT, 0, 0;
truncate EDIT, 0;
print EDIT $edit_content;
close EDIT;
print redirect("$script_name?fid=$forum_id");
} else {
&page_start; print "$lang_not_authorized "; &page_end;
}
}
sub admin {
# I. Forum Config
# 1. General
# 2. Look & Feel
# 3. Attachments
# 4. Mail Settings
# 5. Change Admin Password
# 6. Reset Forum Config
#
# II. Forum Administration
# 1. Add/Edit/Delete Forums
# 2. Delete Topics
# 3. Manage Attachments
#
# III. User Administration
# 1. User Permissions
# 2. User Titles
# 3. Delete Users
# 4. Ban Users
if ($admin_access) {
if (param('admin_action') =~ /^1_(\d*)$/) {
# Forum Configuration
$admin_sub_action = $1;
&forum_configuration;
} elsif (param('admin_action') =~ /^2_(\d*)$/) {
# Forum Administration menu
$admin_sub_action = $1;
&forum_administration;
} elsif (param('admin_action') =~ /^3_(\d*)$/) {
# User Administration menu
$admin_sub_action = $1;
&user_administration;
} elsif (param('blockip')) {
&add_ipblock;
} else {
&page_start;
print <
$lang_administration_area
Forum Configuration
Forum Administration
User Administration
HTML
}
} else {
&page_start;
print <
$lang_administration_area
You are not authorized!
HTML
}
}
sub forum_configuration {
# This sub takes care of all the actions in the Forum Configuration menu in the Administrator Area
# Depending on the value of $admin_sub_action we know what exactly the user wants to do.
# Possible values for $admin_sub_action
# 1 = General
# 2 = Look & Feel
# 3 = Attachments
# 4 = Mail Settings
# 5 = (none)
# 6 = Reset Forum Settings
if ($admin_sub_action == 1 and !param('posted')) {
# General
if ($html_protection eq "on") { $htmlon = " SELECTED"; } else { $htmloff = " SELECTED"; }
if ($show_email_addresses eq "on") { $showmailon = " SELECTED"; } else { $showmailoff = " SELECTED"; }
if ($bbcode eq "on") { $bbcodeon = " SELECTED"; } else { $bbcodeoff = " SELECTED"; }
if ($smileys eq "on") { $smileyson = " SELECTED"; } else { $smileysoff = " SELECTED"; }
if ($hoursystem == 12) { $twelveon = " SELECTED"; } else { $twentyfouron = " SELECTED"; }
if ($date_notation eq "mmddyy") { $mmddyyon = " SELECTED"; } elsif ($date_notation eq "ddmmyy") { $ddmmyyon = " SELECTED"; } elsif ($date_notation eq "yymmdd") { $yymmddon = " SELECTED"; }
if ($author_edit eq "on") { $authediton = " SELECTED"; } else { $autheditoff = " SELECTED"; }
&page_start;
print <
$lang_administration_area
<$smallfont>Forum Configuration
HTML
} elsif ($admin_sub_action == 2 and !param('posted')) {
# Look & Feel
if ($menu_display eq "set1") { $set1_on = "SELECTED"; } elsif ($menu_display eq "set2") { $set2_on = "SELECTED"; } else { $menu_display_text_on = "SELECTED"; }
if ($topic_index_statistics eq "yes") { $topic_index_statistics_on = "SELECTED"; } else { $topic_index_statistics_off = "SELECTED"; }
&page_start;
print <
$lang_administration_area
<$smallfont>Forum Configuration
HTML
} elsif ($admin_sub_action == 3 and !param('posted')) {
# Attachments
$tmp_attachments_uploadmax = $attachments_uploadmax/1024000;
if ($allow_attachments eq "yes") { $allow_attachments_on = " SELECTED"; } else { $allow_attachments_off = " SELECTED"; }
&page_start;
print <
$lang_administration_area
<$smallfont>Forum Configuration
HTML
} elsif ($admin_sub_action == 4 and !param('posted')) {
# Mail Settings
if ($admin_email_notify eq "on") { $admin_email_notify_on = " SELECTED"; } else { $admin_email_notify_off = " SELECTED"; }
if ($mail eq "on") { $mailon = " SELECTED"; } else { $mailoff = " SELECTED"; }
if ($show_email_addresses eq "on") { $showmailon = " SELECTED"; } else { $showmailoff = " SELECTED"; }
&page_start;
print <
$lang_administration_area
<$smallfont>Forum Configuration
HTML
} elsif ($admin_sub_action == 6) {
# Reset Forum Settings
&page_start;
print "$lang_administration_area
<$smallfont>Forum Configuration
\n";
if (param('sent')) {
#reset the settings by deleting the config file
unlink "$simpleforum_dir/simpleforum.conf";
print <
Reset Forum Settings
Forum Settings Reset!
HTML
} else {
#doublecheck if this is what the user wants to do
print "
Reset Forum Settings
This will discard all your forum settings specified in \"Forum Configuration\" and reset them to their defaults. Resetting the Forum will not delete topic data.
Are you sure you want to do this?
";
}
}
if (param('posted')) {
# Write the new configuration to the simpleforum.conf file (For ALL subcathegories of the "Forum Configuration Menu
if ($admin_sub_action == 1) { @variables = ("images_dir","title","subtitle","home_name","home_url","hour_difference","hoursystem","date_notation","html_protection","bbcode","smileys","author_edit","topics_per_page","posts_per_page","popularnumb","language"); }
elsif ($admin_sub_action == 2) { @variables = ("backgroundcolor","backgroundimage","menu_display","topic_index_statistics","tablecolor1","tablecolor2","tablecolor3","tablebordercolor","tablewidth","postformbackground","fontface","fontsize","fontsizesmall","fontcolor","link_color","visited_link_color","link_hover_color"); }
elsif ($admin_sub_action == 3) { @variables = ("attachments_dir","attachments_url","allow_attachments","attachments_uploadmax"); }
elsif ($admin_sub_action == 4) { @variables = ("mail","admin_email","mailprog","admin_email_notify","show_email_addresses"); }
open(CONF, "+>> $simpleforum_dir/simpleforum.conf") or dienice("Couldn't open conf file");
flock CONF, 2;
seek CONF, 0, 0;
$conf_content = join '',
;
seek CONF, 0, 0;
truncate CONF, 0;
foreach $variable (@variables) {
$variable_value = param($variable);
if ($variable eq "attachments_uploadmax") { $variable_value = $variable_value * 1024000; }
if ($conf_content =~ /$variable:(.*?)\n/s) {
$conf_content =~ s/$variable:(.*?)\n/$variable:$variable_value\n/sg;
} else {
$conf_content .= "$variable:$variable_value\n";
}
}
print CONF $conf_content;
close CONF;
print redirect("$script_name?fid=$forum_id&admin=1");
}
}
sub forum_administration {
if ($admin_sub_action == 1) {
# Add/Edit/Delete Forums
&page_start;
print "$lang_forum_administration ";
if (param('posted')) {
if (param('action') eq "addforum") {
#add a forum
$i = "01";
while (!$directory_made) {
if (!-e "$simpleforum_dir/forum_$i") {
#create new directory for this forum
$directory_made = $i;
} else { $i++; }
}
$forum_name = param('forum_name');
$forum_more = param('forum_more');
$forum_perm = param('forum_perm');
$forum_pass = param('forum_pass');
$forum_mods = join "\|", param('forum_mods');
if ($forum_pass) { $forum_pass = encrypt($forum_pass); }
$new_topic_dir = "forum_$directory_made";
mkdir("$simpleforum_dir/$new_topic_dir",0777) or dienice("Could not create the topic directory: $! \n Set the permissions for the SimpleForum directory ($simpleforum_dir) to 777 (chmod 777 $simpleforum_dir). This means that user, group and everyone must have read/write/execute access for the simpleforum-directory ");
open(INFO, "> $simpleforum_dir/$new_topic_dir/forum.info") or dienice("Couldn't create forum.info: $!");
flock INFO, 2;
print INFO <$forum_name
$forum_more
$forum_pass
$forum_perm
$forum_mods
INFO
close INFO;
print <
<$smallfont>Add Forum
New Forum "$forum_name" Created!
HTML
} elsif (param('action') eq "editforum") {
open_dir($simpleforum_dir);
foreach $file(sort(@files)) {
if ($file =~ /^(forum_(\d*))$/) {
$fid = $2;
$tdir = $1;
if (param("forum_name_$tdir") and param("forum_more_$tdir")) {
$forum_name = param("forum_name_$tdir");
$forum_more = param("forum_more_$tdir");
$forum_mods = join "\|", param("forum_mods_$tdir");
if (param("forum_pass_$tdir") eq 'none') {
$forum_pass = "";
} elsif (param("forum_pass_$tdir") eq "") {
$forum_pass = param("forum_pass_old_$tdir");
} else {
$forum_pass = encrypt(param("forum_pass_$tdir"));
}
$forum_perm = param("forum_perm_$tdir");
open(INFO, "+>> $simpleforum_dir/forum_$fid/forum.info") or dienice("Couldn't open forum.info: $!");
flock INFO, 2;
seek INFO, 0, 0;
$info_content = join '', ;
seek INFO, 0, 0;
truncate INFO, 0;
print INFO <$forum_name<\/forum_name>
$forum_more<\/forum_more>
$forum_pass<\/forum_pass>
$forum_perm<\/forum_perm>
$forum_mods<\/forum_mods>
CONTENT
close INFO;
}
}
}
# Forum Order change
foreach $file(sort(@files)) {
if ($file =~ /^(forum_(\d*))$/) {
$fid = $2;
$tdir = $1;
if (param("forum_order_$tdir") ne $fid) {
# We need to be absolutely sure that forums don't get overwritten. Therefore we test the numbers.
$chg_to = param("forum_order_$tdir");
foreach $taken_number(@taken_numbers) {
if ($taken_number eq $chg_to) {
dienice("You have the same forum number twice! Please select unique forum numbers for each forum.Back ");
}
}
push @taken_numbers, $chg_to;
if (param("forum_order_forum_$chg_to") eq $chg_to) {
dienice("You have the same forum number twice! Please select unique forum numbers for each forum.Back ");
} else {
$chg .= ";$fid->$chg_to;";
}
}
}
}
# All systems GO for forum order change
while ($chg =~ /;(\d*?)->(\d*?);/sg) {
$chg_from = $1;
$chg_to = $2;
rename("$simpleforum_dir/forum_$chg_from","$simpleforum_dir/tmp_forum_$chg_to");
}
open_dir($simpleforum_dir);
foreach $file(@files) {
if ($file =~ /^tmp_forum_(\d*)$/) {
$fid = $1;
rename("$simpleforum_dir/$file","$simpleforum_dir/forum_$fid");
}
}
print <
<$smallfont>Edit Forums
Forum Info Updated!
HTML
} elsif (param('action') eq "deleteforum") {
$forum_delete = param('deleteforum');
if (param('confirmed') eq "yes") {
opendir(DEL, "$simpleforum_dir/$forum_delete") or dienice("Couldn't open $forum_delete: $!");
@delfiles = readdir DEL;
closedir DEL;
foreach $delfile(@delfiles) {
if ($delfile ne '.' and $delfile ne '..') {
unlink "$simpleforum_dir/$forum_delete/$delfile" or dienice("Couldn't delete $delfile: $!");
}
}
rmdir "$simpleforum_dir/$forum_delete" or dienice("Couldn't delete $forum_delete: $!");
&edit_statistics_file; #Reset the statistics
print <
<$smallfont>Delete Forum
Forum Deleted!
HTML
exit;
}
if (!param('deleteforum')) { print " You haven't selected a Forum to deleteBack "; exit; }
($tdir,$forum_name) = split(/\|/,$forum_delete);
print <Delete Forum
Are you sure you want to delete \"$forum_name\"?
This action cannot be undone!
Click \"Delete\" if you want to delete $forum_name
HTML
}
} else {
open_dir($simpleforum_dir);
foreach $file(sort(@files)) {
if ($file =~ /^(forum_(\d*))$/) {
$amount_of_forums++; #count the forums for later (forum order form)
push @forum_dirs, $file;
}
}
print <Add/Edit/Delete Forums
HTML
}
} elsif ($admin_sub_action == 2) {
# Delete Topics and Messages
&page_start;
print "$lang_administration_area ";
#get all the topic files
open_dir($topic_dir);
@topics = @files;
#filter the topic files from the files in topic_dir
foreach $tpc(@topics) {
if ($tpc =~ /(.*?).topic$/s) {
($mtime) = (stat("$topic_dir/$tpc")) [9];
push @lastmodifiedtopics, "$mtime\|$tpc";
}
}
@topics = ();
foreach $lastmodifiedtopic(reverse(sort(@lastmodifiedtopics))) {
$lastmodifiedtopic =~ s/(.*?)\|(.*?).topic/$2.topic/s;
push @topics, $lastmodifiedtopic;
}
if (param('posted')) {
#Delete the selected topics
foreach $topic(@topics) {
if ($topic =~ /(.*?).topic$/sg) {
if (param($1)) {
unlink "$topic_dir/$1.topic";
$reset_stats = 1;
}
}
}
if ($reset_stats) { &edit_statistics_file; } #reset the stats file
#Delete replies in topics
#"refresh" @topics
opendir(TOPICS, $topic_dir) or dienice("Couldn't open $topic_dir: $!");
@topics = readdir TOPICS;
closedir TOPICS;
foreach $topic(reverse(sort(@topics))) {
if ($topic =~ /(.*?).topic$/sg) {
$param = "delreplies$1";
if (param($param)) {
#The user wants to delete replies in this topic
$topic_id = $1;
if (!$open_form) {
print "<$smallfont>Edit & Delete Replies // Block IP's<\/font><\/p>
";
$open_form = 1;
}
&delete_replies_form;
}
}
}
if ($open_form) {
print " <\/FORM>\n";
} else {
print "
<$smallfont>Delete Topics
Selected Topics Deleted!
";
}
} elsif (param('delrepliesposted')) {
#delete the selected REPLIES
foreach $topic(@topics) {
if ($topic =~ /(.*?).topic$/sg) {
$topic_id = $1;
if (param($topic_id)) {
@time = param($topic_id);
foreach $time(@time) {
open(TOPIC,"+>> $topic_dir/$topic_id.topic") or dienice("Couldn't open $topic_id.topic: $!");
flock TOPIC,2;
seek TOPIC, 0, 0;
$topic_text = join '', ;
seek TOPIC, 0, 0;
truncate TOPIC, 0;
$topic_text =~ s/^(.*)(.*?)$time<\/time>(.*?)<\/post>(.*)$/$1$4/s;
print TOPIC $topic_text;
close TOPIC;
&edit_statistics_file("msg_amount--");
#if the user deleted the only post left in a topic, delete the topic
if ($topic_text !~ //s) { unlink "$topic_dir/$topic_id.topic"; &edit_statistics_file("tpc_amount--"); }
}
}
}
}
print "
<$smallfont>Delete Topics and Replies
Selected Topics and Replies Deleted!
";
} else {
print <<$smallfont>Delete Topics & Replies
<$smallfont>Tick the topics you want to delete in the
RED column
Tick the topics in which you want to delete replies in the
ORANGE column
If you want to block an IP from someone who posted in a specific topic, also tick the
ORANGE column
$lang_subject
$lang_author
$lang_last_post
HTML
#open, read and print topic content
foreach $topic(@topics) {
if ($topic =~ /(.*?).topic$/sg) {
$topic_id = $1;
#open the topic
open(TOPIC,"< $topic_dir/$topic") or dienice("Couldn't open $topic_dir/$topic : $!");
$topic_content = join '', ;
close TOPIC;
#get necessary content
if ($topic_content =~ /(.*?)<\/name>/s) {
$topic_name = $1;
}
if ($topic_content =~ /(.*?)<\/subject>/s) {
$topic_subject = $1;
}
if ($topic_content =~ /(.*)(.*?)<\/time>(.*?)$/s) {
$topic_time = $2;
}
#find out how many replies on the topic
while ($topic_content =~ //sg) {
$topic_replies++;
}
$topic_replies--;
if (!$topic_replies) {
$topic_replies = undef;
} elsif ($topic_replies == 1) {
$topic_replies = "- $topic_replies $lang_reply";
} else {
$topic_replies = "- $topic_replies $lang_replies";
}
#print the shiz :)
date_time($topic_time);
$topic_subject = add_html($topic_subject);
# # # # HTML # # # #
print <
$topic_subject $topic_replies
$topic_name
<$smallfont>$short_date $hour:$min:$sec $ampm
HTML
# # # END HTML # # #
}
}
# # # # HTML # # # #
print <
HTML
# # # END HTML # # #
}
} elsif ($admin_sub_action == 3) {
# Manage Attachments
if (!param('posted')) {
&page_start;
print <
$lang_administration_area
<$smallfont>Attachments
Attachment
Size
HTML
opendir(DIR, $attachments_dir);
@files = readdir DIR;
closedir (DIR);
foreach $attachment(@files) {
if ($attachment ne ".." and $attachment ne ".") {
($attachment_size) = (stat("$attachments_dir/$attachment")) [7];
$attachment_size_total += $attachment_size;
if ($attachment_size >= 1024000) {
$attachment_size = sprintf("%.2f",($attachment_size/1024000))."Mb";
} else {
$attachment_size = sprintf("%.2f",($attachment_size/1024))."kb";
}
$attachment_printed = 1;
print <
$attachment
$attachment_size
HTML
}
}
if (!$attachment_printed) {
#no attachment was printed
print <
There are currently no attachments
HTML
}
if ($attachment_size_total >= 1024000) {
$attachment_size_total = sprintf("%.2f",($attachment_size_total/1024000))."Mb";
} else {
$attachment_size_total = sprintf("%.2f",($attachment_size_total/1024))."kb";
}
print <
<$smallfont>Total Attachment Size: $attachment_size_total
HTML
} else {
@del_attachments = param('del_attachments');
foreach $del_attachment(@del_attachments) {
unlink "$attachments_dir/$del_attachment" or dienice("Couldn't delete $del_attachment!");
}
&page_start;
print <$lang_administration_area
<$smallfont>Attachments
The selected attachments have been deleted!
HTML
}
} elsif ($admin_sub_action = 4) {
#censorships
if (!param('posted')) {
&page_start;
print <
$lang_administration_area
<$smallfont>Forum Administration
HTML
} else {
# Write the new configuration to the simpleforum.conf file (For ALL subcathegories of the "Forum Configuration Menu
@variables = ("censored_words");
open(CONF, "+>> $simpleforum_dir/simpleforum.conf") or dienice("Couldn't open conf file");
flock CONF, 2;
seek CONF, 0, 0;
$conf_content = join '', ;
seek CONF, 0, 0;
truncate CONF, 0;
foreach $variable (@variables) {
$variable_value = param($variable);
if ($conf_content =~ /$variable:(.*?)\n/s) {
$conf_content =~ s/$variable:(.*?)\n/$variable:$variable_value\n/sg;
} else {
$conf_content .= "$variable:$variable_value\n";
}
}
print CONF $conf_content;
close CONF;
print redirect("$script_name?fid=$forum_id&admin=1");
}
}
}
sub user_administration {
# This sub takes care of all the actions in the User Administration menu in the Administrator Area
# Depending on the value of $admin_sub_action we know what exactly the user wants to do.
# Possible values for $admin_sub_action
# 1 = User Permissions
# 2 = User Titles
# 3 = Delete Users
# 4 = Ban Users
# 5 = Register Users
if ($admin_sub_action == 1) {
if (!param('posted')) {
# User Permissions Form
if ($guest_access eq "on") { $guest_access_on = "SELECTED"; } elsif ($guest_access eq "off") { $guest_access_off = "SELECTED"; } elsif ($guest_access eq "read-only") { $guest_access_read_only = "SELECTED"; }
if ($enable_private_messages eq "on") { $enable_private_messages_on = "SELECTED"; } else { $enable_private_messages_off = "SELECTED"; }
if ($enable_guest_registration eq "on") { $enable_guest_registration_on = "SELECTED"; } else { $enable_guest_registration_off = "SELECTED"; }
&page_start;
print <
$lang_administration_area
<$smallfont>User Permissions
HTML
} else {
@new_administrators = param('administrator_access');
open(CONF, "+>> $simpleforum_dir/simpleforum.conf") or dienice("Couldn't open simpleforum.conf: $!");
flock CONF, 2;
seek CONF, 0, 0;
$conf_content = join '', ;
seek CONF, 0, 0;
truncate CONF, 0;
$new_administrators = join "\|", @new_administrators;
if ($new_administrators) { $conf_content =~ s/admin_account:(.*?)\n/admin_account:$new_administrators\n/s; }
print CONF $conf_content;
close CONF;
# part of the writing to the configuration files is also done below
}
} elsif ($admin_sub_action == 2 and !param('posted')) {
# User Titles Form
&page_start;
if ($enable_user_titles eq "on") { $enable_user_titles_on = "SELECTED"; } else { $enable_user_titles_off = "SELECTED"; }
print <
$lang_administration_area
<$smallfont>User Titles
USER TITLES
User Titles
<$smallfont>Turn user titles on or off
On Off
Automatic User Titles
<$smallfont>Depending on how many posts a user has made on your forum, his "title" will change. You can set the user titles and the amount of posts required to obtain a certain title here.
Manual User Titles
<$smallfont>If a user requires a custom title (e.g. "Administrator", "Member", ...) you can set this here. Users without a custom title will receive the automatic title (see above).
HTML
} elsif ($admin_sub_action == 3) {
# Delete Users
if (!param('confirm_delete')) {
# Print the delete users form
&page_start;
print <
$lang_administration_area
<$smallfont>Delete Users
Check the box next to the user(s) you want to delete and press "Delete Selected Users".
HTML
open_dir($users_dir);
#filter out the profiles and store them in @user_profiles
foreach (@files) {
if (/^.*?\.prf$/) {
push @user_profiles, $_;
}
}
# $delete_amount contains the number of files in $users_dir
$delete_amount = $#user_profiles + 1;
print " \n";
# according to $delete_amount we can calculate the dimensions of the table which contains the users
$table_cols = 4; # colums
$table_rows = int($delete_amount/$table_cols); # rows
if ($table_rows != ($delete_amount/$table_cols)) { $table_rows++; } # (example: 4.3333 must be rounded to 5 instead of 4)
$table_cell_width = int(600/$table_cols); # width of a cell
# print the table containing the user list
print "
HTML
} else {
# Delete the selected users
# $delete_amount is the amount of param's to check (see expl. above)
$delete_amount = param('delete_amount');
for ($i = 1; $i <= $delete_amount; $i++) {
if (param($i)) {
$delete_user = param($i);
if (-e "$users_dir/$delete_user.prf") { unlink "$users_dir/$delete_user.prf"; }
if (-e "$users_dir/private_messages/$delete_user\_in.pmsg") { unlink "$users_dir/private_messages/$delete_user\_in.pmsg"; }
if (-e "$users_dir/private_messages/$delete_user\_out.pmsg") { unlink "$users_dir/private_messages/$delete_user\_out.pmsg"; }
}
}
# redirect back to admin area
print redirect("$script_name?fid=$forum_id&admin=1");
exit;
}
} elsif ($admin_sub_action == 4) {
# Ban Users
if (!param('posted')) {
# Ban Users Form
&page_start;
print <
$lang_administration_area
<$smallfont>Ban Users
HTML
} else {
# The user that will be banned
$ban_user = param('ban_user');
# The time the ban expires
$ban_expires = time + (param('ban_duration_1') * param('ban_duration_2'));
# Open target's profile and set and get
open(PRF, "+>> $users_dir/$ban_user\.prf") or dienice("Couldn't open profile: $!");
flock PRF, 2;
seek PRF, 0, 0;
$prf_content = join '', ;
seek PRF, 0, 0;
truncate PRF, 0;
if ($prf_content =~ /(.*?)<\/user_ban>\n/s) {
$prf_content =~ s/(.*?)<\/user_ban>\n/$ban_expires<\/user_ban>\n/s;
} else {
$prf_content .= "$ban_expires<\/user_ban>\n";
}
if ($prf_content =~ /(.*?)<\/user_ip>/) { $ban_ip = $1; }
print PRF $prf_content;
close PRF;
# Open the ipban file and set the banned IP's to prevent this user from accessing the forum using another account
open (IPBAN, ">> $simpleforum_dir/blocked_ips.conf") or dienice("Couldn't open ipban file: $!");
flock IPBAN, 2;
print IPBAN <$ban_ip$ban_expires
BAN
close IPBAN;
# Redirect back to admin area
print redirect("$script_name?fid=$forum_id&admin=1");
exit;
}
} elsif ($admin_sub_action == 5) {
# register users
®ister;
}
if (param('posted')) {
# Write the new configuration to the simpleforum.conf file (For ALL subcathegories of the "Forum Configuration Menu
if ($admin_sub_action == 1) { @variables = ("guest_access","enable_private_messages","enable_guest_registration"); }
elsif ($admin_sub_action == 2) { @variables = ("enable_user_titles","title_lvl1","title_lvl2","title_lvl3","title_lvl4","title_lvl5","title_lvl6","title_lvl2_posts","title_lvl3_posts","title_lvl4_posts","title_lvl5_posts","title_lvl6_posts"); }
open(CONF, "+>> $simpleforum_dir/simpleforum.conf") or dienice("Couldn't open conf file");
flock CONF, 2;
seek CONF, 0, 0;
$conf_content = join '', ;
seek CONF, 0, 0;
truncate CONF, 0;
foreach $variable (@variables) {
$variable_value = param($variable);
if ($variable eq "attachments_uploadmax") { $variable_value = $variable_value * 1024000; }
if ($conf_content =~ /$variable:(.*?)\n/s) {
$conf_content =~ s/$variable:(.*?)\n/$variable:$variable_value\n/sg;
} else {
$conf_content .= "$variable:$variable_value\n";
}
}
print CONF $conf_content;
close CONF;
print redirect("$script_name?fid=$forum_id&admin=1");
# Change the manual user titles in the profiles
if (param('change_manual_titles')) {
# Set the new user titles in the profiles
open_dir($users_dir);
foreach (@files) {
if (/^(.*?)\.prf$/) {
$profile_title = param($1);
open PRF, "+>> $users_dir/$_" or dienice("Couldn't open $_: $!");
flock PRF, 2;
seek PRF, 0, 0;
$profile_text = join '', ;
seek PRF, 0, 0;
truncate PRF, 0;
$profile_text =~ s/(.*?)<\/user_title>\n/$profile_title<\/user_title>\n/sg;
print PRF $profile_text;
close PRF;
}
}
}
}
}
sub delete_replies_form {
#first we open the specific topic
open(TOPIC,"< $topic_dir/$topic_id.topic") or dienice("Couldn't open $topic_dir/$topic_id.topic");
$topic_content = join '', ;
close TOPIC;
if ($topic_content =~ /(.*?)<\/subject>/s) { $topic_title = $1; }
# # # # HTML # # # #
print <
TOPIC: $topic_title
HTML
# # # END HTML # # #
#get necessary content and print it
while ($topic_content =~ /(.*?)<\/post>/sg) {
$post_content = $1;
if ($post_content =~ /(.*?)<\/name>/sg) {
$post_name = $1;
}
if ($post_content =~ /(.*?)<\/ip>/sg) {
$post_ip = $1;
}
if ($post_content =~ /(.*?)<\/email>/sg) {
$post_email = $1;
}
if ($post_content =~ /(.*?)<\/subject>/sg) {
$post_subject = $1;
}
if ($post_content =~ /(.*?)<\/time>/sg) {
$post_time = $1;
}
if ($post_content =~ /(.*?)<\/message>/sg) {
$post_message = $1;
}
$post_subject = add_html($post_subject); #add smileys, images, url's, ...
$post_message = add_html($post_message); #add smileys, images, url's, ...
#This line takes care of the color switching
if ($tablecolor eq $tablecolor1) { $tablecolor = $tablecolor2; } else { $tablecolor = $tablecolor1; }
#This line adds the link to the email address to the Author's name
if ($post_email) {
if ($post_email =~ /\@/s) { $post_email = "mailto:$post_email"; } else { $blanktarget = "target='_blank'"; }
$post_name = "$post_name ";
}
#Make $post_time "readable" ;)
date_time($post_time);
#Here we print ONE post from the entire topic, in a loop (while)
# # # # HTML # # # #
print <
<$smallfont>$lang_posted_on $short_date $hour:$min:$sec$ampm
$lang_author:
$post_name
IP:
$post_ip Block this IP
Subject:
$post_subject
$lang_message:
$post_message
HTML
# # # END HTML # # #
}
}
sub add_ipblock {
$blockip = param('blockip');
open (IPBAN, "+>> $simpleforum_dir/blocked_ips.conf") or dienice("$! Make sure that the dir $simpleforum_dir has its permissions set to 777");
flock IPBAN, 2;
print IPBAN "$blockip\n";
close IPBAN;
print " $blockip has been blocked";
}
sub search {
if (param('posted')) {
$searchkey = param('searchkey');
$searchfor = param('searchfor');
$searchforums = param('searchforums');
$searchcase = param('searchcase');
$searchtimespan = param('searchtimespan');
if (!$searchkey) { print "$lang_you_must_enter_a_search_key"; return; }
if (length($searchkey) < 3) { print "Search key must contain at least 3 characters "; return; }
@searchchars = split(//,$searchkey);
foreach $char(@searchchars) {
if ($char =~ /\W/) { if ($char ne "\ ") { $bad_chars = 1; } }
}
if ($bad_chars) { print "Bad search phrase `$searchkey'. Please do not use commas or non-alphanumeric characters. "; return; }
if ($searchforums eq 'all') {
open_dir($simpleforum_dir);
foreach $file(@files) {
if ($file =~ /^(forum_\d*)$/) { push @searchforums, $1; }
}
} else {
push @searchforums, $searchforums;
}
#search only in files greater than the current time minus one day/week/...
if ($searchtimespan eq "all") { $searchtimespan = time; }
$searchtimespan = time - $searchtimespan;
foreach $forum_dir(@searchforums) {
open_dir("$simpleforum_dir/$forum_dir");
foreach $topic(@files) {
if ($topic =~ /^(\d*?).topic$/) {
$topic_time = $1;
if ($topic_time ge $searchtimespan) {
open(TPC, "< $simpleforum_dir/$forum_dir/$topic_time.topic") or dienice("couldn't open a topic: $!");
$tpc_content = join '', ;
close TPC;
if ($searchcase eq "insensitive") {
$tpc_content =~ tr/[A-Z]/[a-z]/;
$searchkey =~ tr/[A-Z]/[a-z]/;
}
while ($tpc_content =~ /(.*?)<\/post>/sg and !$found) {
$tpc_post_content = $1;
if ($searchfor eq "post") {
if ($tpc_post_content =~ /(.*?)$searchkey(.*?)<\/subject>/s) {
#match subject
push @results, "$forum_dir/$topic";
$found = 1;
} elsif ($tpc_post_content =~ /(.*?)$searchkey(.*?)<\/message>/s) {
#match message body
push @results, "$forum_dir/$topic";
$found = 1;
}
} elsif ($searchfor eq "author") {
if ($tpc_post_content =~ /(.*?)$searchkey(.*?)<\/name>/s) {
#match author
push @results, "$forum_dir/$topic";
$found = 1;
}
}
}
$found = "";
}
}
}
}
if (@results) {
@topics = @results;
&print_topic_list;
} else {
print "$lang_no_matches $lang_back ";
}
} else {
# Print the search form
# # # # HTML # # # #
print <<$smallfont>» $lang_forum_index $frm_lnk » $lang_search
<$smallfont>$lang_searching_will_take_a_while
HTML
# # # END HTML # # #
}
}
sub help {
#The Help section
# # # # HTML # # # #
print <<$smallfont>» $lang_forum_index $frm_lnk » $lang_help
$lang_help
$lang_smileys
BBCode
<$smallfont>$lang_bbcode_expl
<$smallfont>[b]bold[/b]
<$smallfont>bold
<$smallfont>[u]underline[/u]
<$smallfont>underline
<$smallfont>[i]italic[/i]
<$smallfont>italic
<$smallfont>[center]center[/center]
<$smallfont>center
<$smallfont>[justify]justify[/justify]
<$smallfont>justify
<$smallfont>[right]right[/right]
<$smallfont>right
<$smallfont>[color:red]red text[/color]
<$smallfont>red text
<$smallfont>[h6]h6 header[/h6]
<$smallfont>h6 header
<$smallfont>[pre]text[/pre]
<$smallfont>text
<$smallfont>[img://www.domain.com/w00t.gif]
<$smallfont>
<$smallfont>[quote]Text[/quote]
<$smallfont>Quote:\n \« Text \»
<$smallfont>[url=http://www.domain.com] My Site[/url]
<$smallfont>My Site
$lang_post_icons
<$smallfont>
- $lang_help_regular_topic
- $lang_help_newregular_topic
- $lang_help_popular_topic
- $lang_help_newpopular_topic
HTML
# # # END HTML # # #
}
sub print_emoticon_table {
if ($smileys eq "on") {
print <
HTML
}
}
sub select_a_forum {
if (!$select_a_forum) {
open_dir($simpleforum_dir);
$select_a_forum = <
« $lang_select_forum »
<\/option>
$lang_forum_index
HTML
foreach $file(sort(@files)) {
if ($file =~ /^(forum_(\d*))$/) {
$forum_dir = $1;
$fid = $2;
open(INFO, "< $simpleforum_dir/$forum_dir/forum.info") or dienice("Couldn't open $simpleforum_dir/$forum_dir/forum.info: $!");
$forum_info = join '', ;
close INFO;
if ($forum_info =~ /(.*?)<\/forum_name>/s) { $forum_name = add_html($1); }
if ($forum_info =~ /(.*?)<\/forum_more>/s) { $forum_more = add_html($1); }
$select_a_forum .= <» $forum_name
HTML
}
}
$select_a_forum .= <
HTML
}
return $select_a_forum;
}
sub currently_online {
if ($user eq "guest") { $guest_ip = $ENV{'REMOTE_ADDR'}; }
open (FC, "+>> $simpleforum_dir/stats.sf") or dienice("couldn't open stats file: $!");
flock FC, 2;
seek FC, 0, 0;
$fc_text = join '',;
seek FC, 0, 0;
truncate FC, 0;
#write to stats file
if ($fc_text =~ /(.*?)<\/recentusers>/s) {$recent_users = $1;} else {$fc_text .= "<\/recentusers>\n";}
@recent_users = split('\\|',$recent_users);
foreach $ruser(@recent_users) {
chomp $ruser;
if ($ruser =~ /^(.*):(.*?)$/) {
if (($1 ne $user and $1 ne "guest($guest_ip)") and (time-$2) < 360) {
$newrecent_users = "$ruser|$newrecent_users";
}
}
}
if ($user ne "guest") {
$newrecent_users = "$user:".time."|$newrecent_users";
} else {
$newrecent_users = "$user($guest_ip):".time."|$newrecent_users";
}
$fc_text =~ s/(.*?)<\/recentusers>/$newrecent_users<\/recentusers>/sg;
#print to forum
@newrecent_users = split('\\|',$newrecent_users);
foreach $ruser(@newrecent_users) {
if ($ruser =~ /^(.*?):(\d*?)$/ and $1 and $1 !~ "guest\((.*?)\)") {
open(PROFILE, "< $users_dir/$1\.prf");
$profile_text = join '', ;
close PROFILE;
$seenuser = $1;
$seentime = $2;
if ($profile_text =~ /(.*?)<\/user_name>/) { $online_name = $1; }
if ((time - $seentime) > 240) { $ocolor = "#DF0000"; }
elsif ((time - $seentime) > 120) { $ocolor = "#E77E52"; }
else { $ocolor = "#5F8563"; }
if ($comma) { $currently_online .= ", ";}
$currently_online .= "$online_name ";
$comma = 1;
} elsif ($ruser =~ /^guest\((.*?)\):(.*?)$/) {
$guestcount++;
}
}
if ($guestcount) {
if ($comma) { $currently_online .= ", "; } if ($guestcount > 1) {$guest_s = $lang_guests; } else { $guest_s = $lang_guest; }
$currently_online .= "$guestcount $guest_s \n\n";
}
print FC $fc_text;
close FC;
}
sub statistics {
if ($topic_index_statistics eq "yes") {
open(STATS, "< $simpleforum_dir/stats.sf") or &edit_statistics_file;
$stats_content = join '', ;
if ($stats_content =~ /(\d*)<\/tpc_amount>/s) { $tpc_amount = $1; } else { $reset_stats = 1; }
if ($stats_content =~ /(\d*)<\/msg_amount>/s) { $msg_amount = $1; } else { $reset_stats = 1; }
if ($stats_content =~ /(\d*)<\/usr_amount>/s) { $usr_amount = $1; } else { $reset_stats = 1; }
close STATS;
if ($reset_stats) { &edit_statistics_file; }
date_time(time);
print <
<$smallfont>$title - $lang_forum_statistics
<$smallfont>- $lang_current_forum_date_and_time: $full_date $ampm
- $lang_stats1 $tpc_amount $lang_stats2 $msg_amount $lang_stats3
- $lang_stats4 $usr_amount $lang_stats5
- $lang_currently_online: $currently_online
HTML
}
}
sub edit_statistics_file {
$action = join '', @_;
if ($action =~ /^(.*?)(..)$/ and -e "$simpleforum_dir/stats.sf") {
$action = $1;
$increase_or_decrease = $2;
open(STATS, "+>> $simpleforum_dir/stats.sf");
flock STATS, 2;
seek STATS, 0, 0;
$stats_content = join '',;
if ($stats_content =~ /<$action>(\d*)<\/$action>/s) {
if ($increase_or_decrease eq "++") {
$amount = $1 + 1;
} elsif ($increase_or_decrease eq "--") {
$amount = $1 - 1;
}
$stats_content =~ s/<$action>(\d*)<\/$action>/<$action>$amount<\/$action>/s;
}
seek STATS, 0, 0;
truncate STATS, 0;
print STATS $stats_content;
close STATS;
return;
}
# RESET the stats file (-> check msg_amount and tpc_amount) if no action is given
if (-e "$simpleforum_dir/stats.sf") {
open(STATS, "< $simpleforum_dir/stats.sf");
$stats_content = join '',;
close STATS;
if ($stats_content =~ /(\d*)<\/usr_amount>/s) {
$usr_amount = $1;
}
}
open_dir($simpleforum_dir);
@sffiles = @files;
foreach $sffile(@sffiles) {
if ($sffile =~ /forum_(\d*)/s) {
open_dir("$simpleforum_dir/$sffile");
@topics = @files;
foreach $topic(@topics) {
if ($topic =~ /(\d*).topic/s) {
$tpc_amount++;
open(TPC, "< $simpleforum_dir/$sffile/$topic") or dienice("Couldn't open topic: $!");
$tpc_content = join '', ;
while ($tpc_content =~ /(.*?)<\/post>/sg) {
$msg_amount++;
}
close TPC;
}
}
}
}
if (!$usr_amount) { $usr_amount = 1; }
if (!$tpc_amount) { $tpc_amount = 0; }
if (!$msg_amount) { $msg_amount = 0; }
open(STATS, "> $simpleforum_dir/stats.sf") or dienice("Couldn't create statistics file: $!");
flock STATS, 2;
print STATS <$tpc_amount
$msg_amount
$usr_amount<\/usr_amount>
STATS_CONTENT
close STATS;
}
sub register {
# Register new users
if ($enable_guest_registration eq "off" and !$admin_access) { &page_start; print "Registrations have been turned off by the forum administrator$lang_back "; &page_end; exit; }
if (param('confirmed')) {
# User registered, print confirm message
&page_start;
print <$lang_register
Your account has been created!
Please write your password down somewhere safe. Lost passwords cannot be retrieved. Click \"$lang_personal\" in the top menu to configure the forum to your liking.
$lang_forum_index
HTML
&page_end;
} elsif (!param('posted')) {
# Print the register form
&page_start;
print <$lang_register
<$smallfont>$lang_register_expl
HTML
&page_end;
} else {
# Verify the input and write the new user profile + Login (set sfusr cookie)
$register_user = param('register_user');
$register_password = param('register_password');
$register_password_confirm = param('register_password_confirm');
$profile_file = $register_user;
$profile_file =~ tr/[A-Z]/[a-z]/;
if ($register_password eq $register_password_confirm) {
if (length($register_password) > 3) {
#check passw value for incorrect characters
if ($register_password =~ /\W/) {
#illegal character found
dienice("Illegal character for your password, please use alphanumeric characters only!Back ");
}
} else {
#empty password or less than 4 chars
dienice("The password must contain at least 4 charactersBack ");
}
} else {
#passw don't match
dienice("The 2 given passwords don't match, please enter your password twice the sameBack ");
}
if (!$register_user or !$register_password) { dienice("You forgot to enter a user name or a password$lang_back "); }
$register_password = encrypt($register_password);
if (-e "$users_dir/$profile_file.prf") { dienice("This user already exists! Please choose a different name.$lang_back "); }
open(PROFILE, "> $users_dir/$profile_file.prf") or dienice("Couldn't create profile: $!");
flock PROFILE, 2;
$register_time = time;
$register_ip = $ENV{'REMOTE_ADDR'};
print PROFILE <$register_user
|$register_ip|
$register_password
$register_time
1
0
PRF_CONTENT
close PROFILE;
# log in after registration, except when this user was created by the administrator
if (!$admin_access) {
$cookie = cookie(-name => 'sfusr',
-value => "$profile_file\|$register_password");
print "Set-Cookie: $cookie\n";
}
# remove the user from the Currently Online in stats
open (STATS, "+>> $simpleforum_dir/stats.sf") or dienice("Couldn't open stats file: $!");
flock STATS, 2;
seek STATS, 0, 0;
$stats_content = join '', ;
seek STATS, 0, 0;
truncate STATS, 0;
$stats_content =~ s/(.*?)$user\:\d*?\|(.*?)<\/recentusers>/$1$2<\/recentusers>/sg;
print STATS $stats_content;
close STATS;
# redirect admins to admin area and users to their profile
if ($admin_access) {
print redirect("$script_name?&fid=$forum_id&admin=1");
} else {
print redirect("$script_name?user_settings=1");
}
}
}
sub login {
$login_referer = param('ref');
if (!param('posted')) {
# print the login form
if (!$header_printed) { &page_start; }
print <
$lang_log_in
$lang_login_expl
HTML
if (!$header_printed) { &page_end; }
} else {
# verify user login input and login => set sfusr cookie
$user = param('user');
$user_password_input = param('user_password');
$login_referer = param('login_referer');
if (!$user or !$user_password_input) {
dienice("You forgot to enter your name or password$lang_back ");
}
$user =~ tr/[A-Z]/[a-z]/;
$user_password_input = encrypt($user_password_input);
open(USER_PROFILE, "< $users_dir/$user\.prf") or $error = 1;
flock USER_PROFILE, 2;
@user_profile_content = ;
close USER_PROFILE;
foreach $line (@user_profile_content) {
chomp $line;
if ($line =~ /^<(.*?)>(.*?)<\/(.*?)>$/) {
$$1 = $2;
}
}
if ($user_password_input ne $user_password) { $error = 1; }
if ($error) { dienice("You specified an invalid user name or password$lang_back "); }
if (param('remember_login')) {
$login_time = param('remember_login');
$cookie = cookie(-name => 'sfusr',
-value => "$user\|$user_password",
-expires => $login_time);
} else {
$cookie = cookie(-name => 'sfusr',
-value => "$user\|$user_password");
}
print "Set-Cookie: $cookie\n";
$login_referer =~ s/\$/\&/sg;
# remove the "guest" from the Currently Online visit
open (STATS, "+>> $simpleforum_dir/stats.sf") or dienice("Couldn't open stats file: $!");
flock STATS, 2;
seek STATS, 0, 0;
$stats_content = join '', ;
seek STATS, 0, 0;
truncate STATS, 0;
$stats_content =~ s/(.*?)guest\($ENV{'REMOTE_ADDR'}\)\:\d*?\|(.*?)<\/recentusers>/$1$2<\/recentusers>/sg;
print STATS $stats_content;
close STATS;
print redirect("$login_referer");
}
}
sub logout {
# Log out => empty the sfusr cookie
$cookie = cookie(-name => 'sfusr',
-value => "");
print "Set-Cookie: $cookie\n";
# remove the user from the Currently Online in stats
open (STATS, "+>> $simpleforum_dir/stats.sf") or dienice("Couldn't open stats file: $!");
flock STATS, 2;
seek STATS, 0, 0;
$stats_content = join '', ;
seek STATS, 0, 0;
truncate STATS, 0;
$stats_content =~ s/(.*?)$user\:\d*?\|(.*?)<\/recentusers>/$1$2<\/recentusers>/sg;
print STATS $stats_content;
close STATS;
print redirect("$script_name");
}
sub user_settings {
# user settings
if (!$logged_in) { dienice("You're not logged in"); }
if (param('user_profile')) {
if (!param('posted')) {
#print the edit profile form
&page_start;
open(FC, "< $simpleforum_dir/stats.sf") or die "Could not open stats: $!";
$fc_text = join '', ;
close FC;
if ($fc_text =~ /(.*?)<\/msg_amount>/ and $1) {
$forum_totalposts = $1;
$percent_of_total = sprintf("%.2f",($user_posts/$forum_totalposts)*100);
$posts_per_day = sprintf("%.2f",($user_posts/((time - $user_joindate)/86400)));
$forumstats = "<$smallfont>[$percent_of_total% $lang_of_total / $posts_per_day $lang_posts_per_day]";
}
if ($user_hide_email eq "yes") { $user_hide_email_on = "CHECKED"; }
print <<$smallfont>» $lang_forum_index $frm_lnk » $lang_personal » $lang_my_profile
HTML
&page_end;
} else {
# edit the user's profile file
open(USER_PROFILE, "+>> $users_dir/$user\.prf") or dienice("Couldn't open your profile for writing!");
flock USER_PROFILE, 2;
seek USER_PROFILE, 0, 0;
$user_profile_content = join '', ;
# get and change the values for the user variables
@user_profile_vars = ("user_email","user_hide_email","user_icq","user_aol","user_msn","user_yahoo","user_avatar","user_realname","user_location","user_website","user_occupation","user_interests");
foreach $user_profile_var(@user_profile_vars) {
$user_profile_var_value = param($user_profile_var);
if ($user_profile_content =~ /<$user_profile_var>(.*?)<\/$user_profile_var>\n/s) {
$user_profile_content =~ s/<$user_profile_var>(.*?)<\/$user_profile_var>\n/<$user_profile_var>$user_profile_var_value<\/$user_profile_var>\n/sg;
} else {
$user_profile_content .= "<$user_profile_var>$user_profile_var_value<\/$user_profile_var>\n";
}
}
seek USER_PROFILE, 0, 0;
truncate USER_PROFILE, 0;
# set http:// before the user_website if necessary:
if ($user_profile_content =~ /(.*?)<\/user_website>\n/ and $1 and $1 !~ /^http:\/\//sg) { $user_profile_content =~ s/(.*?)<\/user_website>\n/http:\/\/$1<\/user_website>\n/sg; }
print USER_PROFILE $user_profile_content;
close USER_PROFILE;
print redirect("$script_name?user_settings=1");
exit;
}
} elsif (param('user_prefs')) {
# user preferences
if (!param('posted')) {
# print user preferences form
&page_start;
print <<$smallfont>» $lang_forum_index $frm_lnk » $lang_personal » My Settings
HTML
&page_end;
}
}
sub private_messages {
# This sub handles everything that has to do with private messaging
if ($enable_private_messages eq "off") { &page_start; print "The Private Messaging feature has been disabled by the administrator$lang_back "; &page_end; exit; }
$pmsg_dir = "$users_dir/private_messages"; # This is the directory where the date files are stored
# $box (as defined in the line below) is the "place" where you are inside the private messaging system. It can be either the Inbox or the Outbox or Send Message ("box")
if (param('outbox')) { $box = $lang_outbox; } elsif (param('send_pmsg') or param('sendto')) { $box = $lang_send_message } else { $box = $lang_inbox }
if (!param('del')) {
# print the header for all private messages pages (except when deleting, because the delete part uses a redirect)
# This is the "header" for all the private messages pages
&page_start;
if (param('user_settings')) { $user_settings = param('user_settings'); $user_settings_lnk = " » $lang_personal "; }
#print private messages menu
print "$lang_private_messages <$smallfont>$lang_inbox - $lang_outbox - $lang_send_message ";
print "<$smallfont>
» $lang_forum_index $frm_lnk $user_settings_lnk » $lang_private_messages » $box ";
}
if (param('send_pmsg') or param('sendto')) {
# For sending new private messages
if (!param('posted')) {
# print the send private message form
# param sendto (if it exists) contains the recipient
if (param('sendto')) { $pmsg_recipient = param('sendto'); }
print <
HTML
} else {
# form is submitted; send the message
# check input
$pmsg_recipient = param('pmsg_recipient');
$pmsg_subject = param('pmsg_subject');
$pmsg_message = param('message');
if (!$pmsg_recipient) { $err .= "- select a recipient \n"; }
if (!$pmsg_subject) { $err .= "- enter a subject \n"; }
if (!$pmsg_message) { $err .= "- enter a message \n"; }
if ($err) { print "Message could not be sent. You forgot to \n \n$lang_back "; exit;}
# create pmsg dir if it doesn't already exist
if (!-e $pmsg_dir) { mkdir($pmsg_dir, 0777); }
#open recipient's private messages file and write the new private message (1), dito for outbox of the sender (2)
$pmsg_message .= "\n";
# 1 - Write to recipient's inbox file
open(PMSG,"+>> $pmsg_dir/$pmsg_recipient\_in.pmsg") or die "Couldn't open $pmsg_recipient_in.pmsg";
flock PMSG, 2;
seek PMSG, 0, 0;
$pmsg_text = join '', ;
seek PMSG, 0, 0;
truncate PMSG, 0;
$pmsg_time = time;
print PMSG <
no
$user
$pmsg_time
$pmsg_subject
$pmsg_message
PMSG
print PMSG $pmsg_text;
close PMSG;
# 2 - Write to the sender's outbox file
open(PMSG_OUTBOX,"+>> $pmsg_dir/$user\_out.pmsg") or die "Couldn't open $user_out.pmsg";
flock PMSG_OUTBOX, 2;
seek PMSG_OUTBOX, 0, 0;
$pmsg_outbox_text = join '', ;
seek PMSG_OUTBOX, 0, 0;
truncate PMSG_OUTBOX, 0;
print PMSG_OUTBOX <
$pmsg_recipient
$pmsg_time
$pmsg_subject
$pmsg_message
PMSG
print PMSG_OUTBOX $pmsg_outbox_text;
close PMSG_OUTBOX;
# open the recipient's profile and reset the private messages popup
open (PRFP, "+>> $users_dir/$pmsg_recipient.prf") or dienice("Couldn't open $pmsg_recipient.prf:$!");
flock PRFP,2;
seek PRFP, 0, 0;
$prfp_text = join '', ;
seek PRFP, 0, 0;
truncate PRFP, 0;
if ($prfp_text =~ /(.*?)<\/user_pmsg_popped>\n/s) {
$prfp_text =~ s/(.*?)<\/user_pmsg_popped>\n/no<\/user_pmsg_popped>\n/s;
} else {
$prfp_text .= "no<\/user_pmsg_popped>\n";
}
print PRFP $prfp_text;
close PRFP;
# print a message to ensure the sender that the private message has been sent (and nothing went wrong)
$pmsg_subject = add_html($pmsg_subject); # add html, smileys, bbcode, ...
$pmsg_message = add_html($pmsg_message);
print <
$lang_subject
$pmsg_subject
$lang_message
$pmsg_message
HTML
}
} elsif (param('del')) {
# Delete a private message from inbox or outbox
# set the file in which the message should be deleted, either the inbox file, else the outbox file
if (param('outbox')) { $pmsg_file = "$user\_out.pmsg"; $outbox = param('outbox'); } # outbox file
else { $pmsg_file = "$user\_in.pmsg"; } # inbox file
# The $del_id variable is based on the time when the to-be-deleted-private-message
# was sent. We scan the content of the pmsg and remove the pmsg matching the del_id.
$del_id = param('del');
open(PMSG, "+>> $pmsg_dir/$pmsg_file") or dienice("$pmsg_file: $1");
flock PMSG, 2;
seek PMSG, 0,0;
$pmsg_text = join '', ;
seek PMSG, 0,0;
truncate PMSG, 0;
$pmsg_text =~ s/^(.*)\n.*?\n$del_id<\/pmsg_time>\n.*?<\/pmsg>\n(.*)$/$1$2/sg;
print PMSG $pmsg_text;
close PMSG;
$user_settings = param('user_settings');
# redirecting the user to the inbox or outbox depending on where he came from
print redirect("$script_name?fid=$forum_id&pmsg=1&user_settings=$user_settings&outbox=$outbox");
exit;
} else {
# INBOX & OUTBOX - This will print out all Private Messages in the inbox OR in the outbox
# open private messages file for this user
# Set the file from which to read the messages; either inbox or outbox
if (param('outbox')) { $pmsg_file = "$user\_out.pmsg"; $outbox = param('outbox'); } # outbox file
else { $pmsg_file = "$user\_in.pmsg"; } # inbox file
# open and get the contents from the private messages file
open(PMSG, "+>> $pmsg_dir/$pmsg_file");
flock PMSG, 2;
seek PMSG, 0, 0;
$pmsg_text = join '', ;
$new_pmsg_text = $pmsg_text;
# mark every unread message as read
$new_pmsg_text =~ s/no<\/pmsg_read>\n/yes<\/pmsg_read>\n/sg;
seek PMSG, 0, 0;
truncate PMSG, 0;
print PMSG $new_pmsg_text;
close PMSG;
# The while loop below goes through every private message one by one, parsing and printing the data
while ($pmsg_text =~ /\n(.*?)<\/pmsg>\n/sg) {
$pmsg_printed = 1; # if the private messages file contains one message (and thus prints one message), we disable the "No messages" note.
$pmsg = $1;
# parse the private message (in the loop)
if ($pmsg =~ /(.*?)<\/pmsg_sender>\n/s) { $pmsg_sender = $1; }
if ($pmsg =~ /(.*?)<\/pmsg_read>\n/s) { $pmsg_read = $1; }
if ($pmsg =~ /(.*?)<\/pmsg_time>\n/s) { $pmsg_time = $1; }
if ($pmsg =~ /(.*?)<\/pmsg_subject>\n/s) { $pmsg_subject = $1; }
if ($pmsg =~ /(.*?)<\/pmsg_message>\n/s) { $pmsg_message = $1; }
# reset vars
$pmsg_user = ""; $pmsg_avatar = ""; $pmsg_title = ""; $pmsg_posts = ""; $pmsg_status = "";
# check whether the sender of the message is a registered user
if (-e "$users_dir/$pmsg_sender\.prf") {
$pmsg_sender;
# This is a registered user! Get his avatar, name, post-amount, ...
open(PMSG_PROFILE, "< $users_dir/$pmsg_sender\.prf");
flock PMSG_PROFILE, 2;
$pmsg_profile = join '', ;
close PMSG_PROFILE;
if ($pmsg_profile =~ /(.*?)<\/user_name>\n/s) {
$pmsg_name = "$1 ";
}
if ($pmsg_profile =~ /(.*?)<\/user_avatar>\n/s) {
$pmsg_avatar = $1;
}
if ($pmsg_profile =~ /(.*?)<\/user_posts>\n/s) {
$pmsg_posts = $1;
}
if ($pmsg_profile =~ /(.*?)<\/user_title>\n/s) {
$pmsg_title = $1;
}
} else {
$pmsg_title = $lang_guest;
}
$pmsg_subject = add_html($pmsg_subject); #add smileys, images, url's, ...
$pmsg_message = add_html($pmsg_message);
#This line takes care of the color switching
if ($tablecolor eq $tablecolor1) { $tablecolor = $tablecolor2; } else { $tablecolor = $tablecolor1; }
#Make $pmsg_time "readable" ;)
date_time($pmsg_time);
# determine the user's title
if (!$post_title and $enable_user_titles eq "on") {
if ($post_posts < $title_lvl2_posts) { $post_title = $title_lvl1; }
elsif ($post_posts < $title_lvl3_posts) { $post_title = $title_lvl2; }
elsif ($post_posts < $title_lvl4_posts) { $post_title = $title_lvl3; }
elsif ($post_posts < $title_lvl5_posts) { $post_title = $title_lvl4; }
elsif ($post_posts < $title_lvl6_posts) { $post_title = $title_lvl5; }
elsif ($post_posts) { $post_title = $title_lvl6; }
}
# set the border color for new messages
if ($pmsg_read eq "no") { $borderstyle = "style='border-color:#FF0000;'"; } else { $borderstyle = ""; }
# print the shiz (one message in a loop)
print <<$smallfont>$lang_posted_on $short_date $hour:$min:$sec$ampm
<$bigfont>$pmsg_name
HTML
if ($pmsg_title and $enable_user_titles eq "on") { print " <$smallfont>$pmsg_title"; }
if ($pmsg_posts) { print " <$smallfont>$lang_posts: $pmsg_posts"; }
print <
<$smallfont>$lang_reply | Delete
HTML
if ($pmsg_avatar) { print " "; }
print <
<$bigfont>$pmsg_subject
$pmsg_message
HTML
}
if (!$pmsg_printed) {
# no messages in Inbox
print <
$lang_there_are_currently_no_messages_in_your $box.
\n
HTML
}
}
# print the page footer for every private messages page
&page_end;
}
# # # # DO NOT EDIT ANYTHING BELOW # # # # # # # # # # # # # # # # # #
sub installation {
if ($admin_account) { return undef; } #already installed
$admin_account = param('admin_account');
$admin_password = param('admin_password');
$admin_password1 = param('admin_password1');
$admin_password2 = param('admin_password2');
$images_dir = param('images_dir');
if (!param('step3b')) { # admin log in on installation complete, so don't print the normal headers!
print header . <
Simpleforum $version - Installation
Welcome to Simpleforum Pro $version!
In order to make this script work on your server there are a few steps you need to follow. Please read the instructions carefully!
HTML
}
if (param('step1')) {
if (param('step2')) {
if (param('step3a')) {
if (param('step3b')) {
#installation complete
# assign users directory location and create it if necessary
$users_dir = "$simpleforum_dir/users";
if (!-e $users_dir) {mkdir($users_dir,0777) or dienice("Couldn't create the users directory: $!");}
# write the administrator's profile
$profile_file = $admin_account;
$profile_file =~ tr/[A-Z]/[a-z]/;
if (-e "$users_dir/$profile_file.prf") { print "This user already exists! Please choose a different name.Back "; exit; }
open(PROFILE, "> $users_dir/$profile_file.prf") or dienice("Couldn't create profile: $!");
flock PROFILE, 2;
$register_time = time;
$register_ip = $ENV{'REMOTE_ADDR'};
$admin_password = encrypt($admin_password);
print PROFILE <$admin_account
|$register_ip|
$admin_password
$register_time
1
Administrator
0
PRF_CONTENT
close PROFILE;
# write the simpleforum.conf file
open(CONF, "> $simpleforum_dir/simpleforum.conf") or $die = 1;
if ($die) { print "Couldn't write the configuration to the $simpleforum_dir directory! ($!) Please make sure that you've set the permissions of this directory to 777 (or whatever fits for your webserver's configuration"; exit; }
flock CONF, 2;
print CONF < 'sfusr',
-value => "$profile_file\|$admin_password");
print "Set-Cookie: $cookie\n";
print header."
Simpleforum $version - Installation
Welcome to Simpleforum Pro $version!
Installation complete!
To configure your forum any further, go to the Admin area on your forum by clicking \"Admin\" in the top menu. Enjoy!Click here to enter your forum ";
exit;
} else { # step 3b
# add a slash (/) if necessary
if ($images_dir and $images_dir !~ /^(.*?)\/$/) { $images_dir .= "/"; } elsif (!$images_dir) { $images_dir = "$simpleforum_dir/images/"; }
print <Step 3 - Images!
If you can see the following image, click "Finish!", else click "Continue".
Image:
HTML
}
} else { # step 3a
if ($admin_account) {
while ($admin_account =~ /(\W)/sg) {
if ($1 ne ' ') {
print "Whoops! Illegal character(s) found in your user name, please use alphanumeric characters onlyBack "; exit;
}
}
$profile_file = $admin_account;
$profile_file =~ tr/[A-Z]/[a-z]/;
if (-e "$simpleforum_dir/users/$profile_file.prf") {
print "Whoops! This account already existsBack "; exit;
}
} else {
print "Whoops! You forgot to enter an account name!Back "; exit;
}
if ($admin_password1 eq $admin_password2) {
$admin_password = $admin_password1;
if (length($admin_password) > 3) {
#check passw value for incorrect characters
if ($admin_password !~ /\W/) {
print <Step 3 - Images!
If you can see the following image, click "Finish!", else click "Continue".
Image:
HTML
} else {
#illegal character found
print "Whoops! Incorrect value for the Administrator Password, please use alphanumeric characters only!Back "; exit;
}
} else {
#empty password or less than 4 chars
print "Whoops! The password must contain at least 4 charactersBack "; exit;
}
} else {
#passw don't match
print "Whoops! The 2 given passwords don't match, please enter the admin password twice the sameBack "; exit;
}
}
} else { # step 2
if (!$simpleforum_dir) { print "Whoops! No value given for the simpleforum files directoryBack "; exit; }
if (!-e $simpleforum_dir) { print "Whoops! Looks like the directory ($simpleforum_dir) could not be located! Please set the simpleforum_files directory in the right place, next to $script_name.Back "; exit; }
open(FILE, "> $simpleforum_dir/permissionscheck.txt") or $permissions_error = 1;
print FILE "Test";
close FILE;
if ($permissions_error) { print "Whoops! Could not write to the directory '$simpleforum_dir'. Please set the permissions for this directory to 777 (or whatever fits for your webserver's configuration).Back "; exit; }
open(FILE, "< $simpleforum_dir/permissionscheck.txt") or $permissions_error = 1;
close FILE;
if ($permissions_error) { print "Whoops! Could not read from the directory '$simpleforum_dir'. Please set the permissions for this directory to 777 (or whatever fits for your webserver's configuration).Back "; exit; }
unlink "$simpleforum_dir/permissionscheck.txt";
if (-e "$simpleforum_dir/simpleforum.conf") {
open(FILE, "+>> $simpleforum_dir/simpleforum.conf") or $permissions_error = 1;
close FILE;
if ($permissions_error) { print "Whoops! Your simpleforum.conf file is not readable by the script. This means you have somehow changed its owner/permissions. Please chmod the simpleforum.conf file (located in simpleforum_files) to 777 or whatever fits for your webserver's configuration. If this error keeps appearing, delete the simpleforum.conf file. Note that this will delete your former simpleforum settings. You can keep a copy of the simpleforum.conf file and open it with a texteditor to see the old values of your configuration.Back "; exit; }
}
print <Step 2 - The Administrator Account
This account will have the ability to configure and manage everything that is going on on your forum. You can assign multiple administrators later in the forum configuration, only one is required now.
The password must be at least 4 characters long and may contain only alphanumeric characters! Write your password down somewhere safe because it cannot be recovered when lost!
Password examples:
HTML
}
} else { # step 1
print <Step 1 - The SimpleForum Files directory
This directory, called "simpleforum_files", is the directory where SimpleForum will save all its data in.
The simpleforum_files directory came with the download and should be placed in the same directory you put $script_name and the permissions for this directory should be set to 777 (or whatever fits for your webserver's configuration).
If you have done this, click "Continue" and the script will test if the location is correct and if the permissions for this directory are set correctly.
HTML
}
print <
HTML
exit;
}
sub start {
#Don't edit anything here!
#standard operations
$qs = $ENV{'QUERY_STRING'};
$password = encrypt(param('password'));
$version = "4.0";
$script_name = $ENV{'SCRIPT_FILENAME'};
$script_name =~ s/^(.*)\/(.*?)$/$2/s;
if (-e "$simpleforum_dir/simpleforum.conf") {
open CONF, "$simpleforum_dir/simpleforum.conf" or dienice("Couldn't open simpleforum.conf for reading: $!");
while () {
if (/admin_account:(.*?)\n/) { $admin_account = $1; }
}
close CONF;
} else {
&installation;
}
if (!$admin_account or ($qs eq "installation" and !$admin_account)) { &installation; exit; }
&last_visit;
if (!$simpleforum_dir) { $error .= "the SimpleForum Files Directory is not set. To do this, open $script_name in a texteditor and follow the instructions written there. "; }
if ($error) { print header."Error Error - You got the forum running... BUT: $error"; exit;}
#if the simpleforum_dir does not exist
if (!-e $simpleforum_dir) { print header."Could not locate the SimpleForum Files directory: $! \n This directory, called simpleforum_files (default), came with the $script_name script and should be placed in the same directory where you put $script_name. Set its permissions to 777 (chmod 777 $simpleforum_dir). This means that user, group and everyone must have read/write/execute access for the simpleforum-directory ($simpleforum_dir) If you have done this, and it's still not working, check if your \$simpleforum_dir variable is set correctly in $script_name. (Default) Example: \$simpleforum_dir = \"simpleforum_files\"; "; exit; }
#default settings: do not edit these. They can all be edited from the admin area (on the forum in your browser)
#in case the conf file has not been created yet, these settings will apply to the forum
$images_dir = "$simpleforum_dir/images"; #images directory
$title = "SimpleForum $version"; #Title of your forum (example: John's Forum)
$subtitle = "W e l c o m e !"; #Subtitle that appears below the Title (see above) on the forum index
$home_name = "Home"; #Title of your homepage
$home_url = "http://simpleforum.go.dyndns.org"; #URL for your homepage
$hour_difference = 0; #If the server time is different from your local time. Can be a negative number as well. Expressed in hours. (example: 1, this will set the hour difference to +1 HOUR)
$hoursystem = "12"; #12 or 24 (12 will add AM and PM behind in hour notation)
$date_notation = "ddmmyy"; #Date notation: mmddyy (MM/DD/YY) or ddmmyy (DD/MM/YY)
$html_protection = "on"; #disable html in posts [on/off]
$bbcode = "on"; #allow bbcode [on/off]
$smileys = "on"; #add smileys
$author_edit = "on"; #allow the other to edit his post or not
$backgroundcolor = "#FFFFFF"; #The background color of the forum
$backgroundimage = "$images_dir/background.gif"; #If you want an image for background, specify the URL to the image (e.g. "http://www.domain.com/path/to/image.jpg")
$menu_display = "text"; #Display the menu as text or images
$tablecolor1 = "#E9E6E6"; #Table backgroundcolor 1
$tablecolor2 = "#D8D7D7"; #Table backgroundcolor 2
$tablecolor3 = "#F8F7F7"; #Table backgroundcolor 3
$tablebordercolor = "navy";
$tablewidth = "93%"; #Table width
$postformbackground = "#E9E6E6"; #Table background color for the post/reply form
$fontface = "verdana,arial"; #The font you want to use for your forum, note that the visitor must have the font installed on his computer. By adding a "," you can add a secondary font in case the visitor has not got the font installed (e.g. "arial, verdana"). Empty field will apply the standard font.
$fontsize = "9"; #The size of the font in general, this does not count for headers and such (example: 12, this will make the font size 12pt)
$fontsizesmall = "8"; #The font size of comments, less important text, ...
$fontcolor = "#555555"; #Will change the color for most text on your forum
$topics_per_page = 10; #Amount of topics shown in topic index
$posts_per_page = 20; #Amount of replies shown in a topic
$popularnumb = 15; #Amount of replies required to make a topic "Popular"
$link_color = "#6685CC"; #color of hyperlinks
$visited_link_color = "#6685CC"; #color of visited hyperlinks
$link_hover_color = "#CC6666"; #color when hovering mouse over hyperlinks
$language = "English"; #forum language
$mail = "on"; #activates the mail function of the forum. However, the sendmail program must be operational and the path to sendmail must be set correctly.
$mailprog = '/usr/sbin/sendmail'; #mail program, standard set to unix sendmail.
$show_email_addresses = "off"; #Show/Hide user's email addresses on the forum
$allow_attachments = "yes"; #attachments feature on/off
$attachments_dir = "$simpleforum_dir/attachments";
$attachments_uploadmax = "5120000"; #5 megabites max filesize for uploaded attachments
$guest_access = "read-only"; #allow guest access on your forum [on/read-only/off]
$title_lvl1 = "Level 1 User";
$title_lvl2 = "Level 2 User";
$title_lvl3 = "Level 3 User";
$title_lvl4 = "Level 4 User";
$title_lvl5 = "Level 5 User";
$title_lvl6 = "Level 6 User";
$title_lvl1_posts = "0";
$title_lvl2_posts = "64";
$title_lvl3_posts = "128";
$title_lvl4_posts = "256";
$title_lvl5_posts = "512";
$title_lvl6_posts = "1024";
$enable_user_titles = "on";
$enable_private_messages = "on";
$enable_guest_registration = "on";
#in case the conf file exists, get and modify the standard variables
open CONF, "$simpleforum_dir/simpleforum.conf" or dienice("Couldn't open simpleforum.conf for reading: $!");
while () {
chomp;
if (/^(.*?):(.*?)$/) { $$1 = $2; }
}
close CONF;
# define the font classes so that in the script we can use <$standardfont>,<$smallfont> and <$bigfont>
$bigsize = $fontsize + 1;
$standardfont = "font class='standardfont'";
$smallfont = "font class='smallfont'";
$bigfont = "font class='bigfont'";
if (!$images_dir) { $images_dir = "$simpleforum_dir/images"; } else { $images_dir =~ s/\/$//s; }
if (!$attachments_dir) { $attachments_dir = "$simpleforum_dir/attachments"; } else { $attachments_dir =~ s/\/$//s; }
if (!$attachments_url) { $attachments_url = $attachments_dir; }
# assign users directory location and create it if necessary
$users_dir = "$simpleforum_dir/users";
if (!-e $users_dir) {mkdir($users_dir,0777) or dienice("Couldn't create the users directory: $! Please contact the forum admin");}
$smileys_dir = "$images_dir/smileys";
$script_dir = url(-absolute=>1);
$script_dir =~ s/(.*)\/(.*?)$/$1\//;
if (!-e "$simpleforum_dir/languages/$language.pm") { print header."The language module ($language.pm) is not installed! Place this module that came with the official distribution of SimpleFroum in \"$simpleforum_dir/languages/\""; exit; }
require "$simpleforum_dir/languages/$language.pm";
&set_language_vars;
#check if the language files are updated
if (!$lang_page) { dienice("You haven't got the latest version of the language files installed. Please read the \"upgrade_readme.txt\" file that came with the download for more info. "); }
#Check banned IP's
&ipcheck;
#Get the current forum's info
if ($qs =~ /fid=(\d*)/) {
$forum_id = $1;
if ($forum_id) {
$topic_dir = "$simpleforum_dir/forum_$forum_id";
open(INFO, "< $topic_dir/forum.info") or dienice("Failed to open forum.info (fid=$forum_id): $! Could this be because you just deleted the requested forum?Back ");
$forum_info = join '', ;
close INFO;
if ($forum_info =~ /(.*?)<\/forum_name>/s) { $forum_name = add_html($1); }
if ($forum_info =~ /(.*?)<\/forum_more>/s) { $forum_more = add_html($1); }
if ($forum_info =~ /(.*?)<\/forum_pass>/s) { $forum_pass = $1; }
if ($forum_info =~ /(.*?)<\/forum_mods>/s) { $forum_mods = $1; }
$frm_lnk = " » $forum_name ";
}
}
#Check forum password
if (!&forumpassword_check) { exit; }
#get user information from profile OR if not logged in, get the remembered user name and email address
$cookie = cookie('sfusr');
if ($cookie =~ /^(.*?)\|(.*?)$/s) {
$cookie_user = $1;
$cookie_password = $2;
if (-e "$users_dir/$cookie_user\.prf") {
$user = $cookie_user; $logged_in = 1;
open(USER_PROFILE, "< $users_dir/$cookie_user\.prf") or dienice("Couldn't open profile: $!");
flock USER_PROFILE, 2;
@user_profile_content = ;
$user_profile_content = join '', @user_profile_content;
close USER_PROFILE;
if ($user_profile_content =~ /(.*?)<\/user_password>\n/s) {
$user_password = $1;
if ($cookie_password eq $user_password) {
foreach $line (@user_profile_content) {
chomp $line;
if ($line =~ /^<(user_.*?)>(.*?)<\/(user_.*?)>$/) {
# a single-line variable
$$1 = $2;
} elsif ($line =~ /^<(user_.*?)>(.*?)$/) {
# a multi-line variable
$var = $1;
if ($user_profile_content =~ /<$var>(.*?)<\/$var>\n/s) {
$$var = $1;
}
}
}
} else {
$user = "guest";
$cookie_name = "";
$cookie_email = $cookie_password;
$logged_in = "";
}
}
} else {
$user = "guest";
$cookie_name = $1;
$cookie_email = $2;
}
} else {
$user = "guest";
}
#access for guests denied when $guest_access eq "off"
if ($guest_access eq "off" and $user eq "guest" and $qs ne "register" and $qs !~ /^login(.*?)$/) {
&page_start;
print "Welcome to $title! ";
print "This Forum does not allow for unregistered users to be used. Please $lang_log_in or $lang_register in order to gain access to this Forum. \n";
&login;
&page_end;
exit;
}
# check if the user is an administrator
@admin_accounts = split(/\|/, $admin_account);
foreach $admin_account(@admin_accounts) {
if ($admin_account eq $user or $admin_account eq "unknown_admin") { $admin_access = 1; }
}
# check if the user is a forum moderator
@forum_moderators = split(/\|/, $forum_mods);
foreach $forum_moderator(@forum_moderators) {
if ($forum_moderator eq $user) { $moderator_access = 1; }
}
# add this user to the currently online list
¤tly_online;
# if this is a registered user: see whether the IP has changed.
# if the IP has changed, add it to the list of his IP's
if ($logged_in) {
while ($user_ip =~ /(\d*?\.\d*?\.\d*?\.\d*?)\|/sg and !$matching_ip) {
if ($ENV{'REMOTE_ADDR'} eq $1) { $matching_ip = 1; }
}
if (!$matching_ip) {
# add the ip to the list
$new_ip = $ENV{'REMOTE_ADDR'};
open (PRF, "+>> $users_dir/$user\.prf") or dienice("couldn't open $user\.prf");
flock PRF, 2;
seek PRF, 0, 0;
$profile_text = join '', ;
seek PRF, 0, 0;
truncate PRF, 0;
$profile_text =~ s/(.*?)<\/user_ip>\n/\|$new_ip$1<\/user_ip>\n/s;
print PRF $profile_text;
close PRF;
}
}
# check for new private messages
if ($user_pmsg_popped eq "no" and $logged_in) {
# there's a new message!
$onload = "onLoad=\"if (confirm('You have received a new Private Message.\\n\\nWould you like to see it now?') == true) { location='$script_name?fid=$forum_id&pmsg=1'; }\"";
open(PRF, "> $users_dir/$user.prf") or dienice("Could not open user profile");
flock PRF, 2;
# we already got the file's contents from parsing its values, so we print them again here, yet modified ($user_pmsg_popped = "yes")
$user_profile_content =~ s/no<\/user_pmsg_popped>\n/yes<\/user_pmsg_popped>\n/s;
print PRF $user_profile_content;
close PRF;
}
}
sub date_time {
#Don't edit anything here, unless you know what you're doing.
my($date_time) = @_;
($sec,$min,$hour,$mday,$mon,$year,$day,$yday,$isdst) = localtime($date_time + ($hour_difference *3600));
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mon < 10) { $mon = "0$mon"; }
if ($mday < 10) { $mday = "0$mday"; }
$mon++;
if (!@months or !@months_short or !@days) {
dienice("Incomplete language file!");
}
if ($hoursystem eq "12") {
if ($hour > 11) {
if ($hour > 12) {
$hour = $hour - 12;
}
$ampm = " PM";
} else {
$ampm = " AM";
}
}
$year += 1900;
$full_date = "$days[$day] $mday $months[$mon] $year @ $hour:$min:$sec";
$long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";
$date = "$mday $months_short[$mon] $year";
$year %= 100;
if ($year < 10) { $year = "0$year"; };
if ($date_notation eq "mmddyy") {
$short_date = "$mon/$mday/$year";
} else {
$short_date = "$mday/$mon/$year";
}
}
sub page_end {
#Credits are to be left untouched!! For the up to date "terms of use", see http://simpleforum.go.dyndns.org.
#feel free to *add* some text, just make sure that you leave a link to the simpleforum site
if (!$footer_printed) {
print " <\/body>\n\n<\/HTML>";
$footer_printed = 1;
}
}
sub write_to_topic {
#after submitting and verifying a message, write it to the appropriate topic file
$time = time;
$signature = &random_signature; # get a random signature if available
if (!$topic_id) { # if this is a new topic
$topic_id = $time;
edit_statistics_file("tpc_amount++");
}
if ($logged_in) { # set the status of the sender
$status = "registered";
} else {
$status = "guest";
}
#open topic for writing and write the reply data
open(TOPIC,"+>> $topic_dir/$topic_id.topic") or dienice("Couldn't open $topic_dir/$topic_id.topic: $! Make sure that you set the permissions for the directory \"$topic_dir\" to 777, as described in the readme!");
flock TOPIC, 2;
print TOPIC
#The following is NOT HTML, don't touch!
<
$name
$status
$ENV{'REMOTE_ADDR'}
$email
$subject
$time
$message\n
$signature<\/signature>
TOPIC_CONTENT
close TOPIC;
if (!$logged_in) {
$cookie = cookie(-name => 'sfusr',
-value => "$name\|$email",
-expires => '+365d');
print "Set-Cookie: $cookie\n";
}
edit_statistics_file("msg_amount++");
# update the profile (user_posts)
if ($logged_in) {
open(PROFILE, "+>> $users_dir/$user\.prf") or dienice("Your message has been sent, but the script could not update your profile: $!");
flock PROFILE, 2;
seek PROFILE, 0, 0;
$profile_content = join '', ;
if ($profile_content =~ /(\d*?)<\/user_posts>\n/s) {
$user_posts = $1 + 1;
$profile_content =~ s/(\d*?)<\/user_posts>\n/$user_posts<\/user_posts>\n/s;
}
seek PROFILE, 0, 0;
truncate PROFILE, 0;
print PROFILE $profile_content;
close PROFILE;
}
# Notify the administrator of this new post if the option is enabled
if ($admin_email and $admin_email_notify eq "on") { &admin_email_notify; }
# Send an email-reply if selected by sender
if (param('send_mail') and $mail = "on") { mail_post('email_reply'); }
# Subscribe to this post if selected by sender
if (param('subscribe') and $mail = "on") {
open(TOPIC,"+>> $topic_dir/$topic_id.topic");
flock TOPIC, 2;
seek TOPIC, 0, 0;
$topic_content = join '', ;
seek TOPIC, 0, 0;
while () {
if (/(.*?)<\/subscribe>\n/) {
$subscribe_tags_exist = 1;
$subscribed_users = $1."\|$user";
$topic_content =~ s/(.*?)<\/subscribe>\n/$subscribed_users<\/subscribe>\n/s;
}
}
seek TOPIC, 0, 0;
truncate TOPIC, 0;
if (!$subscribe_tags_exist) { # if the subscribe tags do not exist we must place them
print TOPIC "$user \n\n".$topic_content;
$subscribed_users = $user;
} else { # everything has been done above, just print the new data to the topic file
seek TOPIC, 0, 0;
truncate TOPIC, 0;
print TOPIC $topic_content;
}
close TOPIC;
}
# Send mails to subscribed users
if ($mail = "on") {
if (!$subscribed_users) { # get the subscribed users if we haven't already got them from above
open (TOPIC, "< $topic_dir/$topic_id.topic") or dienice("Couldn't open the topic for reading");
while () {
if (/(.*?)<\/subscribe>\n/) {
$subscribed_users = $1;
$stop_topic_scan2 = 1;
}
}
close TOPIC;
}
if ($subscribed_users) { # if at all anyone is subscribed, get the email addresses
@subscribed_users = split(/\|/, $subscribed_users);
foreach $subscribed_user(@subscribed_users) {
# get email address
$subscribed_user_email = undef;
open(PRF,"$users_dir/$subscribed_user.prf");
while () {
if (/(.*?)<\/user_email>\n/) {
$subscribed_user_email = $1;
}
}
close PRF;
# send the email
if ($subscribed_user_email and $subscribed_user ne $user) {
mail_post('subscribe');
}
}
}
}
}
sub admin_email_notify {
if ($mail ne "on") { return; } #for more security - don't execute this if the mail function isn't on
if (!$email) { $nomail = "no email address given"; }
$topic_url = param('topic_url');
$orig_message = param('message');
$subj = $subject;
if ($orig_message =~ /\[quoted\]..(.*?)\n\[\/quoted\]/s) {
$rquote = $1;
$rquote =~ s/\n/\n\>/sg;
$orig_message =~ s/\[quoted\](.*?)\[\/quoted\]/\> $rquote/s;
}
open (MAIL, "|$mailprog -t") or dienice("Can't access $mailprog! Please make sure your mailprogram is installed and that the path to your mailprogram is set correctly.\n The server returned this error: $!\n If the error is something like \"No such file or directory\" this means the path to your mailprog is incorrect. The administrator can set this path in Administrator area > Forum Configuration");
print MAIL "From: $admin_email ($title)\n";
print MAIL "To: $admin_email\n";
print MAIL "Reply-to: $from\n";
print MAIL "Subject: New Forum Message!\n\n";
print MAIL </sg;
$orig_message =~ s/\[quoted\](.*?)\[\/quoted\]/\> $rquote/s;
}
open (MAIL, "|$mailprog -t") or dienice("Can't access $mailprog! Please make sure your mailprogram is installed and that the path to your mailprogram is set correctly.\n The server returned this error: $!\n If the error is something like \"No such file or directory\" this means the path to your mailprog is incorrect. The administrator can set this path in Administrator area > Forum Configuration");
print MAIL "From: $from\n";
print MAIL "To: $recipient\n";
print MAIL "Reply-to: $from\n";
print MAIL "Subject: $subj\n\n";
print MAIL <The server returned this error: $!\n If the error is something like \"No such file or directory\" this means the path to your mailprog is incorrect. The administrator can set this path in Administrator area > Forum Configuration");
print MAIL "From: $from\n";
print MAIL "To: $recipient\n";
print MAIL "Reply-to: $from\n";
print MAIL "Subject: $subj\n\n";
print MAIL </>/sg;
}
#smileys
# hide smileys from http conversion
$smileys_dir =~ s|http://|smiley://|sg;
if ($smileys eq "on") {
$add_html =~ s~\>\;:\((\W)~ $1~sg;
$add_html =~ s~\>:\((\W)~ $1~sg;
$add_html =~ s~8\|(\W)~ $1~sg;
$add_html =~ s~o\.O(\W)~ $1~sg;
$add_html =~ s~\:blush\:(\W)~ $1~sg;
$add_html =~ s~8\)(\W)~ $1~sg;
$add_html =~ s~\:\'\((\W)~ $1~sg;
$add_html =~ s~\:cry\:(\W)~ $1~sg;
$add_html =~ s~\>\;\:\)(\W)~ $1~sg;
$add_html =~ s~\>\:\)(\W)~ $1~sg;
$add_html =~ s~\:dizzy\:(\W)~ $1~sg;
$add_html =~ s~\:erm\:(\W)~ $1~sg;
$add_html =~ s~L\.L(\W)~ $1~sg;
$add_html =~ s~l\.l(\W)~ $1~sg;
$add_html =~ s~\:D(\W)~ $1~sg;
$add_html =~ s~\^\.\^(\W)~ $1~sg;
$add_html =~ s~\:laugh\:(\W)~ $1~sg;
$add_html =~ s~\:\|(\W)~ $1~sg;
$add_html =~ s~\:geek\:(\W)~ $1~sg;
$add_html =~ s~\>\;\.\<\;(\W)~ $1~sg;
$add_html =~ s~\:\((\W)~ $1~sg;
$add_html =~ s~\:o(\W)~ $1~sg;
$add_html =~ s~\:O(\W)~ $1~sg;
$add_html =~ s~\:x(\W)~ $1~sg;
$add_html =~ s~\:X(\W)~ $1~sg;
$add_html =~ s~\:zzz\:(\W)~ $1~sg;
$add_html =~ s~\:\)(\W)~ $1~sg;
$add_html =~ s~\:p(\W)~ $1~sg;
$add_html =~ s~\:P(\W)~ $1~sg;
$add_html =~ s~\:S(\W)~ $1~sg;
$add_html =~ s~\:s(\W)~ $1~sg;
$add_html =~ s~\:w00t\:(\W)~ $1~sg;
$add_html =~ s~\:\?(\W)~ $1~sg;
$add_html =~ s~\:whistle\:(\W)~ $1~sg;
$add_html =~ s~\;\)(\W)~ $1~sg;
}
#Reply quote
$add_html =~ s~\[quoted\]..(.*?)\[/quoted\]~~s;
$add_html =~ s/\n/ \n/sg;
# hide the [url] tag from the general conversion of http://
$add_html =~ s|\[url=http://(.*?)\]|\[url=temp://$1\]|sg;
#convert URLs to HTML hyperlinks \\ Disabled ending chars: <>'(),"
$add_html =~ s/(http:\/\/(.*?))([\<\>\'\(\)\,\"\ \r\n])/\[url=$1\]$1\[\/url\]$3/g;
# reactivate the [url] tag
$add_html =~ s|\[url=temp://(.*?)\]|\[url=http://$1\]|sg;
# reactivate the smiley
$add_html =~ s|smiley://|http://|sg;
$smileys_dir =~ s|smiley://|http://|sg;
#convert Email addresses to HTML hyperlinks
$add_html =~ s/([\w\-\.]+\@[\w\-\.]+\.[\w\-]+)/$1<\/a>/g;
#bbcode
if ($bbcode eq "on") {
$add_html =~ s|\\\]|]|sg; # escape bbcode by typing \]
$add_html =~ s|\\\[|[|sg; # escape bbcode by typing \[
$add_html =~ s|\[quote\](.*?)\[\/quote\]|Quote:\n\« $1 \» |sg;
$add_html =~ s|\[url://(.*?)\](.*?)\[\/url\]| $2 |sg;
$add_html =~ s|\[url=(.*?)\](.*?)\[\/url\]|$2 |sg;
$add_html =~ s|\[b\](.*?)\[/b\]|$1 |sg;
$add_html =~ s|\[u\](.*?)\[/u\]|$1 |sg;
$add_html =~ s|\[center\](.*?)\[/center\]|$1
|sg;
$add_html =~ s|\[justify\](.*?)\[/justify\]|$1
|sg;
$add_html =~ s|\[right\](.*?)\[/right\]|$1
|sg;
$add_html =~ s|\[i\](.*?)\[/i\]|$1 |sg;
$add_html =~ s|\[color:(.*?)\](.*?)\[/color\]|$2 |sg;
$add_html =~ s|\[pre\](.*?)\[/pre\]|$1 |sg;
$add_html =~ s|\[code\](.*?)\[/code\]|$1
|sg;
$add_html =~ s|\[img://(.*?)\]| |sg;
$add_html =~ s|\[img:(.*?)\]| |sg;
for ($size=1;$size<7;$size++) {
$add_html =~ s/\[h$size\]//sg;
$add_html =~ s/\[\/h$size\]/<\/h$size>/sg;
}
}
return $add_html;
}
sub open_dir {
#open directories and put the filenames in @files
$dir = join '', @_;
opendir(DIR, $dir) or dienice("Couldn't open a directory: $dir: $!");
@files = readdir DIR;
closedir (DIR);
}
sub last_visit {
#lets the script know when you last visited the forum, if cookies are enabled
$newvisit = time;
$raw_cookie = cookie('sflvisited');
if ($raw_cookie =~ /^(\d*)\|(\d*)/s) {
$lastvisit = $1;
$oldvisit = $2;
}
if (($newvisit - $lastvisit) > 500 and $lastvisit) {
$oldvisit = $lastvisit;
$usr_count = 1;
}
#if the user first visits the forum (or when cookies are not enabled) we ignore the "New" posts
if (!$lastvisit) {
$oldvisit = $newvisit;
}
$cookie = cookie(-name => 'sflvisited',
-value => "$newvisit\|$oldvisit",
-expires => '+365d');
# write the cookie
if ($qs !~ /login/ and !$logged_in) { # do not write the cookie when logging in (in case the browser does not support double cookie-writing)
print "Set-Cookie: $cookie\n";
}
if ($usr_count) { edit_statistics_file("usr_amount++"); } #forumvisits + 1
}
sub forumpassword_check {
if (!$forum_pass or !$forum_id) { return 1; } #If there's no password set in config or forum_id is missing, we don't need to check any passwords...
$cookie = cookie('sfpwd');
@sfpwds = split(/\|/, $cookie);
foreach $sfpwd(@sfpwds) {
if ($sfpwd =~ /forum_$forum_id=(.*)/s) {
$cookie_pass = $1;
}
}
if (encrypt(param('forum_pass')) eq $forum_pass or $cookie_pass eq $forum_pass) {
if (!$cookie_pass) { #let the cookies remember the password
$cookie = cookie(-name => 'sfpwd',
-value => "$cookie\|forum_$forum_id=$forum_pass\|",
-expires => '+365d');
print "Set-Cookie: $cookie\n";
} elsif ($cookie_pass ne $forum_pass) { #after the password for a forum has been changed, we must change it in the cookies as well (if the user entered the new password correctly)
$cookie = cookie('sfpwd');
$cookie =~ s/forum_$forum_id=(.*?)\|/forum_$forum_id=$forum_pass\|/s;
$cookie = cookie(-name => 'sfpwd',
-value => "$cookie",
-expires => '+365d');
print "Set-Cookie: $cookie\n";
}
return 1; #password correct, move on
} else {
&page_start;
print <
$forum_name
$lang_enter_password
HTML
&page_end;
return undef;
}
}
sub ipcheck {
open (IPBAN, "+>> $simpleforum_dir/blocked_ips.conf") or return;
flock IPBAN, 2;
seek IPBAN, 0, 0;
while () {
if (/(.*?)<\/ip>(.*?)<\/expires>/) {
$banned_ips = $1; $ban_expires = $2;
if ($ban_expires < time) {
# expired ban
seek IPBAN, 0, 0;
$ipban_content = join '', ;
$ipban_content =~ s/$banned_ips<\/ip>$ban_expires<\/expires>\n//sg;
seek IPBAN, 0, 0;
truncate IPBAN, 0;
print IPBABN $ipban_content;
} else {
while ($banned_ips =~ /(\d*?\.\d*?\.\d*?\.\d*?)\|/) {
if ($ENV{'REMOTE_ADDR'} eq $1) {
# This user has been banned!
&page_start;
print "Access denied ";
&page_end;
exit;
}
}
}
}
}
close IBAN;
}
sub random_signature {
if ($user_sign1) { push @signatures, $user_sign1; }
if ($user_sign2) { push @signatures, $user_sign2; }
if ($user_sign3) { push @signatures, $user_sign3; }
if ($user_sign4) { push @signatures, $user_sign4; }
srand(time() ^ ($$ + ($$ << 15)) );
return $signatures[int(rand($#signatures+1))];
}
sub encrypt {
my $ipas = shift (@_);
$encpass = crypt ($ipas, SiMpLeFoRuM);
return $encpass;
}
sub dienice {
#Makes the script abort on failure, showing the error
$err = join '', @_;
if (!$header_printed) { &page_start; }
print "Whoops! ".$err." ";
&page_end;
exit;
}