Link to home
Start Free TrialLog in
Avatar of onyourmark
onyourmark

asked on

where is it writing to 2

Hello. I am trying to figure out where these scripts write to. Do they write to the file where they are installed (cgi-bin) or to the folder called csv. I have established that the cgi one writes to csv but I am not sure about the parse_input file.
#this script is called parse_input
use strict;
use warnings;


unless( defined( $ARGV[0]) ){
  die "Have to provide filename, ... exiting\n";
}
my $header = [];
open INPUT, "<$ARGV[0]";
open OUTPUT, ">input.csv";
my $_line = 0;

while(<INPUT>){
 chomp;
 if($_line == 0){
   foreach my $_row (0 .. 5){
       $_ =~ s/^(.+?)\,//is;
       my $_item = "$1";
       $_item =~ s/^\s+//is;
       $_item =~ s/\s+$//is;
       $_item =~ s/^\"//is;
       $_item =~ s/\"$//is;
       $_item =~ s/\n//isg;
       $_item =~ s/\r//isg;
       print OUTPUT "\"$_item\"\,";
     }
    $_ =~ s/^\s+//is;
    $_ =~ s/\s+$//is;
    $_ =~ s/^\"//is;
    $_ =~ s/\"$//is;
    $_ =~ s/\n//isg;
    $_ =~ s/\r//isg;
    print OUTPUT "\"$_\"\n";
   }
 else{
   foreach my $_row (0 .. 2){
       $_ =~ s/^(.+?)\,//is;
       my $_item = "$1";
       $_item =~ s/^\s+//is;
       $_item =~ s/\s+$//is;
       $_item =~ s/^\"//is;
       $_item =~ s/\"$//is;
       $_item =~ s/\n//isg;
       $_item =~ s/\r//isg;     
       print OUTPUT "\"$_item\"\,";
     }
    $_ =~ s/^\s+//is;
    $_ =~ s/\s+$//is;
    $_ =~ s/^(.+?)\"\,\"//is;
    my $_text = "$1";
    $_text =~ s/^\s+//is;
    $_text =~ s/\s+$//is;
    $_text =~ s/^\"//is;
    $_text =~ s/\"$//is;
    $_text =~ s/\n//isg;
    $_text =~ s/\r//isg;
    $_text =~ s/\,/ /isg;
    print OUTPUT "\"$_text\"\,";
    $_ =~ s/^\s+//is;
    $_ =~ s/\s+$//is;
    my $_location = "";
    $_ =~ s/^(.+?)\"\,//is;
    if( defined( $1 )){
       $_location = "$1";
      }
    $_location =~ s/^\s+//is;
    $_location =~ s/\s+$//is;
    $_location =~ s/^\"//is;
    $_location =~ s/\"$//is;
    $_location =~ s/\n//isg;
    $_location =~ s/\r//isg;
    $_location =~ s/\,/ /isg;
    print OUTPUT "\"$_location\"\,";
   foreach my $_row (0 .. 1){
       $_ =~ s/^(.+?)\,//is;
       my $_item = "$1";
       $_item =~ s/^\s+//is;
       $_item =~ s/\s+$//is;
       $_item =~ s/^\"//is;
       $_item =~ s/\"$//is;
       $_item =~ s/\n//isg;
       $_item =~ s/\r//isg;
       print OUTPUT "\"$_item\"\," if $_row == 0;
       print OUTPUT "\"$_item\"\n" if $_row == 1;
     }
   }

 $_line++;

}

close INPUT;
close OUTPUT;

Open in new window

#This is a cgi script
use strict;
use warnings;
use CGI;

my $_DOCUMENT_ROOT = 
	"C\:\\HostingSpaces\\getready\\mydomain.com\\wwwroot\\csv";


opendir DIRECT, "$_DOCUMENT_ROOT";
my @filelist = grep {$_ !~ /^\./ } readdir( DIRECT );
closedir DIRECT;

my $_report = '';
my $cgi = CGI->new ;

my $_offset = defined($cgi->param("offset")) ? $cgi->param("offset") : 0;
my $_length = defined($cgi->param("length")) ? $cgi->param("length") : 20; 
my $_action = defined($cgi->param("sub")) ? $cgi->param("sub") : "";
my $_passwd = defined($cgi->param("passw")) ? $cgi->param("passw") : '';
$_passwd = ($_passwd eq "123") ? 1 : '';

