I am testing my perl code. I want to pass filepath as a paramter to the URL of the page.
The perl code is dependent on this filepath entirely.
When i set the filepath inside my perl code. (hard coded path), i am able to execute the perl code without any errors. Here is the variable
my $filename="\\\\sfoaepmdata.dcc.com\\folder\\data.txt";
If i pass it via URL, it doesnt work as expected. Can anyone suggest how to pass filepath as a variable in the URL ?
Here is what all i tried to someohow transfer $filename from url to perl code.
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=\\\\sfoaepmdata.dcc.com\\folder\\data.txt
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=\\sfoaepmdata.dcc.com\folder\data.txt
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=//sfoaepmdata.dcc.com/folder/data.txt
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=////sfoaepmdata.dcc.com//folder//data.txt
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=file://sfoaepmdata.dcc.com/folder/data.txt
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=file:////sfoaepmdata.dcc.com//folder//data.txt
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=http:////sfoaepmdata.dcc.com//folder//data.txt
http://apmqa.dcc.com/cgi-bin/test/editor.pl?filename=http://sfoaepmdata.dcc.com/folder/data.txt
The above data may seem confusing. But please only read values after ?ffilename. Can anyone pls suggest.
I also tried passing other normal paramters and it worked. for e.g.
$account=GEL; the filepath doesnt work.
http://apmqa.dcc.com/cgi-bin/test/editor.pl?account=GEL
the solution was pretty simple. i first need to get the user parameter converted to perl and then work on it accordingly.
$filename = $cgi->param('filename');
By this code, we will get the filepath from the user in $filename and we can work on the required file. Hope it helps someone. thanks.
The passed parameters to the URL would be as shown below
?filename=\\sfoaepmdata.dcc.com\folder\data.txt
Related
I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.
Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.
Due to the fact that I have to create a PDF on my server using the uniqid() function, I must subsequently refer to it as a PHP variable in the rest of my code.
The variable that I create for it is a session variable. I later refer to this session variable in a separate file, which contains my PHPmailer code. I use the following line to attach the session variable to the mail:
$mail->AddStringAttachment($_SESSION[$attachment], "attachment.pdf");
The mail is sent correctly with a PDF attached, called attachment.pdf. However, this attached file, attachment.pdf, is empty. This is despite the fact that the PDF on the server, which the session variable refers to, contains the complete set of data. If I attach the name of the PDF, instead of the session variable, it works correctly.
I don't know why the use of a session variable when attaching the PDF is resulting in an empty file being sent. If anybody may be able to explain why this is happening, or suggest an alternative solution, I would greatly appreciate it!
I'm guessing that $_SESSION[$attachment] contains the name of your generated PDF file, so what you are doing here is attaching the name of the file as an attachment, rather than the file itself. You should probably be using this instead:
$mail->AddAttachment($_SESSION[$attachment], "attachment.pdf");
I have an extension that access a file directory. I use an ajax function to send the path that needs to be access to the controller and in the controller I use a $_GET cause I haven't figure it out how to make it work otherwise.
$image_file_path = $_GET["url_region"];
$d = dir($image_file_path) or die("File not found!");
But of course when you request for something else like ../../.. you can access all other directories.
Could you suggest me a way to sanitize this? Please!
You should provide a cHash as URL parameter and let TYPO3 verify that. This way you can be sure the URL has been generated by TYPO3 itself and thus is valid.
You should consider using t3lib_div::_GET() which unescapes the parameters regardless what php.ini magic_quotes says.
You easily could use a regex to catch all "../" - values of the parameter. The other way could be, that the available paths being defined in a array, or something else, to check up the right access.
I'm playing around with Win32::IE:Mechanize to try to access some authentication-required sites automatically. So far I've achieved moderate success, for example, I can automatically log in to my yahoo mailbox. But I find many sites are using some kind of image verification mechanism, which is possibly called CAPTCHA. I can do nothing to them. But one of the sites I'm trying to auto access is using a plain-text verification code. It is comnposed of four digits, selectable and copyable. But they're not in the source file which can be fetched using
$mech->content;
I searched for the keyword that appears on the webpage but not in the source file through all the files in the Temporary Internet Files but still can't find it.
Any idea what's going on? I was suspecting that the verification code was somehow hidden in some cookie file but I can't seem to find it :(
The following is the code that completes all the fields requirements except for the verification code:
use warnings;
use Win32::IE::Mechanize;
my $url = "http://www.zjsmap.com/smap/smap_login.jsp";
my $eccode = "myeccode";
my $username = "myaccountname";
my $password = "mypassword";
my $verify = "I can't figure out how to let the script get the code yet"
my $mech = Win32::IE::Mechanize->new(visible=>1);
$mech->get($url);
sleep(1); #avoids undefined value error
$mech->form_name("BaseForm");
$mech->field(ECCODE => $eccode);
$mech->field(MEMBERACCOUNT => $username);
$mech->field(PASSWORD => $password);
$mech->field(verify => $verify);
$mech->click();
Like always any suggestions/comments would be greatly appreciated :)
UPDATE
I've figured out a not-so-smart way to solve this problem. Please comment on my own asnwer posted below. Thanks like always :)
This is the reason why they are there. To stop program like yours to do automated stuff ;-)
A CAPTCHA or Captcha is a type of
challenge-response test used in
computing to ensure that the response
is not generated by a computer.
This appears to be an irrelevant number. The page uses it in 3 places: generating it; displaying it on the form next to the input field for it; and checking for the input value being equal to the random number chosen. That is, it is a client-only check. Still, if you disable javascript it looks like, I'm guessing, important cookies don't get set. If you can execute JavaScript in the context of the page (you should be able to with a get method call and a javascript URI), you could change the value of random_number to f.e. 42 and fill that in on the form.
The code is inserted by JavaScript – disable JS, reload the page and see it disappear. You have to hunt through the JS code to get an idea where it comes from and how to replicate it.
Thanks to james2vegas, zoul and Shoban.
I've finally figured out on my own a not-so-smart but at-least-workable way to solve the problem I described here. I'd like to share it here. I think the approach suggested by #james2vegas is probably much better...but anyway I'm learning along the way.
My approach is this:
Although the verification code is not in the source file but since it is still selectable and copyable, I can let my script copy everything in the login page and then extract the verification code.
To do this, I use the sendkeys functions in the Win32::Guitest module to do "Select All" and "Copy" to the login page.
Then I use Win32:Clipboard to get the clipboard content and then Regexp to extract the code. Something like this:
$verify = Win32::Clipboard::GetText();
$verify =~ s/.* (\d{4}).*/$1/msg;
A few thoughts:
The random number is generated by something like this in Perl
my $random_number = int(rand(8999)) + 1000; #var random_number = rand(1000,10000);
And then it checks if $verify == $random_number. I don't know how to catch the value of one-session-only $random_number. I think it is stored somewhere in the memory. If I can capture the value directly then I wouldn't have gone to so much trouble of using this and that extra module.
I'm trying to read out the POST-Data that was sent from a form in a page to my Perl Script. I googled and found out that:
read(STDIN, $param_string, $ENV{'CONTENT_LENGTH'})
reads out the whole Data-String with and writes the whole string to $param_string in the form of
Param1=Value1&Param2=Value2&Param3=Value3
by spliting it at the right places I get the necessary Data.
But I wonder why my $param_string is empty.
When I try the whole thing with GET:
$param_string = $ENV{'QUERY_STRING'};
everything works fine. Does anybody have an idea?
There absolutely no real reason for someone at your level to want to hand parse CGI requests.
Please use CGI::Simple or CGI.pm.
CGI.pm has a lot of baggage (HTML generation, function oriented interface) which makes CGI::Simple preferable.
Using any CGI processing module on CPAN is better than trying to write CGI processing code from scratch.
See parse_query_string in CGI::Simple for a way of accessing parameters passed using the query string when processing a form that is POSTed to your script.
If you want to learn how to do it right, you can read the source code of either module. Reading through the CGI.pm CHANGES file is also instructive.
If you are able to retrieve GET-data but not able to retrieve POST-data, most likely you forgot to change form method from to be post. You can check your submit method by using this condition in if statement:
if ($ENV{'REQUEST_METHOD'} eq "POST"){
read(STDIN, $param_string, $ENV{'CONTENT_LENGTH'});
}else {
$param_string = $ENV{'QUERY_STRING'};
}
Under mod_perl 2, Apache2::Request works for me.