Exemplo n.º 1
0
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Boolean
from sqlalchemy import ForeignKey
from core.classes.model.base import MapifBase
from core.classes.model.session import session
from core.modules import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.user_preferences')


#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# UserPreferences
#-------------------------------------------------------------------------------
class UserPreferences(MapifBase):
    __tablename__ = 'user_preferences'
    __table_args__ = {
        'useexisting': True,
        'sqlite_autoincrement': True  # <!> SQLITE <!>
    }
    #---------------------------------------------------------------------------
Exemplo n.º 2
0
from core.classes.model.session             import MapifSession
from core.classes.model.base                import MapifBase
from core.classes.model.user                import User
from core.classes.model.user                import UserCRUD
from core.classes.model.location            import Location
from core.classes.model.location            import LocationCRUD
from core.classes.model.user_location       import UserLocation
from core.classes.model.user_location       import UserLocationCRUD
from core.classes.model.password_reset      import PasswordReset
from core.classes.model.password_reset      import PasswordResetCRUD
from core.classes.model.user_preferences    import UserPreferences
from core.classes.model.user_preferences    import UserPreferencesCRUD
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.db')
META_REASON_ENUM = [
    'no', 
    'internship', 
    'exchange', 
    'dd', 
    'job', 
    'vacation'
]
#===============================================================================
# MODEL OBJECTS
#===============================================================================
#-------------------------------------------------------------------------------
# _get_complete_database_name
#-------------------------------------------------------------------------------
def _get_complete_database_name(database):
Exemplo n.º 3
0
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import requests
from core.modules import logger
#===============================================================================
# GLOBALS
#===============================================================================
DFLT_TIMEOUT = 2  # 2 seconds of default timeout
EXCEPTION_RAISED = False
modlgr = logger.get('mapif.request')


#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
# get
#-------------------------------------------------------------------------------
def get(url, params, timeout=DFLT_TIMEOUT, headers=None):
    global EXCEPTION_RAISED
    try:
        if headers is None:
            return requests.get(url, params=params, timeout=timeout)
        else:
            return requests.get(url,
Exemplo n.º 4
0
from flask        import escape
from flask        import render_template
from core.modules import ini
from core.modules import logger
from core.modules import request
#===============================================================================
# GLOBALS
#===============================================================================
# See http://api.elasticemail.com/public/help#Email_Send for documentation
_APIURL_ = 'https://api.elasticemail.com/v2/email/send'
_APIKEY_ = None
_EMAIL_TEMPLATE_DIR_ = 'src/templates/emails/'
_EMAIL_ENCODING_ = 'utf-8'
_SENDER_EMAIL_ = '*****@*****.**'
_SENDER_NAME_ = 'MapIf'
modlgr = logger.get('mapif.email')
#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
# init_emails
#-------------------------------------------------------------------------------
def init():
    global _APIKEY_
    try:
        _APIKEY_ = ini.config('EMAILS', 'elasticmail_apikey', default=None)
        if _APIKEY_ is None or _APIKEY_ == '':
            modlgr.warning('No Email APIKEY found')
        else:
            modlgr.debug('Email APIKEY: {0}'.format(_APIKEY_))
    except Exception as ex:
Exemplo n.º 5
0
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import requests
from core.modules import logger
#===============================================================================
# GLOBALS
#===============================================================================
DFLT_TIMEOUT = 2 # 2 seconds of default timeout
EXCEPTION_RAISED = False
modlgr = logger.get('mapif.request')
#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
# get
#-------------------------------------------------------------------------------
def get(url, params, timeout=DFLT_TIMEOUT, headers=None):
    global EXCEPTION_RAISED
    try:
        if headers is None:
            return requests.get(url, params=params, timeout=timeout)
        else:
            return requests.get(url, params=params, timeout=timeout, headers=headers)
    except Exception as e:
        EXCEPTION_RAISED = True
Exemplo n.º 6
0
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy import Float
from core.classes.model.base import MapifBase
from core.classes.model.session import session
from core.modules import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.location')


#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# Location
#-------------------------------------------------------------------------------
class Location(MapifBase):
    __tablename__ = 'location'
    __table_args__ = {
        'useexisting': True,
        'sqlite_autoincrement': True  # <!> SQLITE <!>
    }
    #---------------------------------------------------------------------------
Exemplo n.º 7
0
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
from sqlalchemy                 import Column
from sqlalchemy                 import Integer
from sqlalchemy                 import String
from sqlalchemy                 import Float
from core.classes.model.base    import MapifBase
from core.classes.model.session import session
from core.modules               import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.location')
#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# Location
#-------------------------------------------------------------------------------
class Location(MapifBase):
    __tablename__ = 'location'
    __table_args__ = {
            'useexisting': True, 
            'sqlite_autoincrement': True # <!> SQLITE <!>
    }
    #---------------------------------------------------------------------------
    # attributes
    #---------------------------------------------------------------------------
Exemplo n.º 8
0
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import time
from flask_responses import json_response
from flask import session
from functools import wraps
from core.classes.response import Response
from core.modules import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.wrappers')


#===============================================================================
# DECORATORS
#===============================================================================
#-------------------------------------------------------------------------------
# internal_error_handler
#-------------------------------------------------------------------------------
def internal_error_handler(err_code):
    def wrapper(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):
            try:
                return f(*args, **kwargs)
            except Exception as e:
Exemplo n.º 9
0
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import re
import json
from core.modules import ini
from core.modules import logger
from core.modules import request
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.validator')
_VALIDATORS_ = {
    'email': re.compile('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'),
    'alphanum': re.compile('^\w+$'),
    'int': re.compile('^\d+$'),
    'double': re.compile('^\d+(\.\d+)?$'),
    'phone': re.compile('^(\+\d{2}(\s)?\d|\d{2})(\s)?(\d{2}(\s)?){4}$'),
    'year': re.compile('^\d{4}$'),
    'timestamp': re.compile('^\d{4}(-\d{2}){2}$')
}


#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
Exemplo n.º 10
0
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import bcrypt
from sqlalchemy                 import Column
from sqlalchemy                 import Integer
from sqlalchemy                 import String
from core.classes.model.base    import MapifBase
from core.classes.model.session import session
from core.modules               import logger 
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.user')
#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# User
#-------------------------------------------------------------------------------
class User(MapifBase):
    __tablename__ = 'user'
    __table_args__ = {
        'useexisting': True, 
        'sqlite_autoincrement': True # <!> SQLITE <!>
    }
    #---------------------------------------------------------------------------
    # attributes
    #---------------------------------------------------------------------------
Exemplo n.º 11
0
#===============================================================================
from sqlalchemy import func
from sqlalchemy import Text
from sqlalchemy import Column
from sqlalchemy import String
from sqlalchemy import Integer
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import UniqueConstraint
from core.classes.model.base import MapifBase
from core.classes.model.session import session
from core.modules import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.user_location')


#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# UserLocation
#-------------------------------------------------------------------------------
class UserLocation(MapifBase):
    __tablename__ = 'user_location'
    __table_args__ = (
        UniqueConstraint('uid', 'timestamp'),
        {
            'useexisting': True,
            'sqlite_autoincrement': True  # <!> SQLITE <!>
Exemplo n.º 12
0
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import time
from flask_responses        import json_response
from flask                  import session
from functools              import wraps
from core.classes.response  import Response
from core.modules           import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.wrappers')
#===============================================================================
# DECORATORS
#===============================================================================
#-------------------------------------------------------------------------------
# internal_error_handler
#-------------------------------------------------------------------------------
def internal_error_handler(err_code):
    def wrapper(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):
            try:
                return f(*args, **kwargs)
            except Exception as e:
                timestamp = time.strftime('%d%m%H%M%S')
                desc = '`mapif.{0}()` at `{1}` error: details below.'.format(
Exemplo n.º 13
0
from flask import escape
from flask import render_template
from core.modules import ini
from core.modules import logger
from core.modules import request
#===============================================================================
# GLOBALS
#===============================================================================
# See http://api.elasticemail.com/public/help#Email_Send for documentation
_APIURL_ = 'https://api.elasticemail.com/v2/email/send'
_APIKEY_ = None
_EMAIL_TEMPLATE_DIR_ = 'src/templates/emails/'
_EMAIL_ENCODING_ = 'utf-8'
_SENDER_EMAIL_ = '*****@*****.**'
_SENDER_NAME_ = 'MapIf'
modlgr = logger.get('mapif.email')


#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
# init_emails
#-------------------------------------------------------------------------------
def init():
    global _APIKEY_
    try:
        _APIKEY_ = ini.config('EMAILS', 'elasticmail_apikey', default=None)
        if _APIKEY_ is None or _APIKEY_ == '':
            modlgr.warning('No Email APIKEY found')
        else:
Exemplo n.º 14
0
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS 
#===============================================================================
import configparser
import os
from core.modules import logger
#===============================================================================
# GLOBALS 
#===============================================================================
_CONFIG_ = None
modlgr = logger.get('mapif.ini')
#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
# init
#   Initializes configuration loading it from INI file
#-------------------------------------------------------------------------------
def init(filename):
    global _CONFIG_
    ok = False
    if not _CONFIG_:
        _CONFIG_ = configparser.ConfigParser()
        if len(_CONFIG_.read(filename, encoding='utf-8')) > 0:
            modlgr.debug('Configuration file {0} successfully loaded !'.format(filename))
            ok = True
Exemplo n.º 15
0
from core.modules                   import db
from core.modules                   import validator
from core.modules                   import ini
from core.modules                   import logger
from core.modules                   import emails
from core.modules.wrappers          import internal_error_handler
from core.modules.wrappers          import require_connected
from core.modules.wrappers          import require_disconnected
from core.classes.response          import Response
from core.classes.slack_log_handler import SlackLogHandler
#===============================================================================
# GLOBALS
#===============================================================================
# initialize logger
logger.init()
modlgr = logger.get('mapif.api')
# print current root for debugging
modlgr.debug("Running from {0}".format(os.getcwd()))
# load config file and exit on error
modlgr.debug("Loading configuration file...")
if not ini.init('mapif.ini'):
    modlgr.error("Configuration file is missing. Server can't be started !")
    exit(1)
# install SlackLogHandler if needed
slack_webhook = ini.config('NOTIFICATION', 'slack_webhook', 'MAPIF_SLACK_WEBHOOK')
if slack_webhook is not None:
    modlgr.debug("Installing SlackLogHandler...")
    hdlr = SlackLogHandler(slack_webhook)
    hdlr.setFormatter(logger.FMTR)
    logger.add_handler(hdlr)
# create our little application :)
Exemplo n.º 16
0
#===============================================================================
from sqlalchemy                 import func
from sqlalchemy                 import Text
from sqlalchemy                 import Column
from sqlalchemy                 import String
from sqlalchemy                 import Integer
from sqlalchemy                 import DateTime
from sqlalchemy                 import ForeignKey
from sqlalchemy                 import UniqueConstraint
from core.classes.model.base    import MapifBase
from core.classes.model.session import session
from core.modules               import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.user_location')
#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# UserLocation
#-------------------------------------------------------------------------------
class UserLocation(MapifBase):
    __tablename__ = 'user_location'
    __table_args__ = (
        UniqueConstraint('uid', 'timestamp'),
        {
            'useexisting': True, 
            'sqlite_autoincrement': True # <!> SQLITE <!>
        }
    )
Exemplo n.º 17
0
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
from sqlalchemy                 import Column
from sqlalchemy                 import Integer
from sqlalchemy                 import Boolean
from sqlalchemy                 import ForeignKey
from core.classes.model.base    import MapifBase
from core.classes.model.session import session
from core.modules               import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.user_preferences')
#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# UserPreferences
#-------------------------------------------------------------------------------
class UserPreferences(MapifBase):
    __tablename__ = 'user_preferences'
    __table_args__ = {
        'useexisting': True, 
        'sqlite_autoincrement': True # <!> SQLITE <!>
    }
    #---------------------------------------------------------------------------
    # attributes
    #---------------------------------------------------------------------------
Exemplo n.º 18
0
# IMPORTS
#===============================================================================
from sqlalchemy                 import func
from sqlalchemy                 import Text
from sqlalchemy                 import Column
from sqlalchemy                 import Integer
from sqlalchemy                 import Boolean
from sqlalchemy                 import DateTime
from sqlalchemy                 import ForeignKey
from core.classes.model.base    import MapifBase
from core.classes.model.session import session
from core.modules               import logger
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.password_reset')
#===============================================================================
# CLASSES
#===============================================================================
#-------------------------------------------------------------------------------
# PasswordReset
#-------------------------------------------------------------------------------
class PasswordReset(MapifBase):
    __tablename__ = 'password_reset'
    __table_args__ = {
        'useexisting': True, 
        'sqlite_autoincrement': True # <!> SQLITE <!>
    }
    #---------------------------------------------------------------------------
    # attributes
    #---------------------------------------------------------------------------
Exemplo n.º 19
0
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import configparser
import os
from core.modules import logger
#===============================================================================
# GLOBALS
#===============================================================================
_CONFIG_ = None
modlgr = logger.get('mapif.ini')


#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
# init
#   Initializes configuration loading it from INI file
#-------------------------------------------------------------------------------
def init(filename):
    global _CONFIG_
    ok = False
    if not _CONFIG_:
        _CONFIG_ = configparser.ConfigParser()
        if len(_CONFIG_.read(filename, encoding='utf-8')) > 0:
Exemplo n.º 20
0
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
import re
import json
from core.modules import ini
from core.modules import logger
from core.modules import request
#===============================================================================
# GLOBALS
#===============================================================================
modlgr = logger.get('mapif.validator')
_VALIDATORS_ = {
    'email': re.compile('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'),
    'alphanum': re.compile('^\w+$'),
    'int': re.compile('^\d+$'),
    'double': re.compile('^\d+(\.\d+)?$'),
    'phone': re.compile('^(\+\d{2}(\s)?\d|\d{2})(\s)?(\d{2}(\s)?){4}$'),
    'year': re.compile('^\d{4}$'),
    'timestamp': re.compile('^\d{4}(-\d{2}){2}$')
}
#===============================================================================
# FUNCTIONS
#===============================================================================
#-------------------------------------------------------------------------------
# validate
#   (In)Validates data based on its type using regular expressions