Advertisement
Guest User

Untitled

a guest
May 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #!/usr/bin/perl -wT
  2.  
  3. use DBI;
  4.  
  5. $db="int420_101a20";
  6. $user="int420_101a20";
  7. $passwd="18639171";
  8. $host="db-mysql.zenit";
  9. $connectionInfo="dbi:mysql:$db;$host";
  10.  
  11.  
  12. print "Content-type:text/html\n\n";
  13.  
  14. if ($ENV{REQUEST_METHOD} eq "GET")
  15. {
  16. &browsecatalog;
  17. }
  18. else
  19. {
  20. &parseform;
  21.  
  22. if ($form{submit} eq "Buy")
  23. {
  24. if ($ENV{"HTTP_COOKIE"})
  25. {
  26. &showcheckout;
  27. }
  28. else
  29. {
  30. &showlogin;
  31. }
  32. }
  33. elsif ($form{submit} eq "login")
  34. {
  35. if (&validateuser)
  36. {
  37. &sendlogincookie;
  38. &showcheckout;
  39. }
  40. else
  41. {
  42. &showlogin;
  43. }
  44. }
  45. elsif ($form{submit} eq "checkout")
  46. {
  47. if (&validatecheckout)
  48. {
  49. &insertransaction;
  50. &emailreceipt;
  51. &showreceipt;
  52. }
  53. else
  54. {
  55. &showcheckout;
  56. }
  57. }
  58. }
  59.  
  60.  
  61.  
  62. sub browsecatalog
  63. {
  64. print qq~
  65. <html>
  66. <title>Ninja Warehouse Inventory</title>
  67. </head>
  68. <body bgcolor="black">
  69. <font color="white">
  70. <center>
  71. <br>
  72. <h1> Ninja Items </h1>
  73. <br>
  74. <br>
  75. <table border cellpadding=10>
  76. <tr style="color:#00FF00">
  77. <th>ID Number</th><th>Prod Name</th><th>Description</th><th>Price</th><th>Picture</th><th>Options</th>
  78. </tr>~;
  79.  
  80. $select=qq~select id, idnum, name, descr, price, pic from inventory order by idnum;~;
  81. $dbh=DBI->connect($connectionInfo,$user,$passwd);
  82. $sth=$dbh->prepare($select);
  83. $sth->execute();
  84.  
  85. while (@row=$sth->fetchrow_array())
  86. {
  87. print qq~
  88. <tr style="color:#00FF00"><td>$row[1]</td><td>$row[2]</td> <td>$row[3]</td> <td>\$ $row[4]</td> <td><img src="/img/$row[5]"/></td>
  89. <td>
  90. <form action="stage4.cgi" method="post">
  91. <input type="hidden" name="id" value="$row[0]">
  92. <input type="submit" name="submit" value="Buy">
  93.  
  94. </td>
  95. </tr>~
  96. }
  97. print qq~
  98. </table>
  99. </body>
  100. </html>
  101. ~;
  102.  
  103. }
  104.  
  105. sub parseform
  106. {
  107. read(STDIN, $qstring, $ENV{'CONTENT_LENGTH'});
  108.  
  109. @pairs = split(/&/, $qstring);
  110.  
  111. foreach (@pairs) {
  112. ($key, $value) = split(/=/);
  113. $value =~ tr/+/ /;
  114. $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  115. $form{$key} = $value;
  116. }
  117.  
  118. }
  119.  
  120.  
  121. sub showlogin
  122. {
  123. print qq~
  124. <html>
  125. <head>
  126. <title>Ninja Warehouse</title>
  127. </head>
  128. <body bgcolor="black">
  129. <form action="stage4.cgi" method=POST>
  130. <p>
  131. <font color="white">
  132. <center>
  133. <h2>Ninja Warehouse Customer Registration</h2>
  134. <table border = "0">
  135.  
  136. <tr style="color:#00Ff00"><td> Login Name: </td><td><input type=text name=logn value="$form{logn}" ></td><td> $errors{logn}</td><td> $found</td>
  137. </tr>
  138.  
  139. <tr style="color:#00Ff00"><td> Password: </td><td><input type=text name=passw value="$form{passw}"></td><td> $errors{logn}</td>
  140. </tr>
  141.  
  142. </table>
  143. </font>
  144. <input type=submit value="login" name"login">
  145. </form>
  146. </p>
  147. </center>
  148. </body>
  149. </html>
  150. ~
  151. }
  152.  
  153. sub validateuser
  154. {
  155. $dbh=DBI->connect($connectionInfo,$user,$passwd);
  156. $select=qq~select * from customers where logn='$form{logn}'~;
  157. $sth=$dbh->prepare($select);
  158. $sth->execute;
  159.  
  160. if ($row=$sth->fetchrow_arrayref)
  161. {
  162. $found = "Username found"
  163. }else{
  164. $found = "Username Not found"
  165. }
  166. }
  167.  
  168. sub sendlogincookie
  169. {
  170.  
  171. }
  172.  
  173. sub showcheckout
  174. {
  175. print qq~
  176. <html>
  177. <h2> "Checkout here"</h2>
  178. </html>
  179. ~
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement