· 6 years ago · Dec 25, 2019, 05:24 PM
1<?php
2/** HijaIyh App Framework
3* @author justalinko
4* @version 2.1
5**/
6
7Class Hiapi{
8 public function __construct($api_url , $acc_key,$api_key){
9 $this->API_URL = $api_url;
10 $this->ACCOUNT_KEY = $acc_key;
11 $this->API_KEY = $api_key;
12 }
13 public function get($request)
14 {
15 $fulluris = $this->API_URL.'/index.php/api/get/'.$this->ACCOUNT_KEY.'/'.$this->API_KEY.'/'.$request.'&domain='.$this->getDomain();
16 $setup = [CURLOPT_URL=>$fulluris,
17 CURLOPT_USERAGENT=>'HijaIyh_App',
18 CURLOPT_RETURNTRANSFER=>true,
19 CURLOPT_SSL_VERIFYPEER=>false,
20 CURLOPT_SSL_VERIFYHOST=>false];
21 $c = curl_init();
22 curl_setopt_array($c,$setup);
23 //exit($fulluris);
24 return curl_exec($c);
25 curl_close();
26 }
27 public function getDomain()
28 {
29 return preg_replace('/www\./i','',$_SERVER['SERVER_NAME']);
30 }
31 public function check_live($acc,$api)
32 {
33 $iki = new Iki64;
34 $setup = [CURLOPT_URL=>$this->API_URL.'/index.php/api/get/'.$acc.'/'.$api.'/config?domain='.$this->getDomain(),
35 CURLOPT_USERAGENT=>'HijaIyh_App',
36 CURLOPT_RETURNTRANSFER=>true,
37 CURLOPT_SSL_VERIFYPEER=>false,
38 CURLOPT_SSL_VERIFYHOST=>false];
39 $c = curl_init();
40 curl_setopt_array($c,$setup);
41 $resp = curl_exec($c);
42 $x = "<center><h1>";
43 if(preg_match("/not found/",$resp))
44 {
45 $x.= "<div class='bg-warning text-dark spacer-small'>Request not found 1</div>";
46 }elseif(preg_match("/status/",$resp))
47 {
48 $decode = $this->parse($resp);
49 if($decode['status'] == 'dead')
50 {
51 $x.="<div class='bg-danger text-white spacer-small'>ACCOUNT KEY OR API KEY WAS WRONG !</div>";
52 }elseif($decode['status'] == 'live')
53 {
54 $cdir = dirname(__DIR__).'/config/';
55
56 $x.="<div class='bg-success text-white spacer-small'>SUCCESSFULLY ACTIVATED !</div>";
57 file_put_contents($cdir.'scama.iyh.json',$iki->encode($decode['config'],'HijaIyh_App'));
58 file_put_contents($cdir.'result.iyh.json',$iki->encode($decode['result'],'HijaIyh_App'));
59 file_put_contents($cdir.'.status_hijaiyh','active');
60 file_put_contents($cdir.'.account_key',$iki->encode($acc,'HijaIyh_App'));
61 file_put_contents($cdir.'.api_key',$iki->encode($api,'HijaIyh_App'));
62 $this->getBlocker($acc,$api);
63 }
64 }else{
65 file_put_contents('log.txt',$resp);
66 $x.= "<div class='bg-warning text-dark spacer-small'>Request not found 2</div>";
67
68 }
69 $x.="</h1></center>";
70 return $x;
71 curl_close();
72 }
73 public function p($data = array())
74 {
75
76 $p = '?';
77 $x=0;
78 $c = count($data)-1;
79 foreach($data as $param=>$val)
80 {
81 $p.=$param.'='.$val;
82
83 if($c != $x++)
84 {
85 $p.='&';
86 }
87 }
88
89 return $p;
90 }
91 public function parse($json)
92 {
93 return json_decode($json,true);
94 }
95 public function cblocker($type,$acc,$api)
96 {
97 $setup = [CURLOPT_URL=>$this->API_URL.'/index.php/api/get/'.$acc.'/'.$api.'/blocker/'.$type.'?domain='.$this->getDomain(),
98 CURLOPT_USERAGENT=>'HijaIyh_App',
99 CURLOPT_RETURNTRANSFER=>true,
100 CURLOPT_SSL_VERIFYPEER=>false,
101 CURLOPT_SSL_VERIFYHOST=>false];
102 $c = curl_init();
103 curl_setopt_array($c,$setup);
104 $resp = curl_exec($c);
105 return $resp;
106 curl_close($c);
107 }
108 public function getBlocker($acc,$api)
109 {
110 $cdir = dirname(__DIR__).'/config/';
111 file_put_contents($cdir.'/ip-blacklist.iyh.txt',$this->cblocker('ip',$acc,$api));
112 file_put_contents($cdir.'/hostname-block.iyh.txt',$this->cblocker('host',$acc,$api));
113 file_put_contents($cdir.'/useragent-block.iyh.txt',$this->cblocker('agent',$acc,$api));
114 file_put_contents($cdir.'/isp-block.iyh.txt',$this->cblocker('isp',$acc,$api));
115
116 }
117 public function config()
118 {
119 $s = $this->get('config');
120 return $this->parse($s);
121 }
122 public function bin($bin)
123 {
124 $s = $this->get('bin'.$this->p(['bin' => $bin]));
125 return $this->parse($s);
126 }
127 public function country($ip)
128 {
129 $s = $this->get('country'.$this->p(['ip' => $ip]));
130 return $this->parse($s);
131 }
132 public function checkCard($check)
133 {
134 $core = new hicore;
135 $s = $this->get('valid'.$this->p(['copy' => urlencode($check), 'ip' => $core->userIP() ]));
136 return $this->parse($s);
137 }
138 public function crawler($ua)
139 {
140 $s = $this->get('crawler'.$this->p(['ua' => $ua]));
141 return $this->parse($s);
142 }
143 public function botIp($ip)
144 {
145 $s = $this->get('ipcheck'.$this->p(['ip' => $ip]));
146 return $this->parse($s);
147 }
148 public function api_tr($from,$to,$text)
149 {
150 $s = $this->get('translate'.$this->p(['from' => $from , 'to' => $to,'text' => $text]));
151 return $this->parse($s);
152 }
153 public function change($type = 'result')
154 {
155 $s = $this->get('config');
156 $d = $this->parse($s);
157 $result = $iki->encode($d[$type]);
158 if($type == 'config'){
159 $name = 'scama';
160 }elseif($type == 'result')
161 {
162 $name = 'result';
163 }
164 $fp = fopen(dirname(__DIR__).'/config/'.$name.'.iyh.json','w');
165 fwrite($fp,$result);
166 fclose($fp);
167 }
168 public function active_gak()
169 {
170 $s = $this->get('config');
171 $d = $this->parse($s);
172 if($d['status'] == 'live')
173 {
174 return true;
175 }else{
176 return false;
177 }
178 }
179
180}