Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
bcfce93c
Commit
bcfce93c
authored
10 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Add 'register_new_user' script
parent
dea236e4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
register_new_user
+149
-0
149 additions, 0 deletions
register_new_user
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
150 additions
and
1 deletion
register_new_user
0 → 100755
+
149
−
0
View file @
bcfce93c
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2015 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
argparse
import
getpass
import
hashlib
import
hmac
import
json
import
sys
import
urllib2
import
yaml
def
request_registration
(
user
,
password
,
server_location
,
shared_secret
):
mac
=
hmac
.
new
(
key
=
shared_secret
,
msg
=
user
,
digestmod
=
hashlib
.
sha1
,
).
hexdigest
()
data
=
{
"
user
"
:
user
,
"
password
"
:
password
,
"
mac
"
:
mac
,
"
type
"
:
"
org.matrix.login.shared_secret
"
,
}
server_location
=
server_location
.
rstrip
(
"
/
"
)
print
"
Sending registration request...
"
req
=
urllib2
.
Request
(
"
%s/_matrix/client/api/v1/register
"
%
(
server_location
,),
data
=
json
.
dumps
(
data
),
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
)
try
:
f
=
urllib2
.
urlopen
(
req
)
f
.
read
()
f
.
close
()
print
"
Success.
"
except
urllib2
.
HTTPError
as
e
:
print
"
ERROR! Received %d %s
"
%
(
e
.
code
,
e
.
reason
,)
if
400
<=
e
.
code
<
500
:
if
e
.
info
().
type
==
"
application/json
"
:
resp
=
json
.
load
(
e
)
if
"
error
"
in
resp
:
print
resp
[
"
error
"
]
sys
.
exit
(
1
)
def
register_new_user
(
user
,
password
,
server_location
,
shared_secret
):
if
not
user
:
try
:
default_user
=
getpass
.
getuser
()
except
:
default_user
=
None
if
default_user
:
user
=
raw_input
(
"
New user localpart [%s]:
"
%
(
default_user
,))
if
not
user
:
user
=
default_user
else
:
user
=
raw_input
(
"
New user localpart:
"
)
if
not
user
:
print
"
Invalid user name
"
sys
.
exit
(
1
)
if
not
password
:
password
=
getpass
.
getpass
(
"
Password:
"
)
if
not
password
:
print
"
Password cannot be blank.
"
sys
.
exit
(
1
)
confirm_password
=
getpass
.
getpass
(
"
Confirm password:
"
)
if
password
!=
confirm_password
:
print
"
Passwords do not match
"
sys
.
exit
(
1
)
request_registration
(
user
,
password
,
server_location
,
shared_secret
)
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Used to register new users with a given home server when
"
"
registration has been disabled. The home server must be
"
"
configured with the
'
registration_shared_secret
'
option
"
"
set.
"
,
)
parser
.
add_argument
(
"
-u
"
,
"
--user
"
,
default
=
None
,
help
=
"
Local part of the new user. Will prompt if omitted.
"
,
)
parser
.
add_argument
(
"
-p
"
,
"
--password
"
,
default
=
None
,
help
=
"
New password for user. Will prompt if omitted.
"
,
)
group
=
parser
.
add_mutually_exclusive_group
(
required
=
True
)
group
.
add_argument
(
"
-c
"
,
"
--config
"
,
type
=
argparse
.
FileType
(
'
r
'
),
help
=
"
Path to server config file. Used to read in shared secret.
"
,
)
group
.
add_argument
(
"
-k
"
,
"
--shared-secret
"
,
help
=
"
Shared secret as defined in server config file.
"
,
)
parser
.
add_argument
(
"
server_url
"
,
default
=
"
https://localhost:8480
"
,
nargs
=
'
?
'
,
help
=
"
URL to use to talk to the home server. Defaults to
"
"
'
https://localhost:8480
'
.
"
,
)
args
=
parser
.
parse_args
()
if
"
config
"
in
args
and
args
.
config
:
config
=
yaml
.
safe_load
(
args
.
config
)
secret
=
config
.
get
(
"
registration_shared_secret
"
,
None
)
if
not
secret
:
print
"
No
'
registration_shared_secret
'
defined in config.
"
sys
.
exit
(
1
)
else
:
secret
=
args
.
shared_secret
register_new_user
(
args
.
user
,
args
.
password
,
args
.
server_url
,
secret
)
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
bcfce93c
...
...
@@ -55,5 +55,5 @@ setup(
include_package_data
=
True
,
zip_safe
=
False
,
long_description
=
long_description
,
scripts
=
[
"
synctl
"
],
scripts
=
[
"
synctl
"
,
"
register_new_user
"
],
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment