timeout = 1 socket.setdefaulttimeout(timeout) from loaders import load_config try: from urllib.parse import urlparse, urlencode from urllib.request import urlopen, Request from urllib.error import HTTPError except ImportError: from urlparse import urlparse from urllib import urlencode from urllib2 import urlopen, Request, HTTPError # Load configuration PATH = os.path.dirname(os.path.abspath(__file__)) config = load_config() # Run collector.py start = time.time() output = subprocess.check_output( [sys.executable, os.path.join(PATH, "collector.py")]) data = json.loads(output.decode()) # Graylog if config["reporting"]["engine"] == "elasticsearch": for item in data: url = "http://%s:%s/gelf" % (config["reporting"]["url"], config["reporting"]["port"]) print(url) data = json.dumps(item)
def __init__(self): gtk.Window.__init__(self) self.set_title("U-Air Launcher") self.set_icon_from_file(ICON_PATH) self.set_resizable(False) self.set_size_request(440, 320) self.set_border_width(20) self.set_position(gtk.WIN_POS_CENTER) #load config self.config=load_config() save_config(self.config) #www server process self.server=None #get lang from config self.lang=self.config.get("lang", "en") #connect close event self.connect("destroy", self.close_app) self.fixed = gtk.Fixed() self.label_status = gtk.Label("Status:") self.label_status.set_text(lt("Status", self.lang)+":") #local IP label self.label_local_ip = gtk.Label("Local IP:") label=lt("Local IP", self.lang)+": "+self.config["local_ip"] label+=":"+str(self.config["port"]) self.label_local_ip.set_text(label) self.label_public_ip = gtk.Label("Public IP:") label=lt("Public IP", self.lang)+": "+self.config["global_ip"]+":"+str(self.config["port"]) self.label_public_ip.set_text(label) self.label_gen_password = gtk.Label("Login password:"******"Login password", self.lang)+":") self.label_gen_password_shared = gtk.Label("Shared password:"******"Shared password", self.lang)+":") self.label_set_gen_password = gtk.Label("...") self.label_set_gen_password_shared = gtk.Label("...") self.button_regenerate = gtk.Button("Regenerate password") self.button_regenerate.set_label(lt("Regenerate password", self.lang)) self.button_regenerate.connect("clicked", self.regenerate) self.button_start = gtk.Button("Start") self.button_start.set_label(lt("Start", self.lang)) self.button_start.connect("clicked", self.start) self.button_start.set_size_request(110, 50) self.button_stop = gtk.Button("Stop") self.button_stop.set_label(lt("Stop", self.lang)) self.button_stop.connect("clicked", self.stop) self.button_stop.set_size_request(110, 50) self.button_options = gtk.Button("Options") self.button_options.set_label(lt("Options", self.lang)) self.button_options.set_size_request(130, 30) self.button_options.connect("clicked", self.show_option_window) self.button_about = gtk.Button("About") self.button_about.set_label(lt("About", self.lang)) self.button_about.set_size_request(130, 30) self.button_about.connect("clicked", self.show_about_window) self.button_quit = gtk.Button("Quit") self.button_quit.set_label(lt("Quit", self.lang)) self.button_quit.set_size_request(130, 30) self.button_quit.connect("clicked", self.close_app) self.img_banner = gtk.Image() self.img_banner.set_from_file(os.path.join(ROOT_PATH, "static/banner1.png")) self.fixed.put(self.img_banner, 0, 0) self.fixed.put(self.label_status, 5, 5) #self.fixed.put(self.label_local_ip, 3, 130) #self.fixed.put(self.label_public_ip, 200 ,130) self.fixed.put(self.label_local_ip, 5, 110) self.fixed.put(self.label_public_ip, 5 ,130) self.fixed.put(self.button_regenerate, 70, 200) self.fixed.put(self.button_start, 0, 230) self.fixed.put(self.button_stop, 120, 230) self.fixed.put(self.label_gen_password, 0, 160) self.fixed.put(self.label_set_gen_password, 150, 160) self.fixed.put(self.label_gen_password_shared, 0, 180) self.fixed.put(self.label_set_gen_password_shared, 150, 180) self.fixed.put(self.button_options, 250, 170) self.fixed.put(self.button_about, 250, 210) self.fixed.put(self.button_quit, 250, 250) self.add(self.fixed) #show all self.show_all() #create pictures folder if not exist if not os.path.exists(DEFAULT_IMAGES_PATH): os.mkdir(DEFAULT_IMAGES_PATH) #remove pid file when process not exist remove_orphaned_pidfile(check_pidfile()) #set status self.setstatus() #update start stop buttons self.toggle_start_stop_buttons() #generate new login password self.gen_login_password() self.gen_shared_password()
exit(0) #ignore arguments if len(sys.argv)<2: print("Usage: launcher.pyc start/stop") print("launcher.pyc password <newpassword>") print("launcher.pyc port <new port>") exit(0) #ignore others commands if sys.argv[1] not in ["start", "stop", "password", "port"]: print("Invalid command") exit(0) #remove pid remove_orphaned_pidfile(check_pidfile()) #load config try: config=load_config() except: pass if sys.argv[1]=="start": if check_pidfile(): print("Server already started.") exit(0) gip=get_global_ip_address() lip=get_local_ip_address() #print addresses print("Local IP: %s" % lip) print("Public IP: %s" % gip) #gen passwords pass1=generate_password() pass2=generate_password() config["gen_password"]=hash_password(pass1) config["gen_password_shared"]=hash_password(pass2)
from utils.response import make_cors_headers from loaders import load_config, load_plugins, load_all_files, load_curr_app from analyzer import SimpleAnalyzer from blueprints import register_blueprints __version_info__ = ('2', '21', '1') __version__ = '.'.join(__version_info__) # create app app = Flask(__name__) app.version = __version__ load_config(app) # make importable for plugin folder BASE_DIR = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, os.path.join(BASE_DIR, app.config.get('PLUGIN_DIR'))) # init app app.debug = app.config.get('DEBUG', True) app.template_folder = os.path.join(app.config.get('THEMES_DIR'), app.config.get('THEME_NAME')) app.static_folder = app.config.get('THEMES_DIR') app.static_url_path = '/{}'.format(app.config.get('STATIC_PATH')) # jinja env app.jinja_env.autoescape = False
import json import loaders import os from parsers import Parser from importlib import import_module from threading import Thread PATH = os.path.dirname(os.path.abspath(__file__)) MODULES_PATH = PATH + "/modules/" config = loaders.load_config() tick = loaders.load_tick() results = [] def worker(address, host): parser = Parser.new() parser.global_set_address(address) parser.global_set_host(host) parser.global_set_timestamp( ) if config["reporting"]["timestamp"] == "true" else "" parser.global_pair("host", host["name"]) # Identify all modules modules = [ os.path.splitext(f)[0] for f in os.listdir(MODULES_PATH) if os.path.splitext(f)[1] == ".py" and f != "__init__.py" ]
import os import traceback from loaders import (load_config, load_files, load_keys, load_single_file, watch_files_date) from services.i18n import Translator from blueprints import register_blueprints __version_info__ = ('1', '2', '3') __version__ = '.'.join(__version_info__) # create app app = Flask(__name__) app.version = __version__ load_config(app) # create logs folder logs_folder = app.config['LOGS_DIR'] if not os.path.isdir(logs_folder): os.makedirs(logs_folder) # init app app.debug = app.config.get('DEBUG', True) # encoder app.json_encoder = JSONEncoder # register blueprints register_blueprints(app)