Compare commits

..

3 Commits

3 changed files with 110 additions and 33 deletions

104
index.js
View File

@@ -1,44 +1,94 @@
// const submit = document.getElementById("button");
// submit.addEventListener('click', validate);
mycheckbox = document.getElementById("restricted");
mycheckbox.addEventListener('change',checkboxCallback);
window.onload = function() {
if (mycheckbox.checked) {
document.getElementById("radiusLabel").hidden = false;
document.getElementById("mandatory-radius").hidden = false;
var radiusSelect = document.getElementById("radiusSelect");
radiusSelect.hidden = false;
radiusSelect.required = true;
}
}
var lat = document.getElementById("latitude");
lat.setValue = function(newValue) {
this.value = newValue;
valueReceived();
}
function valueReceived() {
let load = document.getElementById("loadingText");
load.innerHTML = "Location retrieved";
load.style.color = "green";
}
function valueRequested() {
let load = document.getElementById("loadingText");
load.innerHTML = "Location requested. Please wait...";
load.style.color = "red";
}
function checkboxCallback(event) {
if (event.currentTarget.checked) {
getLocation();
}
const radiusLabel = document.getElementById("radiusLabel");
const radiusSelect = document.getElementById("radiusSelect");
const mandatoryRadius = document.getElementById("mandatory-radius");
if (event.currentTarget.checked) {
radiusLabel.hidden = false;
mandatoryRadius.hidden = false;
radiusSelect.hidden = false;
radiusSelect.required = true;
valueRequested();
getLocation();
} else {
radiusLabel.hidden = true;
mandatoryRadius.hidden = true;
radiusSelect.hidden = true;
radiusSelect.required = false;
}
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log("Your browser does not support geolocation.");
}
console.log("GeoLocation");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log("Your browser does not support geolocation.");
}
}
function showPosition(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
console.log("Gotten positions");
console.log(position.coords.latitude);
console.log(position.coords.longitude);
document.getElementById("latitude").value = position.coords.latitude;
document.getElementById("longitude").value = position.coords.longitude;
document.getElementById("latitude").setValue(position.coords.latitude);
document.getElementById("longitude").value = position.coords.longitude;
console.log("done");
}
// submit.addEventListener('click', validate);
function validate() {
//e.preventDefault();
const checked = document.getElementById("restricted");
if (checked.checked) {
const lat = document.getElementById("latitude");
const long = document.getElementById("longitude");
if (lat.value === "" || long.value === "") {
/* wait */
return false
}
}
function validate() {
//e.preventDefault();
const url = document.getElementById("URL");
let glink = document.getElementById("GLink");
const error = document.getElementById("error");
// if (!url) {
// /* Flag */
// }
let valid = true;
const domainExp = new RegExp("^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$");
const filepathExp = new RegExp("^[a-zA-Z]+$");
const url = document.getElementById("URL");
let glink = document.getElementById("GLink");
const error = document.getElementById("error");
// if (!url) {
// /* Flag */
// }
let valid = true;
const domainExp = new RegExp("^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$");
const filepathExp = new RegExp("^[a-zA-Z]+$");
const glinkExp = new RegExp("^[a-zA-Z]*$");
let glinkStr = glink.value;
let count = 0;
@@ -71,8 +121,6 @@ function validate() {
var result = window.confirm("You have left the glink field blank. A random one will be generated for you.");
if (result === false) {
return false;
} else {
glinkStr = getRandomGLink();
}
}

View File

@@ -15,7 +15,7 @@
$keyspace = 'glink';
$session = $cluster->connect($keyspace);
$statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING;');
$statement = $session->prepare('SELECT url,is_geo FROM data WHERE shortlink=? ALLOW FILTERING;');
$result = $session->execute($statement,array('arguments' => array($uri)));
if ($result->count() == 0) {
@@ -28,7 +28,13 @@
printf('The given GLink was invalid, and doesn\'t point to a specific web page.');
exit;
} else {
header("Location: " . $row['url']);
if ($row['is_geo'] == true) {
header("Location: https://glink.zip/reqloc.html");
exit;
} else {
header("Location: " . $row['url']);
exit;
}
}
}
}

View File

@@ -28,13 +28,29 @@ function gen_rand_shortlink($len) {
ini_set('display_errors', 1);
use Casssandra;
$cluster = Cassandra::cluster()->withPersistentSessions(true)->build();
$keyspace = 'glink';
$session = $cluster->connect($keyspace);
$url = $_GET["url"];
if (isset($_GET["restricted"])) {
$is_geo = 1;
} else {
$is_geo = 0;
}
if ($is_geo == 1) {
$radius = $_GET["radius"];
$latitude = $_GET["latitude"];
$latitude = doubleval($latitude);
$longitude = $_GET["longitude"];
$longitude = doubleval($longitude);
}
$matches = preg_match('/^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$/',$url);
if (($matches == 0) || ($matches == false)) {
printf("The URL entered was invalid. Please try again.");
@@ -78,8 +94,15 @@ if ($result->count() != 0) {
$rand_num = rand(0,99999999);
$statement = $session->prepare('INSERT INTO data (id, url, shortlink, when_created) VALUES (?,?,?,toTimestamp(now())) USING TTL 20');
$result = $session->execute($statement,array('arguments' => array($rand_num,$url,$shortlink)));
$statement = $session->prepare('INSERT INTO data (id, url, shortlink, is_geo, radius, latitude, longitude, when_created) VALUES (?,?,?,?,?,?,?,toTimestamp(now())) USING TTL 20');
if ($is_geo == 1) {
$options = array($rand_num,$url,$shortlink,boolval($is_geo),intval($radius), $latitude, $longitude);
} else {
$options = array($rand_num,$url,$shortlink,boolval($is_geo),null,null,null);
}
$result = $session->execute($statement,array('arguments' => $options));
//$stringRepresentation= json_encode($result[0]);