Skip to content

Commit

Permalink
added multiple parallel cURL connections, download button, mass email
Browse files Browse the repository at this point in the history
  • Loading branch information
bpcurse committed Jan 2, 2020
1 parent 8278f3d commit b131adc
Show file tree
Hide file tree
Showing 3 changed files with 404 additions and 239 deletions.
41 changes: 26 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# Nextcloud userexport
Simple php script to export user lists using Nextcloud's user metadata OCS API and curl.
# Nextcloud userexport v0.2.0
PHP script to export user lists using Nextcloud's user metadata OCS API and curl.

## Installation
- Upload index.php and userexport.php to a directory on your webserver and open index.php in a browser. You can point a subdomain like https://export.cloud.example.com at it.
- Upload 'index.php', 'userexport.php' and 'download.php' to a directory on your webserver and open 'index.php' in a browser. You can point a subdomain like https://export.cloud.example.com at it.
- **Make sure it is only accessible via https://** as you will be providing nextcloud admin credentials to it.

## General usage
- Enter the URL of the Nextcloud target instance incl. https://
- Enter a username that has admin rights
- Enter the corresponding password
- Change the display type (if necessary)
- Click on "submit" and wait

Do not use http:// unless you have a very good reason to do so.
The script will block plain http connections and warn you unless you override this security measure with !http://...
The script will block outgoing plain HTTP connections and warn you unless you override this security measure with !http://...

API calls via curl are slow. **Querying hundreds of user accounts can take several minutes**. Be patient :)
API calls via cURL are slow. **Querying several hundred user accounts can take some minutes**. Be patient :)
CURL parallel requests have been implemented in v0.2.0 and provided a relevant speed boost, but that's about as fast as it gets.
Approximately 10-15s/100users.

A progress indicator isn't implemented yet, but it's on the list.

Expand All @@ -24,38 +27,46 @@ You can use the following GET parameters with this script:
- url (URL incl. protocol of the target instance)
- user (admin username to query the records)
- pass (user password) - NOT RECOMMENDED
- type (export type)
- 'table' (display html formatted table)
- type (display type)
- 'table' (display html formatted table) [default]
- 'csv' (display comma separated values)
- 'csv_dl' (download a csv file)
- msg_mode (how to configure the mass email mailto: list)
- 'to'
- 'cc'
- 'bcc' [default] recommended for privacy and legal reasons

If you do not supply one of the parameters you can fill in the responding fields afterwards in the form (e.g. password).
Prefilled form fields can also be edited by user input. Export default is 'csv file download'.
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.

**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&type=table
- https://userexport.mydomain.org/?url=https://cloud.example.com&user=myusername&msg_mode=to

You can download a CSV formatted file for direct import by clicking a button on the results page.

Simple mass mailing to all users on the list is also provided by a button on the results page.
This will open your email application with a mailto: string containing all email addresses as bcc. You can change to 'cc' or 'to' by using a GET parameter.

## How it works
The script uses curl to make calls to Nextcloud's user metadata OCS API and displays them either through an html table or a csv list that can be easily copied to calc/excel. A csv formatted file for direct import can be downloaded, too.
The script uses cURL to make calls to Nextcloud's user metadata OCS API and displays them either through an HTML table or a CSV list that can be easily copied to calc/excel.

https://docs.nextcloud.com/server/17/developer_manual/client_apis/OCS/ocs-api-overview.html#user-metadata

## Nextcloud integration
You can integrate it by using the external sites app and show it only to your admin group.
Prefill URL and user name by using GET parameters and a nextcloud placeholder like this:

https://export.cloud.mydomain.com/?url=https://cloud.example.com&user={uid}&type=csv_dl
https://export.cloud.mydomain.com/?url=https://cloud.example.com&user={uid}

## Known Issues
Error handling isn't yet implemented.

If you end up with some obscure php error messages, the most probable reason is a typo in url, username or password.

## Development
I will try to maintain and enhance this script as long as Nextcloud does not provide GUI based user and group export functions.
As I am not an experienced programmer any hints to enhancements or security issues are highly welcome.
I will try to maintain and enhance this script as long as Nextcloud does not provide (better) GUI based user and group export functions.
Any hints to enhancements or security issues are highly welcome.
If you would like to contribute, please open an issue or a pull request.

## Additional Info
Expand Down
27 changes: 15 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title>Nextcloud user export</title>
<?php
Expand All @@ -13,33 +13,36 @@
if (isset($_GET['pass'])) {
$admin_password = $_GET['pass'];
}
if (isset($_GET['type']) && ($_GET['type'] == 'table' || $_GET['type'] == 'csv'
|| $_GET['type'] == 'csv_dl')) {
$export_type = $_GET['type'];
if (isset($_GET['type'])) {
$export_type = $_GET['type'];
}
if (isset($_GET['msg_mode'])) {
$message_mode = $_GET['msg_mode'];
}

?>
</head>

<body>
<form method='post' action='userexport.php'><font face='Helvetica'>
<input type='text' name='url' size='30'
<form method='post' action='userexport.php' id='auth_form'><font face='Helvetica'>
<label for='url'>Target URL</label>
<input id='url' type='text' name='url' size='30'
placeholder='https://cloud.example.com'
value='<?php echo $nextcloud_url; ?>'>
<input type='text' name='user' size='15' placeholder='username'
<label for='user'>Username</label>
<input id='user' type='text' name='user' size='10' placeholder='username'
value='<?php echo $admin_username; ?>'>
<input type='password' name='pass' size='15' placeholder='password'
<label for='pass'>Password</label>
<input id='pass' type='password' name='pass' size='10' placeholder='password'
value='<?php echo $admin_password; ?>'>
<br><br>
Display results:
Display results as:
<input type='radio' name='export_type' value='table'
<?php if ($export_type == 'table' || $export_type == null)
{echo 'checked=\"checked\"';} ?>> Table
<input type='radio' name='export_type' value='csv'
<?php if ($export_type == 'csv') {echo 'checked=\"checked\"';} ?>> CSV
<br><br>or download:
<input type='radio' name='export_type' value='csv_dl'
<?php if ($export_type == 'csv_dl') {echo 'checked=\"checked\"';} ?>> CSV
<input type="hidden" name="msg_mode" value="<?php echo $message_mode ?>">
<br><br>
<input type='submit' name='submit' value='submit'></font>
</form>
Expand Down
Loading

0 comments on commit b131adc

Please sign in to comment.