Advertisement
Guest User

kcard_login.pl

a guest
Aug 9th, 2013
1,671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6.33 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # file_upload.pl - Demonstration script for file uploads
  4. # over HTML form.
  5. #
  6. # This script should function as is.  Copy the file into
  7. # a CGI directory, set the execute permissions, and point
  8.  
  9.  
  10. use CGI;
  11. use strict;
  12.  
  13. my $PROGNAME = "kcard_upload.pl";
  14.  
  15. my $cgi = new CGI();
  16. sub login_enable{
  17.     open(my $CONFIG_FILE, "<", "/etc/wsd.conf") or die("Could not open wsd.conf"); 
  18.     my ($LOGIN_INFO);
  19.     while( my $line = <$CONFIG_FILE> ){
  20.         chomp($line);      
  21.         if($line=~/Login-Set : (.*)/){               
  22.            $LOGIN_INFO=$1;             
  23.         }
  24.        
  25.    }
  26.    close(CONFIG_FILE);  
  27.    return ($LOGIN_INFO);
  28. }
  29. my $LOGIN_INFO=&login_enable();
  30. print "Content-type: text/html\n\n";
  31. print "<html><head><title>Upload Form</title>";
  32. print "<style>
  33. <!--
  34. body{
  35.     background-color:#ffdee0;
  36. }
  37. -->
  38. </style>";
  39. print "<body>";
  40. #
  41. # If we're invoked directly, display the form and get out.
  42. #
  43. if($LOGIN_INFO =~ /No/)
  44. {
  45. if (! $cgi->param("button") ) {
  46.     DisplayForm();
  47.     exit;
  48. }
  49. }
  50. else
  51. {
  52.   DisplayForm1();
  53. }
  54. #
  55. # We're invoked from the form. Get the filename/handle.
  56. #
  57. my $upfile = $cgi->param('upfile');
  58.  
  59. #
  60. # Get the basename in case we want to use it.
  61. #
  62. my $basename = GetBasename($upfile);
  63. my $count = $basename;
  64. $count = tr/a-z //;
  65. if ($basename eq "" )   #to check null string
  66. {
  67.     #print "<h3>--------------Notice------------------<br>";
  68.     #print "Please select the image file name.";
  69.     #print "[System supports to upload *.jpg, *.bmp, *.gif, *.png.]<br></h3>";  
  70.     exit;  
  71. }
  72.  
  73. my $basename_src = $basename;
  74. $basename =~ tr/a-z/A-Z/;
  75. if( !($basename =~ /.GIF/ || $basename =~ /.JPG/ ||
  76.       $basename =~ /.PNG/ || $basename =~ /.BMP/))
  77. {
  78.     print "<h3>--------------Notice------------------<br>";
  79.     print "$basename_src can\'t upload to server.<br>";
  80.     print "[System supports to upload *.jpg, *.bmp, *.gif, *.png.]<br></h3>";  
  81.     exit;  
  82. }else{
  83.     #print "<h3>--------------Notice------------------<br>";
  84.     #print "$basename_src upload to server.<br>";
  85.     #print "[System supports to upload *.jpg, *.bmp, *.gif, *.png.]<br></h3>";  
  86.     #exit; 
  87. }
  88. #
  89. # At this point, do whatever we want with the file.
  90. #
  91. # We are going to use the scalar $upfile as a filehandle,
  92. # but perl will complain so we turn off ref checking.
  93. # The newer CGI::upload() function obviates the need for
  94. # this. In new versions do $fh = $cgi->upload('upfile');
  95. # to get a legitimate, clean filehandle.
  96. #
  97. no strict 'refs';
  98. #my $fh = $cgi->upload('upfile');
  99. #if (! $fh ) {
  100. #   print "Can't get file handle to uploaded file.";
  101. #   exit(-1);
  102. #}
  103.  
  104. #######################################################
  105. # Choose one of the techniques below to read the file.
  106. # What you do with the contents is, of course, applica-
  107. # tion specific. In these examples, we just write it to
  108. # a temporary file.
  109. #
  110. # With text files coming from a Windows client, probably
  111. # you will want to strip out the extra linefeeds.
  112. ########################################################
  113.  
  114. #
  115. # Get a handle to some file to store the contents
  116. #
  117. if (! open(OUTFILE, ">../DCIM/198_WIFI/$basename") ) {
  118.     print "Can't open ..\/DCIM\/198_WIFI\/$basename for writing - $!";
  119.     exit(-1);
  120. }
  121.  
  122. # give some feedback to browser
  123. print "<b>----------------Notice----------------------</b><br>";
  124. print "<b><font color=\"blue\">Saving the file to DCIM/198_WIFI</font></b><br>";
  125.  
  126. #
  127. # 1. If we know it's a text file, strip carriage returns
  128. #    and write it out.
  129. #
  130. #while (<$upfile>) {
  131. # or
  132. #while (<$fh>) {
  133. #   s/\r//;
  134. #   print OUTFILE "$_";
  135. #}
  136.  
  137. #
  138. # 2. If it's binary or we're not sure...
  139. #
  140. my $nBytes = 0;
  141. my $totBytes = 0;
  142. my $buffer = "";
  143. # If you're on Windows, you'll need this. Otherwise, it
  144. # has no effect.
  145. binmode($upfile);
  146. #binmode($fh);
  147. while ( $nBytes = read($upfile, $buffer, 1024) ) {
  148.     print OUTFILE $buffer;
  149.     $totBytes += $nBytes;
  150. }
  151. close(OUTFILE);
  152.  
  153. #
  154. # Turn ref checking back on.
  155. #
  156. use strict 'refs';
  157.  
  158. # more lame feedback
  159. print "<b>thanks for uploading $basename ($totBytes bytes)</b><br><br>\n"; 
  160. print "<b><font color=\"red\">**Upload Successfully.....</font><br>";
  161. print "</Body></html>";
  162.  
  163. ##############################################
  164. # Subroutines
  165. ##############################################
  166.  
  167. #
  168. # GetBasename - delivers filename portion of a fullpath.
  169. #
  170. sub GetBasename {
  171.     my $fullname = shift;
  172.  
  173.     my(@parts);
  174.     # check which way our slashes go.
  175.     if ( $fullname =~ /(\\)/ ) {
  176.         @parts = split(/\\/, $fullname);
  177.     } else {
  178.         @parts = split(/\//, $fullname);
  179.     }
  180.  
  181.     return(pop(@parts));
  182. }
  183.  
  184. #
  185. # DisplayForm - spits out HTML to display our upload form.
  186. #
  187. sub DisplayForm {
  188. print <<"HTML";
  189. <html>
  190. <head>
  191. <meta http-equiv="content-language" content="zh-tw">
  192. <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
  193. <title>Upload Form</title>
  194. <script type=\"text/javascript\">
  195. if(document.cookie.length != 0){
  196. }
  197. else{
  198.       location.href=\"kcard_login.pl\";        
  199. }
  200. </script>
  201.  
  202. <style>
  203. <!--
  204. body{
  205.     background-color:#ffdee0;
  206. }
  207. -->
  208. </style>
  209. <script LANGUAGE="JavaScript" text="text/javascript">
  210. function check(){
  211.  
  212. }
  213. </script>
  214. <body>
  215. <h3>Please select a image file to upload. (*.bmp, *.jpg, *.gif, *.png)</h3>
  216. <b><font color="red">(Maximum Siz: 50MB)</font></b>
  217. <form name="upform" method="post" action="/cgi-bin/wifi_upload" enctype="multipart/form-data">
  218. Enter a file to upload: <input type="file" id="upfile" name="upfile" width=\"200\"><br><br>
  219. <input type="submit" name="button" value="Upload File">
  220. </form>
  221. HTML
  222. }
  223.  
  224. sub DisplayForm1 {
  225. print <<"HTML";
  226. <html>
  227. <head>
  228. <meta http-equiv="content-language" content="zh-tw">
  229. <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
  230. <title>Upload Form</title>
  231. <script type=\"text/javascript\">
  232. if(document.cookie.length != 0){
  233. }
  234. else{
  235.       location.href=\"kcard_login.pl\";        
  236. }
  237. </script>
  238.  
  239. <style>
  240. <!--
  241. body{
  242.     background-color:#ffdee0;
  243. }
  244. -->
  245. </style>
  246. <script LANGUAGE="JavaScript" text="text/javascript">
  247. function check(){
  248.  
  249. }
  250. </script>
  251. <body>
  252. <h3>Please select a image file to upload. (*.bmp, *.jpg, *.gif, *.png)</h3>
  253. <b><font color="red">(Maximum Siz: 50MB)</font></b>
  254. <form name="upform" method="post" action="/cgi-bin/wifi_upload" enctype="multipart/form-data">
  255. Enter a file to upload: <input type="file" id="upfile" name="upfile" width=\"200\"><br><br>
  256. <input type="submit" name="button" value="Upload File">
  257. </form>
  258. HTML
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement