Skip to content

Commit

Permalink
Jump Shortened URL API - Version 2.1.9!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Simon A. Xaies committed Jun 26, 2019
1 parent d01098b commit e2ed184
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
16 changes: 9 additions & 7 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
##
##


RewriteEngine On
RewriteCond %{HTTP_HOST} !(.*?).([a-z0-9]){1,64}.(localhost|snails.email)$
RewriteCond %{HTTP_HOST} ([a-z0-9]){1,64}.(localhost|snails.email)$
Expand All @@ -24,16 +23,19 @@ RewriteRule ^/(media|css|jquery|images)/(.*?)/(.*?).(.*?)$ ./assets/$1/$2/$3.$4
RewriteRule ^/(media|css|jquery|images)/(.*?).(.*?)$ ./assets/$1/$2.$3 [L,NC,QSA]

RewriteEngine On
RewriteCond %{HTTP_HOST} !(.*?).([a-z0-9]){1,64}.(localhost|snails.email)$
RewriteCond %{HTTP_HOST} ([a-z0-9]){1,64}.(localhost|snails.email)$
RewriteCond %{REQUEST_URI} !^assets/(.*?)$
RewriteCond %{REQUEST_URI} !^([a-z0-9]{2})/(.*?)$
RewriteRule ^favicon.ico$ ./assets/images/favicon.ico [L,NC,QSA]
RewriteRule ^icon.png$ ./assets/images/icon.png [L,NC,QSA]
RewriteRule ^url.api$ ./index.php?action=url [L,NC,QSA]
RewriteRule ^(php|json|serial|xml)/(.*?)$ ./index.php?action=data&response=$1&item=$2 [L,NC,QSA]

RewriteEngine On
RewriteCond %{HTTP_HOST} (.*?).([a-z0-9]){1,64}.(localhost|snails.email)$
RewriteRule ^(php|json|serial|xml)$ ./index.php?response=$1&action=data&subdomain=1 [L,NC,QSA]
RewriteRule ^$ ./index.php?action=jump&subdomain=1 [L,NC,QSA]

RewriteEngine On
RewriteCond %{HTTP_HOST} !(.*?).([a-z0-9]){1,64}.(localhost|snails.email)$
RewriteCond %{HTTP_HOST} ([a-z0-9]){1,64}.(localhost|snails.email)$
RewriteCond %{REQUEST_URI} ^(favicon|icon|url).(ico|png|api)$
RewriteRule ^favicon.ico$ ./assets/images/favicon.ico [L,NC,QSA]
RewriteRule ^icon.png$ ./assets/images/icon.png [L,NC,QSA]
RewriteRule ^url.api$ ./index.php?action=url [L,NC,QSA]

32 changes: 31 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ function jumpShortenURL($url = '')
if ($values['last'] + $values['inactive'] < microtime(true))
unset($jumps[$finger]);
}
$result = $jumps[$hash = md5($url.$referee.microtime(true))] = array("created" => microtime(true), "last" => microtime(true), 'inactive' => (API_DROP_DAYS_INACTIVE * (3600 * 24)), "short" => API_PROTOCOL.API_HOSTNAME.'/v2/'.$referee, "domain" => API_PROTOCOL.$referee.'.'.API_HOSTNAME, 'url' => $url, 'referee' => $referee);
$result = $jumps[$hash = md5($url.$referee.microtime(true))] = array("created" => microtime(true), "last" => microtime(true), 'inactive' => (API_DROP_DAYS_INACTIVE * (3600 * 24)), "short" => API_PROTOCOL.API_HOSTNAME.'/v2/'.$referee, "domain" => API_PROTOCOL.$referee.'.'.API_HOSTNAME, 'url' => $url, 'referee' => $referee, 'timezone' => date_default_timezone_get(), 'data' => array('php' => API_PROTOCOL.API_HOSTNAME.'/php/'.$referee, 'json' => API_PROTOCOL.API_HOSTNAME.'/json/'.$referee, 'serial' => API_PROTOCOL.API_HOSTNAME.'/serial/'.$referee, 'xml' => API_PROTOCOL.API_HOSTNAME.'/xml/'.$referee));
writeRawFile($file, json_encode($jumps));
return $result;
}
Expand Down Expand Up @@ -674,6 +674,36 @@ function jumpFromShortenURL($hash = '')
exit(0);
}

/**
*
* @param unknown_type $url
* @return multitype:number unknown |multitype:string number
*/
function dataFromShortenURL($hash = '')
{
$hostname = array_reverse(explode('.', $_SERVER['HTTP_HOST']));
if (!is_dir(API_PATH_IO_REFEREE))
mkdirSecure(API_PATH_IO_REFEREE, 0777);
if (!is_file($file = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . basename(__DIR__) . '.json'))
$jumps = array();
else
$jumps = json_decode(file_get_contents($file), true);
foreach($jumps as $finger => $values)
{
if (isset($values['last']) && isset($values['inactive']))
if ($values['last'] + $values['inactive'] < microtime(true))
unset($jumps[$finger]);
}
foreach($jumps as $finger => $values)
{
if (strtolower($values['referee']) == strtolower($hash))
{
return $values;
}
}
return array();
}

/**
*
* @param unknown_type $url
Expand Down
8 changes: 6 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
* URI Path Finding of API URL Source Locality
*/
$action = (isset($_REQUEST['action']) && !empty($_REQUEST['action']) ? $_REQUEST['action'] : 'default');
if ($action == 'jump' && $_REQUEST['subdomain'] == true) {
if (($action == 'jump' || $action == 'data') && $_REQUEST['subdomain'] == true) {
$parts = explode(".", $_SERVER['HTTP_HOST']);
$item = $parts[0];
} elseif ($action == 'jump' && !empty($_REQUEST['item']))
} elseif (($action == 'jump' || $action == 'data') && !empty($_REQUEST['item']))
$item = $_REQUEST['item'];

http_response_code(200);
Expand All @@ -51,7 +51,11 @@
case 'url':
$data = jumpShortenURL($_REQUEST['url']);
break;
case 'data':
$data = dataFromShortenURL($item);
break;
}

$response = (isset($_REQUEST['response'])?$_REQUEST['response']:'raw');
// Send Responses
switch ($response)
Expand Down

0 comments on commit e2ed184

Please sign in to comment.