Calling ASP-Actions by WWW::Mechanize (PERL) - asp.net

i need to parse through a list generated by an ASP action (LoadDialog) and i have no clue how to get it done. If I execute the following i simply get an empty HTML file.
#!/usr/bin/perl -w
#
#
use strict;
use WWW::Mechanize;
use HTTP::Cookies;
my $url = "http://MYURL/LOGIN";
my $appurl = "http://MYURL/SOME.asp";
#SOME.asp calls http://MYURL/SOME.asp?Action=LoadDialog" to get results
my $username = 'username';
my $password = 'password';
#login to site
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_name('login');
$mech->field(UserName => $username);
$mech->field(Password => $password);
$mech->click();
# get results from LoadDialog (?!)
$mech->get($appurl);
my $app_content = $mech->content();
print "$app_content\n";
Firebug tells me that ?Action=LoadDialog is getting called by the mentioned URL, but Mechanize doesnt realize it (guessing).
Simply chaning $myappurl to http://MYURL/SOME.asp?Action=LoadDialog gives me an empty HTML file as well.
Is there any chance to get the ASP generated content? I cant use any other Perl modules which "run a browser", I need to find a solution usable in a shell.
Thanks in Advance,
Marley

Related

Edit an existing Pastebin document via API

I am trying to write a function in LUA to edit my pastebin code.
I can use this code to make a HTTP post:
http.post(string url, string postData [, table headers])
I can also use this code for a HTTP get:
http.get(string url [, table headers])
on the Pastebin website https://pastebin.com/api are information about using the API.
I am not sure, if this website can help me to solve my problem.
Does someone know how to fill the headers table?
this is the program i tried:
headers = {}
headers["api_dev_key"]= 'myDevKey...'; // your api_developer_key
headers["api_paste_code"] = 'my edited text'; // your paste text
headers["api_paste_private"] = '0'; // 0=public 1=unlisted 2=private
headers["api_paste_name"] = 'justmyfilename.php'; // name or title of your paste
headers["api_paste_expire_date"] = '10M';
headers["api_paste_format"] = 'php';
headers["api_user_key"] = ''; // if an invalid or expired api_user_key is used, an error will spawn. If no api_user_key is used, a guest paste will be created
headers["api_paste_name"] = myPastebinName;
headers["api_paste_code"] = myPastebinPassword;
http.get("https://pastebin.com/edit/dQMDfbkM", headers)
unfortunately this is not working and on the pastebin API help site is no exsample for editing a paste. just for creating a new one.
for me it is also not clear if I have to use post or get
There is no API for editing pastes directly.
You can only delete old paste and create new with updated text.

Drupal 7 | Preserve file after entity_wrapper unset?

Question is quite simple: How to preserve file on server and in file tables, so its fid is still valid after unsetting/changing value with entity wrapper?
$ewrapper = entity_metadata_wrapper('node', $sourceNode);
unset($sourceNode->field_image[$sourceNode->language][0]);
$ewrapper->save();
Now the related file is deleted as soon as the above is called. Same happends if I use:
$ewrapper->field_image->set($newImage);
In this case I need to keep the old image.
Thanks for your help guys!
I think that you should change file status from FILE_STATUS_TEMPORARY to FILE_STATUS_PERMANENT. Check out this answer here:
https://api.drupal.org/comment/23493#comment-23493
Basically, there is no file_set_status() function, like Drupal 6 had one, but now this code should do the same job:
// First obtain a file object, for example by file_load...
$file = file_load(10);
// Or as another example, the result of a file_save_upload...
$file = file_save_upload('upload', array(), 'public://', FILE_EXISTS_REPLACE);
// Now you can set the status
$file->status = FILE_STATUS_PERMANENT;
// And save the status.
file_save($file);
So, you load file object one or another way, change it's status property and save object back again.

How can I remove a message shown from a different module?

In Drupal 7, I could use the following code.
if ($_SESSION['messages']['status'][0] == t('Registration successful. You are now logged in.')) {
unset($_SESSION['messages']['status']);
}
What is the equivalent code for Drupal 8?
First of all, in Drupal 8, messages are stored in the same $_SESSION['messages'] variable as before. However, using it directly is not a good way, as there exist drupal_set_message and drupal_get_messages functions, which you may freely use.
Then, status messages are shown using status-messages theme. This means that you can write preprocess function for it and make your alteration there:
function mymodule_preprocess_status_messages(&$variables) {
$status_messages = $variables['message_list']['status'];
// Search for your message in $status_messages array and remove it.
}
The main difference with Drupal 7, however, is that now status messages are not always strings, they may be objects of Markup class. They are wrappers around strings and may be cast to underlying string using magic method __toString. This means that they can be compared with and as strings:
function mymodule_preprocess_status_messages(&$variables) {
if(isset($variables['message_list']['status'])){
$status_messages = $variables['message_list']['status'];
foreach($status_messages as $delta => $message) {
if ($message instanceof \Drupal\Component\Render\MarkupInterface) {
if ((string) $message == (string) t("Searched text")) {
unset($status_messages[$delta]);
break;
}
}
}
}
}
Upon reading the related change record, I have discovered \Drupal::messenger()->deleteAll(). I hope this is useful to someone. UPDATE: You should NOT do this, as it removes all subsequent messages as well. Instead, do unset(['_symfony_flashes']['status'][0]).
You can install the module Disable Messages and filter out messages by pattern in the configuration of the module.
For this particular case, you can filter out the message using the following pattern in the module configuration
Registration successful.*
Although the question is asked around Drupal 8 which is no longer supported, the module works for Drupal 7, 8, 9.
You can solve your problem in more than one way.
First way:
You can make minor change in core user module.
Go on:
\core\modules\user\src\RegisterForm.php
In that file you have line you can change:
drupal_set_message($this->t('Registration successful. You are now logged in.'));
NOTE: This is easiest way but in this case way you will edit Drupal core module and that is generally bad practice. In further development you could have problems like overwrite your changes when you do update.
Second way:
You can disable end user message using module. Disable message module have option you need. In module configuration you have text box where you can filter out messages shown to the end users.
Third way:
Messages in Drupal 8 are stored in a session variable and displayed in the page template via the $messages theme variable. When you want to modify the variables that are passed to the template before it's invoked you should use preprocess function. In your case here you can just search string in session variable and alert/remove it before it's displayed.
function yourmodule_preprocess_status_messages(&$variables) {
$message = 'Registration successful. You are now logged in.';
if (isset($_SESSION['messages'])) {
foreach ($_SESSION['messages'] as $type => $messages) {
if ($type == 'status') {
$key = array_search($message, $messages);
if ($key !== FALSE) {
unset($_SESSION['messages'][$type][$key]);
}
}
}
}
}
(Note:Untested code, beware of typos)
Hope this helps!

