PHP script to export users, groups and groupfolders using Nextcloud's OCS APIs user metadata
, capabilities
and groupfolders
via cURL.
The script uses cURL to make calls to Nextcloud's OCS APIs and displays the results either through an HTML table or a CSV list that can be easily copied to calc/excel. You can download a CSV formatted file as well.
https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#user-metadata https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#capabilities-api https://github.com/nextcloud/groupfolders#api
- Upload all files to a directory on your webserver and open
index.php
in a browser. You can point a subdomain likehttps://export.cloud.example.com
at it. - Make sure it is only accessible via https:// as you will be providing Nextcloud admin credentials to it.
- If you overwrite an existing installation, remove the old files from the folder before you upload. Else you might be left with unnecessary files (although it's not an issue).
Remember to backup
config.php
if you have set non-default values.
- Enter the URL of the Nextcloud target instance (https:// will be prepended automatically, if no protocol is specified)
- Enter a username (userID) that has admin (or group admin) rights
- Enter the corresponding password
- Click on "connect" and wait (there is no progress indicator yet)
After the script has successfully downloaded user, group (and groupfolder) data you can access other options from the top navigation bar.
-
Do not use
http://
unless you have a very good reason to do so. The script will block outgoing plain HTTP connections and warn you unless you override this security measure with!http://...
-
Group admins (as long as they do not belong themselves to the
admin
group) will not receive information on users that are members ofadmin
group, even if they are members of the group the group admin manages. This is a restriction of Nextcloud itself.
API calls via cURL are slow. Querying several hundred user accounts can take some minutes. Be patient :)
CURL parallel requests have been implemented since v0.2.0 and provide a relevant speed boost, but that's about as fast as it gets. Approximately 10-15s/100users.
A progress indicator is on the wish list.
- Choose which user metadata should be displayed or downloaded by selecting checkboxes
- Change display type (if necessary) and click on display OR
- Change the column headers option (if necessary) and download data as CSV file by clicking the download button
- Change display type (if necessary) and click on display OR
- Change the column headers option (if necessary) and download data as CSV file by clicking the download button
(only visible if groupfolders app is active and at least one groupfolder is in use)
- Change display type (if necessary) and click on display OR
- Change the column headers option (if necessary) and download data as CSV file by clicking the download button
All tables can be sorted by clicking on the column headers (although not by size).
- Select send mode ('bcc', 'cc' or 'to')
- Select all users or a specific group from the dropdown list
- Set filters (can be combined)
- last login between two dates (including the selected days)
- quota usage over a certain amount of Gigabytes (selectable in 0.5 GB steps)
Clicking 'create list' will open your email application with a 'mailto:' string containing all (filtered) email addresses.
- Simple overview of user/group/(groupfolder) count and quotas.
- This will unset (clear) php session data
You can use the following GET parameters with this script:
Nextcloud target instance and user credentials
url
URL incl. protocoluser
admin username to query the recordspass
user password - not recommended
Display type (display of the results page)
type
table
display html formatted table [default]csv
display comma separated values
Message Mode (how to send mass email)
msg_mode
bcc
recommended for privacy and legal reasons [default]to
cc
Select data to export
select
id
,displayname
,email
,lastLogin
[case sensitive!],backend
,enabled
,total
,used
,free
,groups
,subadmin
,language
,locale
Examples:
https://mydomain.org/userexport.php/?url=https://cloud.example.com&user=myusername&pass=goodpassword&type=csv
https://userexport.mydomain.org/?url=https://cloud.example.com&user=myusername&msg_mode=to&select=id,displayname,enabled,used,lastLogin
If you do not supply one of the parameters you can fill in the corresponding fields afterwards in the form (e.g. password). Prefilled form fields can also be edited by user input.
Several options can be set in config.php. The options are described in comments.
- Authentication
- Folders
- UI language
- UI colors
This software can be translated by adding a language file to the l10n
directory. To translate, duplicate an existing {ISO lang code}.php file, preferably en.php, rename it to the new language code and start translating by editing the lines inside.
An overview of ISO language codes can be found in the l10n
directory, too.
At present, included languages are English (default) and German. Set the language option inside config.php to select a language.
You can integrate it by using the external sites app.
- Show it only to your admin group
- Set UI colors to match your theming
- Prefill URL and username by using GET parameters and a nextcloud placeholder
https://export.cloud.mydomain.com/?url=https://cloud.example.com&user={uid}
Sorting tables by sizes (quota) is not possible, yet. (The sort function cannot handle human readable formats like 50 GB
)
Any hints to enhancements or security issues are highly welcome. If you would like to contribute, please open an issue or a pull request.
Minor version updates and bugfixes (x.x.1) are not always released separately. If you want to use the latest version please download/clone from master.
You can still use the simpler v0.4.1, if you prefer.
Inspired by comments to this github issue: nextcloud/server#14715