Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Matrix Webhook
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Guilhem Saurel
Matrix Webhook
Commits
cde44a74
Commit
cde44a74
authored
6 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
clean
parent
1fcda5d5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-4
4 additions, 4 deletions
README.md
main.py
+18
-24
18 additions, 24 deletions
main.py
with
22 additions
and
28 deletions
README.md
+
4
−
4
View file @
cde44a74
...
...
@@ -6,10 +6,10 @@ Bridge between https://code.ffdn.org/FFDN/wifi-with-me & a matrix room
Set the following environment variables:
-
MMW_BOT_
MATRIX_URL: the url of the matrix homeserver
-
MMW_BOT_
MATRIX_ID: the user id of the bot on this server
-
MMW_BOT_
MATRIX_PW: the password for this user
-
MMW_BOT_
ROOM_ID: the room on which send the notifications
-
MATRIX_URL: the url of the matrix homeserver
-
MATRIX_ID: the user id of the bot on this server
-
MATRIX_PW: the password for this user
-
ROOM_ID: the room on which send the notifications
## Dev
...
...
This diff is collapsed.
Click to expand it.
main.py
+
18
−
24
View file @
cde44a74
...
...
@@ -2,12 +2,6 @@
"""
wifi-with-matrix script.
Bridge between https://code.ffdn.org/FFDN/wifi-with-me & a matrix room
Needs the following environment variables:
- MMW_BOT_MATRIX_URL: the url of the matrix homeserver
- MMW_BOT_MATRIX_ID: the user id of the bot on this server
- MMW_BOT_MATRIX_PW: the password for this user
- MMW_BOT_ROOM_ID: the room on which send the notifications
"""
import
json
...
...
@@ -16,11 +10,12 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from
matrix_client.client
import
MatrixClient
SERVER_ADDRESS
=
(
''
,
int
(
os
.
environ
.
get
(
'
MMW_BOT_PORT
'
,
4785
)))
MATRIX_URL
=
os
.
environ
.
get
(
'
MMW_BOT_MATRIX_URL
'
,
'
https://matrix.org
'
)
MATRIX_ID
=
os
.
environ
.
get
(
'
MMW_BOT_MATRIX_ID
'
,
'
wwm
'
)
MATRIX_PW
=
os
.
environ
[
'
MMW_BOT_MATRIX_PW
'
]
ROOM_ID
=
os
.
environ
[
'
MMW_BOT_ROOM_ID
'
]
SERVER_ADDRESS
=
(
''
,
int
(
os
.
environ
.
get
(
'
PORT
'
,
4785
)))
MATRIX_URL
=
os
.
environ
.
get
(
'
MATRIX_URL
'
,
'
https://matrix.org
'
)
MATRIX_ID
=
os
.
environ
.
get
(
'
MATRIX_ID
'
,
'
wwm
'
)
MATRIX_PW
=
os
.
environ
[
'
MATRIX_PW
'
]
ROOM_ID
=
os
.
environ
[
'
ROOM_ID
'
]
API_KEY
=
os
.
environ
[
'
API_KEY
'
]
class
WWMBotServer
(
HTTPServer
):
...
...
@@ -30,9 +25,9 @@ class WWMBotServer(HTTPServer):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
matrix_
client
=
MatrixClient
(
MATRIX_URL
)
self
.
matrix_token
=
self
.
matrix_
client
.
login
(
username
=
MATRIX_ID
,
password
=
MATRIX_PW
)
self
.
matrix_room
=
self
.
matrix_
client
.
get_rooms
()[
ROOM_ID
]
client
=
MatrixClient
(
MATRIX_URL
)
client
.
login
(
username
=
MATRIX_ID
,
password
=
MATRIX_PW
)
self
.
room
=
client
.
get_rooms
()[
ROOM_ID
]
class
WWMBotForwarder
(
BaseHTTPRequestHandler
):
...
...
@@ -47,18 +42,17 @@ class WWMBotForwarder(BaseHTTPRequestHandler):
"""
length
=
int
(
self
.
headers
.
get
(
'
Content-Length
'
))
data
=
json
.
loads
(
self
.
rfile
.
read
(
length
).
decode
())
name
,
url
=
data
[
'
name
'
],
data
[
'
url
'
]
self
.
server
.
matrix_room
.
send_text
(
f
'
Nouvelle demande de
{
name
}
:
{
url
}
'
)
self
.
ret_ok
()
def
ret_ok
(
self
):
"""
return a success status
"""
self
.
send_response
(
200
)
status
=
'
I need a json dict with name, url, key
'
if
all
(
key
in
data
for
key
in
[
'
name
'
,
'
url
'
,
'
key
'
]):
status
=
'
wrong key
'
if
data
[
'
key
'
]
==
API_KEY
:
status
=
'
OK
'
self
.
server
.
room
.
send_text
(
f
'
Nouvelle demande de
{
data
[
"
name
"
]
}
:
{
data
[
"
url
"
]
}
'
)
self
.
send_response
(
200
if
status
==
'
OK
'
else
401
)
self
.
send_header
(
'
Content-Type
'
,
'
application/json
'
)
self
.
end_headers
()
self
.
wfile
.
write
(
b
"
{
'
status
'
:
'
OK
'
}
"
)
self
.
wfile
.
write
(
b
"
{
'
status
'
:
%a}
"
%
status
)
if
__name__
==
'
__main__
'
:
...
...
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