adding some strings
[moodle-linuxchix.git] / admin / mnet / peers.php
blob2fdf215dcfd01c7d1a02142135440062fb4820dd
1 <?PHP // $Id$
3 // Allows the admin to configure other Moodle hosts info
5 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
6 require_once($CFG->libdir.'/adminlib.php');
7 include_once($CFG->dirroot.'/mnet/lib.php');
9 require_login();
10 admin_externalpage_setup('mnetpeers');
12 $context = get_context_instance(CONTEXT_SYSTEM);
14 require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
16 if (!extension_loaded('openssl')) {
17 admin_externalpage_print_header();
18 print_error('requiresopenssl', 'mnet', '', NULL, true);
21 if (!$site = get_site()) {
22 admin_externalpage_print_header();
23 print_error('nosite', '', '', NULL, true);
26 if (!function_exists('curl_init') ) {
27 admin_externalpage_print_header();
28 print_error('nocurl', 'mnet', '', NULL, true);
31 /// Initialize variables.
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);
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');
44 if (!isset($CFG->mnet_dispatcher_mode)) set_config('mnet_dispatcher_mode', 'off');
46 /// If data submitted, process and store
47 if (($form = data_submitted()) && confirm_sesskey()) {
49 if (!empty($form->wwwroot)) {
50 // ensure we remove trailing slashes
51 $form->wwwroot = preg_replace(':/$:', '', $form->wwwroot);
54 if(!function_exists('xmlrpc_encode_request')) {
55 trigger_error("You must have xml-rpc enabled in your PHP build to use this feature.");
56 error(get_string('xmlrpc-missing', 'mnet'),'peers.php');
57 exit;
60 if (!empty($form->updateregisterall)) {
61 if (!empty($form->registerallhosts)) {
62 set_config('mnet_register_allhosts',1);
63 } else {
64 set_config('mnet_register_allhosts',0);
66 redirect('peers.php', get_string('changessaved'));
67 } else {
69 $mnet_peer = new mnet_peer();
71 if (!empty($form->id)) {
72 $form->id = clean_param($form->id, PARAM_INT);
73 $mnet_peer->set_id($form->id);
74 } else {
75 // PARAM_URL requires a genuine TLD (I think) This breaks my testing
76 $temp_wwwroot = clean_param($form->wwwroot, PARAM_URL);
77 if ($temp_wwwroot !== $form->wwwroot) {
78 trigger_error("We now parse the wwwroot with PARAM_URL. Your URL will need to have a valid TLD, etc.");
79 error(get_string("invalidurl", 'mnet'),'peers.php');
80 exit;
82 unset($temp_wwwroot);
83 $mnet_peer->set_applicationid($form->applicationid);
84 $application = get_field('mnet_application', 'name', 'id', $form->applicationid);
85 $mnet_peer->bootstrap($form->wwwroot, null, $application);
88 if (isset($form->name) && $form->name != $mnet_peer->name) {
89 $form->name = clean_param($form->name, PARAM_NOTAGS);
90 $mnet_peer->set_name($form->name);
93 if (isset($form->deleted) && ($form->deleted == '0' || $form->deleted == '1')) {
94 $mnet_peer->deleted = $form->deleted;
97 if (isset($form->public_key)) {
98 $form->public_key = clean_param($form->public_key, PARAM_PEM);
99 if (empty($form->public_key)) {
100 error(get_string("invalidpubkey", 'mnet'),'peers.php?step=update&amp;hostid='.$mnet_peer->id);
101 exit;
102 } else {
103 $oldkey = $mnet_peer->public_key;
104 $mnet_peer->public_key = $form->public_key;
105 $mnet_peer->public_key_expires = $mnet_peer->check_common_name($form->public_key);
106 if ($mnet_peer->public_key_expires == false) {
107 $mnet_peer->public_key == $oldkey;
108 $errmsg = '<br />';
109 foreach ($mnet_peer->error as $err) {
110 $errmsg .= $err['code'] . ': ' . $err['text'].'<br />';
112 error(get_string("invalidpubkey", 'mnet') . $errmsg ,'peers.php?step=update&amp;hostid='.$mnet_peer->id);
113 exit;
118 // PREVENT DUPLICATE RECORDS ///////////////////////////////////////////
119 if ('input' == $form->step) {
120 if ( isset($mnet_peer->id) && $mnet_peer->id > 0 ) {
121 error(get_string("hostexists", 'mnet', $mnet_peer->id),'peers.php?step=update&amp;hostid='.$mnet_peer->id);
125 if ('input' == $form->step) {
126 include('./mnet_review.html');
127 } elseif ('commit' == $form->step) {
128 $bool = $mnet_peer->commit();
129 if ($bool) {
130 redirect('peers.php?step=update&amp;hostid='.$mnet_peer->id, get_string('changessaved'));
131 } else {
132 error('Invalid action parameter.', 'index.php');
136 } elseif (is_int($hostid)) {
137 $mnet_peer = new mnet_peer();
138 $mnet_peer->set_id($hostid);
139 $currentkey = mnet_get_public_key($mnet_peer->wwwroot, $mnet_peer->application);
140 if($currentkey == $mnet_peer->public_key) unset($currentkey);
141 $form = new stdClass();
142 if ($hostid != $CFG->mnet_all_hosts_id) {
143 include('./mnet_review.html');
144 } else {
145 include('./mnet_review_allhosts.html');
147 } else {
148 $hosts = get_records_sql(' SELECT
149 h.id,
150 h.wwwroot,
151 h.ip_address,
152 h.name,
153 h.public_key,
154 h.public_key_expires,
155 h.transport,
156 h.portno,
157 h.last_connect_time,
158 h.last_log_id,
159 h.applicationid,
160 a.name as app_name,
161 a.display_name as app_display_name,
162 a.xmlrpc_server_url
163 FROM
164 '.$CFG->prefix.'mnet_host h,
165 '.$CFG->prefix.'mnet_application a
166 WHERE
167 h.id != \''.$CFG->mnet_localhost_id.'\' AND
168 h.deleted = \'0\' AND
169 h.applicationid=a.id');
171 if (empty($hosts)) $hosts = array();
172 $applications = get_records('mnet_application');
173 include('./peers.html');