Exemplo n.º 1
0
 public function test_is_remote_site_valid()
 {
     $hub = new local_hub();
     // TODO: move to: https://github.com/moodlehq/moodle-exttests
     $invalidsites = array('http://localhost', 'http://127.0.0.1', 'https://download.moodle.org/does-not-exist');
     foreach ($invalidsites as $site) {
         $this->assertFalse($hub->is_remote_site_valid($site), "{$site} reported valid");
     }
     $validsites = array('http://download.moodle.org', 'http://learn.moodle.net', 'https://learn.gold.ac.uk', 'http://devmooc.net/', 'http://englishwat.com/qvilearn/');
     foreach ($validsites as $site) {
         $this->assertTrue($hub->is_remote_site_valid($site), "{$site} reported invalid");
     }
 }
Exemplo n.º 2
0
        } else {
            $tokenerror = true;
        }
    } else {
        $tokenerror = true;
    }
    if (!empty($tokenerror)) {
        throw new moodle_exception(get_string('freshtokenerror', 'local_hub'));
    }
    echo $OUTPUT->header();
    echo $htmlcontent;
    echo $OUTPUT->footer();
    exit;
}
// Check if the remote site is available.
if (!$hub->is_remote_site_valid($url)) {
    $port = parse_url($url, PHP_URL_PORT);
    if (!empty($port) && $port != 80 && $port != 443) {
        throw new moodle_exception('cannotregisterbadport', 'local_hub', $url, $url);
    }
    throw new moodle_exception('cannotregisternotavailablesite', 'local_hub', $url, $url);
}
//check if the registration password is correct
$hubpassword = get_config('local_hub', 'password');
if (!empty($hubpassword) and $hubpassword != $password) {
    throw new moodle_exception('wronghubpassword', 'local_hub', $url . '/admin/registration/hubselector.php');
}
//check if the site url is already registered
$sitewithsameurl = $hub->get_site_by_url($url);
if (!empty($sitewithsameurl)) {
    $urlexists = true;
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Administrator can see if server can
 * @package   local_hub
 * @copyright 2014 Dan Poltawski <*****@*****.**>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->dirroot . '/local/hub/lib.php';
require_once $CFG->dirroot . "/local/hub/admin/forms.php";
admin_externalpage_setup('checksiteconnectivity');
$hub = new local_hub();
$mform = new local_hub_siteconnectivity_form();
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('checksiteconnectivity', 'local_hub'));
if ($data = $mform->get_data()) {
    if ($hub->is_remote_site_valid($data->url)) {
        echo $OUTPUT->notification(get_string('urlaccessible', 'local_hub', $data->url), 'notifysuccess');
    } else {
        echo $OUTPUT->notification(get_string('urlnotaccessible', 'local_hub', $data->url), 'notifyproblem');
    }
}
$mform->display();
echo $OUTPUT->footer();
Exemplo n.º 4
0
 /**
  * Update site registration
  * two security check:
  * 1- if the url changed, unactivate the site and alert the administrator
  * 2- call the site by web service and confirm it, if confirmation fail, the update is declare failed
  * @return boolean 1 if updated was successfull
  */
 public static function update_site_info($siteinfo)
 {
     // Ensure the current user is allowed to run this function
     $context = context_system::instance();
     self::validate_context($context);
     require_capability('local/hub:updateinfo', $context);
     $params = self::validate_parameters(self::update_site_info_parameters(), array('siteinfo' => $siteinfo));
     //check that the hub can access the site
     $hubmanager = new local_hub();
     if (!$hubmanager->is_remote_site_valid($params['siteinfo']['url'])) {
         throw new moodle_exception('cannotregisternotavailablesite', 'local_hub', $params['siteinfo']['url'], $params['siteinfo']['url']);
     }
     //add ip information
     $params['siteinfo']['ip'] = getremoteaddr();
     //retieve site url
     $token = optional_param('wstoken', '', PARAM_ALPHANUM);
     $siteurl = $hubmanager->get_communication(WSSERVER, REGISTEREDSITE, null, $token)->remoteurl;
     //this following error should never happen
     //(communication record doesn't exist and webservice token exists)
     if (empty($siteurl)) {
         throw new moodle_exception('noexistingcommunication', 'local_hub');
     }
     $result = $hubmanager->register_site($params['siteinfo'], $siteurl);
     return 1;
 }