Skip to content

Instantly share code, notes, and snippets.

@mbikovitsky
Created December 9, 2013 18:39
Show Gist options
  • Select an option

  • Save mbikovitsky/7878051 to your computer and use it in GitHub Desktop.

Select an option

Save mbikovitsky/7878051 to your computer and use it in GitHub Desktop.
Small application for stripping Pidgin logs of private information.
<!-- Copyright (c) 2013 Michael Bikovitsky
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="http://getbootstrap.com/docs-assets/ico/favicon.png">
<title>Pidgin Privateer</title>
<!-- Bootstrap core CSS -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<style type="text/css">body{padding-top:50px}.starter-template{padding:40px 15px;text-align:center}</style>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#" data-dest="#home">Pidgin Privateer</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#" data-dest="#home">Home</a></li>
<li><a href="#" data-dest="#about">About</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container" id="main">
<div class="starter-template" id="home">
<form role="form">
<div class="form-group">
<label for="input">Paste raw Pidgin log here</label>
<textarea class="form-control" id="input" rows="25" style="font-family:monospace;"></textarea>
</div>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" id="skipTwo">
Remove first 2 lines (channel topic and when it was set)
</label>
</div>
<button type="button" class="btn btn-danger" id="btnClear">Clear</button>
<button type="submit" class="btn btn-primary"id="btnProcess">Process</button>
</form>
</div>
<div class="starter-template hidden" id="about">
<h1>About</h1>
<p class="lead">
This is a small application for processing Pidgin chat logs.<br>
Paste your <em>raw</em> log in the provided space and press the button ( you'll know which one :) ).<br>
The application will strip down the <code>HTML</code> and remove any hostnames and IP addresses from the log.
</p>
</div>
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var main = $("#main");
var input = $("#input");
$("div.navbar a").click(function () {
var dest = $(this).data("dest");
main.children().addClass("hidden");
$(dest).removeClass("hidden");
$("ul.nav li a[data-dest=" + dest + "]")
.parent().addClass("active")
.siblings().removeClass("active");
});
var setInput = function (text, error) {
return function () {
text = typeof text !== 'undefined' ? text : "";
error = typeof error !== 'undefined' ? error : false;
if (error) {
input.parent().addClass("has-error");
} else {
input.parent().removeClass("has-error");
}
input.val(text);
input[0].scrollTop = 0;
};
};
$("#btnClear").click(setInput());
$("#btnProcess").click(function () {
var log = $("<div />").append(
$.parseHTML(input.val())
);
setInput()();
log.find("meta, title, h3").remove();
if ($("#skipTwo")[0].checked) {
log.children('font').slice(0, 2).remove();
}
// Let's strip out the hostnames
var parents = log.find("em").parent();
log.find("em").remove();
parents.each(function () {
this.textContent = this.textContent.replace(/\[\] /, "");
});
var newLog = "";
log.children('font').each(function (index) {
newLog += this.textContent + this.nextSibling.textContent + '\n';
});
if (newLog == "") {
setInput(
"An error occurred. Probably this wasn't a valid Pidgin log.",
true
)();
} else {
setInput(newLog)();
}
return false; // Don't actually submit the form
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment