コード例 #1
0
    def __init__(self):
        self.user = config.get("backend_user")
        self.password = config.get("backend_pass")
        self.url = config.get("backend")
        self.auth = requests.auth.HTTPBasicAuth(self.user, self.password)

        self.test_login()
コード例 #2
0
	def put_sample(self, data):
		sha256 = hashlib.sha256(data).hexdigest()
		self.db.put_sample_data(sha256, data)
		if config.get("cuckoo_enabled"):
			self.cuckoo.upload(os.path.join(config.get("sample_dir"), sha256), sha256)
		elif config.get("submit_to_vt"):
			self.vt.upload_file(os.path.join(config.get("sample_dir"), sha256), sha256)
コード例 #3
0
ファイル: ecapp.py プロジェクト: saibaba/ecommerce
def create(name):

    rv =  {'code': 400, 'message' : 'Unknown' , 'link': '%s/ecommerce/%s/' % (config.get("app", "prefix"), name) }

    if (not json_content_type(request, rv))  or  (not empty_content(request, rv)): return rv

    req_json = request.json
    if (not Validator(req_json, db, name).valid(rv)): return rv

    req_raw = request.body.getvalue()

    try:
        objects = db[name]

        # if there is a trigger, fire it
        print "Invoking trigger"
        trigger = BeforePOST(req_raw, db, name)
        trigger.execute()
        if not trigger.ok:
            raise Exception(trigger.message)
        req_json["creationDate"] = datetime.datetime.utcnow()

        obj_id = objects.insert(req_json)
        obj = objects.find_one({"_id":obj_id})
        obj["self"] = "%s/ecommerce/%s/%s" % (config.get("app", "prefix"), name, str(obj_id))
        x = objects.update({'_id':obj_id}, obj, upsert=False)
        rv['code'] = 201
        rv['message'] = 'created'
        rv['link'] = '/ecommerce/%s/%s' % (name, obj_id) 

    except Exception, e:
        rv['message']  =  'Error: %s' % (str(e),)
コード例 #4
0
	def __init__(self, serv, sock, remote):
		self.serv    = serv
		self.sock    = sock
		self.timeout = config.get("telnet_session_timeout")
		self.maxtime = config.get("telnet_max_session_length")
		self.db_id   = 0
		self.remote  = remote
		self.session = None
コード例 #5
0
	def __init__(self):
		self.session  = None
		if config.get("submit_to_vt"):
			self.vt = Virustotal(config.get("vt_key", optional=True))
		else:
			self.vt = None
		self.cuckoo   = Cuckoo(config)
		self.do_ip_to_asn_resolution = config.get("do_ip_to_asn_resolution", optional=True, default=True)
コード例 #6
0
	def checkInitializeDB(self):
		user = self.session.query(User).filter(User.id == 1).first()
		if user == None:
			admin_name = config.get("backend_user")
			admin_pass = config.get("backend_pass")

			print 'Creating admin user "' + admin_name + '" see config for password'
			self.addUser(admin_name, admin_pass, 1)
コード例 #7
0
 def __init__(self, serv, sock, remote):
     self.serv = serv
     self.sock = sock
     self.timeout = config.get("timeout", optional=True,
                               default=15.0)  # Read timeout
     self.maxtime = config.get("maxtime", optional=True,
                               default=50.0)  # Max session time
     self.db_id = 0
     self.remote = remote
     self.session = None
コード例 #8
0
ファイル: ecapp.py プロジェクト: saibaba/ecommerce
def replace(name, id):

    print "*** id = %s" % (id,)

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/%s" % (config.get("app", "prefix"), name, id) }

    if (not json_content_type(request, rv))  or  (not empty_content(request, rv)): return rv
    req_json = request.json
    if (not Validator(req_json, db, name).valid(rv)): return rv

    try:
        obj = get(name, id, rv)

        if obj is not None:
            try:
                req_json["creationDate"] = obj['creationDate']
                req_json["_id"] = obj_id
                req_json["lastUpdateDate"] = datetime.datetime.utcnow()
                req_json["self"] = "%s/ecommerce/%s/%s" % (config.get("app", "prefix"), name, id)
                x = objects.update({'_id':obj_id}, req_json, upsert=False)
                print "**** new id",
                print x
                rv['code'] = 200
            except Exception, e:
                print e
                rv['message'] = 'Error while saving'

    except Exception, e:
        print e
        response.status = 400
        rv['message'] = 'Error while reading'
