DmitrMakeev commited on
Commit
c974b4d
·
verified ·
1 Parent(s): 85a1ea9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -148,7 +148,12 @@ for db in DATABASES:
148
  DATABASE_NEW = 'data_gc.db'
149
 
150
 
151
-
 
 
 
 
 
152
  # Пример данных настроек
153
  api_key_sys_ser = ''
154
  ALLOWED_ORIGIN = ''
@@ -202,10 +207,20 @@ def save_settings(settings_dict):
202
 
203
  @app.route('/settings', methods=['GET'])
204
  def get_settings():
 
 
 
 
 
205
  return jsonify(settings)
206
 
207
  @app.route('/settings', methods=['POST'])
208
  def save_settings_route():
 
 
 
 
 
209
  data = request.json
210
  if data:
211
  for key, value in data.items():
@@ -215,7 +230,6 @@ def save_settings_route():
215
  return jsonify({'status': 'success'})
216
  else:
217
  return jsonify({'status': 'error', 'message': 'No data provided'}), 400
218
-
219
  @app.route('/set')
220
  def index_set():
221
  return render_template('settings.html')
 
148
  DATABASE_NEW = 'data_gc.db'
149
 
150
 
151
+ # Функция для проверки заголовка Origin
152
+ def check_origin():
153
+ origin = request.headers.get('Origin')
154
+ if origin != ALLOWED_ORIGIN:
155
+ return jsonify({"error": "Unauthorized access"}), 403
156
+ return None
157
  # Пример данных настроек
158
  api_key_sys_ser = ''
159
  ALLOWED_ORIGIN = ''
 
207
 
208
  @app.route('/settings', methods=['GET'])
209
  def get_settings():
210
+ # Проверка заголовка Origin
211
+ origin_check = check_origin()
212
+ if origin_check:
213
+ return origin_check
214
+
215
  return jsonify(settings)
216
 
217
  @app.route('/settings', methods=['POST'])
218
  def save_settings_route():
219
+ # Проверка заголовка Origin
220
+ origin_check = check_origin()
221
+ if origin_check:
222
+ return origin_check
223
+
224
  data = request.json
225
  if data:
226
  for key, value in data.items():
 
230
  return jsonify({'status': 'success'})
231
  else:
232
  return jsonify({'status': 'error', 'message': 'No data provided'}), 400
 
233
  @app.route('/set')
234
  def index_set():
235
  return render_template('settings.html')