class Indicator(object): def __init__(self): self.cms = CMS(5000) self.hinter_sum = 0 self.hinter_count = 0 self.freqs = Counter() # Alternatively use SpaceSaving def record(self, key): hint = self.cms.frequancy(key) self.hinter_sum += hint self.hinter_count += 1 self.cms.increment(key) self.freqs[key] += 1 def get_hint(self): return self.hinter_sum / self.hinter_count def est_skew(self): top_k = [(i, log(k[1])) for i, k in zip(range(1, 71), self.freqs.most_common(70))] return -stats.linregress(top_k)[0] def get_indicator(self): skew = self.est_skew() return (self.get_hint() * ((1 - skew**3) if skew < 1 else 0)) / 15.0 def reset(self): self.hinter_sum = 0 self.hinter_count = 0 self.freqs.clear()
def home(): session['logo'] = Config.LOGO tenant_list = CMS.getTenants() if current_user.username == "admin": form = Admin() template = "admin.html" settings = Extensions.get_admin_settings() space_list = [] for tenant in tenant_list: tenant_name = tenant[1] space_filter = tenant_name.replace(" ", "_") print(space_filter) space_list = CMS.getSpaces(space_filter, space_list) form.spaces.choices = space_list try: guestCLP = settings['guest_CLP'] except: guestCLP = "" try: hostCLP = settings['host_CLP'] except: hostCLP = "" else: form = VWR_Admin() template = "index.html" form.tenants.choices = tenant_list if request.method == 'POST': if "tenants" in request.form: tenant_id = request.form['tenants'] if "create_tenant" in request.form: print("create_tenant") CMS.createTenant(request.form['tenant'], settings['guest_CLP']) elif "delete_tenant" in request.form: print("delete_tenant") CMS.deleteTenant(tenant_id) elif "create_guest_CLP" in request.form: print("create_guest_CLP") Guest_CLP_ID = CMS.createGuest_CLP("guest") Extensions.update_admin_settings(Guest_CLP_ID, "") elif "create_host_CLP" in request.form: print("create_host_CLP") Host_CLP_ID = CMS.createHost_CLP("host") Extensions.update_admin_settings("", Host_CLP_ID) elif "delete_spaces" in request.form: print("delete_spaces") spaceIdList = request.form.getlist('spaces') CMS.deleteSpaces(spaceIdList) if current_user.username == "admin": return redirect(url_for('home')) else: return redirect(url_for('vwr', tenant_id=tenant_id)) elif request.method == 'GET': if current_user.username == "admin": return render_template(template, form=form, guestCLP=guestCLP, hostCLP=hostCLP) else: return render_template(template, form=form)
def CreatePatientLink(tenant_name, tenant_id): now = datetime.utcnow() timestamp_now = time.mktime(now.timetuple()) + now.microsecond * 1e-6 timestamp_str = str(timestamp_now).rsplit('.', 1)[1] space_name = tenant_name.replace(" ", "_") + "_" + timestamp_str coSpace_id = CMS.createSpace(space_name, tenant_id) link, callId, ownerJid = CMS.getCoSpaceDetails(coSpace_id) CMS.createAccessMethod(coSpace_id, callId, space_name) return link
def __init__(self, maximum_size, window_percentage=1): super().__init__(maximum_size) self.data = {} self.cms = CMS(maximum_size) self.sentinel_window = Node() # LRU self.sentinel_probation = Node() # SLRU self.sentinel_protected = Node() # SLRU self.max_window_size = (self.maximum_size * window_percentage) // 100 max_main = self.maximum_size - self.max_window_size self.max_protected = max_main * 4 // 5 self.size_window = 0 self.size_protected = 0
def patient(): session['logo'] = Config.LOGO tenant_list = CMS.getTenants() form = VWR_Admin() form.tenants.choices = tenant_list if request.method == 'POST': tenant_id = request.form['tenants'] tenant_name = dict(form.tenants.choices).get(form.tenants.data) now = datetime.utcnow() timestamp_now = time.mktime(now.timetuple()) + now.microsecond * 1e-6 timestamp_str = str(timestamp_now).rsplit('.', 1)[1] space_name = tenant_name.replace(" ", "_") + "_" + timestamp_str coSpace_id = CMS.createSpace(space_name, tenant_id) link, callId, ownerJid = CMS.getCoSpaceDetails(coSpace_id) CMS.createAccessMethod(coSpace_id, callId, space_name) return redirect(link) elif request.method == 'GET': return render_template('index.html', form=form)
def create_link(): if request.method == 'POST': tenant_id = request.form['tenant_id'] print('tenant id: ' + tenant_id) tenant_name = CMS.getTenant(tenant_id) link = CreatePatientLink(tenant_name, tenant_id) data = {"link": link} response = app.response_class(response=json.dumps(data), status=200, mimetype='application/json') return response
def patient(): session['logo'] = Config.LOGO tenant_list = CMS.getTenants() form = VWR_Admin() form.tenants.choices = tenant_list if request.method == 'POST': tenant_id = request.form['tenants'] tenant_name = dict(form.tenants.choices).get(form.tenants.data) link = CreatePatientLink(tenant_name, tenant_id) return redirect(link) elif request.method == 'GET': return render_template('index.html', form=form)
def sendcmd(): if request.method == 'POST': command = request.form['command'] cmd, call_id = command.split('_') coSpace_id = request.form['space_id'] if cmd == "Drop": print("delete call: " + call_id) CMS.deleteCall(call_id) CMS.deleteSpace(coSpace_id) else: userJid = current_user.username CMS.addUserToCospace(coSpace_id, userJid) data = {"result": "success"} response = app.response_class(response=json.dumps(data), status=200, mimetype='application/json') return response
def login(): form = LoginForm() if request.method == 'POST' and form.validate_on_submit(): username = form.username.data if username == "admin": fullName = "Administrator" user_obj, result = Extensions.validate_user( username, form.password.data, fullName) else: success, fullName = CMS.verifyUser(username) if success: user_obj, result = Extensions.validate_user( username, form.password.data, fullName) if result == "success" or result == "changePWD": session['name'] = fullName login_user(user_obj) flash("Logged in successfully!", category='success') if result == "changePWD": return redirect(url_for("settings")) else: return redirect(request.args.get("next") or url_for("home")) flash("Wrong username or password!", category='error') return render_template('login.html', title='login', form=form)
class WTinyLFU(Policy): def __init__(self, maximum_size, window_percentage=1): super().__init__(maximum_size) self.data = {} self.cms = CMS(maximum_size) self.sentinel_window = Node() # LRU self.sentinel_probation = Node() # SLRU self.sentinel_protected = Node() # SLRU self.max_window_size = (self.maximum_size * window_percentage) // 100 max_main = self.maximum_size - self.max_window_size self.max_protected = max_main * 4 // 5 self.size_window = 0 self.size_protected = 0 def record(self, key, size=1): self.cms.increment(key) node = self.data.get(key) if not node: self.misses += 1 new_node = Node(key, Node.Status.Window) new_node.append_to_tail(self.sentinel_window) self.data[key] = new_node self.size_window += 1 if self.size_window > self.max_window_size: self.evict() return False else: self.hits += 1 node.remove() if node.status == Node.Status.Window: node.append_to_tail(self.sentinel_window) elif node.status == Node.Status.Probation: node.status = Node.Status.Protected node.append_to_tail(self.sentinel_protected) self.size_protected += 1 self.demote_protected() elif node.status == Node.Status.Protected: node.append_to_tail(self.sentinel_protected) return True def demote_protected(self): if self.size_protected > self.max_protected: demote = self.sentinel_protected.next_node demote.remove() demote.status = Node.Status.Probation demote.append_to_tail(self.sentinel_probation) self.size_protected -= 1 def evict(self): candidate = self.sentinel_window.next_node candidate.remove() self.size_window -= 1 candidate.status = Node.Status.Probation candidate.append_to_tail(self.sentinel_probation) if len(self.data) > self.maximum_size: victim = self.sentinel_probation.next_node evicted = victim if self.cms.frequancy( candidate.data) > self.cms.frequancy( victim.data) else candidate del self.data[evicted.data] evicted.remove()
def __init__(self): self.cms = CMS(5000) self.hinter_sum = 0 self.hinter_count = 0 self.freqs = Counter() # Alternatively use SpaceSaving
def entry_point(): ''' Main logic ''' # =================== Stg. 1 Getting parametrs ============================= main_obj = pg.url_parse(pg.url) pg.domain = main_obj["domain"] pg.scheme = main_obj["scheme"] # getting a file prefix file_prefix = "_".join([pg.domain, time.strftime("%Y-%m-%d_%H-%M")]) file_out = file_prefix + ".json" # =================== Stg. 2 Getting a page source ========================= pg.get_webpage() if len(pg.data) == 0: print('[!] Web page is empty\n') return False # saving page source in debug mode if len(sys.argv) == 3: if sys.argv[2] == "debug": write_file(pg.data, file_prefix + ".html") # ========================================================================== # parsing a page source soup = BeautifulSoup(pg.data, 'html.parser') # a final report report = dict() report["basic_url"] = pg.url report["internal"] = dict() report["subdomain"] = dict() report["external"] = dict() # getting links for link in soup.find_all('a'): if link.get('href') is not None: href_dic = pg.href_filter(link.get('href')) if href_dic != False: href_text = link.get_text().strip() if href_dic["type"] == "internal": report["internal"][href_dic["href"]] = href_text elif href_dic["type"] == "subdomain": report["subdomain"][href_dic["href"]] = href_text elif href_dic["type"] == "external": report["external"][href_dic["href"]] = href_text else: print("Undefined type of href - %s" % href_text) # CMS detect cms_obj = CMS(pg.data, pg.domain, pg.scheme) cms_obj.cms_detect() if cms_obj.cms != "undefined": cms_obj.get_version() report["cms"] = cms_obj.cms report["cms_version"] = cms_obj.version # getting of security headers report["sec_headers"] = dict() report["sec_headers"]["X-XSS-Protection"] = pg.headers.get( "X-XSS-Protection") report["sec_headers"]["X-Frame-Options"] = pg.headers.get( "X-Frame-Options") report["sec_headers"]["X-Content-Type-Options"] = pg.headers.get( "X-Content-Type-Options") report["sec_headers"]["Content-Security-Policy"] = pg.headers.get( "Content-Security-Policy") report["sec_headers"]["Strict-Transport-Security"] = pg.headers.get( "Strict-Transport-Security") report["sec_headers"]["Public-Key-Pins"] = pg.headers.get( "Public-Key-Pins") # getting of cache headers report["cache_headers"] = dict() report["cache_headers"]["Pragma"] = pg.headers.get("Pragma") report["cache_headers"]["Cache-Control"] = pg.headers.get("Cache-Control") report["cache_headers"]["ETag"] = pg.headers.get("ETag") report["cache_headers"]["Vary"] = pg.headers.get("Vary") report["cache_headers"]["Age"] = pg.headers.get("Age") report["cache_headers"]["Expires"] = pg.headers.get("Expires") report["cache_headers"]["Warning"] = pg.headers.get("Warning") # seaching a substring "cache" in an ignore case for head in list(pg.headers): if "cache" in head.lower(): report["cache_headers"][head] = pg.headers.get(head) # getting of IP and whois dmn_obj = Domain(pg.domain) dmn_obj.get_ip() if dmn_obj.ip != "undefined": dmn_obj.get_netname() report["domain_ip"] = dmn_obj.ip report["domain_netname"] = dmn_obj.whois # write a report to a file with open(file_out, 'w') as json_file: json.dump(report, json_file, ensure_ascii=False, sort_keys=True, indent=0) # write a short report to console console_report = dict() console_report["filename"] = file_out console_report["internal"] = len(report["internal"]) console_report["subdomain"] = len(report["subdomain"]) console_report["external"] = len(report["external"]) console_report["cms"] = report["cms"] console_report["cms_version"] = report["cms_version"] con_report(console_report) return True
def vwr(): tenant_id = request.args.get('tenant_id', None) tenant_name = CMS.getTenant(tenant_id) Callback = Extensions.get_settings(current_user.username) form = EnterEndpoint() form.endpoint.data = Callback form.tenant_id.data = tenant_id call_id_list = CMS.getCalls(tenant_id) calls = len(call_id_list) active_call_list = [] waiting_call_list = [] active_list = [] waiting_list = [] active_dur_list = [] waiting_dur_list = [] active_space_list = [] waiting_space_list = [] #following only needed for active calls uri_list = [] passcode_list = [] link_list = [] owner_list = [] if calls > 0: for call_id in call_id_list: participant_name, participant_id, activator_name = CMS.getParticipants( call_id) duration_mins, coSpace_id = CMS.getCallDetails(call_id) link, callId, ownerJid = CMS.getCoSpaceDetails(coSpace_id) access_method_id = CMS.getAccessMethod(coSpace_id) uri, passcode, link = CMS.getAccessMethodDetails( coSpace_id, access_method_id) main_link, drop_link = link.split("/invited") if len(ownerJid) > 0: active_list.append(participant_name) active_dur_list.append(duration_mins) active_space_list.append(coSpace_id) active_call_list.append(call_id) owner_list.append(ownerJid) uri_list.append(uri) passcode_list.append(passcode) link_list.append(main_link) else: waiting_list.append(participant_name) waiting_dur_list.append(duration_mins) waiting_space_list.append(coSpace_id) waiting_call_list.append(call_id) active_calls = len(active_call_list) waiting_calls = len(waiting_call_list) if request.method == 'POST': if form.validate() == False: flash('All fields are required.') else: print("callid: " + request.form['callid']) if request.form['callid'] is not None: participant_name, participant_id, activator_name = CMS.getParticipants( request.form['callid']) print("activator: " + activator_name) if activator_name == "": CMS.addParticipantToCall(request.form['callid'], request.form['endpoint']) return render_template('vwr.html', form=form, tenant=tenant_name, active_calls=active_calls, waiting_calls=waiting_calls, waiting=zip(waiting_list, waiting_call_list, waiting_dur_list, waiting_space_list), active=zip(active_list, active_call_list, active_dur_list, active_space_list, uri_list, passcode_list, link_list, owner_list))
import requests import csv from cms import CMS with open('SpaceNames.csv', newline='') as csvfile: reader = csv.DictReader(csvfile) for row in reader: name = row['SpaceName'] PIN = row['PIN'] coSpace_id = CMS.createSpace(name, PIN, '') print(name + " has been created. Space id: " + coSpace_id) csvfile.close()