Skip to content

Commit

Permalink
Adds check for localhost based APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sopankhosla committed Aug 15, 2016
1 parent 25e8718 commit f043e1b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion loklak.php
Expand Up @@ -100,6 +100,12 @@ public function status() {
public function account($name, $action=null, $data=null) {
// This API is localhost access ONLY.
$this->requestURL = $this->baseUrl . '/api/account.json';
if($this->requestURL != 'http://localhost:9000') {
$request = array();
$error = "This API has access restrictions: only localhost clients are granted.";
$request['error'] = array_push($request, $error);
return json_encode($request, true);
}
$this->name = $name;
$this->action = $action;
$this->data = json_encode($data);
Expand Down Expand Up @@ -225,12 +231,18 @@ public function user($name, $followers=null, $following=null) {

public function settings() {
$this->requestURL = $this->baseUrl . '/api/settings.json';
if($this->requestURL != 'http://localhost:9000') {
$request = array();
$error = "This API has access restrictions: only localhost clients are granted.";
$request['error'] = array_push($request, $error);
return json_encode($request, true);
}
$request = Requests::get($this->requestURL, array('Accept' => 'application/json'));
if ($request->status_code == 200)
return json_encode($request, true);
else {
$request = array();
$error = "This API has access restrictions: only localhost clients are granted.";
$error = "Something is wrong with the query.";
$request['error'] = array_push($request, $error);
return json_encode($request, true);
}
Expand Down

0 comments on commit f043e1b

Please sign in to comment.