| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?PHP // $Id: peers.php,v 1.14.2.4 2008/08/27 03:33:14 peterbulmer Exp $ 2 3 // Allows the admin to configure other Moodle hosts info 4 5 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); 6 require_once($CFG->libdir.'/adminlib.php'); 7 include_once($CFG->dirroot.'/mnet/lib.php'); 8 9 require_login(); 10 admin_externalpage_setup('mnetpeers'); 11 12 $context = get_context_instance(CONTEXT_SYSTEM); 13 14 require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions"); 15 16 if (!extension_loaded('openssl')) { 17 admin_externalpage_print_header(); 18 print_error('requiresopenssl', 'mnet'); 19 } 20 21 if (!$site = get_site()) { 22 admin_externalpage_print_header(); 23 print_error('nosite', ''); 24 } 25 26 if (!function_exists('curl_init') ) { 27 admin_externalpage_print_header(); 28 print_error('nocurl', 'mnet'); 29 } 30 31 /// Initialize variables. 32 33 // Step must be one of: 34 // input Parse the details of a new host and fetch its public key 35 // commit Save our changes (to a new OR existing host) 36 $step = optional_param('step', NULL, PARAM_ALPHA); 37 $hostid = optional_param('hostid', NULL, PARAM_INT); 38 39 // Fetch some strings for the HTML templates 40 $strmnetservices = get_string('mnetservices', 'mnet'); 41 $strmnetlog = get_string('mnetlog', 'mnet'); 42 $strmnetedithost = get_string('reviewhostdetails', 'mnet'); 43 $strmnetthemes = get_string('mnetthemes', 'mnet'); 44 45 if (!isset($CFG->mnet_dispatcher_mode)) set_config('mnet_dispatcher_mode', 'off'); 46 47 /// If data submitted, process and store 48 if (($form = data_submitted()) && confirm_sesskey()) { 49 50 if (!empty($form->wwwroot)) { 51 // ensure we remove trailing slashes 52 $form->wwwroot = preg_replace(':/$:', '', $form->wwwroot); 53 54 // ensure the wwwroot starts with a http or https prefix 55 if (strtolower(substr($form->wwwroot, 0, 4)) != 'http') { 56 $form->wwwroot = 'http://'.$form->wwwroot; 57 } 58 } 59 60 if(!function_exists('xmlrpc_encode_request')) { 61 trigger_error("You must have xml-rpc enabled in your PHP build to use this feature."); 62 print_error('xmlrpc-missing', 'mnet','peers.php'); 63 exit; 64 } 65 66 if (!empty($form->updateregisterall)) { 67 if (!empty($form->registerallhosts)) { 68 set_config('mnet_register_allhosts',1); 69 } else { 70 set_config('mnet_register_allhosts',0); 71 } 72 redirect('peers.php', get_string('changessaved')); 73 } else { 74 75 $mnet_peer = new mnet_peer(); 76 77 if (!empty($form->id)) { 78 $form->id = clean_param($form->id, PARAM_INT); 79 $mnet_peer->set_id($form->id); 80 } else { 81 // PARAM_URL requires a genuine TLD (I think) This breaks my testing 82 $temp_wwwroot = clean_param($form->wwwroot, PARAM_URL); 83 if ($temp_wwwroot !== $form->wwwroot) { 84 trigger_error("We now parse the wwwroot with PARAM_URL. Your URL will need to have a valid TLD, etc."); 85 print_error("invalidurl", 'mnet','peers.php'); 86 exit; 87 } 88 unset($temp_wwwroot); 89 $mnet_peer->set_applicationid($form->applicationid); 90 $application = get_field('mnet_application', 'name', 'id', $form->applicationid); 91 $mnet_peer->bootstrap($form->wwwroot, null, $application); 92 } 93 94 if (isset($form->name) && $form->name != $mnet_peer->name) { 95 $form->name = clean_param($form->name, PARAM_NOTAGS); 96 $mnet_peer->set_name($form->name); 97 } 98 99 if (isset($form->deleted) && ($form->deleted == '0' || $form->deleted == '1')) { 100 $mnet_peer->updateparams->deleted = $form->deleted; 101 $mnet_peer->deleted = $form->deleted; 102 } 103 104 if (isset($form->public_key)) { 105 $form->public_key = clean_param($form->public_key, PARAM_PEM); 106 if (empty($form->public_key)) { 107 print_error("invalidpubkey", 'mnet', 'peers.php?step=update&hostid='.$mnet_peer->id); 108 exit; 109 } else { 110 $oldkey = $mnet_peer->public_key; 111 $mnet_peer->public_key = $form->public_key; 112 $mnet_peer->updateparams->public_key = addslashes($form->public_key); 113 $mnet_peer->public_key_expires = $mnet_peer->check_common_name($form->public_key); 114 $mnet_peer->updateparams->public_key_expires = $mnet_peer->check_common_name($form->public_key); 115 if ($mnet_peer->public_key_expires == false) { 116 $errmsg = '<br />'; 117 foreach ($mnet_peer->error as $err) { 118 $errmsg .= $err['code'] . ': ' . $err['text'].'<br />'; 119 } 120 error(get_string("invalidpubkey", 'mnet') . $errmsg ,'peers.php?step=update&hostid='.$mnet_peer->id); 121 //print_error("invalidpubkey", 'mnet', 'peers.php?step=update&hostid='.$mnet_peer->id, $errmsg); 122 exit; 123 } 124 } 125 } 126 127 // PREVENT DUPLICATE RECORDS /////////////////////////////////////////// 128 if ('input' == $form->step) { 129 if ( isset($mnet_peer->id) && $mnet_peer->id > 0 ) { 130 print_error("hostexists", 'mnet', 'peers.php?step=update&hostid='.$mnet_peer->id, $mnet_peer->id); 131 } 132 } 133 134 if ('input' == $form->step) { 135 include ('./mnet_review.html'); 136 } elseif ('commit' == $form->step) { 137 $bool = $mnet_peer->commit(); 138 if ($bool) { 139 redirect('peers.php?step=update&hostid='.$mnet_peer->id, get_string('changessaved')); 140 } else { 141 error('Invalid action parameter.', 'index.php'); 142 } 143 } 144 } 145 } elseif (is_int($hostid)) { 146 $mnet_peer = new mnet_peer(); 147 $mnet_peer->set_id($hostid); 148 $currentkey = mnet_get_public_key($mnet_peer->wwwroot, $mnet_peer->application); 149 if($currentkey == $mnet_peer->public_key) unset($currentkey); 150 $form = new stdClass(); 151 if ($hostid != $CFG->mnet_all_hosts_id) { 152 include ('./mnet_review.html'); 153 } else { 154 include ('./mnet_review_allhosts.html'); 155 } 156 } else { 157 $hosts = get_records_sql(' SELECT 158 h.id, 159 h.wwwroot, 160 h.ip_address, 161 h.name, 162 h.public_key, 163 h.public_key_expires, 164 h.transport, 165 h.portno, 166 h.last_connect_time, 167 h.last_log_id, 168 h.applicationid, 169 a.name as app_name, 170 a.display_name as app_display_name, 171 a.xmlrpc_server_url 172 FROM 173 '.$CFG->prefix.'mnet_host h, 174 '.$CFG->prefix.'mnet_application a 175 WHERE 176 h.id != \''.$CFG->mnet_localhost_id.'\' AND 177 h.deleted = \'0\' AND 178 h.applicationid=a.id'); 179 180 if (empty($hosts)) $hosts = array(); 181 $applications = get_records('mnet_application'); 182 include ('./peers.html'); 183 } 184 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |