Subversion Repositories vnag

Rev

Rev 80 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 88
Line 46... Line 46...
46
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-v] [-e] [-u username] [-R regex] [--ipInfoToken token]');
46
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-v] [-e] [-u username] [-R regex] [--ipInfoToken token]');
47
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
47
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
48
 
48
 
49
                $this->cacheFile = $this->get_cache_dir().'/'.hash('sha256','LastCheck:last_ip_cache');
49
                $this->cacheFile = $this->get_cache_dir().'/'.hash('sha256','LastCheck:last_ip_cache');
50
                if (!file_exists($this->cacheFile)) @touch($this->cacheFile);
50
                if (!file_exists($this->cacheFile)) @touch($this->cacheFile);
51
                $this->cache = $this->cacheFile ? json_decode(file_get_contents($this->cacheFile),true) : array();
51
                $this->cache = $this->cacheFile ? @json_decode(file_get_contents($this->cacheFile),true) : array();
52
        }
52
        }
53
 
53
 
54
        public function __destruct() {
54
        public function __destruct() {
55
                if ($this->cacheFile && $this->cacheDirty) {
55
                if ($this->cacheFile && $this->cacheDirty) {
56
                        @file_put_contents($this->cacheFile, json_encode($this->cache));
56
                        @file_put_contents($this->cacheFile, json_encode($this->cache));
Line 65... Line 65...
65
                if ($token) $url .= '?token='.urlencode($token);
65
                if ($token) $url .= '?token='.urlencode($token);
66
 
66
 
67
                // fwrite(STDERR, "Note: Will query $url\n");
67
                // fwrite(STDERR, "Note: Will query $url\n");
68
                $cont = $this->url_get_contents($url);
68
                $cont = $this->url_get_contents($url);
69
                if ($cont === false) return array();
69
                if ($cont === false) return array();
70
                if (($data = @json_decode($cont, true)) === false) return array();
70
                if (($data = @json_decode($cont, true)) === null) return array();
71
                if (isset($data['error'])) return array();
71
                if (isset($data['error'])) return array();
72
 
72
 
73
                if (isset($data['bogon']) && ($data['bogon'])) {
73
                if (isset($data['bogon']) && ($data['bogon'])) {
74
                        // Things like 127.0.0.1 do not belong to anyone
74
                        // Things like 127.0.0.1 do not belong to anyone
75
                        $res = array();
75
                        $res = array();