unable to see header after fpdf creates file

I am working on a wordpress plugin,
I want to create a pdf file, For this I used fpdf
By using this code I am able to generate pdf and save it to server
require('fpdf/html_table.php');
$pdf=new PDF_HTML();
$questions = $_POST['question'];
$count = count($questions);
$quests = "";
$pdf->SetFont('times','',12);
$pdf->SetTextColor(50,60,100);
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');
$pdf->SetFontSize(12);
for($i=1;$i<=$count;$i++)
{
$qus_id = $questions[$i-1];
$get_q = "select * from `SelleXam_question` where `id`='$qus_id'";
$get_q = $wpdb->get_results($get_q);
$questf = "Quest $i : ".$get_q[0]->question;
$pdf->Cell(0, 10, $questf."\n");
$pdf->Ln();
}
$dir='C:/wamp/www/';
$filename= "filename.pdf";
$pdf ->Output($dir.$filename);
echo "Save PDF in folder";
But when it saved and displayed the messge Save PDF in Folder. I am unable to see the header part of the wordpress website.
Or when I use
$pdf->Output($filename,'D');
then is there any way that I can show the file in a link
When you are developing for Wordpress, you can't just echo text at any time. Wordpress has a whole series of actions it goes through to progressively generate the output rendered to the browser. If you generate output at an inappropriate time, you'll mess up Wordpress' ability to generate output at the right time.
If I were developing this, I'd have this function be called as a filter on the_content. Your output code would change to something like this:
function append_pdf_to_content($content) {
//Your existing code
$pdf->Output($filename, 'F');
$pdf_link = "<br><a href='$filename' download>Download PDF</a>"
return $content . $pdf_link;
}
add_filter('the_content', 'append_pdf_to_content');
If you wanted to use the D option, you'll need to link your users to a separate php page using a target='_blank' that calls the download. Otherwise the PDFs headers will override any headers Wordpress is trying to send.
BTW, you also might want to also take a look at mPDF, it's a fork of fpdf and remains in active development.

Is there a (free) way to unpack .zip files without the use of a .DLL in ASP Classic

I would like to be able to unpack a .zip file using ASP classic.
I have had a bit of a poke around on google for something that will allow me to do this, and there seems to be a fair amount libraries out there. However all of these as far as I can tell require me to install a third party DLL.
The server that this script will be deployed on (or more accurately the IT department that control said server) will not allow me to use these to extend ASP's functionality and do what I have been asked to do (totally paradoxical!).
Is there any class library's out there that I might just be able to throw in as an include?
thanks for your time
Not sure is you can make it work with ASP, but in this project you will find a way to unZip in VB using a DLL, but you don't need to register the DLL, just put it somewhere where the class can find it.
I've used it in a VB 6 compiled app, but maybe you can adapt it to ASP. Not sure.
This is the code you will need: UnZip.cls
Hope it helps.
I have solved my problem... it's pretty messy, far from ideal, and dependant on server set up, but for the sake of anyone that has a similar problem and server in future here is how I solved it.
Basically I used PHP's ZIP library which seems to be installed on the server that I'm working on and made an unzip.php file:
<?PHP
$infile = $_REQUEST['infile'];
$outfile = $_REQUEST['outfile'];
$input_folder = "uploads";
$output_folder = "templates";
echo "false";
$zip = zip_open($input_folder."/".$infile);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$fp = fopen($output_folder."/".$outfile."/".zip_entry_name($zip_entry), "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
} else {
echo "false";
exit;
}
}
echo "true";
zip_close($zip);
} else {
echo "false";
exit;
}
?>
Then where I wanted to call this in my ASP script I HTTPXML'd to the PHP file location on same server with my variables as part of the querystring.
Response.Buffer = True
Dim objXMLHTTP, xml
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://" & strdomain & "/unzip.php?infile="& filename &"&outfile=" & out_foldername, False
xml.Send
if xml.responseText = "true" then
SaveFiles = SaveFiles & "(unzip successful!)"
else
SaveFiles = SaveFiles & "(unzip failed!)"
end if
Set xml = Nothing
next
where
filename = The name of the file that you want to unzip
out_folder = The name of the folder that you want put your unzipped files into
strdomain = Request.ServerVariables("HTTP_HOST")
SaveFiles = my return variable.
I'm sure there must be a better way of doing this, but for the time being in my situation this seems to work ok (and hopefully no one will ever know!).

Resources