Пример #1
0
    def get_ui(self):

        if not ldap().conn:
            ui = self.app.inflate("helpdesk:error")
            ui.find("error").set('text', "É necessário configurar a base LDAP")
            return ui
        ui = self.app.inflate('helpdesk:main')
        ldap().syncDB()

        if access("/var/www/helpdesk", F_OK):
            ui.remove("ativar")
        else:
            ui.remove("desativar")

        ui.find("linkHelp").set(
            'url', "http://%s/helpdesk/" % self.app.environ['SERVER_NAME'])
        if Config().getConfig()["fonte_config"] == "redmine" and open(
                '/var/lib/netcontrol/plugins/helpdesk/config').read().split(
                    '=')[1] == 'True':
            ui.find("titulo").set("text", "Servidor configurado")
        elif Config().getConfig()["fonte_config"] == "arquivo_ldap" or open(
                '/var/lib/netcontrol/plugins/helpdesk/config').read().split(
                    '=')[1] == 'False':
            ui.find("titulo").set(
                "text",
                "Servidor ainda não foi configurado ou está desativado, informações abaixo foram coletadas do arquivo de configuração."
            )
            ui.remove("linkHelp")

        for i in Config.indice:
            ui.find(i).set('value', Config().getConfig()[i])

        if self._view == "listarUsers":
            users = self.app.inflate('helpdesk:view')
            msg = users.find('users')
            l = []
            for i in ldap().getUsersLDAP():
                j = ldap().getInfoUser(i)
                msg.append(
                    UI.DTR(
                        UI.DTH(
                            UI.Label(
                                text=j["login"] if j["login"] <> "" else "uid",
                                size=2)),
                        UI.DTH(
                            UI.Label(text=j["nome"]
                                     if j["nome"] <> "" else "giverName",
                                     size=2)),
                        UI.DTH(
                            UI.Label(text=j["sobrenome"]
                                     if j["sobrenome"] <> "" else "sN",
                                     size=2)),
                        UI.DTH(
                            UI.Label(text=j["mail"] if j["mail"] <> "NULL" else
                                     "sem registro",
                                     size=2))))
            self._view = None
            return users

        return ui
Пример #2
0
 def on_submit(self, event, params, vars=None):
     if params[0] == "configurarServer":
         if vars.getvalue("action", '') == "configServer":
             Config().setConfig(
              vars.getvalue('nomeServidor') , vars.getvalue('enderecoServidor') , \
              vars.getvalue('porta') , vars.getvalue('contaLDAP') , vars.getvalue('senhaContLDAP') ,\
              vars.getvalue('baseDN') , vars.getvalue('usuario') , vars.getvalue('nomeUser') , \
              vars.getvalue('sobrenome') , vars.getvalue('email'), vars.getvalue('protSSL')
             )
Пример #3
0
 def encode_auth_token(user_id, seconds=600):
     payload = {
         "exp":
         datetime.datetime.utcnow() +
         datetime.timedelta(days=0, seconds=seconds),
         "iat":
         datetime.datetime.utcnow(),
         "sub":
         user_id
     }
     return jwt.encode(payload=payload,
                       key=Config.get('server_key'),
                       algorithm="HS256")
Пример #4
0
 def on_click(self, event, params, vars=None):
     from os import system
     if params[0] == "listarUsers":
         self._view = params[0]
     elif params[0] == "desativar":
         Config().delConfig()
         open('/var/lib/netcontrol/plugins/helpdesk/config',
              'w').write('servidor=False')
         system("rm /var/www/helpdesk")
     elif params[0] == "ativar":
         open('/var/lib/netcontrol/plugins/helpdesk/config',
              'w').write('servidor=True')
         system("ln -s /usr/share/redmine/public/ /var/www/helpdesk")
         system("chown -R www-data:www-data /var/www/helpdesk/")
Пример #5
0
    return p(body=template('tpl/error',
                           title='404 page not found',
                           msg='The requested page was not found'),
             **kwargs)


def p(**kwargs):
    return page(config, backend, state, **kwargs)


app_dir = os.path.dirname(__file__)
if app_dir:
    os.chdir(app_dir)

import config
config = Config(config)
backend = Backend(config)
state = {}
(state, errors) = load_plugins(config.plugins, config)
if errors:
    for e in errors:
        sys.stderr.write(str(e))
    sys.exit(2)
session_opts = {
    'session.type': 'file',
    'session.cookie_expires': 300,
    'session.data_dir': './session_data',
    'session.auto': True
}
app = SessionMiddleware(app(), session_opts)
debug(True)
Пример #6
0
import jwt
from functools import wraps
from flask import Flask, jsonify, request, session, make_response
from flask_cors import CORS
from werkzeug.security import generate_password_hash, check_password_hash
from backend.database import db_session, db_init
from time import time
from modules.datatypes import Todos, Users, datetime, __COMPLETED__, __NOT_STARTED__
from backend import Config

app = Flask(__name__)
CORS(app)


app.config['SECRET_KEY'] = Config.get('server_key')

__BASE_URI = '/api/v1'
__STATUS_SUCCESS = 'success'
__STATUS_FAIL = 'fail'
__STATUS_TEST = 'test'
__STATUS_NOT_FOUND = 'not found'

stamp = lambda: int(time().__str__()[:10])


def get_jwt_decode_data():
    token = request.headers.get('Authorization')
    session_data = jwt.decode(token, app.config['SECRET_KEY'])
    return session_data