Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
connectivity.php
1 <?php
28 // Prevent the access to the script from the outside world
29 require_once dirname(__FILE__).'/../../include/init.inc';
30 if (empty($GLOBALS['SQ_SYSTEM']->user) || !($GLOBALS['SQ_SYSTEM']->user->canAccessBackend() || $GLOBALS['SQ_SYSTEM']->user->type() == 'simple_edit_user')) {
31  exit;
32 }
33 
34 $url = '';
35 if (isset($_REQUEST['connect_url'])) {
36  $url = $_REQUEST['connect_url'];
37 }//end if
38 
39 $current_url = '';
40 if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['PHP_SELF'])) {
41  $current_url = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
42 }//end if
43 
44 // no url supplied or trying to recurse? return 0.
45 if (empty($url) || (!empty($current_url) && strpos($url, $current_url) !== FALSE)) {
46  echo 0;
47  exit;
48 }
49 
54 $url_ok = @parse_url($url);
55 if (!$url_ok) {
56  echo 0;
57  exit;
58 }
59 
60 $options = array(
61  'FOLLOWLOCATION' => true,
62  'NOBODY' => true,
63  'RETURNTRANSFER' => true,
64  'CONNECTTIMEOUT' => 5,
65  'MAXREDIRS' => 5,
66  'TIMEOUT' => 5,
67  );
68 
69 $response = fetch_url($url, $options, array(), FALSE);
70 if ($response['errornumber'] === 0 && $response['curlinfo']['http_code'] == 200) {
71  echo 1;
72 } else {
73  echo 0;
74 }
75