Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2572096
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/plugins/password/drivers/modoboa.php b/plugins/password/drivers/modoboa.php
new file mode 100644
index 000000000..b315bf56a
--- /dev/null
+++ b/plugins/password/drivers/modoboa.php
@@ -0,0 +1,121 @@
+<?php
+
+/**
+ * Modoboa Password Driver
+ *
+ * Payload is json string containing username, oldPassword and newPassword
+ * Return value is a json string saying result: true if success.
+ *
+ * @version 1.0.1
+ * @author stephane @actionweb.fr
+ *
+ * Copyright (C) 2018, The Roundcube Dev Team
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see http://www.gnu.org/licenses/.
+ *
+ * The driver need modoboa core 1.10.6 or later
+ *
+ * You need to define theses variables in plugin/password/config.inc.php
+ *
+ * $config['password_driver'] = 'modoboa'; // use modoboa as driver
+ * $config['token_api_modoboa'] = ''; // put token number from Modoboa server
+ * $config['password_minimum_length'] = 8; // select same number as in Modoboa server
+ *
+ */
+
+class rcube_modoboa_password
+{
+ function save($curpass, $passwd)
+ {
+ // Init config access
+ $rcmail = rcmail::get_instance();
+ $ModoboaToken = $rcmail->config->get('token_api_modoboa');
+
+ $RoudCubeUsername = $_SESSION['username'];
+ $IMAPhost = $_SESSION['imap_host'];
+
+ // Call GET to fetch values from modoboa server
+ $curl = curl_init();
+
+ curl_setopt_array($curl, array(
+ CURLOPT_URL => "https://" . $IMAPhost . "/api/v1/accounts/?search=" . urlencode($RoudCubeUsername),
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_ENCODING => "",
+ CURLOPT_MAXREDIRS => 10,
+ CURLOPT_TIMEOUT => 30,
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+ CURLOPT_CUSTOMREQUEST => "GET",
+ CURLOPT_HTTPHEADER => array(
+ "Authorization: Token " . $ModoboaToken,
+ "Cache-Control: no-cache",
+ "Content-Type: application/json"
+ ),
+ ));
+
+ $response = curl_exec($curl);
+ $err = curl_error($curl);
+
+ curl_close($curl);
+
+ if ($err) {
+ return PASSWORD_CONNECT_ERROR;
+ }
+
+ // Decode json string
+ $decoded = json_decode($response);
+
+ if (!is_array($decoded)) {
+ return PASSWORD_CONNECT_ERROR;
+ }
+
+ // Get user ID (pk)
+ $userid = $decoded[0]->pk;
+
+ // Encode json with new password
+ $ret['username'] = $decoded[0]->username;
+ $ret['role'] = $decoded[0]->role;
+ $ret['password'] = $passwd; // new password
+ $encoded = json_encode($ret);
+
+ // Call HTTP API Modoboa
+ $curl = curl_init();
+
+ curl_setopt_array($curl, array(
+ CURLOPT_URL => "https://" . $IMAPhost . "/api/v1/accounts/" . $userid . "/",
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_ENCODING => "",
+ CURLOPT_MAXREDIRS => 10,
+ CURLOPT_TIMEOUT => 30,
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
+ CURLOPT_CUSTOMREQUEST => "PUT",
+ CURLOPT_POSTFIELDS => "" . $encoded . "",
+ CURLOPT_HTTPHEADER => array(
+ "Authorization: Token " . $ModoboaToken,
+ "Cache-Control: no-cache",
+ "Content-Type: application/json"
+ ),
+ ));
+
+ $response = curl_exec($curl);
+ $err = curl_error($curl);
+
+ curl_close($curl);
+
+ if ($err) {
+ return PASSWORD_CONNECT_ERROR;
+ }
+
+ return PASSWORD_SUCCESS;
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Mar 19, 9:22 PM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
458771
Default Alt Text
(4 KB)
Attached To
Mode
R3 roundcubemail
Attached
Detach File
Event Timeline
Log In to Comment