home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 October / INTERNET108.ISO / pc / software / windows / messages / greymatter / gm-karma.cgi < prev    next >
Encoding:
Text File  |  2001-12-03  |  10.3 KB  |  363 lines

  1. #!/usr/bin/perl
  2.  
  3. # =============================
  4. # GREYMATTER - Karma Module
  5. # Weblog/Journal Software
  6. # version one point two
  7. # Copyright (c)2000 Noah Grey
  8. # http://noahgrey.com/greysoft/
  9. # =============================
  10.  
  11. # ***  Your possession of this software indicates that you agree to the terms   ***
  12. # *** specified under the "Copyright & Usage" heading in the "manual.txt" file. ***
  13.  
  14. use CGI::Carp qw(fatalsToBrowser);
  15.  
  16. require "gm-library.cgi";
  17.  
  18. my $getin;
  19. if ($ENV{'REQUEST_METHOD'} eq "GET") { $getin = $ENV{'QUERY_STRING'}; } else { $getin = <STDIN>; }
  20.  
  21. @pairs = split(/&/, $getin);
  22. foreach $pair (@pairs) {
  23.     ($name, $value) = split(/=/, $pair);
  24.     $name =~ tr/+/ /;
  25.     $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  26.     $value =~ tr/+/ /;
  27.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  28.     $IN{$name} = $value;
  29. }
  30.  
  31. $userip = $ENV{'REMOTE_ADDR'};
  32.  
  33. &gm_karmabancheck;
  34.  
  35. &gm_readconfig;
  36. &gm_readtemplates;
  37. &gm_readcounter;
  38.  
  39. open (FUNNYFEET, "$EntriesPath/$IN{'entry'}.cgi") || &gm_dangermouse("Can't open $EntriesPath/$IN{'entry'}.cgi.  Please make sure your paths are configured correctly and that your entries/archives directory is CHMODed to 777.");
  40. @entrylines = <FUNNYFEET>;
  41. close (FUNNYFEET);
  42.  
  43. $gmcounter = 0;
  44.  
  45. foreach (@entrylines) {
  46.     chomp ($entrylines[$gmcounter]);
  47.     $gmcounter++;
  48. }
  49.  
  50. ($thisentrynumber, $thisentryauthor, $thisentrysubject, $thisentryweekdaynumber, $thisentrymonth, $thisentryday, $thisentryyearyear, $thisentryhour, $thisentryminute, $thisentrysecond, $thisentryampm, $thisentrypositivekarma, $thisentrynegativekarma, $thisentrycommentsnumber, $thisentryallowkarma, $thisentryallowcomments, $thisentryopenstatus) = split (/\|/, $entrylines[0]);
  51.  
  52. &gm_allowedcheck;
  53. &gm_blankcheck;
  54. &gm_votetwicecheck;
  55. &gm_addkarma;
  56. &gm_freshenafterkarma;
  57.  
  58. # -------------
  59. # check for ban
  60. # -------------
  61.  
  62. sub gm_karmabancheck {
  63.  
  64. open (FUNNYFEET, "gm-banlist.cgi") || &gm_dangermouse("Can't read the banlist file.  Please make sure that gm-banlist.cgi is CHMODed to 666 and is in the same place as all your other Greymatter CGI files.");
  65. @gmbanlist = <FUNNYFEET>;
  66. close (FUNNYFEET);
  67.  
  68. if ($gmbanlist[0] ne "") {
  69.     foreach $gmbanlistline (@gmbanlist) {
  70.         chomp ($gmbanlistline);
  71.         ($checkthisip, $checkthisiphost, $checkthisperson) = split (/\|/, $gmbanlistline);
  72.         if ($userip =~ m/$checkthisip/i) {
  73.  
  74.             if (($keeplog eq "yes") && ($logkarmaandcomments eq "yes")) {
  75.                 &date;
  76.                 open (FUNNYFEET, ">>gm-cplog.cgi") || &gm_dangermouse("Can't write to the control panel log.  Please make sure that gm-cplog.cgi is CHMODed to 666 and is in the same place as all your other Greymatter CGI files.");
  77.                 print FUNNYFEET "<FONT SIZE=1>[$basedate] [$userip]</FONT> <FONT COLOR=\"#FF0000\"><B>A banned IP ($checkthisip/$checkthisiphost";
  78.                 if ($checkthisperson ne "") { print FUNNYFEET ", \"$checkthisperson\""; }
  79.                 print FUNNYFEET ") attempted to cast a $IN{'vote'} karma vote on entry #$IN{'entry'}</B></FONT>\n";
  80.                 close (FUNNYFEET);
  81.             }
  82.  
  83. print "Content-type: text/html\n";
  84.  
  85. print<<GMBANNEDNOTICE;
  86.  
  87. $gmheadtag
  88.  
  89. $gmframetop
  90. You have been banned from voting on this site.<BR>(IP: $userip)
  91. $gmframebottom
  92.  
  93. </BODY>
  94. </HTML>
  95.  
  96. GMBANNEDNOTICE
  97.  
  98. exit;
  99.  
  100.         }
  101.     }
  102. }
  103.  
  104. }
  105.  
  106. # --------------------------------
  107. # check if karma votes can be cast
  108. # --------------------------------
  109.  
  110. sub gm_allowedcheck {
  111.  
  112. if (($posttoarchives eq "no") && ($thisentrynumber <= $newarchivenumber)) {
  113.  
  114. if (($keeplog eq "yes") && ($logkarmaandcomments eq "yes")) {
  115.     &date;
  116.     open (FUNNYFEET, ">>gm-cplog.cgi") || &gm_dangermouse("Can't write to the control panel log.  Please make sure that gm-cplog.cgi is CHMODed to 666 and is in the same place as all your other Greymatter CGI files.");
  117.     print FUNNYFEET "<FONT SIZE=1>[$basedate] [$userip]</FONT> A $IN{'vote'} karma vote was blocked from being added to archived entry #$IN{'entry'}\n";
  118.     close (FUNNYFEET);
  119. }
  120.  
  121. print "Content-type: text/html\n";
  122.  
  123. print<<GMKARMADISALLOWEDNOTICE;
  124.  
  125. $gmheadtag
  126.  
  127. $gmframetop
  128. Sorryùkarma votes cannot be cast on archived entries.  Please use your browser's Back button to return.
  129. $gmframebottom
  130.  
  131. </BODY>
  132. </HTML>
  133.  
  134. GMKARMADISALLOWEDNOTICE
  135.  
  136. exit;
  137.  
  138. }
  139.  
  140. if (($thisentryallowkarma eq "no") || ($thisentryopenstatus eq "closed") || ($allowkarmaorcomments eq "comments") || ($allowkarmaorcomments eq "neither")) {
  141.  
  142. if (($keeplog eq "yes") && ($logkarmaandcomments eq "yes")) {
  143.     &date;
  144.     open (FUNNYFEET, ">>gm-cplog.cgi") || &gm_dangermouse("Can't write to the control panel log.  Please make sure that gm-cplog.cgi is CHMODed to 666 and is in the same place as all your other Greymatter CGI files.");
  145.     print FUNNYFEET "<FONT SIZE=1>[$basedate] [$userip]</FONT> A $IN{'vote'} karma vote was blocked from being cast on entry #$IN{'newcommententrynumber'}\n";
  146.     close (FUNNYFEET);
  147. }
  148.  
  149. print "Content-type: text/html\n";
  150.  
  151. print<<GMKARMABLOCKEDNOTICE;
  152.  
  153. $gmheadtag
  154.  
  155. $gmframetop
  156. Sorryùkarma votes cannot be cast on this entry.  Please use your browser's Back button to return.
  157. $gmframebottom
  158.  
  159. </BODY>
  160. </HTML>
  161.  
  162. GMKARMABLOCKEDNOTICE
  163.  
  164. exit;
  165.  
  166. }
  167.  
  168. }
  169.  
  170. # --------------------------------------
  171. # check if this person has already voted
  172. # --------------------------------------
  173.  
  174. sub gm_votetwicecheck {
  175.  
  176. @pastkarmavotes = split (/\|/, $entrylines[1]);
  177.  
  178. $votedtwice = "no";
  179.  
  180. foreach $googoogajoob (@pastkarmavotes) {
  181.  
  182. if ($googoogajoob eq $userip) {
  183.  
  184. if ($allowmultiplekarmavotes eq "yes") {
  185. $votedtwice = "yes";
  186. } else {
  187.  
  188. if (($keeplog eq "yes") && ($logkarmaandcomments eq "yes")) {
  189.     &date;
  190.     open (FUNNYFEET, ">>gm-cplog.cgi") || &gm_dangermouse("Can't write to the control panel log.  Please make sure that gm-cplog.cgi is CHMODed to 666 and is in the same place as all your other Greymatter CGI files.");
  191.     print FUNNYFEET "<FONT SIZE=1>[$basedate] [$userip]</FONT> A repeat karma vote ($IN{'vote'}) was blocked from being added to entry #$IN{'entry'}\n";
  192.     close (FUNNYFEET);
  193. }
  194.  
  195. print "Content-type: text/html\n";
  196.  
  197. print<<GMVOTETWICEDISALLOWEDNOTICE;
  198.  
  199. $gmheadtag
  200.  
  201. $gmframetop
  202. Sorryùyou can't vote twice on the same entry.  Please use your browser's Back button to return.
  203. $gmframebottom
  204.  
  205. </BODY>
  206. </HTML>
  207.  
  208. GMVOTETWICEDISALLOWEDNOTICE
  209.  
  210. exit;
  211.  
  212. }
  213.  
  214. }
  215.  
  216. }
  217.  
  218. }
  219.  
  220. # ---------------------------
  221. # check if the input is blank
  222. # ---------------------------
  223.  
  224. sub gm_blankcheck {
  225.  
  226. if (($IN{'vote'} eq "") || ($IN{'entry'} eq "")) {
  227.  
  228. print "Content-type: text/html\n";
  229.  
  230. print<<GMBLANKNOTICE;
  231.  
  232. $gmheadtag
  233.  
  234. $gmframetop
  235. Error: Blank fields reported in the karma module input.  Please report to this site's webmaster.
  236. $gmframebottom
  237.  
  238. </BODY>
  239. </HTML>
  240.  
  241. GMBLANKNOTICE
  242.  
  243. exit;
  244.  
  245. }
  246.  
  247. }
  248.  
  249. # ------------------
  250. # add the karma vote
  251. # ------------------
  252.  
  253. sub gm_addkarma {
  254.  
  255. if ($IN{'vote'} eq "positive") {
  256.     $thisentrypositivekarma++;
  257.     $newalltimepktotalnumber++;
  258.     unless ($votedtwice eq "yes") { $entrylines[1] .= "|$userip|P"; }
  259. }
  260. if ($IN{'vote'} eq "negative") {
  261.     $thisentrynegativekarma++;
  262.     $newalltimenktotalnumber++;
  263.     unless ($votedtwice eq "yes") { $entrylines[1] .= "|$userip|N"; }
  264. }
  265.  
  266.  
  267. $entrylines[0] = "$thisentrynumber|$thisentryauthor|$thisentrysubject|$thisentryweekdaynumber|$thisentrymonth|$thisentryday|$thisentryyearyear|$thisentryhour|$thisentryminute|$thisentrysecond|$thisentryampm|$thisentrypositivekarma|$thisentrynegativekarma|$thisentrycommentsnumber|$thisentryallowkarma|$thisentryallowcomments|$thisentryopenstatus";
  268.  
  269. $gmcounter = 0;
  270.  
  271. &date;
  272.  
  273. open (FUNNYFEET, ">$EntriesPath/$IN{'entry'}.cgi") || &gm_dangermouse("Can't write to $EntriesPath/$IN{'entry'}.cgi.  Please make sure that your paths are configured correctly and that your entries/archives directory is CHMODed to 777.");
  274. foreach $entrynewline (@entrylines) { print FUNNYFEET "$entrynewline\n"; }
  275. close (FUNNYFEET);
  276.  
  277. }
  278.  
  279. # ------------------------
  280. # primp, preen, take a bow
  281. # ------------------------
  282.  
  283. sub gm_freshenafterkarma {
  284.  
  285. &gm_writecounter;
  286.  
  287. $aftermath = "$EntriesWebPath/$IN{'entry'}.$entrysuffix";
  288.  
  289. &gm_getentryvariables($IN{'entry'});
  290.  
  291. $aftermath = "$LogWebPath/$indexfilename";
  292. $aftermathprefix = substr($indexfilename, 0, 5);
  293.  
  294. if ($aftermathprefix eq "index") { $aftermath = "$LogWebPath/"; }
  295.  
  296. if ($thisentryisanarchive eq "yes") {
  297.     $aftermath = "$EntriesWebPath/archive-$thisentrymonthmonth$thisentryyearyear\.$entrysuffix";
  298. }
  299.  
  300. if ($generateentrypages eq "yes") {
  301.     if ($thisentrymorebody ne "") {
  302.         &gm_formatentry($gmmoreentrypagetemplate);
  303.     } else {
  304.         &gm_formatentry($gmentrypagetemplate);
  305.     }
  306.     open (THISFILE, ">$EntriesPath/$IN{'entry'}.$entrysuffix") || &gm_dangermouse("Can't write to $EntriesPath/$IN{'entry'}.$entrysuffix.  Please make sure that your paths are configured correctly and that your entries/archives directory is CHMODed to 777.");;
  307.     print THISFILE $entryreturn;
  308.     close (THISFILE);
  309. }
  310.  
  311. if ($thisentryisanarchive eq "no") {
  312.     &gm_generatemainindex;
  313. } else {
  314.     &gm_readcounter;
  315.     $stoppednumber = $newarchivenumber;
  316.     do { &gm_generatearchive($stoppednumber); } until $stoppednumber <= 1;
  317. }
  318.  
  319. &gm_readconfig;
  320.  
  321. if (($NotifyForStatus eq "karma") || ($NotifyForStatus eq "both")) {
  322. if ($NotifyEmail ne "") {
  323.  
  324. &gm_getentryvariables($IN{'entry'});
  325.  
  326. $sendithere = "$mailprog -t";
  327.  
  328. @sendestinations = split (/;/, $NotifyEmail);
  329.  
  330. foreach $destinationow (@sendestinations) {
  331.  
  332. open (MAIL, "|$sendithere") || &gm_dangermouse("Can't open the mail program at $mailprog.  Please make sure you have this configured correctly.");
  333. print MAIL <<__MAILNOTIFY__;
  334. To: $destinationow
  335. From: $destinationow
  336. Subject: [Greymatter] Notice: Karma Vote Cast
  337.  
  338. A $IN{'vote'} karma vote has just been cast by $userip IP on entry #$thisentrynumber ($thisentrysubject).  That brings this entry to $thisentrypositivekarma positive and $thisentrynegativekarma negative karma votes for a $thisentrytotalkarma total karma rating.
  339.  
  340. -----
  341. Greymatter $gmversion
  342. http://noahgrey.com/greysoft/
  343.  
  344. __MAILNOTIFY__
  345.  
  346. close(MAIL);
  347.  
  348. }
  349.  
  350. }
  351. }
  352.  
  353. if (($keeplog eq "yes") && ($logkarmaandcomments eq "yes")) {
  354.     &date;
  355.     open (FUNNYFEET, ">>gm-cplog.cgi") || &gm_dangermouse("Can't write to the control panel log.  Please make sure that gm-cplog.cgi is CHMODed to 666 and is in the same place as all your other Greymatter CGI files.");
  356.     print FUNNYFEET "<FONT SIZE=1>[$basedate] [$userip]</FONT> <I>A $IN{'vote'} karma vote was cast on entry #$thisentrynumber ($thisentrysubject)</I>\n";
  357.     close (FUNNYFEET);
  358. }
  359.  
  360. print "Location: $aftermath\n\n";
  361.  
  362. }
  363.