Frontend init
							
								
								
									
										54
									
								
								frontend/frontend.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -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
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.1 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_African Union(OAS).png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 666 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Arab League.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_CARICOM.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_CIS.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.6 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Commonwealth.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.3 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_England.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 498 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_European Union.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Islamic Conference.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Kosovo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_NATO.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.0 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Northern Cyprus.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 809 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Northern Ireland.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 713 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_OPEC.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.1 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Olimpic Movement.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 976 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Red Cross.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 445 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Scotland.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.6 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Somaliland.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 843 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_United Nations.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.3 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/_Wales.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ad.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.1 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ae.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 563 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/af.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 990 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ag.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ai.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/al.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1007 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/am.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 591 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/an.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 769 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ao.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 933 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/aq.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1019 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ar.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 611 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/as.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/at.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 466 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/au.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/aw.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 806 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/az.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 826 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ba.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.3 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bb.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 947 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bd.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 998 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/be.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 648 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bf.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 740 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bg.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 483 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bh.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 907 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bj.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 607 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bm.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bn.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 829 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/br.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.6 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bs.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 834 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bt.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.3 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bw.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 583 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/by.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 859 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/bz.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ca.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1005 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cd.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cf.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 779 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cg.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ch.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 631 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ci.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 629 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ck.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cl.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 657 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cm.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 804 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cn.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 793 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/co.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 510 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cr.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 568 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cu.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1016 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cv.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 890 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cy.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 729 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/cz.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 849 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/de.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 602 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/dj.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1004 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/dk.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 595 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/dm.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/do.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 625 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/dz.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 962 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ec.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.0 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ee.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 522 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/eg.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 622 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/eh.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 966 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/er.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.5 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/es.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 873 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/et.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.0 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/fi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 523 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/fj.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.3 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/fm.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 910 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/fo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 607 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/fr.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 637 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ga.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 560 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gb.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gd.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/ge.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 868 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gg.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 773 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gh.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 739 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.0 KiB | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gl.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 925 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gm.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 573 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gn.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 701 B | 
							
								
								
									
										
											BIN
										
									
								
								frontend/static/img/flags/gp.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.0 KiB | 
 Giulio
						Giulio