Browse Source

Frontend init

Giulio 3 years ago
parent
commit
bfeb1f67b1
100 changed files with 54 additions and 0 deletions
  1. 54 0
      frontend/frontend.py
  2. BIN
      frontend/static/img/flags/_ASEAN.png
  3. BIN
      frontend/static/img/flags/_African Union(OAS).png
  4. BIN
      frontend/static/img/flags/_Arab League.png
  5. BIN
      frontend/static/img/flags/_CARICOM.png
  6. BIN
      frontend/static/img/flags/_CIS.png
  7. BIN
      frontend/static/img/flags/_Commonwealth.png
  8. BIN
      frontend/static/img/flags/_England.png
  9. BIN
      frontend/static/img/flags/_European Union.png
  10. BIN
      frontend/static/img/flags/_Islamic Conference.png
  11. BIN
      frontend/static/img/flags/_Kosovo.png
  12. BIN
      frontend/static/img/flags/_NATO.png
  13. BIN
      frontend/static/img/flags/_Northern Cyprus.png
  14. BIN
      frontend/static/img/flags/_Northern Ireland.png
  15. BIN
      frontend/static/img/flags/_OPEC.png
  16. BIN
      frontend/static/img/flags/_Olimpic Movement.png
  17. BIN
      frontend/static/img/flags/_Red Cross.png
  18. BIN
      frontend/static/img/flags/_Scotland.png
  19. BIN
      frontend/static/img/flags/_Somaliland.png
  20. BIN
      frontend/static/img/flags/_United Nations.png
  21. BIN
      frontend/static/img/flags/_Wales.png
  22. BIN
      frontend/static/img/flags/ad.png
  23. BIN
      frontend/static/img/flags/ae.png
  24. BIN
      frontend/static/img/flags/af.png
  25. BIN
      frontend/static/img/flags/ag.png
  26. BIN
      frontend/static/img/flags/ai.png
  27. BIN
      frontend/static/img/flags/al.png
  28. BIN
      frontend/static/img/flags/am.png
  29. BIN
      frontend/static/img/flags/an.png
  30. BIN
      frontend/static/img/flags/ao.png
  31. BIN
      frontend/static/img/flags/aq.png
  32. BIN
      frontend/static/img/flags/ar.png
  33. BIN
      frontend/static/img/flags/as.png
  34. BIN
      frontend/static/img/flags/at.png
  35. BIN
      frontend/static/img/flags/au.png
  36. BIN
      frontend/static/img/flags/aw.png
  37. BIN
      frontend/static/img/flags/az.png
  38. BIN
      frontend/static/img/flags/ba.png
  39. BIN
      frontend/static/img/flags/bb.png
  40. BIN
      frontend/static/img/flags/bd.png
  41. BIN
      frontend/static/img/flags/be.png
  42. BIN
      frontend/static/img/flags/bf.png
  43. BIN
      frontend/static/img/flags/bg.png
  44. BIN
      frontend/static/img/flags/bh.png
  45. BIN
      frontend/static/img/flags/bi.png
  46. BIN
      frontend/static/img/flags/bj.png
  47. BIN
      frontend/static/img/flags/bm.png
  48. BIN
      frontend/static/img/flags/bn.png
  49. BIN
      frontend/static/img/flags/bo.png
  50. BIN
      frontend/static/img/flags/br.png
  51. BIN
      frontend/static/img/flags/bs.png
  52. BIN
      frontend/static/img/flags/bt.png
  53. BIN
      frontend/static/img/flags/bw.png
  54. BIN
      frontend/static/img/flags/by.png
  55. BIN
      frontend/static/img/flags/bz.png
  56. BIN
      frontend/static/img/flags/ca.png
  57. BIN
      frontend/static/img/flags/cd.png
  58. BIN
      frontend/static/img/flags/cf.png
  59. BIN
      frontend/static/img/flags/cg.png
  60. BIN
      frontend/static/img/flags/ch.png
  61. BIN
      frontend/static/img/flags/ci.png
  62. BIN
      frontend/static/img/flags/ck.png
  63. BIN
      frontend/static/img/flags/cl.png
  64. BIN
      frontend/static/img/flags/cm.png
  65. BIN
      frontend/static/img/flags/cn.png
  66. BIN
      frontend/static/img/flags/co.png
  67. BIN
      frontend/static/img/flags/cr.png
  68. BIN
      frontend/static/img/flags/cu.png
  69. BIN
      frontend/static/img/flags/cv.png
  70. BIN
      frontend/static/img/flags/cy.png
  71. BIN
      frontend/static/img/flags/cz.png
  72. BIN
      frontend/static/img/flags/de.png
  73. BIN
      frontend/static/img/flags/dj.png
  74. BIN
      frontend/static/img/flags/dk.png
  75. BIN
      frontend/static/img/flags/dm.png
  76. BIN
      frontend/static/img/flags/do.png
  77. BIN
      frontend/static/img/flags/dz.png
  78. BIN
      frontend/static/img/flags/ec.png
  79. BIN
      frontend/static/img/flags/ee.png
  80. BIN
      frontend/static/img/flags/eg.png
  81. BIN
      frontend/static/img/flags/eh.png
  82. BIN
      frontend/static/img/flags/er.png
  83. BIN
      frontend/static/img/flags/es.png
  84. BIN
      frontend/static/img/flags/et.png
  85. BIN
      frontend/static/img/flags/fi.png
  86. BIN
      frontend/static/img/flags/fj.png
  87. BIN
      frontend/static/img/flags/fm.png
  88. BIN
      frontend/static/img/flags/fo.png
  89. BIN
      frontend/static/img/flags/fr.png
  90. BIN
      frontend/static/img/flags/ga.png
  91. BIN
      frontend/static/img/flags/gb.png
  92. BIN
      frontend/static/img/flags/gd.png
  93. BIN
      frontend/static/img/flags/ge.png
  94. BIN
      frontend/static/img/flags/gg.png
  95. BIN
      frontend/static/img/flags/gh.png
  96. BIN
      frontend/static/img/flags/gi.png
  97. BIN
      frontend/static/img/flags/gl.png
  98. BIN
      frontend/static/img/flags/gm.png
  99. BIN
      frontend/static/img/flags/gn.png
  100. BIN
      frontend/static/img/flags/gp.png