コード例 #9
0
	def parse_shellcode(self, data):		
		# Hajime exclusive!
		
		if len(data) == 480:
			sockaddr = data[0xf0:0xf0+8]
			sockaddr = struct.unpack(">HHBBBB", sockaddr)
			
			if sockaddr[0] == 0x0200:
				ip   = str(sockaddr[2]) + "." + str(sockaddr[3]) + "." + str(sockaddr[4]) + "." + str(sockaddr[5])
				port = sockaddr[1]
				url  = "tcp://" + ip + ":" + str(port)
				dbg("Stub downloader started: " + url)
				
				if config.get("fake_dl", optional=True, default=False):
					self.record.add_file(str(hash(url)), url=url)
				else:
					try:
						s = socket.create_connection((ip, port), timeout=10)
				
						data = ""
						while True:
							chunk = s.recv(1024)
							if len(chunk) == 0:
								break
							data += chunk
				
						s.close()
				
						self.record.add_file(data, url=url)
					except:
						traceback.print_exc()
コード例 #10
0
class selectAllUser(unittest.TestCase):
    # 错误编码
    __result_code = config.read_data("api_result_code")
    # 当前模块名
    __module = os.path.split(os.path.dirname(os.path.abspath(__file__)))[1]
    # 当前接口名称
    __method = sys._getframe().f_code.co_name
    # URL
    __url = config.get("server", "host") + __module + '/' + __method
    # 当前模块的配置文件
    __config = Config(config=os.path.join(DATA_PATH, __module + '.ini'))
    # 当前接口的参数
    __params = __config.read_data(__method)

    def send(self, params):
        result = HTTPsClient(self.__url).send(params)
        # 直接输出字典会有中文乱码的情况
        # 所以使用json库中的dumps方法
        logger.debug(json.dumps(params, ensure_ascii=False))
        logger.debug(json.dumps(result, ensure_ascii=False))
        return result

    def test_success(self):
        '''测试成功'''
        code_result = self.send(self.__params)['code']
        self.assertEqual(str(code_result),
                         self.__result_code["STATUS_SUCCESS_CODE"])

    def test_token_not_exist(self):
        '''token不存在'''
        params = self.__params.copy()
        params['token'] = 12345678910
        code_result = self.send(params)['code']
        self.assertEqual(str(code_result),
                         self.__result_code["TOKEN_NOT_EXIST_CODE"])

    def test_token_expired(self):
        '''token过期'''
        params = self.__params.copy()
        params['token'] = "123456"
        code_result = self.send(params)['code']
        self.assertEqual(str(code_result),
                         self.__result_code["TOKEN_INVALID_CODE"])

    def test_token_is_None(self):
        '''token为None'''
        params = self.__params.copy()
        params['token'] = None
        code_result = self.send(params)['code']
        self.assertEqual(str(code_result),
                         self.__result_code["TOKEN_NOT_EXIST_CODE"])

    def test_token_is_empty(self):
        '''token为空'''
        params = self.__params.copy()
        params['token'] = ""
        code_result = self.send(params)['code']
        self.assertEqual(str(code_result),
                         self.__result_code["TOKEN_NOT_EXIST_CODE"])
コード例 #11
0
 def tearDown(self):
     params = {"id": insertUser.user_id}
     url = config.get("server",
                      "host") + self.__module + '/' + 'deleteUserById'
     result = HTTPsClient(url).send(params)
     logger.debug(json.dumps(params, ensure_ascii=False))
     logger.debug(json.dumps(url, ensure_ascii=False))
     logger.debug(json.dumps(result, ensure_ascii=False))
コード例 #12
0
    def __init__(self):
        self.back = get_backend()
        self.logfile = config.get("log_raw", optional=True)
        self.log_samples = config.get("log_samples",
                                      optional=True,
                                      default=False)
        self.sample_dir = config.get("sample_dir",
                                     optional=not (self.log_samples))

        self.urlset = {}

        self.ip = None
        self.user = None
        self.password = None
        self.date = None
        self.urls = []
        self.stream = []
コード例 #13
0
    def __init__(self):
        self.session = None
        if config.get("submit_to_vt"):
            self.vt = Virustotal(config.get("vt_key", optional=True))
        else:
            self.vt = None
        self.cuckoo = Cuckoo(config)

        self.do_ip_to_asn_resolution = False
        self.ip2asn = config.get("ip_to_asn_resolution",
                                 optional=True,
                                 default=True)
        if self.ip2asn == "offline":
            self.do_ip_to_asn_resolution = True
            self.fill_db_ipranges()
        if self.ip2asn == "online":
            self.do_ip_to_asn_resolution = True
コード例 #14
0
def get_backend():
    if _BACKEND:
        return _BACKEND
    elif config.get("backend", optional=True) != None:
        _BACKEND = client.Client()
        return _BACKEND
    else:
        return None
コード例 #15
0
def get_backend():
    global BACKEND

    if BACKEND != None:
        return BACKEND
    elif config.get("backend", optional=True) != None:
        BACKEND = client.Client()
        return BACKEND
    else:
        return None
コード例 #16
0
    def download(self, host, port, fname):
        if config.get("fake_dl", optional=True, default=False):
            return str(hash(host + str(port) + fname))

        output = DummyIO()
        client = TftpClient(host, port)

        self.env.write("Trying " + host + ":" + str(port) + " ... ")
        client.download(fname, output, timeout=5, packethook=self.pkt)
        return output.data
コード例 #17
0
    def __init__(self):
        self.back = get_backend()
        self.logfile = config.get("log_raw", optional=True)

        self.urlset = {}

        self.ip = None
        self.user = None
        self.password = None
        self.date = None
        self.urls = []
        self.stream = []
コード例 #18
0
	def dl(self, env, url, path=None, echo=True):	
		host = "hostname.tld"
		ip   = "127.0.0.1"
		date = "2014-12-24 04:13:37"
		if echo:
		    env.write("--"+date+"--  " + url + "\n")
		    env.write("Resolving "+host+" ("+host+")... "+ip+"\n")
		    env.write("Connecting to  "+host+" ("+host+")|"+ip+"|:80...")
		    
		if path == None:
			path = url.split("/")[-1].strip()
		if path == "":
			path = "index.html"

		if config.get("fake_dl", optional=True, default=False):
			data = str(hash(url))
			info = ""
		else:
			hdr = { "User-Agent" : "Wget/1.15 (linux-gnu)" }
			r = requests.get(url, stream=True, timeout=5.0, headers=hdr)

			if echo:
				env.write(" connected\nHTTP request sent, awaiting response... 200 OK\n")
				env.write("Length: unspecified [text/html]\n")
				env.write("Saving to: '"+path+"'\n\n")
				env.write("     0K .......... 7,18M=0,001s\n\n")
				env.write(date+" (7,18 MB/s) - '"+path+"' saved [11213]\n")

			data = ""
			for chunk in r.iter_content(chunk_size = 4096):
				data = data + chunk

			info = ""
			for his in r.history:
				info = info + "HTTP " + str(his.status_code) + "\n"
				for k,v in his.headers.iteritems():
				    info = info + k + ": " + v + "\n"
				    info = info + "\n"

			info = info + "HTTP " + str(r.status_code) + "\n"
			for k,v in r.headers.iteritems():
				info = info + k + ": " + v + "\n"

		env.writeFile(path, data)
		env.action("download", {
		    "url":  url,
		    "path": path,
		    "info": info
		})
コード例 #19
0
def get_connection():
    """ get connection """
    server = config.get('mssql', 'server')
    database = config.get('mssql', 'database')
    username = config.get('mssql', 'username')
    password = config.get('mssql', 'password')
    driver= '{ODBC Driver 13 for SQL Server}'
    
    cnxn = None
    attempts = 0
    start_run_time = datetime.now()

    while cnxn is None:
        try:
            cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+password)
        except:
            attempts += 1
            if attempts % 10:
                print_now('Unable to open database connection...')

    if attempts > 0:
        print_now('Opening database connection took {}'.format(datetime.now() - start_run_time))

    return cnxn
コード例 #20
0
ファイル: ecschema.py プロジェクト: saibaba/ecommerce
def get_schema(name):

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/metadata/schema" % (config.get("app", "prefix"), name, ), 'data': None }

    try:
    
        objects = mongo.db[name +"_schema"]
        obj = objects.find_one({"type":"schema"})

        if obj is None:
            rv['code'] = 404
            rv['data'] = { 'code' : 404, 'message': 'not found' }
        else:
            obj = sanitize(obj)
            obj["self"] = "%s/ecommerce/%s/metadata/schema" % (config.get("app", "prefix"), name)
            rv['code'] = 200
            rv['data'] = obj

    except Exception, e:
        rv['code'] = 400
        rv['data'] = { 'code': 400, 'message' : 'Error: %s' % (str(e), ) }
コード例 #21
0
ファイル: ecapp.py プロジェクト: saibaba/ecommerce
def get_all(name):

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s" % (config.get("app", "prefix"), name) }

    try:
    
        objects = db[name]
        objs = list(objects.find())

        if objs is None or len(objs) == 0:
            rv['code'] = 200
            rv['message'] = 'no content'
            rv['data'] = None
        else:
            for obj in objs:
                sanitize(obj)

            rv['data'] = {name : objs }
            rv['code'] = 200
            rv['message'] = 'successful'

    except Exception, e:
        print e
        rv['code'] = 400
コード例 #22
0
ファイル: ecapp.py プロジェクト: saibaba/ecommerce
def update(name, id):

    print "*** id = %s" % (id,)

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/%s" % (config.get("app", "prefix"), name, id) }

    if (not json_content_type(request, rv))  or  (not empty_content(request, rv)): return rv

    req_json = request.json

    if (not Validator(req_json, db, name).valid(rv)): return rv

    try:

        obj = get(name, id, rv)
        if obj is not None:
            for k in req_json.keys():
                obj[k] = req_json[k]

            print obj
            obj_id = obj["_id"]
            del obj["_id"]

            obj["lastUpdateDate"] = datetime.datetime.utcnow()
            obj["self"] = "%s/ecommerce/%s/%s" % (config.get("app", "prefix"), name, id)
            objects = db[name]
            x = objects.update({'_id':obj_id}, {"$set": obj}, upsert=False)
            print "Update result:", 
            print x
            rv['code'] = 200
            rv['message'] = 'Updated'

    except Exception, e:
        print e
        rv['code'] = 400
        rv['message'] = str(e)
コード例 #23
0
ファイル: db.py プロジェクト: mthq/telnet-iot-honeypot
import json
import sqlalchemy
import random

from decorator import decorator

from sqlalchemy import Table, Column, BigInteger, Integer, Float, String, MetaData, ForeignKey, Text, Index

from sqlalchemy.sql import select, join, insert, text
from sqlalchemy.orm import relationship, sessionmaker, scoped_session
from sqlalchemy.pool import QueuePool
from sqlalchemy.ext.declarative import declarative_base

from util.config import config

is_sqlite = "sqlite://" in config.get("sql")

print("Creating/Connecting to DB")

@decorator
def db_wrapper(func, *args, **kwargs):
	self = args[0]
	if self.session:
		return func(*args, **kwargs)
	else:
		self.db      = get_db()
		self.session = self.db.sess

		try:
			return func(*args, **kwargs)
			self.session.commit()
