当前位置: 首页>>代码示例>>PHP>>正文


PHP mnet_peer::set_id方法代码示例

本文整理汇总了PHP中mnet_peer::set_id方法的典型用法代码示例。如果您正苦于以下问题:PHP mnet_peer::set_id方法的具体用法?PHP mnet_peer::set_id怎么用?PHP mnet_peer::set_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mnet_peer的用法示例。


在下文中一共展示了mnet_peer::set_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1:

 function refresh_key()
 {
     global $CFG;
     // set up an RPC request
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $mnetrequest = new mnet_xmlrpc_client();
     // Use any method - listServices is pretty lightweight.
     $mnetrequest->set_method('system/listServices');
     // Do RPC call and store response
     if ($mnetrequest->send($this) === true) {
         // Ok - we actually don't care about the result
         $temp = new mnet_peer();
         $temp->set_id($this->id);
         if ($this->public_key != $temp->public_key) {
             $newkey = clean_param($temp->public_key, PARAM_PEM);
             if (!empty($newkey)) {
                 $this->public_key = $newkey;
                 $this->updateparams->public_key = $newkey;
                 $this->commit();
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:25,代码来源:remote_client.php

示例2:

 function refresh_key()
 {
     // set up an RPC request
     $mnetrequest = new mnet_xmlrpc_client();
     // Use any method - listServices is pretty lightweight.
     $mnetrequest->set_method('system/listServices');
     // Do RPC call and store response
     if ($mnetrequest->send($this) === true) {
         // Ok - we actually don't care about the result
         $temp = new mnet_peer();
         $temp->set_id($this->id);
         if ($this->public_key != $temp->public_key) {
             $newkey = param_clean($temp->public_key, PARAM_PEM);
             if (!empty($newkey)) {
                 $this->public_key = $newkey;
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:21,代码来源:remote_client.php

示例3: resolve_theme

 /**
  * Work out the theme this page should use.
  *
  * This depends on numerous $CFG settings, and the properties of this page.
  *
  * @return string the name of the theme that should be used on this page.
  */
 protected function resolve_theme()
 {
     global $CFG, $USER, $SESSION;
     if (empty($CFG->themeorder)) {
         $themeorder = array('course', 'category', 'session', 'user', 'site');
     } else {
         $themeorder = $CFG->themeorder;
         // Just in case, make sure we always use the site theme if nothing else matched.
         $themeorder[] = 'site';
     }
     $mnetpeertheme = '';
     if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id) {
         require_once $CFG->dirroot . '/mnet/peer.php';
         $mnetpeer = new mnet_peer();
         $mnetpeer->set_id($USER->mnethostid);
         if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') {
             $mnetpeertheme = $mnetpeer->theme;
         }
     }
     $devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse);
     // The user is using another device than default, and we have a theme for that, we should use it.
     $hascustomdevicetheme = core_useragent::DEVICETYPE_DEFAULT != $this->devicetypeinuse && !empty($devicetheme);
     foreach ($themeorder as $themetype) {
         switch ($themetype) {
             case 'course':
                 if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && !$hascustomdevicetheme) {
                     return $this->_course->theme;
                 }
                 break;
             case 'category':
                 if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) {
                     $categories = $this->categories;
                     foreach ($categories as $category) {
                         if (!empty($category->theme)) {
                             return $category->theme;
                         }
                     }
                 }
                 break;
             case 'session':
                 if (!empty($SESSION->theme)) {
                     return $SESSION->theme;
                 }
                 break;
             case 'user':
                 if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && !$hascustomdevicetheme) {
                     if ($mnetpeertheme) {
                         return $mnetpeertheme;
                     } else {
                         return $USER->theme;
                     }
                 }
                 break;
             case 'site':
                 if ($mnetpeertheme) {
                     return $mnetpeertheme;
                 }
                 // First try for the device the user is using.
                 if (!empty($devicetheme)) {
                     return $devicetheme;
                 }
                 // Next try for the default device (as a fallback).
                 $devicetheme = core_useragent::get_device_type_theme(core_useragent::DEVICETYPE_DEFAULT);
                 if (!empty($devicetheme)) {
                     return $devicetheme;
                 }
                 // The default device theme isn't set up - use the overall default theme.
                 return theme_config::DEFAULT_THEME;
         }
     }
     // We should most certainly have resolved a theme by now. Something has gone wrong.
     debugging('Error resolving the theme to use for this page.', DEBUG_DEVELOPER);
     return theme_config::DEFAULT_THEME;
 }
开发者ID:fliphess,项目名称:moodle,代码行数:81,代码来源:pagelib.php

示例4: send


//.........这里部分代码省略.........
             }
         }
         if (!$isOpen) {
             trigger_error("None of our keys could open the payload from host {$mnet_peer->wwwroot} with id {$mnet_peer->id}.");
             $this->error[] = '3:No key match';
             return false;
         }
         if (strpos(substr($payload, 0, 100), '<signedMessage>')) {
             $sig_parser = new mnet_encxml_parser();
             $sig_parser->parse($payload);
         } else {
             $this->error[] = '2:Payload not signed: ' . $payload;
             return false;
         }
     } else {
         if (!empty($crypt_parser->remoteerror)) {
             $this->error[] = '4: remote server error: ' . $crypt_parser->remoteerror;
         } else {
             if (!empty($crypt_parser->error)) {
                 $crypt_parser_error = $crypt_parser->error[0];
                 $message = '3:XML Parse error in payload: ' . $crypt_parser_error['string'] . "\n";
                 if (array_key_exists('lineno', $crypt_parser_error)) {
                     $message .= 'At line number: ' . $crypt_parser_error['lineno'] . "\n";
                 }
                 if (array_key_exists('line', $crypt_parser_error)) {
                     $message .= 'Which reads: ' . $crypt_parser_error['line'] . "\n";
                 }
                 $this->error[] = $message;
             } else {
                 $this->error[] = '1:Payload not encrypted ';
             }
         }
         $crypt_parser->free_resource();
         return false;
     }
     // Margin of error is the time it took the request to complete.
     $margin_of_error = $timestamp_receive - $timestamp_send;
     // Guess the time gap between sending the request and the remote machine
     // executing the time() function. Marginally better than nothing.
     $hysteresis = $margin_of_error / 2;
     $remote_timestamp = $sig_parser->remote_timestamp - $hysteresis;
     $time_offset = $remote_timestamp - $timestamp_send;
     if ($time_offset > 0) {
         $threshold = get_config('mnet', 'drift_threshold');
         if (empty($threshold)) {
             // We decided 15 seconds was a pretty good arbitrary threshold
             // for time-drift between servers, but you can customize this in
             // the config_plugins table. It's not advised though.
             set_config('drift_threshold', 15, 'mnet');
             $threshold = 15;
         }
         if ($time_offset > $threshold) {
             $this->error[] = '6:Time gap with ' . $mnet_peer->name . ' (' . $time_offset . ' seconds) is greater than the permitted maximum of ' . $threshold . ' seconds';
             return false;
         }
     }
     $this->xmlrpcresponse = base64_decode($sig_parser->data_object);
     $this->response = xmlrpc_decode($this->xmlrpcresponse);
     curl_close($ch);
     // xmlrpc errors are pushed onto the $this->error stack
     if (is_array($this->response) && array_key_exists('faultCode', $this->response)) {
         // The faultCode 7025 means we tried to connect with an old SSL key
         // The faultString is the new key - let's save it and try again
         // The re_key attribute stops us from getting into a loop
         if ($this->response['faultCode'] == 7025 && empty($mnet_peer->re_key)) {
             $record = new stdClass();
             $record->id = $mnet_peer->id;
             if ($this->response['faultString'] == clean_param($this->response['faultString'], PARAM_PEM)) {
                 $record->public_key = $this->response['faultString'];
                 $details = openssl_x509_parse($record->public_key);
                 if (is_array($details) && isset($details['validTo_time_t'])) {
                     $record->public_key_expires = $details['validTo_time_t'];
                     update_record('mnet_host', $record);
                     $mnet_peer2 = new mnet_peer();
                     $mnet_peer2->set_id($record->id);
                     $mnet_peer2->re_key = true;
                     $this->send($mnet_peer2);
                 } else {
                     $this->error[] = $this->response['faultCode'] . " : " . $this->response['faultString'];
                 }
             } else {
                 $this->error[] = $this->response['faultCode'] . " : " . $this->response['faultString'];
             }
         } else {
             if (!empty($CFG->mnet_rpcdebug)) {
                 $guidance = get_string('error' . $this->response['faultCode'], 'mnet');
             } else {
                 $guidance = '';
             }
             $this->error[] = $this->response['faultCode'] . " : " . $this->response['faultString'];
         }
     }
     // ok, it's signed, but is it signed with the right certificate ?
     // do this *after* we check for an out of date key
     $verified = openssl_verify($this->xmlrpcresponse, base64_decode($sig_parser->signature), $mnet_peer->public_key);
     if ($verified != 1) {
         $this->error[] = 'Invalid signature';
     }
     return empty($this->error);
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:101,代码来源:client.php

