chg: Improve support of self generated user-agents

pull/156/head
Raphaël Vinot 2021-01-20 20:54:37 +01:00
parent f0c7e42bd9
commit c8cc56f78b
3 changed files with 34 additions and 17 deletions

View File

@ -49,6 +49,7 @@ time_delta_on_index = get_config('generic', 'time_delta_on_index')
blur_screenshot = get_config('generic', 'enable_default_blur_screenshot')
max_depth = get_config('generic', 'max_depth')
use_own_ua = get_config('generic', 'use_user_agents_users')
enable_mail_notification = get_config('generic', 'enable_mail_notification')
enable_context_by_users = get_config('generic', 'enable_context_by_users')
enable_categorization = get_config('generic', 'enable_categorization')
@ -449,7 +450,10 @@ def index():
if request.method == 'HEAD':
# Just returns ack if the webserver is running
return 'Ack'
update_user_agents()
if use_own_ua:
lookyloo.build_ua_file()
else:
update_user_agents()
return index_generic()
@ -538,14 +542,16 @@ def capture_web():
os=os, browser=browser)
return redirect(url_for('tree', tree_uuid=perma_uuid))
user_agents: Dict[str, Any] = {}
if get_config('generic', 'use_user_agents_users'):
lookyloo.build_ua_file()
# NOTE: For now, just generate the file, so we have an idea of the size
# user_agents = get_user_agents('own_user_agents')
if use_own_ua:
user_agents = get_user_agents('own_user_agents')
if not user_agents:
user_agents = get_user_agents()
user_agents.pop('by_frequency')
return render_template('capture.html', user_agents=user_agents,
# get most frequest UA that isn't a bot (yes, it is dirty.)
for ua in user_agents.pop('by_frequency'):
if 'bot' not in ua['useragent'].lower():
default_ua = ua
break
return render_template('capture.html', user_agents=user_agents, default=default_ua,
max_depth=max_depth, personal_ua=request.headers.get('User-Agent'))

View File

@ -2,15 +2,20 @@ $("#os").change(function(){
var os_name = $(this).find(":selected").val().replace(/(:|\.|\[|\]|,|=)/g, "\\$1").replace(/ /g,"_");
var first_browser_name = $("[id='" + os_name + "']").find('select option:first-child').val().replace(/(:|\.|\[|\]|,|=)/g, "\\$1").replace(/ /g,"_");
// Hide and disable everything
$("#os > option").removeAttr('selected');
$(".style-sub-1").hide();
$(".style-sub-1 > div > select").attr('disabled', true);
$(".style-sub-1 > div > select").removeAttr('selected');
$(".style-sub-2").hide();
$(".style-sub-2 > div > select").attr('disabled', true);
$(".style-sub-2 > div > select").removeAttr('selected');
$("[id='" + os_name + "']").show();
$("[id='" + os_name + "'] > div > select").removeAttr('disabled');
$("[id='" + os_name + "'] > div > select option:first").prop('selected',true);
$("[id='" + os_name + '_' + first_browser_name + "']").show();
$("[id='" + os_name + '_' + first_browser_name + "'] > div > select").removeAttr('disabled');
$("[id='" + os_name + '_' + first_browser_name + "'] > div > select option:first").prop('selected',true);
});
$('select[name="browser"]').change(function(){
@ -18,8 +23,10 @@ $('select[name="browser"]').change(function(){
var os_name = $(this).parent().parent().attr("id").replace(/(:|\.|\[|\]|,|=)/g, "\\$1").replace(/ /g,"_");
// Hide what makes sense
$(".style-sub-1 > div > select").removeAttr('selected');
$(".style-sub-2").hide();
$(".style-sub-2 > div > select").attr('disabled', true);
$(".style-sub-2 > div > select").removeAttr('selected');
$("[id='" + os_name + '_' + browser_name + "']").show();
$("[id='" + os_name + '_' + browser_name + "'] > div > select").removeAttr('disabled');

View File

@ -94,33 +94,37 @@
<div class="col-sm-10">
<select class="form-control" name="os" id="os">
{% for os in user_agents.keys() %}
<option value="{{ os }}">{{ os }}</option>
<!-- Select the default os -->
<option value="{{ os }}" {% if os==default['os'] %}selected{% endif %}>{{ os }}</option>
{% endfor%}
</select>
</div>
</div>
{% for os, browsers in user_agents.items() %}
<div id="{{os.replace(' ', '_')}}" class="style-sub-1 form-group row" {% if not loop.first %}style="display: none;"{%endif%}>
<!-- Hide the browsers that aren't part of the default os -->
<div id="{{os.replace(' ', '_')}}" class="style-sub-1 form-group row" {% if not os==default['os'] %}style="display: none;"{%endif%}>
<label for="browser" class="col-sm-2 col-form-label">Browser Type:</label>
<div class="col-sm-10">
<!-- Disable all the selects, unless it is the first one in the OS list-->
<select class="form-control" name="browser" {% if not loop.first %}disabled{%endif%}>
<!-- Disable all the selects not related to the default os -->
<select class="form-control" name="browser" {% if not os==default['os'] %}disabled{%endif%}>
{% for browser in browsers.keys()%}
<option value="{{ browser }}">{{ browser }}</option>
<!-- Select the default browser -->
<option value="{{ browser }}" {% if browser==default['browser'] %}selected{% endif %}>{{ browser }}</option>
{% endfor%}
</select>
</div>
</div>
{% set outer_loop = loop %}
{% for browser, user_agents in browsers.items()%}
<div id="{{os.replace(' ', '_')}}_{{browser.replace(' ', '_')}}" class="style-sub-2 form-group row" {% if not loop.first or not outer_loop.first %} style="display: none;"{%endif%}>
<!-- Hide the user agents that aren't part of the default OS and browsers that aren't part of the default os -->
<div id="{{os.replace(' ', '_')}}_{{browser.replace(' ', '_')}}" class="style-sub-2 form-group row" {% if not os==default['os'] or not browser==default['browser']%} style="display: none;"{%endif%}>
<label for="user_agent" class="col-sm-2 col-form-label">User Agent:</label>
<div class="col-sm-10">
<!-- Disable all the selects, unless it is the first one in the OS list and in the browser list-->
<select class="form-control" name="user_agent" {% if not outer_loop.first or not loop.first %}disabled{%endif%}>
<!-- Disable all the selects, unless it is in default os and browser -->
<select class="form-control" name="user_agent" {% if not os==default['os'] or not browser==default['browser'] %}disabled{%endif%}>
{% for user_agent in user_agents %}
<option value="{{ user_agent }}">{{ user_agent }}</option>
<!-- Select the default ua -->
<option value="{{ user_agent }}" {% if user_agent==default['useragent'] %}selected{% endif %}>{{ user_agent }}</option>
{% endfor%}
</select>
</div>