+ 54 - 0
frontend/frontend.py

@@ -0,0 +1,54 @@
+import sqlite3, time, uuid, json
+from flask import Flask, request, render_template, jsonify
+conn = sqlite3.connect('texts.db', check_same_thread=False)
+conn.row_factory = sqlite3.Row
+
+def load_config():
+    with open('config/api.json') as config:
+        api = json.load(config)
+
+    config = {
+        "api": api
+    }
+    return config
+
+config = load_config()
+
+app = Flask(__name__)
+
+@app.route('/',  methods=['GET'])
+def index():
+    numbers = conn.execute('SELECT (SELECT body FROM public_messages WHERE `to` = msisdn ORDER BY timestamp), (SELECT `from` FROM public_messages WHERE `to` = msisdn ORDER BY timestamp), * FROM public_numbers;').fetchall()
+    return render_template('index.html', numbers=numbers)
+
+@app.route('/public/<uid>',  methods=['GET'])
+def show_public(uid):
+    num = conn.execute("SELECT msisdn, country FROM public_numbers WHERE uid = ?;", [uid]).fetchone()
+    if num is None:
+        return 'Not found', 404
+    messages = conn.execute("SELECT * FROM public_messages WHERE `to` = ?;", [num['msisdn']]).fetchall()
+    return render_template('messages.html', num=num, messages=messages);
+
+@app.route('/api/receive',  methods=['PUT'])
+def receive():
+    message = request.get_json()
+
+    if 'key' not in message or message['key'] != config["api"]["key"]:
+        return 'Forbidden', 403
+    
+    numbers = list()
+    for n in conn.execute('SELECT msisdn FROM public_numbers;').fetchall():
+        numbers.append(n[0])
+
+    if message['msisdn'] not in numbers:
+        conn.execute('INSERT INTO public_numbers (uid, msisdn, country) VALUES (?, ?, ?);', (str(uuid.uuid4()), message['msisdn'], 'it'))
+        conn.commit()
+
+    try:
+        conn.execute('INSERT INTO public_messages (uid, `to`, `from`, body, `timestamp`) VALUES (?, ?, ?, ?, ?);', [str(uuid.uuid4()), message['msisdn'], message['from'], message['text'], int(time.time())])
+        conn.commit()
+
+    return jsonify('Ok'), 200
+
+if __name__ == "__main__":
+    app.run()

BIN
frontend/static/img/flags/_ASEAN.png


BIN
frontend/static/img/flags/_African Union(OAS).png


BIN
frontend/static/img/flags/_Arab League.png


BIN
frontend/static/img/flags/_CARICOM.png


BIN
frontend/static/img/flags/_CIS.png


BIN
frontend/static/img/flags/_Commonwealth.png


BIN
frontend/static/img/flags/_England.png


BIN
frontend/static/img/flags/_European Union.png


BIN
frontend/static/img/flags/_Islamic Conference.png


