}
        }
        //OUTPUT: create token form
        echo $OUTPUT->header();
        echo $OUTPUT->heading(get_string('createtoken', 'webservice'));
        if (!empty($errormsg)) {
            echo $errormsg;
        }
        $mform->display();
        echo $OUTPUT->footer();
        die;
        break;
    case 'delete':
        $token = $webservicemanager->get_created_by_user_ws_token($USER->id, $tokenid);
        //Delete the token
        if ($confirm and confirm_sesskey()) {
            $webservicemanager->delete_user_ws_token($token->id);
            redirect($tokenlisturl);
        }
        ////OUTPUT: display delete token confirmation box
        echo $OUTPUT->header();
        $renderer = $PAGE->get_renderer('core', 'webservice');
        echo $renderer->admin_delete_token_confirmation($token);
        echo $OUTPUT->footer();
        die;
        break;
    default:
        //wrong url access
        redirect($tokenlisturl);
        break;
}
Ejemplo n.º 2
0
        $params = array();
        $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
        require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php";
        $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hubtodirectorycommunication->token);
        try {
            $result = $xmlrpcclient->call($function, $params);
        } catch (Exception $e) {
            $error = get_string('errorunregistration', 'local_hub', $e->getMessage());
        }
    }
    if (empty($error)) {
        if (!empty($directorytohubcommunication)) {
            //delete the web service token
            $webservice_manager = new webservice();
            $tokentodelete = $webservice_manager->get_user_ws_token($directorytohubcommunication->token);
            $webservice_manager->delete_user_ws_token($tokentodelete->id);
            //delete the communication
            $hub->delete_communication($directorytohubcommunication);
        }
        if (!empty($hubtodirectorycommunication)) {
            $hub->delete_communication($hubtodirectorycommunication);
        }
    }
    redirect(new moodle_url('/local/hub/admin/register.php', array('sesskey' => sesskey(), 'error' => $error)));
}
/////// UPDATE ACTION ////////
// update the hub registration (in fact it is a new registration)
$update = optional_param('update', 0, PARAM_INT);
if ($update && confirm_sesskey()) {
    //update the registration
    $function = 'hubdirectory_update_hub_info';
Ejemplo n.º 3
0
if (!is_siteadmin($USER->id) && !empty($CFG->enablewebservices) && has_capability('moodle/webservice:createtoken', $usercontext)) {
    require $CFG->dirroot . '/webservice/lib.php';
    $action = optional_param('action', '', PARAM_ALPHANUMEXT);
    $tokenid = optional_param('tokenid', '', PARAM_SAFEDIR);
    $confirm = optional_param('confirm', 0, PARAM_BOOL);
    $webservice = new webservice();
    // Load the webservice library.
    $wsrenderer = $PAGE->get_renderer('core', 'webservice');
    if ($action == 'resetwstoken') {
        $token = $webservice->get_created_by_user_ws_token($USER->id, $tokenid);
        // Display confirmation page to Reset the token.
        if (!$confirm) {
            $resetconfirmation = $wsrenderer->user_reset_token_confirmation($token);
        } else {
            // Delete the token that need to be regenerated.
            $webservice->delete_user_ws_token($tokenid);
        }
    }
    // No point creating the table is we're just displaying a confirmation screen.
    if (empty($resetconfirmation)) {
        $webservice->generate_user_ws_tokens($USER->id);
        // Generate all token that need to be generated.
        $tokens = $webservice->get_user_ws_tokens($USER->id);
        foreach ($tokens as $token) {
            if ($token->restrictedusers) {
                $authlist = $webservice->get_ws_authorised_user($token->wsid, $USER->id);
                if (empty($authlist)) {
                    $token->enabled = false;
                }
            }
        }
Ejemplo n.º 4
0
 function delete_site($id, $unregistercourses = false)
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/hub/locallib.php';
     $sitetodelete = $this->get_site($id);
     //unregister the courses first
     if (!empty($unregistercourses)) {
         $this->delete_courses($sitetodelete->id);
     }
     $sitetohubcommunication = $this->get_communication(WSSERVER, REGISTEREDSITE, $sitetodelete->url);
     if (!empty($sitetohubcommunication)) {
         //delete the token for this site
         require_once $CFG->dirroot . '/webservice/lib.php';
         $webservice_manager = new webservice();
         $tokentodelete = $webservice_manager->get_user_ws_token($sitetohubcommunication->token);
         $webservice_manager->delete_user_ws_token($tokentodelete->id);
         //delete the communications to this hub
         $this->delete_communication($sitetohubcommunication);
     }
     // Send email to the site administrator.
     $contactuser = local_hub_create_contact_user($sitetodelete->contactemail ? $sitetodelete->contactemail : $CFG->noreplyaddress, $sitetodelete->contactname ? $sitetodelete->contactname : get_string('noreplyname'));
     $emailinfo = new stdClass();
     $hubinfo = $this->get_info();
     $emailinfo->hubname = $hubinfo['name'];
     $emailinfo->huburl = $hubinfo['url'];
     $emailinfo->sitename = $sitetodelete->name;
     $emailinfo->siteurl = $sitetodelete->url;
     $emailinfo->unregisterpagelink = $sitetodelete->url . '/admin/registration/index.php?huburl=' . $hubinfo['url'] . '&force=1&unregistration=1';
     email_to_user($contactuser, get_admin(), get_string('emailtitlesitedeleted', 'local_hub', $emailinfo), get_string('emailmessagesitedeleted', 'local_hub', $emailinfo));
     $this->unregister_site($sitetodelete);
 }
Ejemplo n.º 5
0
 /**
  * Unregister site
  * @return bool 1 if unregistration was successfull
  */
 public static function unregister_site()
 {
     global $DB, $CFG;
     // Ensure the current user is allowed to run this function
     $context = context_system::instance();
     self::validate_context($context);
     require_capability('local/hub:updateinfo', $context);
     //clean params
     $params = self::validate_parameters(self::unregister_site_parameters(), array());
     //retieve the site communication
     $token = optional_param('wstoken', '', PARAM_ALPHANUM);
     $hub = new local_hub();
     $communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, null, $token);
     //retrieve the site
     $siteurl = $communication->remoteurl;
     $site = $hub->get_site_by_url($siteurl);
     //unregister the site
     if (!empty($site)) {
         $hub->unregister_site($site);
     }
     //delete the web service token
     require_once $CFG->dirroot . '/webservice/lib.php';
     $webservice_manager = new webservice();
     $tokentodelete = $webservice_manager->get_user_ws_token($communication->token);
     $webservice_manager->delete_user_ws_token($tokentodelete->id);
     //delete the site communication
     $hub->delete_communication($communication);
     return true;
 }