Esempio n. 1
0
 /**
  * Parse the robots.txt text file to find the sitemap
  *
  * @return string|boolean
  */
 protected function getSitemapUrl()
 {
     $request = new Request($this->request->getUrl(), $this->input->getOption('insecure'));
     $response = $request->get('robots.txt');
     $sitemap = new Sitemap();
     $sitemap->setRequest($this->request);
     return $sitemap->getSitemapFromRobotsTxt($response);
 }
Esempio n. 2
0
 /**
  * Test a good all match
  */
 public function testFindMatchInResponseAllGood()
 {
     $response = new \stdClass();
     $response->code = 200;
     $response->body = 'Hello world!';
     $request = new Request();
     $match = $request->findMatchInResponse($response, '/(Hello) (world)!/', true);
     $this->assertSame('world', $match[2]);
 }
Esempio n. 3
0
 /**
  * Initialize command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $this->request = new Request();
     $this->request->setInsecure($this->input->getOption('insecure'));
     $style = new OutputFormatterStyle('white', 'blue', array('bold'));
     $this->output->getFormatter()->setStyle('header', $style);
     $this->setUrl($input->getArgument('url'));
 }
Esempio n. 4
0
 /**
  * Get an instance of the Request object
  *
  * @return \MageScan\Request
  */
 public function getRequest()
 {
     if ($this->request === null) {
         $this->setRequest(new Request());
         if (isset($_SERVER['ALLOW_INSECURE']) && $_SERVER['ALLOW_INSECURE']) {
             $this->request->setInsecure(true);
         }
     }
     return $this->request;
 }
Esempio n. 5
0
 /**
  * Parse the robots.txt text file to find the sitemap
  *
  * @return string
  */
 protected function getSitemapUrl()
 {
     $request = new Request();
     $response = $request->fetch($this->url . 'robots.txt');
     $sitemap = new Sitemap();
     $sitemap->setRequest($this->request);
     $sitemap = $sitemap->getSitemapFromRobotsTxt($response);
     if ($sitemap === false) {
         $this->output->writeln('<error>Sitemap is not declared in robots.txt</error>');
         return $this->url . 'sitemap.xml';
     }
     $this->output->writeln('<info>Sitemap is declared in robots.txt</info>');
     return (string) $sitemap;
 }
Esempio n. 6
0
 /**
  * Check for a valid sitemap
  *
  * @return void
  */
 public function checkSitemap()
 {
     $rows = [];
     $response = $this->request->get('robots.txt');
     $sitemap = new Sitemap();
     $sitemap->setRequest($this->request);
     $sitemapUrl = $sitemap->getSitemapFromRobotsTxt($response);
     if ($sitemapUrl === false) {
         $rows[] = ['<span class="fail">Sitemap is not declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span>'];
         $sitemapUrl = $this->url . 'sitemap.xml';
     } else {
         $rows[] = ['<span class="pass">Sitemap is declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span></span>'];
     }
     $response = $this->request->get($sitemapUrl);
     if ($response->getStatusCode() == 200) {
         $rows[] = ['<span class="pass"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is accessible</span>'];
     } else {
         $rows[] = ['<span class="fail"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is not accessible</span>'];
     }
     $this->respond(['body' => $rows]);
 }
Esempio n. 7
0
 /**
  * Check if a given patch is installed
  *
  * @param string $endpoint
  *
  * @return integer
  */
 public function check($endpoint)
 {
     $request = new Request(self::BASE_URL);
     $response = $request->get($endpoint . '?s=' . $this->url);
     return $this->parseResponse($response);
 }
Esempio n. 8
0
 * @category  MageScan
 * @package   MageScan
 * @author    Steve Robbins <*****@*****.**>
 * @copyright 2015 Steve Robbins
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
 * @link      https://github.com/steverobbins/magescan
 */
require_once '../vendor/autoload.php';
use MageScan\Url;
use MageScan\Request;
$suggestUrl = '';
if (isset($_GET['url'])) {
    $url = $_GET['url'];
    $magescanUrl = new Url();
    $url = $magescanUrl->clean(urldecode($_GET['url']));
    $request = new Request();
    $response = $request->fetch($url, array(CURLOPT_NOBODY => true));
    if (isset($response->header['Location'])) {
        $suggestUrl = $response->header['Location'];
    }
    if (isset($response->header['location'])) {
        $suggestUrl = $response->header['location'];
    }
    $suggestUrl = trim($suggestUrl, '/');
} else {
    $url = false;
}
?>
<!DOCTYPE html>
<html>
<head>
Esempio n. 9
0
 /**
  * Check for a valid sitemap
  *
  * @return void
  */
 public function checkSitemap()
 {
     $rows = array();
     $request = new Request();
     $response = $request->fetch($this->url . 'robots.txt');
     $sitemap = new Sitemap();
     $sitemapUrl = $sitemap->getSitemapFromRobotsTxt($response);
     if ($sitemapUrl === false) {
         $rows[] = array('<span class="fail">Sitemap is not declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span>');
         $sitemapUrl = $this->url . 'sitemap.xml';
     } else {
         $rows[] = array('<span class="pass">Sitemap is declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span></span>');
     }
     $request = new Request();
     $response = $request->fetch((string) $sitemapUrl, array(CURLOPT_NOBODY => true, CURLOPT_FOLLOWLOCATION => true));
     if ($response->code == 200) {
         $rows[] = array('<span class="pass"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is accessible</span>');
     } else {
         $rows[] = array('<span class="fail"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is not accessible</span>');
     }
     $this->respond(array('body' => $rows));
 }
Esempio n. 10
0
 /**
  * Download the latest version of magescan
  *
  * @param string $filename
  *
  * @return void
  */
 protected function downloadLatestVersion($filename)
 {
     $request = new Request();
     $response = $request->fetch(self::URL_DOWNLOAD);
     return file_put_contents($filename, $response->body) !== false;
 }
Esempio n. 11
0
 /**
  * Test a good all match
  *
  * @return void
  */
 public function testFindMatchInResponseAllGood()
 {
     $body = 'Hello world!';
     $response = $this->mockResponse(200, $body);
     $request = new Request();
     $match = $request->findMatchInResponse($response->getBody()->getContents(), '/(Hello) (world)!/', true);
     $this->assertSame('world', $match[2]);
 }
Esempio n. 12
0
 * @category  MageScan
 * @package   MageScan
 * @author    Steve Robbins <*****@*****.**>
 * @copyright 2015 Steve Robbins
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
 * @link      https://github.com/steverobbins/magescan
 */
require_once '../vendor/autoload.php';
use MageScan\Url;
use MageScan\Request;
$suggestUrl = '';
if (isset($_GET['url'])) {
    $url = $_GET['url'];
    $magescanUrl = new Url();
    $url = $magescanUrl->clean(urldecode($_GET['url']));
    $request = new Request($url, false);
    $response = $request->get($url);
    $headers = $response->getHeaders();
    if (isset($headers['Location'])) {
        $suggestUrl = $headers['Location'];
    }
    $suggestUrl = trim($suggestUrl, '/');
} else {
    $url = false;
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Mage Scan<?php