$_action = '' unless $_action;
$_action = '' unless $_passwd;
if($_action){

      if(defined($cgi->upload("upload"))){
        my $filename = "$_DOCUMENT_ROOT\\Input.csv";
        my $upload_filehandle = $cgi->upload("upload");
        open OUTFILE, ">$filename";
         binmode OUTFILE;
         binmode $upload_filehandle;
         while(<$upload_filehandle>){
            print OUTFILE "$_";
          }
        close OUTFILE;
        system("perl parse_input.pl");
       }

 system("perl mainprog.pl $_offset $_length");        
 $_report = "<br><a style=\'backgrond-color: \#f2f233; color: \#770022; font: 16px Helvetica;\' href=\'\/csv\/report.csv\'> <b> Resultant CSV file  <\/b> <\/a>&nbsp; &nbsp; <a style=\'backgrond-color: \#f2f233; color: \#770022; font: 16px Helvetica;\' href=\'\/csv\/reducedreport.csv\'> <b> Resultant CSV file 2 (condensed) \ <\/b> <\/a> <br>\n";
}

print $cgi->header;
print $cgi->start_html(-title=>'Twitter statistics');
print "<div style=\'padding: 12px 12px 12px 12px;\' > <h3> CSV files <\/h3> \n <table>";
my $_k = 0;
my $_astyle = "style=\'border: 1px solid \#eef2ff; background-color: \#fffaf2; font: 14px Georgia; margin: 12px 12px 12px 12px;\'";
foreach(@filelist){
 print "<tr>" if ($_k % 3) == 0;
 print "<td> <a $_astyle href=\'\/csv/$_\' > $_ <\/a> <\/td> \n";
 print "<\/tr>" if ($_k % 3) == 2;
 $_k++;
}
print "<\/table><\/div>\n";

print "$_report\n";

print <<HERE_GOES;

<div style='padding: 12px 12px 12px 12px; margin: 12px 12px 12px 12px;
font: 14px Arial; border: 1px solid #337799; background-color: #f7faff;
color: #002233;'>

<form method='post' action='/cgi-bin/task.cgi' enctype='multipart/form-data'>
<table><tr>
<tr><td><label for='passw'> <i><b> Password: <\/b><\/i> <\/label> </td>
<td><input type='password' name='passw' value=''> </td></tr>
<tr><td><label for='upload'> <i><b> Upload another "input.csv" <\/b><\/i> </label></td>
<td><input type='file' name='upload'> </td></tr>

<tr><td><label for='offset'> <i> Offset </i> </label></td>
<td><input type='text' name='offset' value='0' style='width: 48px;'> </td> 
</tr>
<tr><td><label for='length'> <i> Length </i> </label></td>
<td><select name='length'> 
<option value='10'> 10 </option>
<option value='20' selected> 20 </option>
<option value='30'> 30 </option>
<option value='40'> 40 </option>
<option value='50'> 50 </option>
<option value='60'> 60 </option>
</select></td>                
</tr>
<tr><td colspan='2'> <input type='submit' name = 'sub' value='Submit'> 
</td></tr>
</table>
</form>
</div>
HERE_GOES

print $cgi->end_html;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of imaki06
imaki06

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of onyourmark
onyourmark

ASKER

Hi Tintin,
Thank you. Why are you saying it will be in the cgi-bin? By the way, you are correct about the location of the cgi folder.
The CGI script calls parse_input and as parse_input doesn't specify a full path for the output file, it will be created in the current working directory of the calling script.

There's a possibility it may be in:

C:\HostingSpaces\getready\mydomain.com\wwwroot

if you are using IIS.
Wow, cool, I guess I get it! Thank you. One more thing. Since yes I am using IIS, why is there a possibility it is wwwroot if it is IIS?
I think what TinTin was saying is that it depends on how the IIS is configured. For example, it can be configured that when someone puts in the URL http://www.yourdomain.com/cgi-bin/myscript.cgi, it actually points to C:\HostingSpaces\getready\mydomain.com\wwwroot\cgi-bin on the server.

So it depends on how the configuration is set. I would guess that it's not likely at wwwroot.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial