Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1372c6d34 | ||
|
|
098514660f | ||
|
|
07970f36e3 | ||
|
|
1e81988bf5 | ||
|
|
217c79d867 | ||
|
|
4c63223050 | ||
|
|
41a1acc36b | ||
|
|
9e1c2cca4e | ||
|
|
74c106aa87 | ||
|
|
700833b532 | ||
|
|
31ecf15e95 | ||
|
|
8afc94b51c | ||
|
|
2885dddccc | ||
|
|
0e4b7bc4d9 | ||
|
|
d6d13338e3 | ||
|
|
43ee70c01e | ||
|
|
6dfe28dab5 | ||
|
|
04e60b112b | ||
|
|
9e4c2dcbae | ||
|
|
1160a52753 | ||
|
|
af6ac9fb22 | ||
|
|
e1734746c0 | ||
|
|
21ad3135c8 | ||
|
|
f87b2c82c9 | ||
|
|
c25f4bada6 | ||
|
|
4f34a6db0f | ||
|
|
a7e41f77d2 | ||
|
|
6c4e47b395 | ||
|
|
3816d4128c | ||
|
|
fdaa591882 | ||
|
|
6b5c96a383 | ||
|
|
8ed2352fbe | ||
|
|
f613301f24 | ||
|
|
f51bb5714e | ||
|
|
065426b026 | ||
|
|
3a24fc34ca | ||
|
|
a95df3c6b1 | ||
|
|
2744e4fb80 | ||
|
|
5179a7ec05 | ||
|
|
18a5d23d07 | ||
|
|
f43b3f2fd3 | ||
|
|
ea30d3ca56 | ||
|
|
e86542d8f7 | ||
|
|
dab55b9562 | ||
|
|
c2cd361171 | ||
|
|
eaee6b7c81 | ||
|
|
282e3bcaf1 | ||
|
|
c037edbc58 | ||
|
|
2c4c05acd6 | ||
|
|
39fa71faba | ||
|
|
9ecf83b1d6 | ||
|
|
54d1d030ec | ||
|
|
8651e6a157 | ||
|
|
28632834af | ||
|
|
a19031d444 | ||
|
|
bae23caa87 | ||
|
|
0d8cb8688d | ||
|
|
430c9fa09a | ||
|
|
d0f58c52a2 | ||
|
|
3540a50d86 | ||
|
|
2422592c74 | ||
|
|
d235d49dc6 | ||
|
|
d3c79af8cf | ||
|
|
7862e885ed | ||
|
|
8ebb1381c9 | ||
|
|
ed34626ef6 | ||
|
|
4273d97f5f | ||
|
|
a8ad95f44e | ||
|
|
2bee24931a | ||
|
|
876803b844 | ||
|
|
ea1c9f7322 | ||
|
|
2d2a683549 | ||
|
|
b6659da190 | ||
|
|
54b20f1335 | ||
|
|
aaacb23d41 | ||
|
|
804fc061ed | ||
|
|
706b948be0 | ||
|
|
be91a4c9b4 |
@@ -2,12 +2,23 @@
|
|||||||
[](https://github.com/valentineus/moodle-webhooks/releases)
|
[](https://github.com/valentineus/moodle-webhooks/releases)
|
||||||
[](https://travis-ci.org/valentineus/moodle-webhooks)
|
[](https://travis-ci.org/valentineus/moodle-webhooks)
|
||||||
[](https://www.codacy.com/app/valentineus/moodle-webhooks)
|
[](https://www.codacy.com/app/valentineus/moodle-webhooks)
|
||||||
[](https://gitter.im/valentineus/auth-link)
|
[](https://gitter.im/valentineus/moodle-webhooks)
|
||||||
|
|
||||||
Webhooks allow applications to subscribe to Moodle events.
|
Adding Webhooks to Moodle.
|
||||||
|
The Webhooks feature allows applications to receive real-time notification of changes to certain data.
|
||||||
|
|
||||||
**Attention!**:
|
Using Webhooks, your application will be able to receive notifications of changes to selected topics and their fields.
|
||||||
This plugin is in active development.
|
Because of this, you do not have to rely on continuous or even periodic requests to check for updates.
|
||||||
|
Notifications about Webhooks updates are sent as POST requests to the callback URL you specified.
|
||||||
|
Notifications can indicate the very fact of a field change or include a new value.
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
* Use any number of services for notification;
|
||||||
|
* Customizing each external service;
|
||||||
|
* Interception of all events in the Moodle system;
|
||||||
|
* Use a secret phrase to authenticate requests;
|
||||||
|
* [JSON](https://en.wikipedia.org/wiki/JSON) - Format of outgoing data;
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a class for sending data.
|
|
||||||
*
|
|
||||||
* @package local_webhooks
|
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace local_webhooks;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
class curl {
|
|
||||||
public function __construct() {
|
|
||||||
if (!function_exists('curl_init')) {
|
|
||||||
print_error('nocurl', 'mnet');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function request($url, $data) {
|
|
||||||
$ch = curl_init($url);
|
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
||||||
'Content-Type: application/json',
|
|
||||||
'Content-Length: ' . strlen($data))
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the form of editing the service.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace local_webhooks;
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
require_once($CFG->libdir . "/formslib.php");
|
||||||
|
|
||||||
|
use report_eventlist_list_generator;
|
||||||
|
use lang_string;
|
||||||
|
use moodleform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description editing form definition.
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class service_edit_form extends moodleform {
|
||||||
|
/**
|
||||||
|
* @param string $baseurl
|
||||||
|
*/
|
||||||
|
public function __construct($baseurl) {
|
||||||
|
parent::__construct($baseurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preparing data before displaying.
|
||||||
|
*
|
||||||
|
* @param object $record
|
||||||
|
*/
|
||||||
|
public function set_data($record) {
|
||||||
|
if (!empty($record->events)) {
|
||||||
|
$record->events = unserialize(gzuncompress(base64_decode($record->events)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::set_data($record);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the standard structure of the form.
|
||||||
|
*/
|
||||||
|
protected function definition() {
|
||||||
|
$mform =& $this->_form;
|
||||||
|
$size = array("size" => 60);
|
||||||
|
|
||||||
|
/* Form heading */
|
||||||
|
$mform->addElement("header", "editserviceheader", new lang_string("service", "webservice"));
|
||||||
|
|
||||||
|
/* Name of the service */
|
||||||
|
$mform->addElement("text", "title", new lang_string("name", "moodle"), $size);
|
||||||
|
$mform->addRule("title", null, "required");
|
||||||
|
$mform->setType("title", PARAM_NOTAGS);
|
||||||
|
|
||||||
|
/* Callback address */
|
||||||
|
$mform->addElement("text", "url", new lang_string("url", "moodle"), $size);
|
||||||
|
$mform->addRule("url", null, "required");
|
||||||
|
$mform->setType("url", PARAM_URL);
|
||||||
|
|
||||||
|
/* Enabling the service */
|
||||||
|
$mform->addElement("advcheckbox", "enable", new lang_string("enable", "moodle"));
|
||||||
|
$mform->setType("enable", PARAM_BOOL);
|
||||||
|
$mform->setDefault("enable", 1);
|
||||||
|
$mform->setAdvanced("enable");
|
||||||
|
|
||||||
|
/* Token */
|
||||||
|
$mform->addElement("text", "token", new lang_string("token", "webservice"), $size);
|
||||||
|
$mform->setType("token", PARAM_NOTAGS);
|
||||||
|
|
||||||
|
/* Additional information */
|
||||||
|
$mform->addElement("text", "other", new lang_string("sourceext", "plugin"), $size);
|
||||||
|
$mform->setType("other", PARAM_NOTAGS);
|
||||||
|
$mform->setAdvanced("other");
|
||||||
|
|
||||||
|
/* Content type */
|
||||||
|
$contenttype = array("json" => "application/json", "x-www-form-urlencoded" => "application/x-www-form-urlencoded");
|
||||||
|
$mform->addElement("select", "type", "Content type", $contenttype);
|
||||||
|
$mform->setAdvanced("type");
|
||||||
|
|
||||||
|
/* Form heading */
|
||||||
|
$mform->addElement("header", "editserviceheaderevent", new lang_string("edulevel", "moodle"));
|
||||||
|
|
||||||
|
/* List of events */
|
||||||
|
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
|
||||||
|
$events = array();
|
||||||
|
|
||||||
|
/* Formation of the list of elements */
|
||||||
|
foreach ($eventlist as $event) {
|
||||||
|
$events[$event["component"]][] =& $mform->createElement("checkbox", $event["eventname"], $event["eventname"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Displays groups of items */
|
||||||
|
foreach ($events as $key => $event) {
|
||||||
|
$mform->addGroup($event, "events", $key, "<br />", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Control Panel */
|
||||||
|
$this->add_action_buttons(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registration of the system of events.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines how to work with events.
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class response_get extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Init method.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data["crud"] = "u";
|
||||||
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return localised event name.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("answer", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return $this->other["status"];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The event handler.
|
|
||||||
*
|
|
||||||
* @package local_webhooks
|
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace local_webhooks;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
class events {
|
|
||||||
public static function handler($event) {
|
|
||||||
$enabled = boolval(get_config('local_webhooks', 'enabled'));
|
|
||||||
$url = get_config('local_webhooks', 'url');
|
|
||||||
|
|
||||||
if ($enabled && !empty($url)) {
|
|
||||||
$data = $event->get_data();
|
|
||||||
$json = json_encode($data);
|
|
||||||
|
|
||||||
$curl = new curl();
|
|
||||||
$curl::request($url, $json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event handler.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace local_webhooks;
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
require_once($CFG->libdir . "/filelib.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines how to work with events.
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class handler {
|
||||||
|
/**
|
||||||
|
* External handler.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
*/
|
||||||
|
public static function events($event) {
|
||||||
|
$enable = get_config("local_webhooks", "enable");
|
||||||
|
|
||||||
|
if (boolval($enable)) {
|
||||||
|
$data = $event->get_data();
|
||||||
|
self::transmitter($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transmitter, processing event and services.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
private static function transmitter($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$callbacks = $DB->get_recordset("local_webhooks_service");
|
||||||
|
|
||||||
|
if ($callbacks->valid()) {
|
||||||
|
foreach ($callbacks as $callback) {
|
||||||
|
self::handler_callback($data, $callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$callbacks->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes each callback.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param object $callback
|
||||||
|
*/
|
||||||
|
private static function handler_callback($data, $callback) {
|
||||||
|
if (boolval($callback->enable)) {
|
||||||
|
$events = array();
|
||||||
|
if (!empty($callback->events)) {
|
||||||
|
$events = unserialize(gzuncompress(base64_decode($callback->events)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($events[$data["eventname"]])) {
|
||||||
|
if (!empty($callback->token)) {
|
||||||
|
$data["token"] = $callback->token;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($callback->other)) {
|
||||||
|
$data["extra"] = $callback->other;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::send($data, $callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sending data to the node.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param object $callback
|
||||||
|
*/
|
||||||
|
private static function send($data, $callback) {
|
||||||
|
$curl = new \curl();
|
||||||
|
$curl->setHeader(array("Content-Type: application/$callback->type"));
|
||||||
|
$curl->post($callback->url, json_encode($data));
|
||||||
|
$response = $curl->getResponse();
|
||||||
|
self::logger($callback, $response);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event logging.
|
||||||
|
*
|
||||||
|
* @param array $response
|
||||||
|
* @param object $callback
|
||||||
|
*/
|
||||||
|
private static function logger($callback, $response) {
|
||||||
|
$status = "Error sending request";
|
||||||
|
if (!empty($response["HTTP/1.1"])) {
|
||||||
|
$status = $response["HTTP/1.1"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$event = \local_webhooks\event\response_get::create(
|
||||||
|
array(
|
||||||
|
"context" => \context_system::instance(0),
|
||||||
|
"objectid" => $callback->id,
|
||||||
|
"other" => array(
|
||||||
|
"status" => $status
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-7
@@ -22,15 +22,14 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
$config = get_config('local_webhooks');
|
|
||||||
$observers = array(
|
$observers = array(
|
||||||
array(
|
array(
|
||||||
'eventname' => '*',
|
"eventname" => "*",
|
||||||
'callback' => '\local_webhooks\events::handler',
|
"callback" => "\local_webhooks\\handler::events",
|
||||||
'includefile' => null,
|
"includefile" => null,
|
||||||
'priority' => 200,
|
"priority" => 200,
|
||||||
'internal' => true
|
"internal" => true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171029" COMMENT="XMLDB file for Moodle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
|
||||||
|
<TABLES>
|
||||||
|
<TABLE NAME="local_webhooks_service" COMMENT="A table for storing callback services.">
|
||||||
|
<FIELDS>
|
||||||
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
|
||||||
|
<FIELD NAME="enable" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
|
||||||
|
<FIELD NAME="title" TYPE="text" NOTNULL="true" SEQUENCE="false" />
|
||||||
|
<FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
||||||
|
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
||||||
|
<FIELD NAME="token" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
||||||
|
<FIELD NAME="events" TYPE="text" NOTNULL="false" SEQUENCE="false" />
|
||||||
|
<FIELD NAME="other" TYPE="text" NOTNULL="false" SEQUENCE="false" />
|
||||||
|
</FIELDS>
|
||||||
|
<KEYS>
|
||||||
|
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
|
||||||
|
</KEYS>
|
||||||
|
</TABLE>
|
||||||
|
</TABLES>
|
||||||
|
</XMLDB>
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service editor.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/../../config.php");
|
||||||
|
require_once(__DIR__ . "/classes/editform.php");
|
||||||
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
|
|
||||||
|
admin_externalpage_setup("managelocalplugins");
|
||||||
|
|
||||||
|
$serviceid = optional_param("serviceid", 0, PARAM_INT);
|
||||||
|
|
||||||
|
require_login();
|
||||||
|
|
||||||
|
/* Link generation */
|
||||||
|
$urlparameters = array("serviceid" => $serviceid);
|
||||||
|
$managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters);
|
||||||
|
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
|
||||||
|
$PAGE->set_url($baseurl, $urlparameters);
|
||||||
|
|
||||||
|
/* Configure the context of the page */
|
||||||
|
$context = context_system::instance();
|
||||||
|
$PAGE->set_context($context);
|
||||||
|
|
||||||
|
/* Preparing a template for data */
|
||||||
|
$titlepage = new lang_string("externalservice", "webservice");
|
||||||
|
$servicerecord = new stdClass;
|
||||||
|
|
||||||
|
/* Create an editing form */
|
||||||
|
$mform = new \local_webhooks\service_edit_form($PAGE->url);
|
||||||
|
|
||||||
|
/* Cancel processing */
|
||||||
|
if ($mform->is_cancelled()) {
|
||||||
|
redirect($managerservice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Getting the data */
|
||||||
|
if ($editing = boolval($serviceid)) {
|
||||||
|
$servicerecord = $DB->get_record("local_webhooks_service", array("id" => $serviceid), "*", MUST_EXIST);
|
||||||
|
$mform->set_data($servicerecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Processing of received data */
|
||||||
|
if ($data = $mform->get_data()) {
|
||||||
|
if (!empty($data->events)) {
|
||||||
|
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($editing) {
|
||||||
|
$data->id = $serviceid;
|
||||||
|
$DB->update_record("local_webhooks_service", $data);
|
||||||
|
redirect($managerservice, new lang_string("eventwebserviceserviceupdated", "webservice"));
|
||||||
|
} else {
|
||||||
|
$DB->insert_record("local_webhooks_service", $data);
|
||||||
|
redirect($managerservice, new lang_string("eventwebserviceservicecreated", "webservice"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Page template */
|
||||||
|
$PAGE->set_pagelayout("admin");
|
||||||
|
$PAGE->set_heading($titlepage);
|
||||||
|
$PAGE->set_title($titlepage);
|
||||||
|
|
||||||
|
/* The page title */
|
||||||
|
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"), new moodle_url("/admin/settings.php", array("section" => "local_webhooks")));
|
||||||
|
$PAGE->navbar->add(new lang_string("externalservices", "webservice"), $managerservice);
|
||||||
|
$PAGE->navbar->add($titlepage);
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
|
/* Displays the form */
|
||||||
|
$mform->display();
|
||||||
|
|
||||||
|
echo $OUTPUT->footer();
|
||||||
@@ -15,16 +15,11 @@
|
|||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strings for component 'local_webhooks', language 'en'.
|
* Strings for component "local_webhooks", language "en".
|
||||||
*
|
*
|
||||||
* @package local_webhooks
|
* @package local_webhooks
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$string['local_webhooksdescription'] = '';
|
$string["pluginname"] = "WebHooks";
|
||||||
$string['pluginname'] = 'WebHook\'s';
|
|
||||||
$string['enabled'] = 'Enabled';
|
|
||||||
$string['enabled_help'] = 'Enable event tracking.';
|
|
||||||
$string['url'] = 'URL';
|
|
||||||
$string['url_help'] = 'Web address of the remote service.';
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
|
||||||
//
|
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Moodle is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strings for component 'local_webhooks', language 'ru'.
|
|
||||||
*
|
|
||||||
* @package local_webhooks
|
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['local_webhooksdescription'] = '';
|
|
||||||
$string['pluginname'] = 'WebHook\'s';
|
|
||||||
$string['enabled'] = 'Включить';
|
|
||||||
$string['enabled_help'] = 'Включить отслеживание событий.';
|
|
||||||
$string['url'] = 'URL';
|
|
||||||
$string['url_help'] = 'Веб-адрес удалённой службы.';
|
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service Management Manager.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/../../config.php");
|
||||||
|
require_once($CFG->libdir . "/tablelib.php");
|
||||||
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
|
|
||||||
|
admin_externalpage_setup("managelocalplugins");
|
||||||
|
|
||||||
|
$hideshowid = optional_param("hideshowid", 0, PARAM_INT);
|
||||||
|
$deleteid = optional_param("deleteid", 0, PARAM_INT);
|
||||||
|
|
||||||
|
require_login();
|
||||||
|
|
||||||
|
/* Link generation */
|
||||||
|
$managerservice = "/local/webhooks/managerservice.php";
|
||||||
|
$editservice = "/local/webhooks/editservice.php";
|
||||||
|
$baseurl = new moodle_url($managerservice);
|
||||||
|
$PAGE->set_url($baseurl);
|
||||||
|
|
||||||
|
/* Configure the context of the page */
|
||||||
|
$context = context_system::instance();
|
||||||
|
$PAGE->set_context($context);
|
||||||
|
|
||||||
|
/* Delete the service */
|
||||||
|
if (boolval($deleteid) && confirm_sesskey()) {
|
||||||
|
$DB->delete_records("local_webhooks_service", array("id" => $deleteid));
|
||||||
|
redirect($PAGE->url, new lang_string("eventwebserviceservicedeleted", "webservice"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieving a list of services */
|
||||||
|
$callbacks = $DB->get_records_select("local_webhooks_service", null, null, $DB->sql_order_by_text("id"));
|
||||||
|
|
||||||
|
/* Switching the status of the service */
|
||||||
|
if (boolval($hideshowid) && confirm_sesskey()) {
|
||||||
|
$callback = $callbacks[$hideshowid];
|
||||||
|
|
||||||
|
if (!empty($callback)) {
|
||||||
|
$callback->enable = !boolval($callback->enable);
|
||||||
|
$DB->update_record("local_webhooks_service", $callback);
|
||||||
|
redirect($PAGE->url, new lang_string("eventwebserviceserviceupdated", "webservice"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Page template */
|
||||||
|
$titlepage = new lang_string("externalservices", "webservice");
|
||||||
|
$PAGE->set_pagelayout("admin");
|
||||||
|
$PAGE->set_title($titlepage);
|
||||||
|
$PAGE->set_heading($titlepage);
|
||||||
|
|
||||||
|
/* The page title */
|
||||||
|
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"), new moodle_url("/admin/settings.php", array("section" => "local_webhooks")));
|
||||||
|
$PAGE->navbar->add($titlepage, $baseurl);
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
|
/* Table declaration */
|
||||||
|
$table = new flexible_table("webhooks-service-table");
|
||||||
|
|
||||||
|
/* Customize the table */
|
||||||
|
$table->define_columns(array("title", "url", "actions"));
|
||||||
|
$table->define_headers(array(new lang_string("name", "moodle"), new lang_string("url", "moodle"), new lang_string("actions", "moodle")));
|
||||||
|
$table->define_baseurl($baseurl);
|
||||||
|
$table->setup();
|
||||||
|
|
||||||
|
foreach ($callbacks as $callback) {
|
||||||
|
/* Filling of information columns */
|
||||||
|
$titlecallback = html_writer::div($callback->title, "title");
|
||||||
|
$urlcallback = html_writer::div($callback->url, "url");
|
||||||
|
|
||||||
|
/* Defining service status */
|
||||||
|
$hideshowicon = "t/show";
|
||||||
|
$hideshowstring = new lang_string("enable", "moodle");
|
||||||
|
if (boolval($callback->enable)) {
|
||||||
|
$hideshowicon = "t/hide";
|
||||||
|
$hideshowstring = new lang_string("disable", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Link to enable / disable the service */
|
||||||
|
$hideshowlink = new moodle_url($managerservice, array("hideshowid" => $callback->id, "sesskey" => sesskey()));
|
||||||
|
$hideshowitem = $OUTPUT->action_icon($hideshowlink, new pix_icon($hideshowicon, $hideshowstring));
|
||||||
|
|
||||||
|
/* Link for editing */
|
||||||
|
$editlink = new moodle_url($editservice, array("serviceid" => $callback->id));
|
||||||
|
$edititem = $OUTPUT->action_icon($editlink, new pix_icon("t/edit", new lang_string("edit", "moodle")));
|
||||||
|
|
||||||
|
/* Link to remove */
|
||||||
|
$deletelink = new moodle_url($managerservice, array("deleteid" => $callback->id, "sesskey" => sesskey()));
|
||||||
|
$deleteitem = $OUTPUT->action_icon($deletelink, new pix_icon("t/delete", new lang_string("delete", "moodle")));
|
||||||
|
|
||||||
|
/* Adding data to the table */
|
||||||
|
$table->add_data(array($titlecallback, $urlcallback, $hideshowitem . $edititem . $deleteitem));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Display the table */
|
||||||
|
$table->print_html();
|
||||||
|
|
||||||
|
/* Add service button */
|
||||||
|
$addurl = new moodle_url("/local/webhooks/editservice.php");
|
||||||
|
echo $OUTPUT->single_button($addurl, new lang_string("addaservice", "webservice"), "get");
|
||||||
|
|
||||||
|
echo $OUTPUT->footer();
|
||||||
+10
-7
@@ -22,15 +22,18 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
$settings = null;
|
||||||
if ($hassiteconfig) {
|
if ($hassiteconfig) {
|
||||||
$settings = new admin_settingpage('local_webhooks', get_string('pluginname', 'local_webhooks'));
|
$settings = new admin_settingpage("local_webhooks", new lang_string("pluginname", "local_webhooks"));
|
||||||
$ADMIN->add('localplugins', $settings);
|
$ADMIN->add("localplugins", $settings);
|
||||||
|
|
||||||
$settings->add(new admin_setting_configcheckbox('local_webhooks/enabled', get_string('enabled', 'local_webhooks'),
|
/* The switch of the interceptor of events */
|
||||||
get_string('enabled_help', 'local_webhooks'), false));
|
$settings->add(new admin_setting_configcheckbox("local_webhooks/enable", new lang_string("enable", "moodle"), new lang_string("enablews", "webservice"), false));
|
||||||
|
|
||||||
$settings->add(new admin_setting_configtext('local_webhooks/url', get_string('url', 'local_webhooks'),
|
/* Link to the service manager */
|
||||||
get_string('url_help', 'local_webhooks'), 'http://example.com/endpoint', PARAM_URL, 40));
|
$linktext = new lang_string("externalservices", "webservice");
|
||||||
|
$linkurl = new moodle_url("/local/webhooks/managerservice.php");
|
||||||
|
$settings->add(new admin_setting_heading("local_webhooks_managerservice", null, html_writer::link($linkurl, $linktext)));
|
||||||
}
|
}
|
||||||
+6
-5
@@ -22,9 +22,10 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
$plugin->release = '0.0.0 (Build: 2017101900)';
|
|
||||||
$plugin->version = 2017101900;
|
$plugin->release = "1.1.1 (Build: 2017102910)";
|
||||||
|
$plugin->version = 2017102910;
|
||||||
$plugin->requires = 2016112900;
|
$plugin->requires = 2016112900;
|
||||||
$plugin->component = 'local_webhooks';
|
$plugin->component = "local_webhooks";
|
||||||
$plugin->maturity = MATURITY_ALPHA;
|
$plugin->maturity = MATURITY_STABLE;
|
||||||
Reference in New Issue
Block a user