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
72df4207
Unverified
Commit
72df4207
authored
2 years ago
by
David Robertson
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Remove contrib/scripts/kick_users.py (#12908)
parent
796a0312
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
changelog.d/12908.removal
+1
-0
1 addition, 0 deletions
changelog.d/12908.removal
contrib/scripts/kick_users.py
+0
-88
0 additions, 88 deletions
contrib/scripts/kick_users.py
with
1 addition
and
88 deletions
changelog.d/12908.removal
0 → 100644
+
1
−
0
View file @
72df4207
Remove contributed `kick_users.py` script. This is broken under Python 3, and is not added to the environment when `pip install`ing Synapse.
This diff is collapsed.
Click to expand it.
contrib/scripts/kick_users.py
deleted
100755 → 0
+
0
−
88
View file @
796a0312
#!/usr/bin/env python
import
json
import
sys
import
urllib
from
argparse
import
ArgumentParser
import
requests
def
_mkurl
(
template
,
kws
):
for
key
in
kws
:
template
=
template
.
replace
(
key
,
kws
[
key
])
return
template
def
main
(
hs
,
room_id
,
access_token
,
user_id_prefix
,
why
):
if
not
why
:
why
=
"
Automated kick.
"
print
(
"
Kicking members on %s in room %s matching %s
"
%
(
hs
,
room_id
,
user_id_prefix
)
)
room_state_url
=
_mkurl
(
"
$HS/_matrix/client/api/v1/rooms/$ROOM/state?access_token=$TOKEN
"
,
{
"
$HS
"
:
hs
,
"
$ROOM
"
:
room_id
,
"
$TOKEN
"
:
access_token
},
)
print
(
"
Getting room state => %s
"
%
room_state_url
)
res
=
requests
.
get
(
room_state_url
)
print
(
"
HTTP %s
"
%
res
.
status_code
)
state_events
=
res
.
json
()
if
"
error
"
in
state_events
:
print
(
"
FATAL
"
)
print
(
state_events
)
return
kick_list
=
[]
room_name
=
room_id
for
event
in
state_events
:
if
not
event
[
"
type
"
]
==
"
m.room.member
"
:
if
event
[
"
type
"
]
==
"
m.room.name
"
:
room_name
=
event
[
"
content
"
].
get
(
"
name
"
)
continue
if
not
event
[
"
content
"
].
get
(
"
membership
"
)
==
"
join
"
:
continue
if
event
[
"
state_key
"
].
startswith
(
user_id_prefix
):
kick_list
.
append
(
event
[
"
state_key
"
])
if
len
(
kick_list
)
==
0
:
print
(
"
No user IDs match the prefix
'
%s
'"
%
user_id_prefix
)
return
print
(
"
The following user IDs will be kicked from %s
"
%
room_name
)
for
uid
in
kick_list
:
print
(
uid
)
doit
=
input
(
"
Continue? [Y]es
\n
"
)
if
len
(
doit
)
>
0
and
doit
.
lower
()
==
"
y
"
:
print
(
"
Kicking members...
"
)
# encode them all
kick_list
=
[
urllib
.
quote
(
uid
)
for
uid
in
kick_list
]
for
uid
in
kick_list
:
kick_url
=
_mkurl
(
"
$HS/_matrix/client/api/v1/rooms/$ROOM/state/m.room.member/$UID?access_token=$TOKEN
"
,
{
"
$HS
"
:
hs
,
"
$UID
"
:
uid
,
"
$ROOM
"
:
room_id
,
"
$TOKEN
"
:
access_token
},
)
kick_body
=
{
"
membership
"
:
"
leave
"
,
"
reason
"
:
why
}
print
(
"
Kicking %s
"
%
uid
)
res
=
requests
.
put
(
kick_url
,
data
=
json
.
dumps
(
kick_body
))
if
res
.
status_code
!=
200
:
print
(
"
ERROR: HTTP %s
"
%
res
.
status_code
)
if
res
.
json
().
get
(
"
error
"
):
print
(
"
ERROR: JSON %s
"
%
res
.
json
())
if
__name__
==
"
__main__
"
:
parser
=
ArgumentParser
(
"
Kick members in a room matching a certain user ID prefix.
"
)
parser
.
add_argument
(
"
-u
"
,
"
--user-id
"
,
help
=
"
The user ID prefix e.g.
'
@irc_
'"
)
parser
.
add_argument
(
"
-t
"
,
"
--token
"
,
help
=
"
Your access_token
"
)
parser
.
add_argument
(
"
-r
"
,
"
--room
"
,
help
=
"
The room ID to kick members in
"
)
parser
.
add_argument
(
"
-s
"
,
"
--homeserver
"
,
help
=
"
The base HS url e.g. http://matrix.org
"
)
parser
.
add_argument
(
"
-w
"
,
"
--why
"
,
help
=
"
Reason for the kick. Optional.
"
)
args
=
parser
.
parse_args
()
if
not
args
.
room
or
not
args
.
token
or
not
args
.
user_id
or
not
args
.
homeserver
:
parser
.
print_help
()
sys
.
exit
(
1
)
else
:
main
(
args
.
homeserver
,
args
.
room
,
args
.
token
,
args
.
user_id
,
args
.
why
)
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