コード例 #24
0
class Client:
    user = config.get("user")
    url = config.get("backend")

    next_id = 0

    def put_session(self, session, retry=True):

        try:
            r = requests.put(self.url + "/conns", json=session, timeout=20.0)
        except requests.exceptions.RequestException:
            dbg("Cannot connect to backend")
            return []

        if r.status_code == 200:
            return r.json()
        elif retry:
            msg = r.raw.read()
            dbg("Backend upload failed, retrying (" + str(msg) + ")")
            return self.put_session(session, False)
        else:
            msg = r.raw.read()
            raise IOError(msg)

    def put_sample_info(self, f, retry=True):
        try:
            sha256 = f["sha256"]
            r = requests.put(self.url + "/sample/" + sha256,
                             json=f,
                             timeout=20.0)
        except requests.exceptions.RequestException:
            dbg("Cannot connect to backend")
            return

        if r.status_code == 200:
            return r.json()
        elif retry:
            msg = r.raw.read()
            dbg("Backend upload failed, retrying (" + str(msg) + ")")
            return self.put_sample_info(f, False)
        else:
            msg = r.raw.read()
            raise IOError(msg)

    def put_sample(self, data, retry=True):

        try:
            r = requests.post(self.url + "/file", data=data, timeout=20.0)
        except requests.exceptions.RequestException:
            dbg("Cannot connect to backend")
            return

        if r.status_code == 200:
            return
        elif retry:
            msg = r.raw.read()
            dbg("Backend upload failed, retrying (" + str(msg) + ")")
            return self.put_sample(sha256, filename, False)
        else:
            msg = r.raw.read()
            raise IOError(msg)
コード例 #25
0
 def __init__(self, config):
     self.url_base = config.get("cuckoo_url_base")
     self.api_user = config.get("cuckoo_user")
     self.api_passwd = config.get("cuckoo_passwd")
     self.cuckoo_force = config.get("cuckoo_force")
コード例 #26
0
ファイル: ecapp.py プロジェクト: saibaba/ecommerce
import sys
import traceback
import logging

from pymongo import MongoClient
from bson.objectid import ObjectId

import datetime
from ecommerce.eutil import *

from trigger import BeforePOST
from validate import Validator

app = Bottle()

client = MongoClient(config.get('objectstore', 'mongo_host'), int(config.get('objectstore', 'mongo_port')))
db = client.ecommerce

def json_content_type(req, rv):
    if req.headers['CONTENT_TYPE'] != 'application/json':
        rv['code'] = 415 
        rv['message'] = 'Unsupported Media Type %s : Expecting %s'  % (req.headers['CONTENT_TYPE'], "application/json")
        return False
    else:
        return  True

def empty_content(req, rv):
    if req.json is None:
        rv['code'] = 400 
        rv['message'] = 'Bad Request : Expecting non empty json'
        return False
コード例 #27
0
ファイル: ecschema.py プロジェクト: saibaba/ecommerce
            raise Exception("Empty code or no proper content-type to recognize as json")
    except Exception, e:
        response.status = 400
        rv['data'] =  {'code': 400, 'message' : 'Could not retrieve script: %s' % (str(e),)  }

    if code is not None:   
        try:
            objects = mongo.db[name + "_schema"]
            content = {}
            content["creationDate"] = datetime.datetime.utcnow()
            content["schema"] = code
            content["type"] = "schema"
            obj = objects.remove({"type":"schema"})
            obj_id = objects.insert(content)
            rv['code'] = 201
            rv['link'] = '%s/ecommerce/%s/metadata/schema' % (config.get("app", "prefix"), name,) 
            rv['data']  = { 'code' : 201, 'message' : 'Created' }

        except Exception, e:
            rv['code'] = 400
            rv['data'] = {'code': 400, 'message' : 'Error: %s' % (str(e)) }

    response.status = rv['code']
    response.location  = rv['link']
    return rv['data']

@app.get('/ecommerce/<name>/metadata/schema')
def get_schema(name):

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/metadata/schema" % (config.get("app", "prefix"), name, ), 'data': None }
コード例 #28
0
ファイル: backend.py プロジェクト: mthq/telnet-iot-honeypot
def run():
    signal.signal(15, stop)
    socketio.run(app,
                 host=config.get("http_addr"),
                 port=config.get("http_port"))
コード例 #29
0
    def dl(self, env, url, path=None, echo=True):
        u = urlparse.urlparse(url)

        host = u.hostname
        ip = "127.0.0.1"
        port = u.port if u.port else 80
        date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        if echo:
            env.write("--" + date + "--  " + url + "\n")
            env.write("Resolving " + host + " (" + host + ")... " + ip + "\n")
            env.write("Connecting to  " + host + " (" + host + ")|" + ip +
                      "|:" + str(port) + "...")

        if path == None:
            path = url.split("/")[-1].strip()
        if path == "":
            path = "index.html"

        if config.get("fake_dl", optional=True, default=False):
            data = str(hash(url))
            info = ""
        else:
            hdr = {"User-Agent": "Wget/1.15 (linux-gnu)"}
            r = None
            try:
                r = requests.get(url, stream=True, timeout=5.0, headers=hdr)
                if echo:
                    env.write(" connected\n")
                    env.write(
                        "HTTP request sent, awaiting response... 200 OK\n")
                    env.write("Length: unspecified [text/html]\n")
                    env.write("Saving to: '" + path + "'\n\n")
                    env.write("     0K .......... 7,18M=0,001s\n\n")
                    env.write(date + " (7,18 MB/s) - '" + path +
                              "' saved [11213]\n")

                data = ""
                for chunk in r.iter_content(chunk_size=4096):
                    data = data + chunk

                info = ""
                for his in r.history:
                    info = info + "HTTP " + str(his.status_code) + "\n"
                    for k, v in his.headers.iteritems():
                        info = info + k + ": " + v + "\n"
                        info = info + "\n"

                info = info + "HTTP " + str(r.status_code) + "\n"
                for k, v in r.headers.iteritems():
                    info = info + k + ": " + v + "\n"
            except requests.ConnectTimeout as e:
                data = None
                info = "Download failed"
                if echo:
                    env.write(" failed: Connection timed out.\n")
                    env.write("Giving up.\n\n")
            except requests.ConnectionError as e:
                data = None
                info = "Download failed"
                if echo:
                    env.write(" failed: Connection refused.\n")
                    env.write("Giving up.\n\n")
            except requests.ReadTimeout as e:
                data = None
                info = "Download failed"
                if echo:
                    env.write(" failed: Read timeout.\n")
                    env.write("Giving up.\n\n")
            except Exception as e:
                data = None
                info = "Download failed"
                if echo:
                    env.write(" failed: " + str(e.message) + ".\n")
                    env.write("Giving up.\n\n")

        if data:
            env.writeFile(path, data)

        env.action("download", {
            "url": url,
            "path": path,
            "info": info,
            "data": data
        })
コード例 #30
0
    def run(self):
        print_now('TradeResultPredictor starting running, configuration = {}'.format(self.configuration_id))

        run_results = get_completed_run_results_by_configuration_id(self.configuration_id)
        tbl = PrettyTable()
        tbl.field_names = [
            'iMA_Period', 
            'TotalNetProfit', 
            'MaximalDrawdown',
            'TotalTrades',
            'Last 3 trades',
            'Last trade date',
            'Predicted 3 trades',
            'Total for predicted 3 trades',
            'Train RMSE / Test RMSE'
        ]

        for run_results in run_results:
            configuration_option = get_option_by_id(run_results['OptionId'])

            trades = get_run_result_trades_by_result_id(run_results['ResultId'])
            # drop unneeded columns
            dataset = trades.drop(trades.columns.difference(['Profit']), 1).values[:,:]

            perceptron = MultilayerPerceptron(run_results['ResultId'], dataset, verbose=self.verbose)
            stats = perceptron.train()
            predicted_trades = perceptron.predict(look_forth = 3)

            testScoreRMSE = 'N/A'
            if stats['TestScore']['RMSE'] != 'N/A':
                testScoreRMSE = '{0:.2f}'.format(stats['TestScore']['RMSE'])

            tbl.add_row([
                configuration_option['iMA_Period'],
                run_results['TotalNetProfit'],
                run_results['MaximalDrawdown'],
                run_results['TotalTrades'],
                ' | '.join(['{0:.2f}'.format(t['Profit']) for idx, t in trades.tail(3).iterrows()]),
                trades['CloseTime'].iloc[-1].strftime('%Y.%m.%d %H:%M'),
                ' | '.join(['{0:.2f}'.format(t) for t in predicted_trades]),
                '{0:.2f}'.format(np.sum(predicted_trades)),
                '{0:.2f} / {1}'.format(stats['TrainScore']['RMSE'], testScoreRMSE)
            ])

        if config.has_section("smtp"):
            smtp_user = config.get('smtp', 'user')
            smtp_password = config.get('smtp', 'password')
            recipients = config.get('smtp', 'recipients')

            tbl_attr = { 
                'style': 'border: 1px solid black; border-collapse: collapse;',
                'cellpadding': 5,
                'border': 1
            }

            subject = 'WSRT predictions {}'.format(datetime.now().strftime('%Y-%m-%d %H:%M'))

            elapsed = datetime.now() - self.start_time
            body = 'Report generated on {}<br/>'.format(datetime.now().strftime('%Y-%m-%d %H:%M'))
            body += 'Report generation took {}<br/>'.format(elapsed)
            
            body += '<br/>'
            body += tbl.get_html_string(attributes=tbl_attr)
            body += '<br/><br/>'

            body += 'Thanks'

            self._send_notification(subject, body, smtp_user, smtp_password, recipients)
            
            print_now('TradeResultPredictor notifications sent, configuration_id = {}'.format(self.configuration_id))
コード例 #31
0
ファイル: eccode.py プロジェクト: saibaba/ecommerce
            raise Exception("Empty code or no proper content-type to recognize as json")
    except Exception, e:
        response.status = 400
        rv['data'] =  {'code': 400, 'message' : 'Could not retrieve script: %s' % (str(e),)  }

    if code is not None:   
        try:
            objects = mongo.db[name + "_triggers"]
            content = {}
            content["creationDate"] = datetime.datetime.utcnow()
            content["type"] = "beforePOST"
            content["code"] = code
            obj = objects.remove({"type":"beforePOST"})
            obj_id = objects.insert(content)
            rv['code'] = 201
            rv['link'] = '%s/ecommerce/%s/metadata/triggers/beforePOST' % (config.get("app", "prefix"), name,) 
            rv['data']  = { 'code' : 201, 'message' : 'Created' }

        except Exception, e:
            rv['code'] = 400
            rv['data'] = {'code': 400, 'message' : 'Error: %s' % (str(e)) }

    response.status = rv['code']
    response.location  = rv['link']
    return rv['data']

@app.get('/ecommerce/<name>/metadata/triggers/beforePOST')
def get_bp(name):

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/metadata/triggers/beforePOST" % (config.get("app", "prefix"), name, ), 'data': None }
コード例 #32
0
ファイル: ecapp.py プロジェクト: saibaba/ecommerce
def delete(name, id):
    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/%s" % (config.get("app", "prefix"), name, id) }

    try:
        obj = get(name, id, rv)

        if obj is not None:
            try:
                x = objects.remove(qry)
                rv['code'] = 200
                rv['message'] = 'successfully deleted'
            except Exception, e:
                print e
                rv['message'] = 'Error while deleting'

    except Exception, e:
        print e
        response.status = 400
        rv['message'] = 'Error while reading'
コード例 #33
0
ファイル: db.py プロジェクト: mthq/telnet-iot-honeypot
	def __init__(self, sess):
		self.sample_dir    = config.get("sample_dir")
		self.limit_samples = 32
		self.limit_urls    = 32
		self.limit_conns   = 32
		self.sess          = sess
コード例 #34
0
ファイル: ecapp.py プロジェクト: saibaba/ecommerce
def get_one(name, id):

    print "*** id = %s" % (id,)

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/%s" % (config.get("app", "prefix"), name, id) }

    try:
        obj = get(name, id, rv)
        if obj is not None:
            obj = sanitize(obj)
            rv['data'] = obj
            rv['code'] = 200
            rv['message'] = 'successful'

    except Exception, e:
        rv['code'] = 400
        rv['message'] = str(e)
コード例 #35
0
import sys
import json
import traceback

from util.config import config

