(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



We no longer offer ftp downloads. If there is a file you need referenced here, please contact me by email and I will get it to you.

Simple FAQ Creator



This is a pair of programs to create and maintain a simple FAQ web page. The administrative inteface lets you add questions and answers, modify existing entries, and control the sort order. The simplest way to explain it is to show you the screens:


Simple FAQ Administration

Please choose:

Headers and Footers

New

Edit

Sort/Delete

Review


This is the main screen for administration. Review simply dumps out the FAQ as the users will see it. Headers and footers let you enter content that will appear before and after the FAQ entries.

When adding new content or editing, you also enter keywords that do not appear in the FAQ as displayed, but will be used for searching:


Simple FAQ Administration

Question:

Index keywords:

Answer:

FAQ means Frequently Asked Questions.






Note that HTML markup is allowed in the content.

Sorting is done simply by selecting the FAQ entry:


Select FAQ and click "Go" to sort or delete


After selecting the FAQ, this screen allows sorting or deletion. We require both checkboxes to be checked for a delete.
(How do I use this program?)

Delete (must check both)

Move UP DOWN Lines


That's about it. It's pretty simple, but effective.

Download faqadmin.pl

Download faq.pl (user interface)

Here's the code for the admin functions:

#!/usr/bin/perl
use CGI qw(:standard);
foreach $i (param) {
  foreach $j (param($i) ) {
    $$i=$j;
  }
}
dbmopen %list, "YOURDATAPATH/data/faqlist", 0700 or die "can't open faqlist";
dbmopen %data, "/YOURDATAPATH/faqdat", 0700 or die "can't open faqlist";
dbmopen %fkey, "/YOURDATAPATH/data/faqkeys", 0700 or die "can't open faqlist";
if (defined $posting) {
  posthead() if $posthead;
  postedit() if $postedit;
  postfaq() if $postfaq;
  mkhead() if $choice eq "Headers";
  editing() if $choice eq "Edit";
  newedit() if $choice eq "New";
  sortmesel() if $choice eq "Sort";
  sortmehow() if $sortit;
  sortme() if $sortnow;
  review() if $choice eq "Review";
  dbmclose %list;
  dbmclose %data;
  dbmclose %fkey;
  exit 0;
}

closeit();

sub newedit {
  $which="(New)";
  postedit();
}
sub closeit {
 main();
 dbmclose %list;
  dbmclose %data;
  dbmclose %fkey;
 exit 0;
}
sub main {
header();
print <<EOF;
<H1><CENTER>FAQ Administration</CENTER></H1>
<p>Please choose:<p>
<form method="POST" action="/cgi-bin/kfaq/faqadmin.pl">
<p><input type=radio name="choice" value="Headers" > Headers and Footers 
<p><input type=radio name="choice" value="New" > New
<p><input type=radio name="choice" value="Edit" > Edit
<p><input type=radio name="choice" value="Sort" > Sort/Delete
<p><input type=radio name="choice" value="Review" > Review
<p><input type=submit name="posting" value="Go" > 
</form>
</body>
</html>
EOF
}
sub sortme {
$items=scalar (keys (%list));
$items -= 2;
 if ($killme and $killmeyes) {
   delete $list{$which};
   delete $data{$which};
   delete $fkey{$which};
   review();
 }
 $hold1=$list{$which}; 
 $hold2=$data{$which}; 
 $hold3=$fkey{$which}; 
 $pos=$which;
 $pos=~ s/line:00*//;
 $pos += $howmuch if ($move eq "down");
 $pos -= $howmuch if ($move eq "up");
 $pos=1 if $pos <1;
 $pos=$items if $pos > $items;
 $x=1;
 $before=$list{'header'};
 $after=$list{'footer'};
 foreach (sort keys %list) {
   next if $_ eq $which;
   next if not /^line:/;
   $newkey=sprintf "%.5d",$x;
   if ($x == $pos) {
     $x++;
     $newkey=sprintf "%.5d",$x;
   }
   $nlist{$newkey}=$list{$_};
   $ndata{$newkey}=$data{$_};
   $nfkey{$newkey}=$fkey{$_};
   $x++;
 }
 $newkey=sprintf "%.5d",$pos;
 $nlist{$newkey}=$hold1;
 $ndata{$newkey}=$hold2;
 $nfkey{$newkey}=$hold3;
 
 %list=();
 %data=();
 %fkey=();
$list{'header'}=$before;
$list{'footer'}=$after;
 foreach (sort keys %nlist) {
   $newkey=sprintf "line:%.5d",$_;
   $list{$newkey}=$nlist{$_};
   $data{$newkey}=$ndata{$_};
   $fkey{$newkey}=$nfkey{$_};
 }

 review();
}
sub sortmehow {
 header();
print "<H1><CENTER>FAQ Administration</CENTER></H1><p>";
$list{$which} =~ s/\</</g;
$data{$which} =~ s/\</</g;
$fkey{$which} =~ s/\</</g;
$list{$which} =~ s/\>/>/g;
$data{$which} =~ s/\>/>/g;
$fkey{$which} =~ s/\>/>/g;
print <<EOF;
<p>($list{$which})
<form method="POST" action="/cgi-bin/kfaq/faqadmin.pl">
<p>Delete (must check both) <input type=checkbox name="killme">
<input type=checkbox name="killmeyes">
<p>Move <input type=radio name="move" value="up"> UP
<input type=radio name="move" value="down"> DOWN
<input type=text size=3 name="howmuch"> Lines
<p><input type=hidden name="which" value="$which" > 
<p><input type=hidden name="sortnow" value="done" > 
<p><input type=submit name="posting" value="Do it" > 
</form>
</body>
</html>
EOF
  dbmclose %list;
  dbmclose %data;
  dbmclose %fkey;
exit 0;

}
sub sortmesel {
 header();
$items=scalar (keys (%list));
$items -= 1;
$items=5 if $items > 5;
print <<EOF;
<H1><CENTER>FAQ Administration</CENTER></H1>
<p>Select FAQ and click "Go" to sort or delete
<form method="POST" action="/cgi-bin/kfaq/faqadmin.pl">
<select name="which" size=$items>
EOF
foreach (sort keys %list) {
  $list{$_}=~ s/</\</g;
  $list{$_}=~ s/>/\>/g;
  next if not /^line:/;
  print "<option value=$_>$list{$_}";
}
print <<EOF;
</select>
<p><input type=hidden name="sortit" value="done" > 
<p><input type=submit name="posting" value="Go" > 
</form>
</body>
</html>
EOF
  dbmclose %list;
  dbmclose %data;
  dbmclose %fkey;
exit 0;

}
sub mkhead {
  header();
print <<EOF;
<H1><CENTER>FAQ Administration</CENTER></H1>
<p>HTML tags allowed.  Enter the text that will appear before and 
after your main faq list.
<form method="POST" action="/cgi-bin/kfaq/faqadmin.pl">
<p>Text before FAQ List: <p><textarea name="textheader" cols=80 rows=8>$list{'header'}</textarea>
<p>Text after FAQ List: <p><textarea name="textfooter" cols=80 rows=8>$list{'footer'}</textarea>
<p><input type=hidden name="posthead" value="done" > 
<p><input type=submit name="posting" value="Record" > 
</form>
</body>
</html>
EOF

}
sub postedit {
  header();
print "<H1><CENTER>FAQ Administration</CENTER></H1><p>";
$list{'(New)'}="";
$list{$which} =~ s/\</</g;
$data{$which} =~ s/\</</g;
$fkey{$which} =~ s/\</</g;
$list{$which} =~ s/\>/>/g;
$data{$which} =~ s/\>/>/g;
$fkey{$which} =~ s/\>/>/g;
print <<EOF;
<p>
<form method="POST" action="/cgi-bin/kfaq/faqadmin.pl">
<p>Question: <input type=text size=80 name="faqline" value="$list{$which}">
<p>Index keywords: <input type=text size=80 name="faqkeys" value="$fkey{$which}">
<p>Answer:<br> <textarea name="faqdata" cols=80 rows=8>$data{$which}</textarea>
<p>
<p><input type=hidden name="which" value="$which" > 
<p><input type=hidden name="postfaq" value="done" > 
<p><input type=submit name="posting" value="Record" > 
</form>
</body>
</html>
EOF
}
sub postfaq {
my $x=1;
  if ($which eq "(New)") {
   $which=sprintf "line:%.5d",$x;
   while ($list{$which}) {
     $x++;
     $which=sprintf("line:%.5d",$x);
   }
 }
 $list{$which}=$faqline;
 $data{$which}=$faqdata;
 $fkey{$which}=$faqkeys;
 closeit();
}
sub editing {
 header();
$items=scalar (keys (%list));
$items -= 1;
$items=5 if $items > 5;
print <<EOF;
<H1><CENTER>FAQ Administration</CENTER></H1>
<p>Select FAQ and click "Go"
<form method="POST" action="/cgi-bin/kfaq/faqadmin.pl">
<select name="which" size=$items>
<option selected value="(New)">(New)
EOF
foreach (sort keys %list) {
  $list{$_}=~ s/</\</g;
  $list{$_}=~ s/>/\>/g;
  next if not /^line:/;
  print "<option value=$_>$list{$_}";
}
print <<EOF;
</select>
<p><input type=hidden name="postedit" value="done" > 
<p><input type=submit name="posting" value="Go" > 
</form>
</body>
</html>
EOF
}
sub review {
  header();
  print "<h2>FAQS</h2>";
  print "<a href=\"/cgi-bin/kfaq/faqadmin.pl\">Main</a>";
  print "<p>$list{'header'}"; 
  foreach (sort keys %list) {
    $list{$_}=~ s/\</</g;
    $list{$_}=~ s/\>/>/g;
    $data{$_}=~ s/\</</g;
    $data{$_}=~ s/\>/>/g;
    next if not /^line:/;
    print "<h2>$list{$_}</h2>";
    print "<p> $data{$_}";
   }
  print "<p>$list{'footer'}"; 
  print <<EOF;
</body>
</html>
EOF
dbmclose %list;
  dbmclose %data;
  dbmclose %fkey;
exit 0;
}

sub header {
print <<EOF;;
content-type: text/html

<HTML>
<HEAD>
<TITLE>FAQ</TITLE>
</HEAD>
<body bgcolor="#FFFFFF">
EOF
}
 sub posthead {
$list{'header'}=$textheader;
$list{'footer'}=$textfooter;
closeit();
}
 

And here's the user interface:

#!/usr/bin/perl
use Text::Soundex;
use CGI qw(:standard);
foreach $i (param) {
  foreach $j (param($i) ) {
    $$i=$j;
  }
}
dbmopen %list, "YOURDATAPATH/data/faqlist", 0700 or die "can't open faqlist";
dbmopen %data, "/YOURDATAPATH/faqdat", 0700 or die "can't open faqlist";
dbmopen %fkey, "/YOURDATAPATH/data/faqkeys", 0700 or die "can't open faqlist";
search() if ($posting and $what); 
review();
exit 0;

sub search {
  header();
  print "<p>$list{'header'}"; 
  print <<EOF;
<p>
<form method="POST" action="/cgi-bin/kfaq/faq.pl">
<p><input type=text size=20 name="what">
<input type=submit name="posting" value="Search" > (leave blank for all) 
EOF
  @searches=split / /, $what;
  $found="";
  foreach (@searches) {
    $smatch=soundex($_);
    foreach (sort keys %list) {
      next if not /line:/;
      $matched=$_;
      $words=$list{$_};
      $words .=  $data{$_};
      $words .=  $fkey{$_};
      @mywords=split / /,$words;
      foreach (@mywords) {
        if ($smatch eq soundex($_)) {
          $found{$matched}=$_; 
          last;
        }
      }
      
    }
  }
  foreach (sort keys %found) {
    $list{$_}=~ s/\</</g;
    $list{$_}=~ s/\>/>/g;
    $data{$_}=~ s/\</</g;
    $data{$_}=~ s/\>/>/g;
    print "<h2>$list{$_}</h2>";
    print "<p>$data{$_}";
   }
  print "<p>$list{'footer'}"; 
  print <<EOF;
</body>
</html>
EOF
dbmclose %list;
exit 0;
}

sub review {
  header();
  print "<h2>FAQS</h2>";
  print "<p>$list{'header'}"; 
  print <<EOF;
<p>
<form method="POST" action="/cgi-bin/kfaq/faq.pl">
<p><input type=text size=20 name="what">
<input type=submit name="posting" value="Search" > 
EOF
  foreach (sort keys %list) {
    $list{$_}=~ s/\</</g;
    $list{$_}=~ s/\>/>/g;
    $data{$_}=~ s/\</</g;
    $data{$_}=~ s/\>/>/g;
    next if not /^line:/;
    print "<h2>$list{$_}</h2>";
    print "<p>$data{$_}";
   }
  print "<p>$list{'footer'}"; 
  print <<EOF;
</body>
</html>
EOF
dbmclose %list;
exit 0;
}

sub header {
print <<EOF;;
content-type: text/html

<HTML>
<HEAD>
<TITLE>FAQS</TITLE>
</HEAD>
<body bgcolor="#FFFFFF">
EOF
}
 

Download faqadmin.pl

Download faq.pl (user interface)

With any program like this that accepts html as input, you have to be concerned with someone deliberately putting "bad" html code in - javascript or other code that might subvert or damage. One way to do that is to allow only a specific set of input tags. For example, your code might do:
$input =~ s/</\&lt;/g;
$input =~ s/\&lt;p>/<p>/ig;

That eliminates everything but simple paragraph tags. None of that is included in the sample code here.

Publish your articles, comments, book reviews or opinions here!

© November 2002 Tony Lawrence All rights reserved




Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

cartoon


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Perl
       - Programming
       - Web/HTML
       - Code


Unix/Linux Consultants

Skills Tests

Guest Post Here








card_image






My Favorites

Change Congress