diff --git a/README.md b/README.md index 5c12047..cd8c3c7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,68 @@ -# voipsms +# voipSMS -Python flask app that uses voip.ms to manage a number of DID numbers for SMS. Can be used to get mostly anonymous texts and sms verification. \ No newline at end of file +Python flask app that uses voip.ms to manage a number of DID numbers for SMS. Can be used to get mostly anonymous texts and sms verification. + +## How to use + +1. Clone the repo + +`git clone http://git.community.i2p/anons-voip/voipsms.git && cd voipsms` + +2. Create and activate a python venv + +`python3 -m venv venv && source ./venv/bin/activate` + +3. Install requirements + +`pip install -r requirements.txt` + +4. Set your config + +`vim config.json` + +[Read about how to set up your config here!](./README.md#Config) + +5. Start up the server + +`./run` + +## Config + +The config used in this project uses the JSON format and expects a `username` and `password` + +Ex: +``` + { + "username":"voipms-email", + "password":"voipms-api-password" + } +``` + + +## Endpoints + +### /numbers + +*Returns a list of numbers in use* + +Supports: GET + + Returns a list of javascript objects with keys: did (int as string), sms_available (boolean as int), mms_available (boolean as int) + +### /sms + +*Returns sms/mms messages for a given number* + +Supports: GET,POST +Expects: string `did` + + Returns a list of javascript objects with keys: message (string), did (int as string), contact (string as int), date (date as string), media (list) + +### /enablesms + +*[DISABLED] Enables sms feature for a given number* + +Supports: GET,POST +Expects: string `did` + + Returns a boolean as int \ No newline at end of file diff --git a/app/did.py b/app/did.py new file mode 100644 index 0000000..795503d --- /dev/null +++ b/app/did.py @@ -0,0 +1,14 @@ +from voipms.api import Client + +def get_numbers(client): + params = { + } + did_info = client.dids.fetch(params=params) + info = [] + for did in did_info["dids"]: + desired_did_info = {"mms_available":None,"sms_available":None,"did":None} + for key in did: + if key in desired_did_info: + desired_did_info[key] = did[key] + info.append(desired_did_info) + return info \ No newline at end of file diff --git a/app/server.py b/app/server.py new file mode 100755 index 0000000..c8779a0 --- /dev/null +++ b/app/server.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +from flask import Flask, request, abort +from voipms.api import Client +import did, sms +import json + +app = Flask(__name__) +with open("config.json",'r') as conf_file: + conf = json.load(conf_file) +client = Client(conf["username"],conf["password"]) + + +@app.route("/", methods=['GET']) +def default(): + return 'Check out the project' + +@app.route("/numbers", methods=['GET']) +def get_numbers(): + return did.get_numbers(client) + +@app.route("/sms",methods=['GET', 'POST']) +def get_sms(): + did = request.args.get('did') + return sms.get_sms(client, did) + + +@app.route("/enablesms",methods=['GET', 'POST']) +def set_sms(): + abort(403) + did = request.args.get('did') + return sms.get_sms(client, did) + + +if __name__ == "__main__": + from waitress import serve + serve(app, host="0.0.0.0", port=8080) diff --git a/app/sms.py b/app/sms.py new file mode 100644 index 0000000..7f36fe8 --- /dev/null +++ b/app/sms.py @@ -0,0 +1,16 @@ +from voipms.api import Client + +def get_sms(client, did): + params = { + "did":did, + "type":1, + "all_messages":1 + } + return client.dids.sms.fetch(params=params) + +def enable_sms(client, did): + params = { + "did":did, + "enable":1, + } + return client.dids.sms.set(params=params) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ec88332..265f5ea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ voipms-python flask +waitress requests \ No newline at end of file diff --git a/run b/run index 79c83e2..b7a2624 100755 --- a/run +++ b/run @@ -1,2 +1,3 @@ #!/bin/bash -flask --app app/server run --host=0.0.0.0 --port 8080 +#flask --app app/server run --host=0.0.0.0 --port 8080 +python3 app/server.py