-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_resource.php
90 lines (81 loc) · 3.59 KB
/
create_resource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Passbolt ~ Open source password manager for teams
* Copyright (c) Passbolt SA (https://www.passbolt.com)
*
* Licensed under GNU Affero General Public License version 3 of the or any later version.
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
* @link https://www.passbolt.com Passbolt(tm)
*/
require(__DIR__ . '/lib/gpg_auth.php');
if (!extension_loaded('gnupg')) {
trigger_error('You must enable the gnupg extension.', E_USER_ERROR);
}
if (!extension_loaded('curl')) {
trigger_error('You must enable the curl extension.', E_USER_ERROR);
}
/**
* Important: To use this example you will have to edit the configuration file located
* in /config/config.php and adjust the variables (url and key).
*/
// Get config.
$config = require(__DIR__ . '/config/config.php');
$gpgAuth = new GpgAuth($config['server_url'], $config['private_key_path'], $config['private_key_passphrase']);
// Login in passbolt. This step will return a cookie that can be used in other curl calls.
$cookie = $gpgAuth->login();
// In the example we use an already encrypted secret
$postParams = [
'name' => 'My password',
'secrets' => [[
'data' => "-----BEGIN PGP MESSAGE-----
Version: OpenPGP.js v4.6.2
Comment: https://openpgpjs.org
wcFMAxYTR81eetNbAQ/9Houri7re0RVIsPrvfY1EjdQoSZ9AyEXrh5HFJIwD
IVpBX8ox+2NIzEgBipusVdeSN2itFzjuckiiUDi5EZE9n3J4JHty0WRkyxEN
/QZUKv6m3m1umUYKRUPwthoqbMymFwJkjlna/EoFBOnN3bydEQWcMvf0VUWe
q9CzH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38x3tt8wEXReZ2zsW4
3XCV0AELRlv1h4DQVbt/X7mnd6HWfmqMXGHaSDhh7XC06inqO9DD7yNSdTAs
E7bCo6+V6h45gcvmqkOeD5OR4PAvHGUBzP3oz6imXo5QDPn/FUbrpLhqKBF7
aT+i769muW2VNmXsjpGrBDVxcLn1lGnrUq0KMX4RhOmwhOabJZYpSQVhx6z8
EEGobrCgDXWItdo7YGHdunMFeG6P7QJl8BjZlp+ot471AjW4T32soDn0biWC
XULWuYQ9T7GLpupX+TLPI/jwQh+y0ezi2EkhdS72WF67vHDUWA==
=WAp0
-----END PGP MESSAGE-----
"
]]
];
// Simple example of creating a resource.
$ch = curl_init($config['server_url'] . '/resources.json?api-version=v2');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $gpgAuth->getCookie(true));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postParams));
$extraHeaders = array(
"X-CSRF-Token: {$gpgAuth->csrfToken}",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $extraHeaders);
$response = curl_exec($ch);
curl_close($ch);
echo $response;