if len(sys.argv) > 1 and sys.argv[1] == "cleardb":
    print("This will DELETE ALL DATA except users and cached asn data")
    print("from the database currently used at:")
    print("")
    print("    " + config.get("sql"))
    print("")
    print(
        "If you really want to DELETE ALL DATA, type 'delete' and press enter."
    )
    print("")
    doit = sys.stdin.readline()
    print("")
    if doit.strip() != "delete":
        print("ABORTED")
        sys.exit(0)

    from backend.db import delete_everything
    delete_everything()
    sys.exit(0)

# Import from backend is faster:
# Benchmark:
# 	CPU:        Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
# 	Storage:    Samsung SSD PM961
#	File size:  7,3M
コード例 #36
0
ファイル: ecschema.py プロジェクト: saibaba/ecommerce
def create_schema(name):

    rv = { 'code' : 400, 'message': 'Unknown Error', 'link' : "%s/ecommerce/%s/metadata/schema" % (config.get("app", "prefix"), name, ), 'data': None }

    code = None
    try:
        if request.headers['CONTENT_TYPE'] != 'application/json' :
            raise Exception("Content type must be application/json")
        code = request.body.getvalue()

        if code is None:
            raise Exception("Empty code or no proper content-type to recognize as json")
    except Exception, e:
        response.status = 400
        rv['data'] =  {'code': 400, 'message' : 'Could not retrieve script: %s' % (str(e),)  }
コード例 #37
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
from handler import app
from util.config import config
from util.models import db

CWD = os.getcwd()

app.config['SIJAX_STATIC_PATH'] = os.path.join(CWD, 'resource', 'static', 'js',
                                               'sijax')
app.config['SIJAX_JSON_URI'] = os.path.join(CWD, 'resource', 'static', 'js',
                                            'sijax', 'json2.js')
app.config['SQLALCHEMY_DATABASE_URI'] = config.get('db', 'uri')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SECRET_KEY'] = config.get('global', 'secret')

if __name__ == '__main__':
    db.init_app(app)
    app.run(host='0.0.0.0',
            port=config.getint('global', 'port'),
            debug=True if config.getint('global', 'debug') else False)
コード例 #38
0
	def __init__(self):
		self.session = None
		self.salt    = config.get("backend_salt")
		self.checkInitializeDB()
コード例 #39
0
def run():
    signal.signal(15, stop)

    app.run(host=config.get("http_addr"),
            port=config.get("http_port"),
            threaded=True)
コード例 #40
0
    srv.stop()


if not os.path.exists("samples"):
    os.makedirs("samples")

if __name__ == "__main__":
    action = None

    if len(sys.argv) > 1:
        action = sys.argv[1]

    if action == None:
        switcher = {
            "default": 2323,
            "custom": config.get("custom_port"),
            "shivaLR": 2424,
            "jetDirect": 2525,
            "firstClassMsg": 2626,
            "ambitCable": 2727,
            "nortel": 2828,
            "arubaSwitch": 2929,
            "busybox": 2121
        }
        port = type = switcher.get(config.get("device_profile"),
                                   lambda: "Invalid type")
        srv = Telnetd(port)
        signal.signal(signal.SIGINT, signal_handler)
        srv.run()
    elif action == "import":
        fname = sys.argv[2]
コード例 #41
0
        if arg == "-c":
            if i + 1 < len(sys.argv):
                configFile = sys.argv[i + 1]
                print("Using config file " + configFile)
                i += 1
                continue
            else:
                print("warning: expected argument after \"-c\"")
        else:
            action = arg

    if configFile:
        config.loadUserConfig(configFile)

    if action == None:
        socket.setdefaulttimeout(15)

        srv = Telnetd(config.get("telnet_addr"), config.get("telnet_port"))
        signal.signal(signal.SIGINT, signal_handler)
        srv.run()
    elif action == "import":
        fname = sys.argv[2]
        import_file(fname)
    elif action == "rerun":
        fname = sys.argv[2]
        rerun_file(fname)
    elif action == "shell":
        test_shell()
    else:
        print("Command " + action + " unknown.")