Advertisement
swaggboi

new_cgi

Jan 25th, 2022
1,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.05 KB | None | 0 0
  1. diff --git a/cgi-bin/guest_mm.cgi b/cgi-bin/guest_mm.cgi
  2. index c130773..5b918e0 100755
  3. --- a/cgi-bin/guest_mm.cgi
  4. +++ b/cgi-bin/guest_mm.cgi
  5. @@ -10,209 +10,5 @@ use utf8;
  6.  use open qw{:std :utf8}; # Fix "Wide character in print" warning
  7.  use CGI qw{-utf8};       # Needed to parse unicode params
  8.  use CGI::Carp qw{fatalsToBrowser};
  9. -use XML::LibXML;
  10. -use WebService::Mattermost;
  11. -#use Data::Dumper;        # Uncomment for debugging
  12.  
  13. -## Variables ##
  14. -
  15. -# Create CGI object (query)
  16. -my $q = CGI->new();
  17. -
  18. -# Open banned phrases and users files
  19. -open(my $thoughtCrimes, '.msg.bans') or die "$@";
  20. -open(my $nameBans,     '.name.bans') or die "$@";
  21. -
  22. -# Get creds file
  23. -my $dotfile           = ".mmCreds.xml";
  24. -# Create XML::LibXML object
  25. -my $dom               = XML::LibXML->load_xml(location => $dotfile);
  26. -# Grab the values from creds file
  27. -my %conf;
  28. -$conf{'authenticate'} = 1;
  29. -$conf{'username'}     = $dom->findvalue('/credentials/username');
  30. -$conf{'password'}     = $dom->findvalue('/credentials/password');
  31. -$conf{'base_url'}     = $dom->findvalue('/credentials/base_url');
  32. -my $chan              = $dom->findvalue('/credentials/channel_id');
  33. -my $spam              = $dom->findvalue('/credentials/spam_chan_id');
  34. -# Create new WebService::Mattermost objects (mm && resource)
  35. -my $mm                = WebService::Mattermost->new(%conf);
  36. -my $resource          = $mm->api->posts;
  37. -
  38. -## Functions ##
  39. -
  40. -# Print the form
  41. -sub form_out {
  42. -    # Begin printing the form
  43. -    print $q->div(
  44. -        {-class => "inner"},
  45. -
  46. -        # Little bit of text
  47. -        $q->p("Use the form below to sign the guestbook and send
  48. -              SwaggNet a message. Please be patient after submitting
  49. -              as messages are checked for spam via cutting-edge
  50. -              Swagg::AI blockchain techmology."),
  51. -        "\n", # Newlines to make it pretty
  52. -
  53. -        # Opening form tag
  54. -        $q->start_form(
  55. -            -name   => 'main',
  56. -            -method => 'POST'
  57. -        ), "\n",
  58. -
  59. -        # Opening table tag
  60. -        $q->start_table(), "\n",
  61. -
  62. -        # Name field
  63. -        $q->Tr(
  64. -            $q->th("Name:"),
  65. -            $q->td(
  66. -                $q->textfield(
  67. -                    -name => "name",
  68. -                    -size => 40
  69. -                )
  70. -            )
  71. -        ), "\n",
  72. -
  73. -        # Location field
  74. -        $q->Tr(
  75. -            $q->th("Location:"),
  76. -            $q->td(
  77. -                $q->textfield(
  78. -                    -name => "location",
  79. -                    -size => 40
  80. -                )
  81. -            )
  82. -        ), "\n",
  83. -
  84. -        # Message box
  85. -        $q->Tr(
  86. -            $q->th("Message:"),
  87. -            $q->td(
  88. -                $q->textarea(
  89. -                    -name    => "message",
  90. -                    -columns => 50,
  91. -                    -rows    => 10
  92. -                )
  93. -            )
  94. -        ), "\n",
  95. -
  96. -        # Submit button
  97. -        $q->Tr(
  98. -            $q->th(' '), # Non-breaking space
  99. -            $q->td($q->submit(-value => "Submit"))
  100. -        ), "\n",
  101. -
  102. -        # Closing table tag
  103. -        $q->end_table(), "\n",
  104. -
  105. -        # Closing form tag
  106. -        $q->end_form(), "\n"
  107. -        ) . "\n";
  108. -}
  109. -
  110. -# Process params & say thanks
  111. -sub params_in {
  112. -    # Params to variables
  113. -    my $name     = $q->param("name");
  114. -    my $location = $q->param("location");
  115. -    my $message  = $q->param("message");
  116. -
  117. -    # Enforce max length for params
  118. -    if (length($name) < 1 || length($name) >= 40) {
  119. -        die "Name field must be between 1 and 40 characters\n"
  120. -    }
  121. -    elsif (length($location) < 1 || length($location) >= 40) {
  122. -        die "Location field must be between 1 and 40 characters\n"
  123. -    }
  124. -    elsif (length($message) < 1 || length($message) >= 1900) {
  125. -        die "Message field must be between 1 and 1900 characters\n"
  126. -    }
  127. -
  128. -    # Variable set for banned user
  129. -    my ($ban, $trigger);
  130. -
  131. -    # Parse the banned names list
  132. -    chomp(my @nameBan = <$nameBans>);
  133. -    for (@nameBan) {
  134. -        last if $ban;
  135. -
  136. -        if ($name =~ /$_/i) {
  137. -            $ban     = 1;
  138. -            $trigger = $_;
  139. -        }
  140. -    }
  141. -
  142. -    # Parse the banned phrases list
  143. -    chomp(my @thoughtCrime = <$thoughtCrimes>);
  144. -    for (@thoughtCrime) {
  145. -        last if $ban;
  146. -
  147. -        if ($message =~ /$_/i) {
  148. -            $ban     = 1;
  149. -            $trigger = $_;
  150. -        }
  151. -    }
  152. -
  153. -    # Send it unless ban is true; else send it to spam if spam chan is
  154. -    # defined
  155. -    unless ($ban) {
  156. -        $resource->create(
  157. -            {
  158. -                channel_id => "$chan",
  159. -                message    => "$name from $location says: $message"
  160. -            }
  161. -            );
  162. -    }
  163. -    elsif ($spam) {
  164. -        $resource->create(
  165. -            {
  166. -                channel_id => "$spam",
  167. -                message    => "$name from $location says: $message\n\n" .
  168. -                              "Spam trigger: `$trigger`"
  169. -            }
  170. -            );
  171. -    }
  172. -
  173. -    # Say thanks (even if banned, e.g. shadow ban)
  174. -    print $q->div(
  175. -        {-class => "inner"},
  176. -        $q->h2("Thanks!"),
  177. -        $q->p("Your note has been sent, thanks for using the
  178. -              guestbook.")
  179. -        ) . "\n";
  180. -}
  181. -
  182. -## Begin script ##
  183. -
  184. -# Print header
  185. -print $q->header(-charset => 'UTF-8');
  186. -
  187. -# Print the head & title, begin the body
  188. -print $q->start_html(
  189. -    -title => 'SwaggNet Guestbook',
  190. -    -style => '/css/swagg.css'
  191. -    );
  192. -
  193. -# Heading
  194. -print $q->div(
  195. -    {-class => "outer"},
  196. -    $q->h1("Swagg::Net Guestbook"),
  197. -    $q->br(),
  198. -    "\n"
  199. -    ) . "\n";
  200. -
  201. -# Process returned params if present; else print form
  202. -$q->param() ? params_in() : form_out();
  203. -
  204. -# Print link to go back to homepage in footer
  205. -print $q->div(
  206. -    {-class => "inner"},
  207. -    $q->br(),
  208. -    "<footer>Go back to", # CGI.pm doesn't have footer tag?
  209. -    $q->a({-href => "/"}, "homepage"),
  210. -    "</footer>\n"         # Closing footer tag
  211. -    );
  212. -
  213. -# Close body
  214. -print $q->end_html() . "\n";
  215. +print CGI->redirect('https://guestbook.swagg.net');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement