Exemple #1
0
# import python library

from ob_logger import Logger

logger = Logger("MPW")


class SERVER_STATE(object):
    HALT = 0
    STARTING = 1
    RUNNING = 2


class PipeNo(object):
    STDIN = 0
    STDOUT = 1
    STDERR = 2


class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton,
                                        cls).__call__(*args, **kwargs)
        return cls._instances[cls]


def start_process_watcher():
    from .mq_events import WatcherEvents
Exemple #2
0
__author__ = 'Nigshoxiz'

import time
import datetime
import re, os
import json
from random import randint
import hashlib, traceback
import yaml
from app.error_code import errcode

# password hash salt
salt = b"\x87\x93\xfb\x00\xfa\xc2\x88\xba$\x86\x98\'\xba\xa8\xc6"

from ob_logger import Logger
_logger = Logger("_utils", debug=False)


# consts
class PRIVILEGES:
    ULTIMATE = 0
    ROOT_USER = 1
    FREE_USER = 2
    INST_OWNER = 4
    EVERYONE = 8


def get_file_directory():
    full_path = os.path.realpath(__file__)
    path, file = os.path.split(full_path)
    return path
Exemple #3
0
__author__ = "Nigshoxiz"
from app.controller.global_config import GlobalConfig
from app.controller.config_env import DatabaseEnv
from sqlalchemy_utils import create_database, database_exists
from app import app, db
from app.model import Users, UserToken, JavaBinary

from datetime import datetime
from ob_logger import Logger
import traceback
import json

g_logger = Logger("StartUp", debug=True)
from app.utils import PRIVILEGES


def init_database(logger=None):

    gc = GlobalConfig.getInstance()

    db_env = DatabaseEnv()

    if logger == None:
        logger = g_logger

    db_type = db_env.getDatabaseType()

    if gc.get("init_super_admin") == True:
        if db_type == "sqlite":
            database_uri = "sqlite:///%s/%s.db" % (db_env.get("sqlite_dir"),
                                                   db_env.get("db_name"))
__author__ = "Nigshoxiz"

import sqlite3
import os
import traceback
import logging
from ob_logger import Logger
logger = Logger("GbConf", debug=True)


class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton,
                                        cls).__call__(*args, **kwargs)
        return cls._instances[cls]


class GlobalConfigDatabase(object):
    """
    This database manages ob_panel global configuration.
    For simplicity, we use Python's sqlite3 module directly (instead of sql_alchemy)
    to execute SQL operations.
    """
    def __init__(self):
        self.BASE_DIR = os.path.join(os.path.expanduser("~"), "ob_panel")
        self.SQLITE_DIR = os.path.join(self.BASE_DIR, "sql")

        SQLITE_DIR = self.SQLITE_DIR
Exemple #5
0
__author__ = "Nigshoxiz"
from urllib.error import HTTPError
from urllib.request import urlopen, Request
import os, ssl, json, inspect, random, string, copy, time, traceback, threading, shutil
from app.utils import is_debug
# add logger
from ob_logger import Logger
logger = Logger("dlMC", debug=is_debug())


class AbruptException(Exception):
    def __init__(self):
        Exception.__init__(self)

    def __str__(self):
        return "Just an exception!"


class DownloaderPool(object):

    instance = None

    def __init__(self):
        self.pool = {}

        pass

    @staticmethod
    def getInstance():
        if DownloaderPool.instance == None:
            DownloaderPool.instance = DownloaderPool()
Exemple #6
0
import os, yaml
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from app.controller.global_config import GlobalConfig
from app.tools.mq_proxy import WS_TAG, MessageQueueProxy

from ob_logger import Logger
logger = Logger("APP", debug=True)

app = Flask(__name__)

# shut up, please. I don't wanna see your useless notice again !!
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True

# close SQLalchemy debug mode
app.config["SQLALCHEMY_ECHO"] = False
app.config['SECRET_KEY'] = 'secret!'
app.config['REDIS_QUEUE_KEY'] = 'reboot_queue'

gc = GlobalConfig.getInstance()
# set sqlalchemy database uri
if gc.get("database_uri") != None:
    app.config["SQLALCHEMY_DATABASE_URI"] = gc.get("database_uri")

# init flask-SQLAlchemy
db = SQLAlchemy(app)

# read config.yaml directly
zmq_port = int(yaml.load(open("config.yaml","r")).get("broker").get("listen_port"))
proxy = MessageQueueProxy(WS_TAG.APP ,router_port=zmq_port)
Exemple #7
0
__author__ = "Nigshoxiz"

from ob_logger import Logger
from app.utils import is_debug

logger = Logger("MsgQ", debug=is_debug())


class PRIVILEGES:
    NONE = 0x0000
    INST_OWNER = 0x0001
    ROOT_USER = 0x0100


from .server import start_zeromq_broker
Exemple #8
0
__author__ = "Nigshoxiz"

import zmq, inspect, threading, time, zmq, json
from uuid import uuid4
from . import SingletonP, WS_TAG, MessageUserStatusPool
from .event_handler import MessageEventHandler
import traceback

# logging system
from ob_logger import Logger

logger = Logger("MsgQ", debug=False)


class MessageQueueProxy(metaclass=SingletonP):
    '''
    What is a .. Message Queue Proxy?
    A message queue proxy takes responsibility for receiving message from message queue
    and send message to it.
    Because we use a standalone websocket server, we use message queue to delegate
    websocket server to send websocket message, instead of sending message directly.
    '''
    TAGS = WS_TAG

    def __init__(self, tag, router_port=852):
        self.ws_tag = tag
        self.context = zmq.Context()

        self.sock_send = None

        self.router_port = router_port
Exemple #9
0
from .manager import FTPManager
from .mq_events import FTPAccountEventHandler
from app.tools.mq_proxy import MessageQueueProxy, WS_TAG
from app.utils import is_debug, read_config_yaml
from ob_logger import Logger

logger = Logger("FTM", debug=is_debug())


def start_FTP_manager():

    _config = read_config_yaml()
    zmq_port = _config['broker']['listen_port']
    port = _config['ftp']['listen_port']

    proxy = MessageQueueProxy(WS_TAG.FTM, router_port=zmq_port)
    proxy.register(FTPAccountEventHandler)
    proxy.listen(background=True)

    manager = FTPManager()
    manager.set_port(port)

    logger.info("This is FTP Manager, listening port %s" % port)
    manager.launch(background=False)