BIN
frontend/static/img/flags/_Kosovo.png


BIN
frontend/static/img/flags/_NATO.png


BIN
frontend/static/img/flags/_Northern Cyprus.png


BIN
frontend/static/img/flags/_Northern Ireland.png


BIN
frontend/static/img/flags/_OPEC.png


BIN
frontend/static/img/flags/_Olimpic Movement.png


BIN
frontend/static/img/flags/_Red Cross.png


BIN
frontend/static/img/flags/_Scotland.png


BIN
frontend/static/img/flags/_Somaliland.png


BIN
frontend/static/img/flags/_United Nations.png


BIN
frontend/static/img/flags/_Wales.png


BIN
frontend/static/img/flags/ad.png


BIN
frontend/static/img/flags/ae.png


BIN
frontend/static/img/flags/af.png


BIN
frontend/static/img/flags/ag.png


BIN
frontend/static/img/flags/ai.png


BIN
frontend/static/img/flags/al.png


BIN
frontend/static/img/flags/am.png


BIN
frontend/static/img/flags/an.png


BIN
frontend/static/img/flags/ao.png


BIN
frontend/static/img/flags/aq.png


BIN
frontend/static/img/flags/ar.png


BIN
frontend/static/img/flags/as.png


BIN
frontend/static/img/flags/at.png


BIN
frontend/static/img/flags/au.png


BIN
frontend/static/img/flags/aw.png


BIN
frontend/static/img/flags/az.png


BIN
frontend/static/img/flags/ba.png


BIN
frontend/static/img/flags/bb.png


BIN
frontend/static/img/flags/bd.png


BIN
frontend/static/img/flags/be.png


BIN
frontend/static/img/flags/bf.png


BIN
frontend/static/img/flags/bg.png


BIN
frontend/static/img/flags/bh.png


BIN
frontend/static/img/flags/bi.png


BIN
frontend/static/img/flags/bj.png


BIN
frontend/static/img/flags/bm.png


BIN
frontend/static/img/flags/bn.png


BIN
frontend/static/img/flags/bo.png


BIN
frontend/static/img/flags/br.png


BIN
frontend/static/img/flags/bs.png


BIN
frontend/static/img/flags/bt.png


BIN
frontend/static/img/flags/bw.png


BIN
frontend/static/img/flags/by.png


BIN
frontend/static/img/flags/bz.png


BIN
frontend/static/img/flags/ca.png


BIN
frontend/static/img/flags/cd.png


BIN
frontend/static/img/flags/cf.png


BIN
frontend/static/img/flags/cg.png


BIN
frontend/static/img/flags/ch.png


BIN
frontend/static/img/flags/ci.png


BIN
frontend/static/img/flags/ck.png


BIN
frontend/static/img/flags/cl.png


BIN
frontend/static/img/flags/cm.png


BIN
frontend/static/img/flags/cn.png


BIN
frontend/static/img/flags/co.png


BIN
frontend/static/img/flags/cr.png


BIN
frontend/static/img/flags/cu.png


BIN
frontend/static/img/flags/cv.png


BIN
frontend/static/img/flags/cy.png


BIN
frontend/static/img/flags/cz.png


BIN
frontend/static/img/flags/de.png


BIN
frontend/static/img/flags/dj.png


BIN
frontend/static/img/flags/dk.png


BIN
frontend/static/img/flags/dm.png


BIN
frontend/static/img/flags/do.png


BIN
frontend/static/img/flags/dz.png


BIN
frontend/static/img/flags/ec.png


BIN
frontend/static/img/flags/ee.png


BIN
frontend/static/img/flags/eg.png


BIN
frontend/static/img/flags/eh.png


BIN
frontend/static/img/flags/er.png


BIN
frontend/static/img/flags/es.png


BIN
frontend/static/img/flags/et.png


BIN
frontend/static/img/flags/fi.png


BIN
frontend/static/img/flags/fj.png


BIN
frontend/static/img/flags/fm.png


BIN
frontend/static/img/flags/fo.png


BIN
frontend/static/img/flags/fr.png


BIN
frontend/static/img/flags/ga.png


BIN
frontend/static/img/flags/gb.png


BIN
frontend/static/img/flags/gd.png


BIN
frontend/static/img/flags/ge.png


BIN
frontend/static/img/flags/gg.png


BIN
frontend/static/img/flags/gh.png


BIN
frontend/static/img/flags/gi.png


BIN
frontend/static/img/flags/gl.png


BIN
frontend/static/img/flags/gm.png


BIN
frontend/static/img/flags/gn.png


BIN
frontend/static/img/flags/gp.png


Some files were not shown because too many files changed in this diff