示例5: elseif

            }
        }
        if ('input' == $form->step) {
            include './mnet_review.html';
        } elseif ('commit' == $form->step) {
            $bool = $mnet_peer->commit();
            if ($bool) {
                redirect('peers.php?step=update&amp;hostid=' . $mnet_peer->id, get_string('changessaved'));
            } else {
                print_error('invalidaction', 'error', 'index.php');
            }
        }
    }
} elseif (is_int($hostid)) {
    $mnet_peer = new mnet_peer();
    $mnet_peer->set_id($hostid);
    $currentkey = mnet_get_public_key($mnet_peer->wwwroot, $mnet_peer->application);
    if ($currentkey == $mnet_peer->public_key) {
        unset($currentkey);
    }
    $form = new stdClass();
    if ($hostid != $CFG->mnet_all_hosts_id) {
        $credentials = $mnet_peer->check_credentials($mnet_peer->public_key);
        include './mnet_review.html';
    } else {
        include './mnet_review_allhosts.html';
    }
} else {
    $hosts = $DB->get_records_sql('  SELECT 
                                    h.id, 
                                    h.wwwroot, 
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:peers.php

示例6: array

 /**
  * The IdP uses this function to kill child sessions on other hosts
  *
  * @param   string  $username       Username for session to kill
  * @param   string  $useragent      SHA1 hash of user agent to look for
  * @return  string                  A plaintext report of what has happened
  */
 function kill_children($username, $useragent)
 {
     global $CFG, $USER, $DB;
     $remoteclient = null;
     if (defined('MNET_SERVER')) {
         $remoteclient = get_mnet_remote_client();
     }
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $userid = $DB->get_field('user', 'id', array('mnethostid' => $CFG->mnet_localhost_id, 'username' => $username));
     $returnstring = '';
     $mnetsessions = $DB->get_records('mnet_session', array('userid' => $userid, 'useragent' => $useragent));
     if (false == $mnetsessions) {
         $returnstring .= "Could find no remote sessions\n";
         $mnetsessions = array();
     }
     foreach ($mnetsessions as $mnetsession) {
         // If this script is being executed by a remote peer, that means the user has clicked
         // logout on that peer, and the session on that peer can be deleted natively.
         // Skip over it.
         if (isset($remoteclient->id) && $mnetsession->mnethostid == $remoteclient->id) {
             continue;
         }
         $returnstring .= "Deleting session\n";
         $mnet_peer = new mnet_peer();
         $mnet_peer->set_id($mnetsession->mnethostid);
         $mnet_request = new mnet_xmlrpc_client();
         $mnet_request->set_method('auth/mnet/auth.php/kill_child');
         // set $token and $useragent parameters
         $mnet_request->add_param($username);
         $mnet_request->add_param($useragent);
         if ($mnet_request->send($mnet_peer) === false) {
             debugging("Server side error has occured on host {$mnetsession->mnethostid}: " . join("\n", $mnet_request->error));
         }
     }
     $ignore = $DB->delete_records('mnet_session', array('useragent' => $useragent, 'userid' => $userid));
     if (isset($remoteclient) && isset($remoteclient->id)) {
         session_kill_user($userid);
     }
     return $returnstring;
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:47,代码来源:auth.php

示例7: current_theme

/**
 * Returns the name of the current theme
 *
 * @uses $CFG
 * @uses $USER
 * @uses $SESSION
 * @uses $COURSE
 * @uses $SCRIPT
 * @return string
 */
function current_theme()
{
    global $CFG, $USER, $SESSION, $COURSE, $SCRIPT;
    if (empty($CFG->themeorder)) {
        $themeorder = array('page', 'course', 'category', 'session', 'user', 'site');
    } else {
        $themeorder = $CFG->themeorder;
    }
    if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id) {
        require_once $CFG->dirroot . '/mnet/peer.php';
        $mnet_peer = new mnet_peer();
        $mnet_peer->set_id($USER->mnethostid);
    }
    $theme = '';
    foreach ($themeorder as $themetype) {
        if (!empty($theme)) {
            continue;
        }
        switch ($themetype) {
            case 'page':
                // Page theme is for special page-only themes set by code
                if (!empty($CFG->pagetheme)) {
                    $theme = $CFG->pagetheme;
                }
                break;
            case 'course':
                if (!empty($CFG->allowcoursethemes) and !empty($COURSE->theme)) {
                    $theme = $COURSE->theme;
                }
                break;
            case 'category':
                if (!empty($CFG->allowcategorythemes)) {
                    /// Nasty hack to check if we're in a category page
                    if ($SCRIPT == '/course/category.php') {
                        global $id;
                        if (!empty($id)) {
                            $theme = current_category_theme($id);
                        }
                        /// Otherwise check if we're in a course that has a category theme set
                    } else {
                        if (!empty($COURSE->category)) {
                            $theme = current_category_theme($COURSE->category);
                        }
                    }
                }
                break;
            case 'session':
                if (!empty($SESSION->theme)) {
                    $theme = $SESSION->theme;
                }
                break;
            case 'user':
                if (!empty($CFG->allowuserthemes) and !empty($USER->theme)) {
                    if (isloggedin() and $USER->mnethostid != $CFG->mnet_localhost_id && $mnet_peer->force_theme == 1 && $mnet_peer->theme != '') {
                        $theme = $mnet_peer->theme;
                    } else {
                        $theme = $USER->theme;
                    }
                }
                break;
            case 'site':
                if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id && $mnet_peer->force_theme == 1 && $mnet_peer->theme != '') {
                    $theme = $mnet_peer->theme;
                } else {
                    $theme = $CFG->theme;
                }
                break;
            default:
                /// do nothing
        }
    }
    /// A final check in case 'site' was not included in $CFG->themeorder
    if (empty($theme)) {
        $theme = $CFG->theme;
    }
    return $theme;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:87,代码来源:weblib.php

示例8: definition

 /**
  * Describes the form, with the triplet (service_name, publish, subscribe).
  */
 public function definition()
 {
     global $CFG, $SESSION, $DB;
     // Settings variables.
     $mform =& $this->_form;
     // Master services.
     $defaultservices = $DB->get_records('mnet_service', array('offer' => 1), 'name');
     // get version info to get real names
     $self_mnet_peer = new mnet_peer();
     $self_mnet_peer->set_id($CFG->mnet_localhost_id);
     $myservices = mnet_get_service_info($self_mnet_peer);
     if (!empty($defaultservices)) {
         // Services fieldset.
         $mform->addElement('header', 'servicesform', get_string('servicesformselection', 'local_vmoodle'));
         $grid =& $mform->addElement('elementgrid', 'grid', get_string('mainservicesformselection', 'local_vmoodle'));
         $row = array();
         $row[] = get_string('publish', 'local_vmoodle');
         $row[] = get_string('subscribe', 'local_vmoodle');
         $row[] = '';
         $row[] = '';
         $grid->setColumnNames($row);
         foreach ($defaultservices as $defaultservice) {
             $row = array();
             $row[] = $mform->createElement('advcheckbox', 'main_' . $defaultservice->name . '_publish');
             $row[] = $mform->createElement('advcheckbox', 'main_' . $defaultservice->name . '_subscribe');
             $row[] = $mform->createElement('static', 'main_' . $defaultservice->name . '_description');
             $row[] = $mform->createElement('hidden', 'main_' . $defaultservice->name . '_id');
             $description = $defaultservice->description;
             if (empty($description)) {
                 $version = current($myservices[$defaultservice->name]);
                 $langmodule = ($version['plugintype'] == 'mod' ? '' : $version['plugintype'] . '_') . $version['pluginname'];
                 // TODO there should be a moodle-wide way to do this
                 $description = get_string($defaultservice->name . '_name', $langmodule);
             }
             $mform->setDefault('main_' . $defaultservice->name . '_description', $description);
             $mform->setDefault('main_' . $defaultservice->name . '_id', $defaultservice->id);
             $mform->setType('main_' . $defaultservice->name . '_id', PARAM_INT);
             $grid->addRow($row);
         }
         // Services fieldset.
         $grid =& $mform->addElement('elementgrid', 'grid', get_string('peerservicesformselection', 'local_vmoodle'));
         $row = array();
         $row[] = get_string('publish', 'local_vmoodle');
         $row[] = get_string('subscribe', 'local_vmoodle');
         $row[] = '';
         $row[] = '';
         $grid->setColumnNames($row);
         foreach ($defaultservices as $defaultservice) {
             $row = array();
             $row[] = $mform->createElement('advcheckbox', 'peer_' . $defaultservice->name . '_publish');
             $row[] = $mform->createElement('advcheckbox', 'peer_' . $defaultservice->name . '_subscribe');
             $row[] = $mform->createElement('static', 'peer_' . $defaultservice->name . '_description');
             $row[] = $mform->createElement('hidden', 'peer_' . $defaultservice->name . '_id');
             $description = $defaultservice->description;
             if (empty($description)) {
                 $version = current($myservices[$defaultservice->name]);
                 $langmodule = ($version['plugintype'] == 'mod' ? '' : $version['plugintype'] . '_') . $version['pluginname'];
                 // TODO there should be a moodle-wide way to do this
                 $description = get_string($defaultservice->name . '_name', $langmodule);
             }
             $mform->setDefault('peer_' . $defaultservice->name . '_description', $description);
             $mform->setDefault('peer_' . $defaultservice->name . '_id', $defaultservice->id);
             $mform->setType('peer_' . $defaultservice->name . '_id', PARAM_INT);
             $grid->addRow($row);
         }
         // Submit button.
         $mform->addElement('submit', 'submitbutton', get_string('edit'));
     } else {
         // Confirmation message.
         $message_object = new stdclass();
         $message_object->message = get_string('badservicesnumber', 'local_vmoodle');
         $message_object->style = 'notifyproblem';
         // Save confirm message before redirection.
         $SESSION->vmoodle_ma['confirm_message'] = $message_object;
         new moodle_url('/local/vmoodle/view.php', array('view' => 'management'));
     }
 }
开发者ID:gabrielrosset,项目名称:moodle-local_vmoodle,代码行数:80,代码来源:ServicesStrategy_Form.php

示例9: req_unenrol_user

 /**
  * Send request to unenrol our user from the remote course
  *
  * Updates our remote enrolments cache if the unenrolment was successful.
  *
  * @uses mnet_xmlrpc_client Invokes XML-RPC request
  * @param object $user our user
  * @param object $remotecourse record from mnetservice_enrol_courses table
  * @return true|string true if success, error message from the remote host otherwise
  */
 public function req_unenrol_user(stdclass $user, stdclass $remotecourse)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $peer = new mnet_peer();
     $peer->set_id($remotecourse->hostid);
     $request = new mnet_xmlrpc_client();
     $request->set_method('enrol/mnet/enrol.php/unenrol_user');
     $request->add_param($user->username);
     $request->add_param($remotecourse->remoteid);
     if ($request->send($peer) === true) {
         if ($request->response === true) {
             // clear the cached information
             $DB->delete_records('mnetservice_enrol_enrolments', array('hostid' => $peer->id, 'userid' => $user->id, 'remotecourseid' => $remotecourse->remoteid, 'enroltype' => 'mnet'));
             return true;
         } else {
             return serialize(array('invalid response: ' . print_r($request->response, true)));
         }
     } else {
         return serialize($request->error);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:32,代码来源:locallib.php

示例10:

 /**
  * Does Foo
  *
  * @param int    $mnethostid The id of the remote mnethost
  * @return array              Whether the user can login from the remote host
  */
 function req_unenrol_user($userid, $courseid)
 {
     global $CFG;
     global $USER;
     global $MNET;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     // in case the remote host doesn't have it
     $username = get_field('user', 'username', 'id', $userid);
     $course = get_record('mnet_enrol_course', 'id', $courseid);
     // get the Service Provider info
     $mnet_sp = new mnet_peer();
     $mnet_sp->set_id($course->hostid);
     // set up the RPC request
     $mnetrequest = new mnet_xmlrpc_client();
     $mnetrequest->set_method('enrol/mnet/enrol.php/unenrol_user');
     $mnetrequest->add_param($username);
     $mnetrequest->add_param($course->remoteid);
     // TODO - prevent removal of enrolments that are not of
     // type mnet...
     // Thunderbirds are go! Do RPC call and store response
     if ($mnetrequest->send($mnet_sp) === true) {
         if ($mnetrequest->response == true) {
             // remove enrolment cached in mnet_enrol_assignments
             delete_records_select('mnet_enrol_assignments', "userid={$userid} AND courseid={$course->id}");
             return true;
         }
     }
     return false;
 }
开发者ID:r007,项目名称:PMoodle,代码行数:35,代码来源:enrol.php

示例11: array

 /**
  * The IdP uses this function to kill child sessions on other hosts
  *
  * @param   string  $username       Username for session to kill
  * @param   string  $useragent      SHA1 hash of user agent to look for
  * @return  string                  A plaintext report of what has happened
  */
 function kill_children($username, $useragent)
 {
     global $CFG, $USER, $MNET_REMOTE_CLIENT, $DB;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $userid = $DB->get_field('user', 'id', array('mnethostid' => $CFG->mnet_localhost_id, 'username' => $username));
     $returnstring = '';
     $mnetsessions = $DB->get_records('mnet_session', array('userid' => $userid, 'useragent' => $useragent));
     if (false == $mnetsessions) {
         $returnstring .= "Could find no remote sessions\n";
         $mnetsessions = array();
     }
     foreach ($mnetsessions as $mnetsession) {
         // If this script is being executed by a remote peer, that means the user has clicked
         // logout on that peer, and the session on that peer can be deleted natively.
         // Skip over it.
         if (isset($MNET_REMOTE_CLIENT->id) && $mnetsession->mnethostid == $MNET_REMOTE_CLIENT->id) {
             continue;
         }
         $returnstring .= "Deleting session\n";
         $mnet_peer = new mnet_peer();
         $mnet_peer->set_id($mnetsession->mnethostid);
         $mnet_request = new mnet_xmlrpc_client();
         $mnet_request->set_method('auth/mnet/auth.php/kill_child');
         // set $token and $useragent parameters
         $mnet_request->add_param($username);
         $mnet_request->add_param($useragent);
         if ($mnet_request->send($mnet_peer) === false) {
             debugging("Server side error has occured on host {$mnetsession->mnethostid}: " . join("\n", $mnet_request->error));
         }
     }
     $ignore = $DB->delete_records('mnet_session', array('useragent' => $useragent, 'userid' => $userid));
     if (isset($MNET_REMOTE_CLIENT) && isset($MNET_REMOTE_CLIENT->id)) {
         $start = ob_start();
         // Save current session and cookie-use status
         $cookieuse = ini_get('session.use_cookies');
         ini_set('session.use_cookies', false);
         $sesscache = $_SESSION;
         $sessidcache = session_id();
         // Replace existing mnet session with user session & unset
         session_write_close();
         unset($_SESSION);
         session_id($mnetsession->session_id);
         session_start();
         session_unregister("USER");
         session_unregister("SESSION");
         unset($_SESSION);
         $_SESSION = array();
         session_write_close();
         // Restore previous info
         ini_set('session.use_cookies', $cookieuse);
         session_name('MoodleSession' . $CFG->sessioncookie);
         session_id($sessidcache);
         session_start();
         $_SESSION = $sesscache;
         session_write_close();
         $end = ob_end_clean();
     } else {
         $_SESSION = array();
     }
     return $returnstring;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:68,代码来源:auth.php

示例12: addslashes

 /**
  * The IdP uses this function to kill child sessions on other hosts
  *
  * @param   string  $username       Username for session to kill
  * @param   string  $useragent      SHA1 hash of user agent to look for
  * @return  string                  A plaintext report of what has happened
  */
 function kill_children($username, $useragent)
 {
     global $CFG, $USER, $MNET_REMOTE_CLIENT;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     $userid = get_field('user', 'id', 'mnethostid', $CFG->mnet_localhost_id, 'username', addslashes($username));
     $returnstring = '';
     $sql = "\n            select\n                *\n            from\n                {$CFG->prefix}mnet_session s\n            where\n                s.userid     = '{$userid}' AND\n                s.useragent  = '{$useragent}'";
     // If we are being executed from a remote machine (client) we don't have
     // to kill the moodle session on that machine.
     if (isset($MNET_REMOTE_CLIENT) && isset($MNET_REMOTE_CLIENT->id)) {
         $excludeid = $MNET_REMOTE_CLIENT->id;
     } else {
         $excludeid = -1;
     }
     $mnetsessions = get_records_sql($sql);
     if (false == $mnetsessions) {
         $returnstring .= "Could find no remote sessions\n{$sql}\n";
         $mnetsessions = array();
     }
     foreach ($mnetsessions as $mnetsession) {
         $returnstring .= "Deleting session\n";
         if ($mnetsession->mnethostid == $excludeid) {
             continue;
         }
         $mnet_peer = new mnet_peer();
         $mnet_peer->set_id($mnetsession->mnethostid);
         $mnet_request = new mnet_xmlrpc_client();
         $mnet_request->set_method('auth/mnet/auth.php/kill_child');
         // set $token and $useragent parameters
         $mnet_request->add_param($username);
         $mnet_request->add_param($useragent);
         if ($mnet_request->send($mnet_peer) === false) {
             debugging("Server side error has occured on host {$mnetsession->mnethostid}: " . join("\n", $mnet_request->error));
         }
     }
     $ignore = delete_records('mnet_session', 'useragent', $useragent, 'userid', $userid);
     if (isset($MNET_REMOTE_CLIENT) && isset($MNET_REMOTE_CLIENT->id)) {
         $start = ob_start();
         $uc = ini_get('session.use_cookies');
         ini_set('session.use_cookies', false);
         $sesscache = clone $_SESSION;
         $sessidcache = session_id();
         session_write_close();
         unset($_SESSION);
         session_id($mnetsession->session_id);
         session_start();
         session_unregister("USER");
         session_unregister("SESSION");
         unset($_SESSION);
         $_SESSION = array();
         session_write_close();
         ini_set('session.use_cookies', $uc);
         session_name('MoodleSession' . $CFG->sessioncookie);
         session_id($sessidcache);
         session_start();
         $_SESSION = clone $sesscache;
         session_write_close();
         $end = ob_end_clean();
     } else {
         $_SESSION = array();
     }
     return $returnstring;
 }
开发者ID:kai707,项目名称:ITSA-backup,代码行数:70,代码来源:auth.php

示例13: send


//.........这里部分代码省略.........
     $decryptedenvelope = '';
     //                                          &$decryptedenvelope
     $isOpen = openssl_open(base64_decode($data), $decryptedenvelope, base64_decode($key), $this->mnet->get_private_key());
     if (!$isOpen) {
         // Decryption failed... let's try our archived keys
         $openssl_history = get_config('mnet', 'openssl_history');
         if (empty($openssl_history)) {
             $openssl_history = array();
             set_config('openssl_history', serialize($openssl_history), 'mnet');
         } else {
             $openssl_history = unserialize($openssl_history);
         }
         foreach ($openssl_history as $keyset) {
             $keyresource = openssl_pkey_get_private($keyset['keypair_PEM']);
             $isOpen = openssl_open(base64_decode($data), $decryptedenvelope, base64_decode($key), $keyresource);
             if ($isOpen) {
                 // It's an older code, sir, but it checks out
                 break;
             }
         }
     }
     if (!$isOpen) {
         trigger_error("None of our keys could open the payload from host {$mnet_peer->wwwroot} with id {$mnet_peer->id}.");
         $this->error[] = '3:No key match';
         return false;
     }
     if (strpos(substr($decryptedenvelope, 0, 100), '<signedMessage>')) {
         $sig_parser = new mnet_encxml_parser();
         $sig_parser->parse($decryptedenvelope);
     } else {
         $this->error[] = '2:Payload not signed: ' . $decryptedenvelope;
         return false;
     }
     // Margin of error is the time it took the request to complete.
     $margin_of_error = $timestamp_receive - $timestamp_send;
     // Guess the time gap between sending the request and the remote machine
     // executing the time() function. Marginally better than nothing.
     $hysteresis = $margin_of_error / 2;
     $remote_timestamp = $sig_parser->remote_timestamp - $hysteresis;
     $time_offset = $remote_timestamp - $timestamp_send;
     if ($time_offset > 0) {
         $threshold = get_config('mnet', 'drift_threshold');
         if (empty($threshold)) {
             // We decided 15 seconds was a pretty good arbitrary threshold
             // for time-drift between servers, but you can customize this in
             // the config_plugins table. It's not advised though.
             set_config('drift_threshold', 15, 'mnet');
             $threshold = 15;
         }
         if ($time_offset > $threshold) {
             $this->error[] = '6:Time gap with ' . $mnet_peer->name . ' (' . $time_offset . ' seconds) is greater than the permitted maximum of ' . $threshold . ' seconds';
             return false;
         }
     }
     $this->xmlrpcresponse = base64_decode($sig_parser->data_object);
     $this->response = xmlrpc_decode($this->xmlrpcresponse);
     // xmlrpc errors are pushed onto the $this->error stack
     if (is_array($this->response) && array_key_exists('faultCode', $this->response)) {
         // The faultCode 7025 means we tried to connect with an old SSL key
         // The faultString is the new key - let's save it and try again
         // The re_key attribute stops us from getting into a loop
         if ($this->response['faultCode'] == 7025 && empty($mnet_peer->re_key)) {
             mnet_debug('recieved an old-key fault, so trying to get the new key and update our records');
             // If the new certificate doesn't come thru clean_param() unmolested, error out
             if ($this->response['faultString'] != clean_param($this->response['faultString'], PARAM_PEM)) {
                 $this->error[] = $this->response['faultCode'] . " : " . $this->response['faultString'];
             }
             $record = new stdClass();
             $record->id = $mnet_peer->id;
             $record->public_key = $this->response['faultString'];
             $details = openssl_x509_parse($record->public_key);
             if (!isset($details['validTo_time_t'])) {
                 $this->error[] = $this->response['faultCode'] . " : " . $this->response['faultString'];
             }
             $record->public_key_expires = $details['validTo_time_t'];
             $DB->update_record('mnet_host', $record);
             // Create a new peer object populated with the new info & try re-sending the request
             $rekeyed_mnet_peer = new mnet_peer();
             $rekeyed_mnet_peer->set_id($record->id);
             $rekeyed_mnet_peer->re_key = true;
             return $this->send($rekeyed_mnet_peer);
         }
         if (!empty($CFG->mnet_rpcdebug)) {
             if (get_string_manager()->string_exists('error' . $this->response['faultCode'], 'mnet')) {
                 $guidance = get_string('error' . $this->response['faultCode'], 'mnet');
             } else {
                 $guidance = '';
             }
         } else {
             $guidance = '';
         }
         $this->error[] = $this->response['faultCode'] . " : " . $this->response['faultString'] . "\n" . $guidance;
     }
     // ok, it's signed, but is it signed with the right certificate ?
     // do this *after* we check for an out of date key
     if (!openssl_verify($this->xmlrpcresponse, base64_decode($sig_parser->signature), $mnet_peer->public_key)) {
         $this->error[] = 'Invalid signature';
     }
     return empty($this->error);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:101,代码来源:client.php

示例14: resolve_theme

    /**
     * Work out the theme this page should use.
     *
     * This depends on numerous $CFG settings, and the properties of this page.
     *
     * @return string the name of the theme that should be used on this page.
     */
    protected function resolve_theme() {
        global $CFG, $USER, $SESSION;

        if (empty($CFG->themeorder)) {
            $themeorder = array('course', 'category', 'session', 'user', 'site');
        } else {
            $themeorder = $CFG->themeorder;
            // Just in case, make sure we always use the site theme if nothing else matched.
            $themeorder[] = 'site';
        }

        $mnetpeertheme = '';
        if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id) {
            require_once($CFG->dirroot.'/mnet/peer.php');
            $mnetpeer = new mnet_peer();
            $mnetpeer->set_id($USER->mnethostid);
            if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') {
                $mnetpeertheme = $mnetpeer->theme;
            }
        }

        $theme = '';
        foreach ($themeorder as $themetype) {
            switch ($themetype) {
                case 'course':
                    if (!empty($CFG->allowcoursethemes) and !empty($this->course->theme)) {
                        return $this->course->theme;
                    }

                case 'category':
                    if (!empty($CFG->allowcategorythemes)) {
                        $categories = $this->categories;
                        foreach ($categories as $category) {
                            if (!empty($category->theme)) {
                                return $category->theme;
                            }
                        }
                    }

                case 'session':
                    if (!empty($SESSION->theme)) {
                        return $SESSION->theme;
                    }

                case 'user':
                    if (!empty($CFG->allowuserthemes) and !empty($USER->theme)) {
                        if ($mnetpeertheme) {
                            return $mnetpeertheme;
                        } else {
                            return $USER->theme;
                        }
                    }

                case 'site':
                    if ($mnetpeertheme) {
                        return $mnetpeertheme;
                    } else if(!empty($CFG->themelegacy) && $this->browser_is_outdated()) {
                        $this->_legacythemeinuse = true;
                        return $CFG->themelegacy;
                    } else {
                    	return $CFG->theme;
                    }
            }
        }
    }
开发者ID:nuckey,项目名称:moodle,代码行数:72,代码来源:pagelib.php

示例15: callRemoteMethod

 public function callRemoteMethod($method, $parameters, $server = null)
 {
     global $CFG, $SynchServerController;
     require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
     // For the demo, our 'remote' host is actually our local host.
     $wwwroot = $CFG->wwwroot;
     //$method = 'synch/mnet/synch.php/getBackupById';
     // Get local server.
     $localServer = $SynchServerController->checkAndCreateLocalServer();
     global $Out;
     //$Out->print_r($localServer, '$localServer = ');
     // Cannot continue without a local server
     if (empty($localServer)) {
         return null;
     }
     if (empty($server)) {
         //$Out->append('Generating default remote server');
         //$server = new synch_modal_Server();
         //$server->mnetHostId = 1020000003;
         $server = $SynchServerController->getRemoteServer();
     }
     //$Out->print_r($server, '$server = ');
     // Cannot continue without a remote server to call
     if (empty($server) || synch_empty($server->mnetHostId)) {
         return null;
     }
     // mnet_peer pulls information about a remote host from the database.
     $mnet_peer = new mnet_peer();
     $mnet_peer->set_wwwroot($wwwroot);
     $mnethostid = $server->mnetHostId;
     $mnet_peer->set_id($mnethostid);
     // Create a new request object
     $mnet_request = new mnet_xmlrpc_client();
     // Tell it the path to the method that we want to execute
     $mnet_request->set_method($method);
     // Set the time out to something decent in seconds
     //$mnet_request->set_timeout(600);
     //set_time_limit(120);
     // Add parameters for your function. The mnet_concatenate_strings takes three
     // parameters, like mnet_concatenate_strings($string1, $string2, $string3)
     // PHP is weakly typed, so you can get away with calling most things strings,
     // unless it's non-scalar (i.e. an array or object or something).
     foreach ($parameters as $param) {
         $mnet_request->add_param($param[0], $param[1]);
     }
     // We send the request:
     $mnet_request->send($mnet_peer);
     return $mnet_request->response;
 }
开发者ID:r007,项目名称:PMoodle,代码行数:49,代码来源:synch_synch_controller.php


注:本文中的mnet_peer::set_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。