"theoretically working version"
This commit is contained in:
Pták 2024-04-19 22:17:30 +02:00
parent 9ccf272720
commit 9f7ca5bccd
3 changed files with 101 additions and 0 deletions

50
conf/templates/index.html Normal file
View file

@ -0,0 +1,50 @@
<html>
<head>
<title> Signal Bridge </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
label, p {
font-family: monospace;
letter-spacing: .17em;
overflow:hidden;
}
.center{
display: flex;
justify-content: center;
}
.input{
border-radius: 25px;
border: 2px solid gray;
padding: 10px;
margin: 10px
}
#button:hover {background-color: #888B8D}
#button:active {
background-color: #666;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>
</head>
<body>
<div class="center">
<div class="typewriter">
<h1> Pošli svou zprávu</h1></div>
</div>
<div class="center">
<form action="/sender" method="post" enctype="multipart/form-data":>
<label for="Message">Zpráva: </label><br>
<textarea rows="5" cols="60" name="message" id="message"placeholder="Zadejte Zprávu" class="input"></textarea> <br><br>
<input type="submit" class="input" id="button" value="Odeslat">
</form>
{% if text %}
<p>{{text|safe}}</p>
{% endif %}
</div>
<h3> </h3>
</body>
</html>

33
main.py Normal file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python3
from flask import Flask, render_template, request, redirect, url_for
from dotenv import load_dotenv
import signal
import threading
import os
import threading
load_dotenv()
app = Flask(__name__, template_folder='./conf/templates')
filename = os.environ.get("NUMBERS_FILENAME")
port = os.environ.get("PORT")
@app.route("/")
def index():
return render_template("index.html",)
@app.route("/sender", methods=['POST'])
def send_form():
if request.method == 'POST':
text = request.form.get("message")
contacts = data.get_phone_numbers(filename)
thread = threading.Thread(target=signal.send, args=(contacts, text))
thread.start()
return redirect(url_for("index") + "?notice=Odesláno")
app.run(host="0.0.0.0", port=8080)

18
signal.py Normal file
View file

@ -0,0 +1,18 @@
import subprocess
exe = "signal-cli"
def send(contacts, message):
subprocess.run([
exe,
"send",
*contacts,
"-m",
message
], encoding="utf-8")
def receive():
subprocess.run([
exe,
"receive"
])