ajuste rota mounting e criação de repositorio de imagem
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
|
@ -1,30 +1,13 @@
|
||||||
{
|
{
|
||||||
"info_html": [
|
"info_html": [
|
||||||
{
|
{
|
||||||
"imagem_Cab": "",
|
"usuario": "Daivid",
|
||||||
"A_cab": "..",
|
"empresa": "ItGuys",
|
||||||
"button_Cab": "Logout",
|
"imagemUser": "../Acessts/Imagens/1605305486169.jpg",
|
||||||
"imagem_segumento_1": "../Acessts/Imagens/Iconis/seta-direita.png",
|
"imagemFun": "../Acessts/Imagens/01160209321024.jpg",
|
||||||
"imagem_User_1_segumento_2": "../Acessts/Imagens/Iconis/profile-user.png",
|
"Permissoes_Monitor": "true",
|
||||||
"imagem_User_2_segumento_2": "../Acessts/Imagens/Iconis/profile-user.png",
|
"Imagem_empresa" : ""
|
||||||
"texto_User_segumento_2": "Usuario",
|
|
||||||
"texto_Empresa_segumento_2": "itguys",
|
|
||||||
"Menu_home_a": "https://dev.itguys.com.br/ambiente_do_usu%C3%A1rio/html/construindo.html",
|
|
||||||
"Menu_home_img": "../Acessts/Imagens/Iconis/home.png",
|
|
||||||
"Menu_home_text": "Home",
|
|
||||||
"Menu_Monitor_a": "./Tela_Monitoramento/Monitoramento copy.html",
|
|
||||||
"Menu_Monitor_img": "../Acessts/Imagens/Iconis/monitor.png",
|
|
||||||
"Menu_Monitor_text": "Monitoramento",
|
|
||||||
"Menu_Servicedesk_a": "https://servicedesk.itguys.com.br/HomePage.do",
|
|
||||||
"Menu_Servicedesk_img": "../Acessts/Imagens/Iconis/technical-support.png",
|
|
||||||
"Menu_Servicedesk_text": "Servicedesk",
|
|
||||||
"Menu_Suporte_a": "https://api.whatsapp.com/send?phone=5521966344698",
|
|
||||||
"Menu_Suporte_img": "../Acessts/Imagens/Iconis/central-de-atendimento.png",
|
|
||||||
"Menu_Suporte_text": "Suporte",
|
|
||||||
"Menu_Config_a": "./Tela_config/Config_Ambiente_usuario.html",
|
|
||||||
"Menu_Config_img": "../Acessts/Imagens/Iconis/engrenagem - Copia.png",
|
|
||||||
"Menu_Config_text": "Configuracões",
|
|
||||||
"Tela": "https://dev.itguys.com.br/ambiente_do_usu%C3%A1rio/html/construindo.html"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"config_influxdb": [
|
"config_influxdb": [
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import Flask, request, jsonify, send_from_directory
|
from flask import Flask, request, jsonify, send_from_directory,url_for,send_file
|
||||||
from flask_mysqldb import MySQL
|
from flask_mysqldb import MySQL
|
||||||
from MySQLdb.cursors import DictCursor
|
from MySQLdb.cursors import DictCursor
|
||||||
import ldap3
|
import ldap3
|
||||||
|
|
@ -51,8 +51,17 @@ app.config['SMTP_PASSWORD'] = os.getenv('SMTP_PASSWORD')
|
||||||
app.config['SMTP_PORT'] = os.getenv('SMTP_PORT')
|
app.config['SMTP_PORT'] = os.getenv('SMTP_PORT')
|
||||||
app.config['SMTP_RECIPIENT'] = os.getenv('SMTP_RECIPIENT')
|
app.config['SMTP_RECIPIENT'] = os.getenv('SMTP_RECIPIENT')
|
||||||
|
|
||||||
|
# Diretório onde as imagens sigilosas estão armazenadas
|
||||||
|
PROTECTED_FOLDER = '/var/www/ambiente_python/Respositorio_img/'
|
||||||
mysql = MySQL(app)
|
mysql = MySQL(app)
|
||||||
|
|
||||||
|
# Função auxiliar para obter o caminho completo da imagem
|
||||||
|
def get_protected_image_path(filename):
|
||||||
|
file_path = os.path.join(PROTECTED_FOLDER, filename)
|
||||||
|
# Verifica se o arquivo existe no diretório seguro
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
return file_path
|
||||||
|
return None
|
||||||
|
|
||||||
def token_required(f):
|
def token_required(f):
|
||||||
@wraps(f) # Adiciona wraps aqui para manter o nome da função original
|
@wraps(f) # Adiciona wraps aqui para manter o nome da função original
|
||||||
|
|
@ -178,56 +187,69 @@ def login():
|
||||||
# Captura qualquer outra exceção LDAP genérica
|
# Captura qualquer outra exceção LDAP genérica
|
||||||
return jsonify({'Erro 500': f'Erro LDAP: {str(e)}'}), 500
|
return jsonify({'Erro 500': f'Erro LDAP: {str(e)}'}), 500
|
||||||
|
|
||||||
|
@app.route('/get_profile_picture/<path:filename>', methods=['GET'])
|
||||||
|
@token_required # Garante que apenas usuários autenticados possam acessar
|
||||||
|
def get_profile_picture(filename):
|
||||||
|
# O 'filename' já pode incluir subpastas, por exemplo: "usuarios/perfil/joao_perfil.jpg"
|
||||||
|
file_path = get_protected_image_path(filename)
|
||||||
|
|
||||||
|
if file_path and os.path.isfile(file_path):
|
||||||
|
return send_file(file_path, mimetype='image/jpg') # Ajuste o mimetype conforme o tipo da imagem
|
||||||
|
else:
|
||||||
|
return jsonify({'msg': 'Imagem não encontrada ou acesso não permitido'}), 404
|
||||||
|
|
||||||
|
|
||||||
@app.route('/mounting', methods=['GET'])
|
@app.route('/mounting', methods=['GET'])
|
||||||
@token_required
|
@token_required # Verificação de token para autenticação
|
||||||
def mounting():
|
def mounting():
|
||||||
# Decodifica o token para obter o e-mail do usuário
|
# Decodifica o token para obter o e-mail do usuário
|
||||||
token = request.headers.get('x-access-token')
|
token = request.headers.get('x-access-token')
|
||||||
data = jwt.decode(token, app.config['SECRET_KEY'], algorithms=["HS256"])
|
data = jwt.decode(token, app.config['SECRET_KEY'], algorithms=["HS256"])
|
||||||
username_full = data['user']
|
username_full = data['user']
|
||||||
|
|
||||||
# Extrair o domínio do email do usuário autenticado
|
|
||||||
domain = username_full.split('@')[1]
|
|
||||||
|
|
||||||
# Verifica se o usuário está autenticado
|
# Verifica se o usuário está autenticado
|
||||||
if not username_full:
|
if not username_full:
|
||||||
return jsonify({'msg': 'Token inválido!'}), 401
|
return jsonify({'msg': 'Token inválido!'}), 401
|
||||||
|
|
||||||
# Consultar o banco de dados para obter o nome da empresa com base no domínio
|
# Extrair o nome de usuário e o domínio do email do usuário autenticado
|
||||||
|
username = username_full.split('@')[0]
|
||||||
|
domain = username_full.split('@')[1]
|
||||||
|
|
||||||
|
# Consultar o banco de dados para obter as informações do usuário (nome, img_perfil, img_fundo)
|
||||||
cur = mysql.connection.cursor()
|
cur = mysql.connection.cursor()
|
||||||
cur.execute("SELECT nome FROM empresa WHERE dominio = %s", (domain,))
|
cur.execute("SELECT nome, img_perfil, img_fundo FROM usuarios WHERE usuario = %s", (username,))
|
||||||
|
usuario_result = cur.fetchone()
|
||||||
|
|
||||||
|
if usuario_result is None:
|
||||||
|
cur.close()
|
||||||
|
return jsonify({'msg': 'Usuário não encontrado no banco de dados'}), 404
|
||||||
|
|
||||||
|
nome_usuario, img_perfil_path, img_fundo_path = usuario_result
|
||||||
|
|
||||||
|
# Consultar o banco de dados para obter o nome e o logo da empresa com base no domínio
|
||||||
|
cur.execute("SELECT nome, logo FROM empresa WHERE dominio = %s", (domain,))
|
||||||
empresa_result = cur.fetchone()
|
empresa_result = cur.fetchone()
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
# Verifica se a empresa foi encontrada
|
|
||||||
if empresa_result is None:
|
if empresa_result is None:
|
||||||
return jsonify({'msg': 'Empresa não encontrada no banco de dados para o domínio fornecido'}), 404
|
return jsonify({'msg': 'Empresa não encontrada no banco de dados para o domínio fornecido'}), 404
|
||||||
|
|
||||||
# Obtém o nome da empresa
|
nome_empresa, logo_empresa_path = empresa_result
|
||||||
nome_empresa = empresa_result[0]
|
|
||||||
|
|
||||||
# Definir o caminho do diretório onde os arquivos JSON estão armazenados
|
# Montar a resposta JSON com os caminhos relativos das imagens e outras informações
|
||||||
json_directory = './json/' # Substitua pelo caminho real do diretório
|
response_data = {
|
||||||
|
'usuario': {
|
||||||
|
'nome': nome_usuario,
|
||||||
|
'img_perfil': f"/get_profile_picture/{img_perfil_path}", # Caminho relativo para a imagem de perfil
|
||||||
|
'img_fundo': f"/get_profile_picture/{img_fundo_path}" # Caminho relativo para a imagem de fundo
|
||||||
|
},
|
||||||
|
'empresa': {
|
||||||
|
'nome': nome_empresa,
|
||||||
|
'logo': f"/get_profile_picture/{logo_empresa_path}" # Caminho relativo para o logo da empresa
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Nome do arquivo JSON correspondente ao nome da empresa
|
return jsonify(response_data), 200
|
||||||
json_filename = f"{nome_empresa}.json"
|
|
||||||
|
|
||||||
# Caminho completo para o arquivo JSON
|
|
||||||
json_filepath = os.path.join(json_directory, json_filename)
|
|
||||||
|
|
||||||
# Verificar se o arquivo JSON existe
|
|
||||||
if not os.path.isfile(json_filepath):
|
|
||||||
return jsonify({'msg': 'Arquivo JSON não encontrado para a empresa fornecida'}), 404
|
|
||||||
|
|
||||||
# Carregar o conteúdo do arquivo JSON mantendo a ordem
|
|
||||||
with open(json_filepath, 'r') as json_file:
|
|
||||||
json_data = json.load(json_file, object_pairs_hook=OrderedDict)
|
|
||||||
|
|
||||||
# Extrair apenas o conteúdo de 'info_html'
|
|
||||||
info_html_content = json_data.get('info_html', {})
|
|
||||||
|
|
||||||
# Retornar a resposta JSON com apenas o conteúdo de 'info_html'
|
|
||||||
return jsonify(info_html_content)
|
|
||||||
|
|
||||||
@app.route('/api/options', methods=['GET'])
|
@app.route('/api/options', methods=['GET'])
|
||||||
@token_required
|
@token_required
|
||||||
|
|
|
||||||