1/* visit counter Joomla! Plugin 2 * 3 * @author Joachim Schmidt - [email protected] 4 * @copyright Copyright (C) 2013 Joachim Schmidt. All rights reserved. 5 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL 6 * 7 * change activity: 8 * 01.02.2015: Release V2.0.0 for Joomla 3.x 9 * 09.08.2022: add geolocation server check 10 * 20.11.2023: add parameter option for url-base 11 */ 12function check_Server(num) { 13 switch (num) { 14 case 1: 15 var url = 'http://www.geoplugin.net/json.gp'; 16 17 fetch(url).then(function(response) { 18 return response.json(); 19 }).then(function(data) { 20 21 var resp = ' ' + url + ' responded with: \n'; 22 if (data.geoplugin_status == 200) 23 success = 'success'; 24 else 25 success = 'error'; 26 var status = '\n\tstatus = ' + success; 27 var ip = '\n\tip = ' + data.geoplugin_request; 28 var code = data.geoplugin_countryCode; 29 var country = '\n\tcountry = ' + data.geoplugin_countryName + ' (' + code + ')'; 30 31 alert(resp + status + ip + country); 32 33 }).catch(function() { 34 alert("connection failed"); 35 }); 36 break; 37 38 case 2: 39 var url = 'http://ip-api.com/json/'; 40 fetch(url).then(function(response) { 41 return response.json(); 42 }).then(function(data) { 43 44 var resp = ' ' + url + ' responded with: \n'; 45 var status = '\n\tstatus = ' + data.status; 46 var ip = '\n\tip = ' + data.query; 47 var code = data.countryCode; 48 var country = '\n\tcountry = ' + data.country + ' (' + code + ')'; 49 50 alert(resp + status + ip + country); 51 52 }).catch(function() { 53 alert("connection failed"); 54 }); 55 56 break; 57 58 case 3: 59 var url = 'https://ip2c.org/77.55.235.217'; 60 fetch(url) 61 .then((response) => response.text()) 62 .then((text) => { 63 var result = text.split(";"); 64 var resp = ' https://ip2c.org responded with: \n'; 65 if (result[0] == 1) 66 var success = 'success'; 67 else 68 var success = 'error'; 69 var status = '\n\tstatus = ' + success; 70 var ip = '\n\tip = 77.55.235.217'; 71 var code = result[1]; 72 var country = '\n\tcountry = ' + result[3] + ' (' + code + ')'; 73 74 alert(resp + status + ip + country); 75 76 }).catch(function() { 77 alert("connection failed"); 78 }); 79 80 break; 81 82 case 4: 83 var key = document.getElementById('jform_params_server4').value; 84 if (key.length < 32) { 85 alert(' https://ipapi.co \n\n\tError: invalid or missing access key ' + key); 86 exit; 87 } 88 var url = 'https://ipapi.co/json/?key=' + key; 89 fetch(url) 90 .then((response) => response.json()) 91 .then((json) => { 92 93 var resp = ' https://ipapi.co responded with: \n'; 94 95 if (json.error) { 96 var status = '\n\tstatus = error'; 97 var reason = '\n\treason = ' + json.reason; 98 var msg = '\n\tmessage = ' + json.message; 99 alert(resp + status + reason + msg); 100 } 101 else { 102 var status = '\n\tstatus = success'; 103 var ip = '\n\tip = ' + json.ip; 104 var code = json.country_code; 105 var country = '\n\tcountry = ' + json.country_name + ' (' + code + ')'; 106 alert(resp + status + ip + country); 107 } 108 109 }).catch(function() { 110 alert("connection failed"); 111 }); 112 break; 113 114 default: 115 alert('server invalid'); 116 return; 117 } 118 119 return; 120 121} 122 123function jsvisit_getHTTPObject() { 124 var xhr = false; 125 if (window.XMLHttpRequest) { 126 xhr = new XMLHttpRequest(); 127 } else if (window.ActiveXObject) { 128 try { 129 xhr = new ActiveXObject("Msxml2.XMLHTTP"); 130 } catch (e) { 131 try { 132 xhr = new ActiveXObject("Microsoft.XMLHTTP"); 133 } catch (e) { 134 xhr = false; 135 } 136 } 137 } 138 return xhr; 139} 140 141function jsvisit_setCookie(c_name, value, exdays) { 142 var exdate = new Date(); 143 var domain = document.location.hostname; 144 exdate.setDate(exdate.getDate() + exdays); 145 var c_value = escape(value) 146 + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) 147 + "; path=/; domain=." + domain; 148 document.cookie = c_name + "=" + c_value; 149} 150 151function jsvisit_getCookie(c_name) { 152 var c_value = document.cookie; 153 var c_start = c_value.indexOf(" " + c_name + "="); 154 if (c_start == -1) { 155 c_start = c_value.indexOf(c_name + "="); 156 } 157 if (c_start == -1) { 158 c_value = null; 159 } else { 160 c_start = c_value.indexOf("=", c_start) + 1; 161 var c_end = c_value.indexOf(";", c_start); 162 if (c_end == -1) { 163 c_end = c_value.length; 164 } 165 c_value = unescape(c_value.substring(c_start, c_end)); 166 } 167 return c_value; 168} 169 170function jsvisitCountVisitors(session, base) { 171 172 var request = jsvisit_getHTTPObject(); 173 174 if (request) { 175 request.onreadystatechange = function() { 176 jsvisit_parseResponse(request); 177 }; 178 179 var sendRequest = true; 180 if (session > 0) { 181 // check if there is a cookie for this user 182 var exdate = new Date(); 183 184 var visit_date = jsvisit_getCookie("visitortime"); 185 session = parseInt(session) * 60000; 186 var check1 = exdate.getTime() - parseInt(visit_date); 187 //var check2 = check1 / 60000; 188 //alert(Math.round(check2) +"min"); 189 if (visit_date != null && visit_date != "") { 190 if (exdate.getTime() < parseInt(visit_date) + parseInt(session)) 191 sendRequest = false;
192 } 193 194 value = exdate.getTime(); 195 jsvisit_setCookie('visitortime', value, 31); 196 } 197 198 // send request 199 if (sendRequest) { 200 var url = base + 'index.php?option=com_ajax&plugin=jsvisit_counter&group=system&format=raw'; 201 //alert(url); 202 request.open("POST", url, true); 203 request.send(null); 204 } 205 } 206} 207 208function jsvisit_parseResponse(request) { 209 if (request.readyState == 4) { 210 if (request.status == 200 || request.status == 304) { 211 jsvisit_processReceived(request.responseText); 212 } 213 } 214} 215 216function jsvisit_processReceived(returnData) { 217 //alert (returnData); 218 return false; 219}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.