Prechádzať zdrojové kódy

fix ip info on settings page

CauseFX 4 rokov pred
rodič
commit
d76017c23a
4 zmenil súbory, kde vykonal 77 pridanie a 35 odobranie
  1. 22 0
      api/classes/organizr.class.php
  2. 13 0
      api/v2/routes/ip.php
  3. 42 35
      js/custom.js
  4. 0 0
      js/custom.min.js

+ 22 - 0
api/classes/organizr.class.php

@@ -289,6 +289,28 @@ class Organizr
 		return true;
 	}
 	
+	public function getIpInfo($ip = null)
+	{
+		if (!$ip) {
+			$this->setResponse(422, 'No IP Address supplied');
+			return false;
+		}
+		try {
+			$options = array('verify' => false);
+			$response = Requests::get('https://ipinfo.io/' . $ip . '/?token=ddd0c072ad5021', array(), $options);
+			if ($response->success) {
+				$api = json_decode($response->body, true);
+				$this->setResponse(200, null, $api);
+				return true;
+			} else {
+				$this->setResponse(500, 'An error occurred', null);
+			}
+		} catch (Requests_Exception $e) {
+			$this->setResponse(500, 'An error occurred', $e->getMessage());
+		}
+		return false;
+	}
+	
 	public function setAPIResponse($result = null, $message = null, $responseCode = null, $data = null)
 	{
 		if ($result) {

+ 13 - 0
api/v2/routes/ip.php

@@ -0,0 +1,13 @@
+<?php
+$app->get('/ip/{ip}', function ($request, $response, $args) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	if ($Organizr->checkRoute($request)) {
+		if ($Organizr->qualifyRequest(1, true)) {
+			$Organizr->getIpInfo($args['ip']);
+		}
+	}
+	$response->getBody()->write(jsonE($GLOBALS['api']));
+	return $response
+		->withHeader('Content-Type', 'application/json;charset=UTF-8')
+		->withStatus($GLOBALS['responseCode']);
+});

+ 42 - 35
js/custom.js

@@ -1751,41 +1751,48 @@ $(document).on('click', ".showMoreHealth", function(){
 });
 //IP INFO
 $(document).on('click', ".ipInfo", function(){
-    $.getJSON("https://ipinfo.io/"+$(this).text()+"/?token=ddd0c072ad5021", function (response) {
-        var region = (typeof response.region == 'undefined') ? ' N/A' : response.region;
-        var ip = (typeof response.ip == 'undefined') ? ' N/A' : response.ip;
-        var hostname = (typeof response.hostname == 'undefined') ? ' N/A' : response.hostname;
-        var loc = (typeof response.loc == 'undefined') ? ' N/A' : response.loc;
-        var org = (typeof response.org == 'undefined') ? ' N/A' : response.org;
-        var city = (typeof response.city == 'undefined') ? ' N/A' : response.city;
-        var country = (typeof response.country == 'undefined') ? ' N/A' : response.country;
-        var phone = (typeof response.phone == 'undefined') ? ' N/A' : response.phone;
-        var div = '<div class="row">' +
-            '<div class="col-lg-12">' +
-            '<div class="white-box">' +
-            '<h3 class="box-title">'+ip+'</h3>' +
-            '<div class="table-responsive">' +
-            '<table class="table">' +
-            '<tbody>' +
-            '<tr><td class="text-left">Hostname</td><td class="txt-oflo text-right">'+hostname+'</td></tr>' +
-            '<tr><td class="text-left">Location</td><td class="txt-oflo text-right">'+loc+'</td></tr>' +
-            '<tr><td class="text-left">Org</td><td class="txt-oflo text-right">'+org+'</td></tr>' +
-            '<tr><td class="text-left">City</td><td class="txt-oflo text-right">'+city+'</td></tr>' +
-            '<tr><td class="text-left">Country</td><td class="txt-oflo text-right">'+country+'</td></tr>' +
-            '<tr><td class="text-left">Phone</td><td class="txt-oflo text-right">'+phone+'</td></tr>' +
-            '<tr><td class="text-left">Region</td><td class="txt-oflo text-right">'+region+'</td></tr>' +
-            '</tbody>' +
-            '</table>' +
-            '</div>' +
-            '</div>' +
-            '</div>' +
-            '</div>';
-        swal({
-            content: createElementFromHTML(div),
-            buttons: false,
-            className: 'bg-org'
-        });
-    });
+	organizrAPI2('GET','api/v2/ip/'+$(this).text()).success(function(data) {
+		try {
+			let response = data.response.data;
+			var region = (typeof response.region == 'undefined') ? ' N/A' : response.region;
+			var ip = (typeof response.ip == 'undefined') ? ' N/A' : response.ip;
+			var hostname = (typeof response.hostname == 'undefined') ? ' N/A' : response.hostname;
+			var loc = (typeof response.loc == 'undefined') ? ' N/A' : response.loc;
+			var org = (typeof response.org == 'undefined') ? ' N/A' : response.org;
+			var city = (typeof response.city == 'undefined') ? ' N/A' : response.city;
+			var country = (typeof response.country == 'undefined') ? ' N/A' : response.country;
+			var phone = (typeof response.phone == 'undefined') ? ' N/A' : response.phone;
+			var div = '<div class="row">' +
+				'<div class="col-lg-12">' +
+				'<div class="white-box">' +
+				'<h3 class="box-title">'+ip+'</h3>' +
+				'<div class="table-responsive inbox-center">' +
+				'<table class="table">' +
+				'<tbody>' +
+				'<tr><td class="text-left">Hostname</td><td class="txt-oflo text-right">'+hostname+'</td></tr>' +
+				'<tr><td class="text-left">Location</td><td class="txt-oflo text-right">'+loc+'</td></tr>' +
+				'<tr><td class="text-left">Org</td><td class="txt-oflo text-right">'+org+'</td></tr>' +
+				'<tr><td class="text-left">City</td><td class="txt-oflo text-right">'+city+'</td></tr>' +
+				'<tr><td class="text-left">Country</td><td class="txt-oflo text-right">'+country+'</td></tr>' +
+				'<tr><td class="text-left">Phone</td><td class="txt-oflo text-right">'+phone+'</td></tr>' +
+				'<tr><td class="text-left">Region</td><td class="txt-oflo text-right">'+region+'</td></tr>' +
+				'</tbody>' +
+				'</table>' +
+				'</div>' +
+				'</div>' +
+				'</div>' +
+				'</div>';
+			swal({
+				content: createElementFromHTML(div),
+				buttons: false,
+				className: 'bg-org'
+			});
+		}catch(e) {
+			organizrCatchError(e,data);
+		}
+	}).fail(function(xhr) {
+		OrganizrApiError(xhr, 'API Error');
+	});
 });
 // set active for group list
 $(document).on('click', '.allGroupsList', function() {

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 0
js/custom.min.js


Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov