Last active
February 18, 2016 02:22
-
-
Save jondoesntgit/8758b45a9903aa3f9467 to your computer and use it in GitHub Desktop.
Email Grabber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Pragma: public"); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
header("Content-Type: application/force-download"); | |
header("Content-Type: application/octet-stream"); | |
header("Content-Type: application/download"); | |
header("Content-Disposition: attachment;filename=email.txt"); | |
header("Content-Transfer-Encoding: binary "); | |
$input = $_GET['val']; | |
$arr = explode(",", $input); | |
foreach ($arr as $val) { | |
echo "$val@andrews.edu\n"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// A proxy for the Andrews directory JSON | |
$search_query = $_GET['val']; | |
$ch = curl_init("https://www.andrews.edu/directory/{$search_query}/json"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$results = curl_exec($ch); | |
curl_close($ch); | |
echo $results; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Email grabber</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> | |
<style> | |
table {margin: auto; cellpadding: 10px;} | |
td {padding:10px;} | |
th {padding:10px;} | |
</style> | |
</head> | |
<body> | |
<div class="jumbotron"> | |
<h1>Email Grabber</h1> | |
</div> | |
<div class="col-md-6 col-md-offset-3"> | |
<div class="row text-center"> | |
<h4>Search</h4> | |
<button id="download-emails" class="btn btn-default status-saved">Download 0 emails</button> | |
<p>Input your search query here.</p> | |
<div class="col-md-10 col-md-offset-1"> | |
<div class="input-group"> | |
<input id="search-input" class="form-control" type="text" size="30" placeholder="example: Pazvakawambwa"></input> | |
<span class="input-group-btn"><button id="search-button" class="btn btn-default">Search</button></span><span class="input-group-btn"></span> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<p id="results"></p> | |
</div> | |
</div> | |
</body> | |
<script> | |
var savedStudents = []; | |
search = function(){ | |
query = encodeURI($("#search-input").val()); | |
// Use this if site is hosted on Andrews server (CORS) | |
baseURL = 'http://www.andrews.edu/directory/'; | |
extension = "/json"; | |
URL = baseURL + query + extension; | |
// Use this as a proxy if not hosted on Andrews server | |
baseURL = 'get.php?val=' | |
URL = baseURL + query; | |
$.ajax({ | |
url: URL, | |
}).done(function(results) { | |
var preamble = "<table><tr><th>First</th><th>Last</th><th>Is student?</th><th>Email</th><th>Save</th></tr>"; | |
var tableData = ""; | |
var postamble = "</table>"; | |
$.each(JSON.parse(results), function(index, element){ | |
buttonClass = (savedStudents.indexOf(element.u) > -1) ? "btn-success" : "btn-default"; | |
tableData += "<tr><td>" + element.f + "</td>" | |
+ "<td>" + element.l + "</td>" | |
+ "<td>" + element.s + "</td>" | |
+ "<td>" + element.u + "</td>" | |
+ "<td><button class='save btn " + buttonClass + "' id='" + element.u + "'>Save</button></td>" | |
+ "</tr>"; | |
}) | |
table = preamble + tableData + postamble; | |
$("#results").html(preamble + tableData + postamble); | |
$(".save").click(function() { | |
username = this.id; | |
button = this; | |
savedStudents.push(this.id); | |
$(button).removeClass("btn-default"); | |
$(button).addClass("btn-success"); | |
$(".status-saved").html( "Download "+ savedStudents.length + " emails"); | |
}) | |
}) | |
} | |
download = function(){ | |
param = encodeURI(savedStudents) | |
URL = "download.php?val=" + param | |
console.log(URL); | |
window.location = URL; | |
} | |
$(".status-saved").click(download); | |
$("#search-button").click(search); | |
$("input").keypress(function (e) { | |
if (e.which == 13) { | |
search(); | |
} | |
}) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment