<!DOCTYPE html>
<html>

	<head>
	  <meta charset="utf-8">
	  <meta name="viewport" content="width=device-width, initial-scale=1.0">

	  <title>Tags Export - AIL</title>
		<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">

	  <!-- Core CSS -->
	  <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
	  <link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
	  <link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
	 	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.css') }}" rel="stylesheet" type="text/css" />
	  <!-- JS -->
	  <script type="text/javascript" src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
	  <script language="javascript" src="{{ url_for('static', filename='js/jquery.js') }}"></script>
		<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
	  <script src="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"></script>
	  <script src="{{ url_for('static', filename='js/dataTables.bootstrap.js') }}"></script>

		<style>
			.tooltip-inner {
				text-align: left;
				height: 200%;
				width: 200%;
				max-width: 500px;
				max-height: 500px;
				font-size: 13px;
			}
			xmp {
				white-space:pre-wrap;
				word-wrap:break-word;
			}
			.test thead{
				background: #d91f2d;
				color: #fff;
			}
			.mouse_pointer{
				cursor: pointer;
			}
		</style>

	</head>
	<body>

            {% include 'navbar.html' %}

    <div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->

			<div class="container">
  			<div class="row">
						<div class="col-md-6">

				      <div class="panel panel-primary">
				        <div class="panel-heading"> MISP Auto Event Creation
				          {% if misp_active %}
				            <span class="label label-success pull-right"> Enabled</span>
				          {% endif %}
				          {% if not misp_active %}
				            <span class="label label-danger pull-right"> Disabled</span>
				          {% endif %}
				        </div>
				        <div class="panel-body">

									<div class="text-center">
										<img id="misp-logo" src="{{url_for('static', filename='image/misp-logo.png') }}" class="text-center" >
									</div>
									<br>

									{% if flag_misp %}
					          {% if misp_active %}
					          <a href="{{ url_for('PasteSubmit.disable_misp_auto_event') }}" class="btn btn-danger pull-right">
					            <i class="fa fa-times fa"></i> Disable Event Creation
					          </a>
					          {% endif %}
					          {% if not misp_active %}
					          <a href="{{ url_for('PasteSubmit.enable_misp_auto_event') }}" class="btn btn-success pull-right">
					            <i class="fa fa-check-square-o fa"></i> Enable Event Creation
					          </a>
					          {% endif %}
									{% endif %}

									{% if not flag_misp %}
										<button class="btn btn-danger pull-right disabled">
											<i class="fa fa-times fa"></i> MISP is not connected
										</button>
									{% endif %}
				        </div>
				      </div>
						</div>

					<div class="col-md-6">
						<div class="panel panel-primary" style="min-width: 500px;">
				      <div class="panel-heading">The hive auto export
				        {% if hive_active %}
				          <span class="label label-success pull-right"> Enabled</span>
				        {% endif %}
				        {% if not hive_active %}
				          <span class="label label-danger pull-right"> Disabled</span>
				        {% endif %}
				      </div>
				      <div class="panel-body">

								<div class="text-center">
									<img id="misp-logo" src="{{url_for('static', filename='image/thehive-logo.png') }}" width="500">
								</div>

								{% if flag_hive %}
					        {% if hive_active %}
					        <a href="{{ url_for('PasteSubmit.disable_hive_auto_alert') }}" class="btn btn-danger pull-right">
					          <i class="fa fa-times fa"></i> Disable Alert Creation
					        </a>
					        {% endif %}
					        {% if not hive_active %}
					        <a href="{{ url_for('PasteSubmit.enable_hive_auto_alert') }}" class="btn btn-success pull-right">
					          <i class="fa fa-check-square-o fa"></i> Enable Alert Creation
					        </a>
					        {% endif %}
								{% endif %}
								{% if not flag_hive %}
									<button class="btn btn-danger pull-right disabled">
										<i class="fa fa-times fa"></i> The Hive is not connected
									</button>
								{% endif %}
				      </div>
				    </div>
					</div>

				</div>
			</div>

      <form action="{{ url_for('PasteSubmit.tag_export_edited') }}" id="checkboxForm" method='post'>


				<div class="container">
	  			<div class="row">

							<div class="col-md-6">

								<div class="panel panel-info">
									<div class="panel-heading">
										Metadata :
										<span class="pull-right">&nbsp;&nbsp;&nbsp;</span>
										<span class="badge pull-right">{{ nb_tags_whitelist_misp }}</span>
							 	<ul class="list-group"><li class="list-group-item">
									<table class="test table table-striped table-bordered table-hover table-responsive " id="myTable_misp">
										<thead>
											<tr>
												<th>Whitelist</th>
												<th>Tag</th>
											</tr>
										</thead>
										<tbody>

											{% for tag in list_export_tags %}
												<tr>
														<td>
						                  {% if status_misp[loop.index0] %}
																<div style="display:none;">Enabled</div>
						                    <input type="checkbox" value="{{ tag }}" name="tag_enabled_misp" checked>
															{% endif %}
						                  {% if not status_misp[loop.index0] %}
																<div style="display:none;">Disabled</div>
																<input type="checkbox" value="{{ tag }}" name="tag_enabled_misp" >
															{% endif %}
						                </td>
														<td>
															{{ tag }}
															{% if not is_infoleak_tag[loop.index0] %}
																<div class="btn-link btn-interaction pull-right mouse_pointer" data-toggle="tooltip" title="Delete this tag" onclick="delete_push_tag('{{ tag }}')">
																	<span class="glyphicon glyphicon-trash"></span>
																</div>
															{% endif %}
														</td>
												</tr>
											{%  endfor %}

										</tbody>
									</table>
								</li></ul>
								</div></div>
							</div>

							<div class="col-md-6">

								<div class="panel panel-info">
									<div class="panel-heading">
										Metadata :
										<span class="pull-right">&nbsp;&nbsp;&nbsp;</span>
										<span class="badge pull-right">{{ nb_tags_whitelist_hive }}</span>
							 	<ul class="list-group"><li class="list-group-item">

									<table class="test table table-striped table-bordered table-hover table-responsive " id="myTable_hive">
										<thead>
											<tr>
												<th>Whitelist</th>
												<th>Tag</th>
											</tr>
										</thead>
										<tbody>

											{% for tag in list_export_tags %}
												<tr>
														<td>
						                  {% if status_hive[loop.index0] %}
																<div style="display:none;">Enabled</div>
						                    <input type="checkbox" value="{{ tag }}" name="tag_enabled_hive" checked>
															{% endif %}
						                  {% if not status_hive[loop.index0] %}
																<div style="display:none;">Disabled</div>
																<input type="checkbox" value="{{ tag }}" name="tag_enabled_hive" >
															{% endif %}
						                </td>
														<td>
															{{ tag }}
															{% if not is_infoleak_tag[loop.index0] %}
																<div class="btn-link btn-interaction pull-right mouse_pointer" data-toggle="tooltip" title="Delete this tag" onclick="delete_push_tag('{{ tag }}')">
																	<span class="glyphicon glyphicon-trash"></span>
																</div>
															{% endif %}
														</td>
												</tr>
											{%  endfor %}

										</tbody>
									</table>
								</li></ul>
								</div></div>
							</div>

						</div>
					</div>


	      <div class="input-group-btn text-center">
	          <button class="btn btn-primary btn-lg" onclick="submitActiveTags()">
	              <i class="fa fa-check-square-o fa"></i>
	              Update Tags
	          </button>
	      </div>

      </form>

			<div>

				<div id="add_custom_tag_modal" class="modal fade" role="dialog">
					<div class="modal-dialog">

						<!-- Modal content-->
						<div id="mymodalcontent" class="modal-content">
							<div class="modal-header" style="border-bottom: 4px solid #48c9b0; background-color: #48c9b0; color: #ffffff;">
								<h2 class="text-center">Add Custom Tag</h2>

							</div>

							<div class="modal-body">
								<div class="form-group input-group" style="margin-bottom: 0px;">
                  <span class="input-group-addon"><i class="fa fa-tag fa"></i></span>
                  <input id="new_custom_tag" class="form-control" placeholder="Add a new custom tag to the tag export" type="text">
                </div>
							</div>

							<div class="modal-footer">
								<button class="btn btn-primary btn-tags" onclick="add_custom_tag()">
										<span class="glyphicon glyphicon-plus"></span>
										<span class="label-icon">Add Custom Tag</span>
								</button>
								<button type="button" class="btn btn-default" data-dismiss="modal" >Close</button>

							</div>
						</div>
					</div>
				</div>

				<button type="button" class="btn btn-primary pull-right" data-toggle="modal" data-target="#add_custom_tag_modal" data-url="{{ url_for('Tags.taxonomies') }}">
					<span class="glyphicon glyphicon-plus "></span> Add Custom Tag
				</button>
			</div>

      </div>
            <!-- /#page-wrapper -->


</body>

<script>
var table_misp
var table_hive
$(document).ready(function(){

		table_misp = $('#myTable_misp').DataTable(
			{
				"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
				"iDisplayLength": 10,
				"order": [[ 1, "asc" ]]
			}
		);

		table_hive = $('#myTable_hive').DataTable(
			{
				"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
				"iDisplayLength": 10,
				"order": [[ 1, "asc" ]]
			}
		);

});
</script>

<script>
  function submitActiveTags(){
		table_misp.destroy()
		table_misp = $('#myTable_misp').DataTable(
			{
				"iDisplayLength": -1,
			}
		);
		table_hive.destroy()
		table_hive = $('#myTable_hive').DataTable(
			{
				"iDisplayLength": -1,
			}
		);
  }

	function delete_push_tag(tag){
		//var row_tr = $(this).closest("tr");
		$.get("{{ url_for('PasteSubmit.delete_push_tag') }}", { tag: tag }, function(data, status){
				if(status == "success") {
						//row_tr.remove();
						window.location.reload(false);
				}
		});
	}

	function add_custom_tag(){
		$.get("{{ url_for('PasteSubmit.add_push_tag') }}", { tag: document.getElementById('new_custom_tag').value }, function(data, status){
				if(status == "success") {
						//row_tr.remove();
						window.location.reload(false);
				}
		});
	}
</script>

</html>
