2 // Allows the admin to configure services for remote hosts
4 require_once(dirname(dirname(dirname(__FILE__
))) . '/config.php');
5 require_once($CFG->libdir
.'/adminlib.php');
6 include_once($CFG->dirroot
.'/mnet/lib.php');
9 admin_externalpage_setup('mnetpeers');
11 $context = get_context_instance(CONTEXT_SYSTEM
);
13 require_capability('moodle/site:config', $context, $USER->id
, true, "nopermissions");
15 if (!$site = get_site()) {
16 print_error('nosite', '', '', NULL, true);
19 /// Initialize variables.
21 // Step must be one of:
22 // input Parse the details of a new host and fetch its public key
23 // commit Save our changes (to a new OR existing host)
24 // force Go ahead with something we've been warned is strange
25 $step = optional_param('step', NULL, PARAM_ALPHA
);
26 $hostid = optional_param('hostid', NULL, PARAM_INT
);
32 $stradministration = get_string('administration');
33 $strconfiguration = get_string('configuration');
34 $strmnetsettings = get_string('mnetsettings', 'mnet');
35 $strmnetservices = get_string('mnetservices', 'mnet');
36 $strmnetlog = get_string('mnetlog', 'mnet');
37 $strmnetedithost = get_string('reviewhostdetails', 'mnet');
38 $strmneteditservices = get_string('reviewhostservices', 'mnet');
40 $mnet_peer = new mnet_peer();
42 if (($form = data_submitted()) && confirm_sesskey()) {
43 $mnet_peer->set_id($hostid);
45 foreach($_POST['exists'] as $key => $value) {
46 $host2service = get_record('mnet_host2service', 'hostid', $_POST['hostid'], 'serviceid', $key);
47 $publish = (isset($_POST['publish'][$key]) && $_POST['publish'][$key] == 'on')?
1 : 0;
48 $subscribe = (isset($_POST['subscribe'][$key]) && $_POST['subscribe'][$key] == 'on')?
1 : 0;
50 if (false == $host2service && ($publish == 1 ||
$subscribe == 1)) {
51 $host2service = new stdClass();
52 $host2service->hostid
= $_POST['hostid'];
53 $host2service->serviceid
= $key;
55 $host2service->publish
= $publish;
56 $host2service->subscribe
= $subscribe;
58 $host2service->id
= insert_record('mnet_host2service', $host2service);
59 } elseif ($host2service->publish
!= $publish ||
$host2service->subscribe
!= $subscribe) {
60 $host2service->publish
= $publish;
61 $host2service->subscribe
= $subscribe;
62 $tf = update_record('mnet_host2service', $host2service);
67 if (is_int($hostid)) {
68 if (0 == $mnet_peer->id
) $mnet_peer->set_id($hostid);
69 $mnet_peer->nextstep
= 'verify';
71 $id_list = $mnet_peer->id
;
72 if (!empty($CFG->mnet_all_hosts_id
)) {
73 $id_list .= ', '.$CFG->mnet_all_hosts_id
;
76 $concat = sql_concat('COALESCE(h2s.id,0) ', ' \'-\' ', ' svc.id');
91 {$CFG->prefix}mnet_service2rpc s2r,
92 {$CFG->prefix}mnet_rpc r,
93 {$CFG->prefix}mnet_service svc
95 {$CFG->prefix}mnet_host2service h2s
97 h2s.hostid in ($id_list) AND
98 h2s.serviceid = svc.id
101 s2r.serviceid = svc.id AND
106 $resultset = get_records_sql($query);
108 if (is_array($resultset)) {
109 $resultset = array_values($resultset);
111 $resultset = array();
114 require_once $CFG->dirroot
.'/mnet/xmlrpc/client.php';
116 $remoteservices = array();
117 if ($hostid != $CFG->mnet_all_hosts_id
) {
118 // Create a new request object
119 $mnet_request = new mnet_xmlrpc_client();
121 // Tell it the path to the method that we want to execute
122 $mnet_request->set_method('system/listServices');
123 $mnet_request->send($mnet_peer);
124 if (is_array($mnet_request->response
)) {
125 foreach($mnet_request->response
as $service) {
126 $remoteservices[$service['name']][$service['apiversion']] = $service;
131 $myservices = array();
132 foreach($resultset as $result) {
133 $result->hostpublishes
= false;
134 $result->hostsubscribes
= false;
135 if (isset($remoteservices[$result->name
][$result->apiversion
])) {
136 if ($remoteservices[$result->name
][$result->apiversion
]['publish'] == 1) {
137 $result->hostpublishes
= true;
139 if ($remoteservices[$result->name
][$result->apiversion
]['subscribe'] == 1) {
140 $result->hostsubscribes
= true;
144 if (empty($myservices[$result->name
][$result->apiversion
])) {
145 $myservices[$result->name
][$result->apiversion
] = array('serviceid' => $result->serviceid
,
146 'name' => $result->name
,
147 'offer' => $result->offer
,
148 'apiversion' => $result->apiversion
,
149 'parent_type' => $result->parent_type
,
150 'parent' => $result->parent
,
151 'hostsubscribes' => $result->hostsubscribes
,
152 'hostpublishes' => $result->hostpublishes
156 // allhosts_publish allows us to tell the admin that even though he
157 // is disabling a service, it's still available to the host because
158 // he's also publishing it to 'all hosts'
159 if ($result->hostid
== $CFG->mnet_all_hosts_id
&& $CFG->mnet_all_hosts_id
!= $mnet_peer->id
) {
160 $myservices[$result->name
][$result->apiversion
]['allhosts_publish'] = $result->publish
;
161 $myservices[$result->name
][$result->apiversion
]['allhosts_subscribe'] = $result->subscribe
;
162 } elseif (!empty($result->hostid
)) {
163 $myservices[$result->name
][$result->apiversion
]['I_publish'] = $result->publish
;
164 $myservices[$result->name
][$result->apiversion
]['I_subscribe'] = $result->subscribe
;
170 redirect('peers.php', get_string('nohostid','mnet'), '5');
174 include('./mnet_services.html');