I'm currently trying to get Netbeans as an IDE to work with PHP Files. Part of the work is to get Xdebug to run properly. I have gotten Xdebug to work on a Windows machine but this is my first try on Linux.
I have gotten the correct module I followed the instructions on http://xdebug.org/wizard.php
I have a Correct phpinfo() output also, with the Xdebugsection pressent and everything. I can't post the output of my phpinfo() but everything seems ok there. The configuration in my php.ini file is as follows:
[XDebug]
zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9101
[ZendModules]
Xdebug
I only want to be able to connect to the port 9101 (The port Xdebug listens on). I have gotten the following small script from a website to do so.
<?php
$address = '127.0.0.1';
$port = 9101;
print $port . " " .$address . "\n";
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
print "sock = " . $sock . "\n";
socket_bind($sock, $address, $port) or die('Unable to bind');
print "socket bind worked \n";
socket_listen($sock);
print "listening on sock\n";
$client = socket_accept($sock);
echo "connection established: $client";
socket_close($client);
socket_close($sock);
?>
When I run this script, I get the following output:
michael#michael-Inspiron-N5030:~$ php5 testXdebug.php
9101 127.0.0.1
sock = Resource id #4
socket bind worked
listening on sock
This means the Script will not finish running, it just stops there an nothing else happens.
does somebody have an idea what might be causing this?
Related
I have this script to send email. Everything works except that after the email is sent I receive the error below. It has to be something simple I am missing. I checked and cgi file is 755 and since it gets to the sub and executes its got to be coder error. Any help greatly appreciated.
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
The error in the server log is:
[Tue Jan 17 16:00:23.475272 2023] [cgi:error] [pid 230679] [client 69.90.223.10:35014] End of script output before headers: test3.cgi
Here is the code I am using, Perl CGI on Linux
#!/usr/bin/perl -Tw
# use warnings;
use strict;
use Net::SMTP;
send_mail('mail.xxxxxxx.com', # Host
'order#xxxxxxxxx.com', #From
'yyyyyyy#gmail.com', #to
'Just a test, from mail.xxxxxx.com please ignore', #Message body
"Testing mail server email.\n" # Subject
);
exit;
sub send_mail {
my ($SMTP_HOST, $from, $to_addr, $body, $subject, $msg) = #_;
$msg = "MIME-Version: 1.0\n"
. "From: $from\n"
. "To: " . ( ref($to_addr) ? join(';', #$to_addr) : $to_addr ) . "\n"
. "Subject: $subject\n\n" # Double \n
. $body;
#
# Open a SMTP session
#
my $smtp = Net::SMTP->new( $SMTP_HOST,
Debug => 0, # Change to a 1 to turn on debug messages
Port => 587,
);
die("SMTP ERROR: Unable to open smtp session.\n")
if(!defined($smtp) || !($smtp));
die("Failed to set FROM address\n")
if (! ($smtp->mail( $from ) ) );
die("Failed to set receipient\n")
if (! ($smtp->recipient( ( ref($to_addr) ? #$to_addr : $to_addr ) ) ) );
$smtp->data( $msg );
$smtp->quit;
}
Checked File attributes they are 755
Since it ran the code an performed the send email the Char set should be correct
Being new to Perl not sure what else to check
This isn't a CGI program. You send no response for the request. Since there is no response (not even an invalid one), the script exits with nothing sent to standard output. The server realizes this is a problem, creates the 500 server error response, and adds to the error log that the script output ended before headers, which is the first thing the server expected to see.
You might want to start with a basic CGI tutorial to see how CGI works.
But, also realize that sending mail through a CGI program is a very 1990s thing to do. We don't typically do that anymore because we all figured out that letting anyone trigger mail through a public server was a bad idea.
I am beginner to Perl and I have to write a script which could change the IP address after every 1 hour.
I want to change it because I receive some data from a dongle from a website and that website has some time limit to receive that data, so currently we need to unplug the connecting device and use another to
change IP address. (I mean I have to request DHCP for another IP.)
But currently I am asked to write a script using Perl. Could someone please help me how to do that?
My try to do it is :
#!/usr/bin/perl
# Simple DHCP client - sending a broadcasted DHCP Discover request
use IO::Socket::INET;
use Net::DHCP::Packet;
use Net::DHCP::Constants;
use POSIX qw(setsid strftime);
# sample logger
sub logger{
my $str = shift;
print STDOUT strftime "[%d/%b/%Y:%H:%M:%S] ", localtime;
print STDOUT "$str\n";
}
logger("DHCPd tester - dummy client");
logger("Opening socket");
$handle = IO::Socket::INET->new(Proto => 'udp',
Broadcast => 1,
PeerPort => '67',
LocalPort => '68',
PeerAddr => '255.255.255.255',
)
|| die "Socket creation error: $#\n"; # yes, it uses $# here
# create DHCP Packet DISCOVER
$discover = Net::DHCP::Packet->new(
Xid => 0x12345678,
DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER(),
DHO_VENDOR_CLASS_IDENTIFIER() => 'foo',
);
logger("Sending DISCOVER to 127.0.0.1:67");
logger($discover->toString());
$handle->send($discover->serialize())
or die "Error sending:$!\n";
logger("Waiting for response from server");
$handle->recv($buf, 4096) || die("recv:$!");
logger("Got response");
$response = new Net::DHCP::Packet($buf);
logger($response->toString());
# create DHCP Packet REQUEST
$request = Net::DHCP::Packet->new(
Xid => 0x12345678,
Ciaddr => $response->yiaddr(),
DHO_DHCP_MESSAGE_TYPE() => DHCPREQUEST(),
DHO_VENDOR_CLASS_IDENTIFIER() => 'foo',
DHO_DHCP_REQUESTED_ADDRESS() => $response->yiaddr(),
);
logger("Sending REQUEST to 127.0.0.1:67");
logger($request->toString());
$handle->send($request->serialize())
or die "Error sending:$!\n";
logger("Waiting for response from server");
$handle->recv($buf, 4096) || die("recv:$!");
logger("Got response");
$response = new Net::DHCP::Packet($buf);
logger($response->toString());
It's output on terminal is :
C:\shekhar_Axestrack_Intern\IpAddressChangeScripts>test6.pl
[08/Jan/2015:18:01:01] DHCPd tester - dummy client
[08/Jan/2015:18:01:01] Opening socket
[08/Jan/2015:18:01:01] Sending DISCOVER to 127.0.0.1:67
[08/Jan/2015:18:01:01] op = BOOTREQUEST
htype = HTYPE_ETHER
hlen = 6
hops = 0
xid = 12345678
secs = 0
flags = 0
ciaddr = 0.0.0.0
yiaddr = 0.0.0.0
siaddr = 0.0.0.0
giaddr = 0.0.0.0
chaddr =
sname =
file =
Options :
DHO_DHCP_MESSAGE_TYPE(53) = DHCPDISCOVER
DHO_VENDOR_CLASS_IDENTIFIER(60) = foo
padding [0] =
[08/Jan/2015:18:01:01] Waiting for response from server
//And it is stuck here since last 45 minutes....
My idea to do it is:
I will send a request to server (DHCP) (I think DHCPREQUEST() do that)that please provide me new IP adress.
Could some one please let me know if my last line will print ID adress or not ? I mean :
$response = new Net::DHCP::Packet($buf);
logger($response->toString());
EDIT:
I also tried this on suggestion by the experienced guys below but it still do not change IP adress (even i tried to run this perl code 4 times without success in IP change-Even i tried to run manually ipconfig /renew but still the IP is same all the time).
my $ipconfig = `ipconfig /renew`;
my $ipcfg_success = $?;
print $ipconfig;
if ($ipcfg_success == 0) {
do print "n succesfully runned \n";
} else {
do "\n succesfully NOT sunned \n";
}
Writing a DHCP client isn't going to change your system's IP address. You need to use the system's client.
system('ipconfig /release & ipconfig /renew');
You're not guaranteed to get a new address, though. It causes less headaches if machines always have the same IP address, so DHCP servers tend to always give the same address to a machine.
This more of a comment but it grew too long.
Just have your script call ipconfig /release and ipconfig /renew with a few seconds in between. That will request a new IP from the DHCP server, just as your script apparently tries to do.
Of course you are not exactly guaranteed a new IP that way, that depends on the configuration of the DHCP server but you are dependent on that either way. If the possible range of addresses is very small and you are afraid you might get the old IP by bad luck, check and renew again if it happened. If you get the same IP every time, it most likely means that the server recognizes you (by MAC or hostname) and assigns your static IP to you. In that case all you can do is talk to your network adminstrator (a course of action i would suggest anyways).
If you really need a guarantee, then you have to ditch DHCP and set your own IP. That however requires that you have some range of IPs reserved just for you. Otherwise your network administrator might hunt you down with their crossbow.
Be aware that depending on what that dongle is for and who set up that time limit, they may do anyways.
I wrote some code with help from examples but when I run it I'm getting error in Ubuntu Server 12.04.2 LTS:
Failed to connect to , problem connecting to "localhost", port 4242: Connection refused at /usr/local/share/perl/5.14.2/MozRepl/Client.pm line 144
How can i fix this ?
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize::Firefox;
use HTTP::Cookies;
my $username = "test";
my $password = "t3st";
my $mech = WWW::Mechanize::Firefox->new();
$mech->get("http://test.com/login.php"); print "Logging, Please Wait.\n";
$mech->submit_form(
form_number => 0,
fields => {
username => "$username",
password => "$password",
}
);
Install MozRepl firefox add-on on your firefox
Once installed, start the MozRepl in your firefox as below:
Tools->MozRepl->Start
Confirm that MozRepl is listening on port 4242 as below:
netstat -anp | grep firefox
tcp 0 0 127.0.0.1:4242 0.0.0.0:* LISTEN 1438/firefox
Good Luck !!
Note: I am not able to format this answer properly as SO formatting is not working as expected.
It is important to add to the answers above that since version 18, Firefox no longer displays the "Tools" menu unless you type the F10 key, or select "Options -> Menu bar".
Do you have the mozrepl plugin installed and enabled and configured for port 4242?
I am using Openssh module to connect to hosts using the (async => 1) option.
How is it possible to trap connection errors for those hosts that are not able to connect.I do not want the error to appear in the terminal but instead be stored in a data structure, since I want to finally format all the data as a cgi script.When I run the script the hosts that has a connection problem throw error in the terminal.The code executes further and try to run commands on disconnected hosts.I want to isolate the disconnected hosts.
my (%ssh, %ls); #Code copied from CPAN Net::OpenSSH
my #hosts = qw(host1 host2 host3 host4 );
# multiple connections are stablished in parallel:
for my $host (#hosts) {
$ssh{$host} = Net::OpenSSH->new($host, async => 1);
$ssh{$host}->error and die "no remote connection "; <--- doesn't work here! :-(
}
# then to run some command in all the hosts (sequentially):
for my $host (#hosts) {
$ssh{$host}->system('ls /');
}
$ssh{$host}->error and die "no remote connection doesn't work".
Any help will be appreciated.
Thanks
You run async connections. So program continue work and dont wait when connection is establised.
After new with async option you try to check error but it is not defined because connection in progress and no information about error.
As i understand you need wait after first loop until connection process got results.
Try to use ->wait_for_master(0);
If a false value is given, it will finalize the connection process and wait until the multiplexing socket is available.
It returns a true value after the connection has been succesfully established. False is returned if the connection process fails or if it has not yet completed (then, the "error" method can be used to distinguish between both cases).
for my $host (#hosts) {
$ssh{$host} = Net::OpenSSH->new($host, async => 1);
}
for my $host (#hosts) {
unless ($ssh{$host}->wait_for_master(0)) {
# check $ssh{$host}->error here. For example delete $ssh{$host}
}
}
# Do work here
I don't check this code.
PS: Sorry for my English. Hope it helps you.
I have a simple requirement of screen scraping a web-page (simple URL based reports) and direct the HTML response to an output file. The URL will however redirect to an authentication (HTTPS Login) page with "form based" authentication (no javascript) and upon authentication the report I am trying to view should show up in the $response (as HTML). Interestingly, my code is working just fine in a Windows machine, however the same code below is not working in AIX machine and it looks like the click_button() function call does nothing. I have tried click(), submit(), but none is working so instead of getting the actual report all I get is the logon screen in the HTML output file. Any ideas, what can be wrong?
use WWW::Mechanize;
use strict;
my $username = "admin";
my $password = "welcome1";
my $outpath = "/home/data/output";
my $fromday = 7;
my $url = "https://www.myreports.com/tax_report.php";
my $name = "tax_report";
my $outfile = "$outpath/$name.html";
my $mech = WWW::Mechanize->new(noproxy =>'0');
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon++; # since it will start from 0
$mday--; # yesterdays date (to day)
$fromday = $mday - $days; #(from day)
#Create URL extension for generating report with previous date
my $dt_range = "?Y&dc_date1=$mon%2F$fromday%2F$year&dc_date2=$mon%2F$mday%2F$year";
my $url = $url . $dt_range;
$mech->get($url);
$mech->field(login => "$username");
$mech->field(passwd => "$password");
$mech->add_handler("request_send", sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });
$mech->click_button(value=>"Login now");
my $response = $mech->content();
print "Generating report: $name...\n";
open (OUT, ">>$outfile")|| die "Cannot create report file $outfile";
print OUT "$response";
close OUT;
The WWW::Mechanize version in both the Machines are same i.e. 1.54 but the Win machine perl version is 5.10.1 whereas the AIX machine's Perl version is 5.8.8.
Other Alternatives Used -
my $inputobject=$mech->current_form()->find_input( undef,'submit' );
print $inputobject->value . "\n";
$mech->click_button(input => $inputobject);
print $mech->status() . "\n";
The $inputobject shows the correct button element as in the HTML source and the second print returns a status of 200 which apparently stands for OK. But its still not working in the AIX machine.
UPDATE- It seems that the site I am trying to connect to has an un-trusted SSL certificate. I tried the program on three different machines Windows PC, Mac and AIX. On the Windows Machine the program works and I was able to login to the website through the browsers (Chrome, Firefox,IE). However in Mac, the login just won't work (through the browsers) and it shows an un-trusted certificate error (or warning!) this probably means the proxy settings are not set up, the Perl program won't work either. And lastly the AIX where the Perl is not working as well. Not sure how to bypass this un-trusted SSL certificate issue here. Any help will be appreciated.
UPDATE2: Included below lines of code in the script to see logging details and found that I was being re-directed (HTTP 302) since my IP was filtered by the server Firewall. Once the AIX ip was added to the server's firewall exception the script worked perfectly. The two lines below were the life saver-
$mech->add_handler("request_send", sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });
Can you use the following line before my $mech = WWW::Mechanize->new(noproxy =>'0'); of your perl code and try again ?
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;