summaryrefslogtreecommitdiff
path: root/bin/create-user
blob: 02cb7da192e0df6f5e3cf86982afb10881f55389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env php

<?php

$options = getopt("", ["username:", "password:", "server:"]);

foreach (["username", "password", "server"] as $variable) {
    if (! array_key_exists($variable, $options)) {
        die("missing $variable");
    }
}

file_get_contents("https://$options[server]/_matrix/client/v3/register", false, stream_context_create([
    "http" => [
        "header" => ["Content-Type: application/json"],
        "method" => "POST",
        "content" => json_encode([
            "device_id" => "matrix-php-cli",
            "inhibit_login" => true,
            "password" => $options["password"],
            "username" => $options["username"],
        ]),
    ]
]));