devopssantana /
aapanel
| 1 | <?php |
||
| 2 | |||
| 3 | namespace DevOpsSantana\AAPanel; |
||
| 4 | |||
| 5 | |||
| 6 | /** |
||
| 7 | * Class AAPanelConnect |
||
| 8 | * @package DevOpsSantana\AAPanel |
||
| 9 | * @author Rogério Santana <https://github.com/devopssantana> |
||
| 10 | * @since : 2022 |
||
| 11 | */ |
||
| 12 | |||
| 13 | abstract class AAPanelConnect |
||
| 14 | { |
||
| 15 | |||
| 16 | /** @var string */ |
||
| 17 | protected $serverKey; |
||
| 18 | |||
| 19 | /** @var string */ |
||
| 20 | protected $serverUrl; |
||
| 21 | |||
| 22 | /** @var array */ |
||
| 23 | protected $data; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Class Construct |
||
| 27 | */ |
||
| 28 | public function __construct() |
||
| 29 | { |
||
| 30 | $this->serverUrl = AAPANEL_SERVER_URL; |
||
| 31 | $this->serverKey = AAPANEL_SERVER_KEY; |
||
| 32 | |||
| 33 | $this->GetKeyData(); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @description Generate Coookie |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | private function GetKeyData() |
||
| 41 | { |
||
| 42 | $now_time = time(); |
||
| 43 | |||
| 44 | $this->data = array( |
||
| 45 | 'request_token' => md5($now_time . '' . md5($this->serverKey)), |
||
| 46 | 'request_time' => $now_time |
||
| 47 | ); |
||
| 48 | |||
| 49 | return $this; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @description Execute Action in AAPanel Server |
||
| 54 | * @param $url |
||
| 55 | * @param $data |
||
| 56 | * @param int $timeout |
||
| 57 | * |
||
| 58 | */ |
||
| 59 | protected function Execute($url, $data, int $timeout = 60) |
||
| 60 | { |
||
| 61 | $cookie_file = './' . md5($this->serverUrl) . '.cookie'; |
||
| 62 | if (!file_exists($cookie_file)) { |
||
| 63 | $fp = fopen($cookie_file, 'w+'); |
||
| 64 | fclose($fp); |
||
| 65 | } |
||
| 66 | |||
| 67 | // //CURLOPT_CUSTOMREQUEST |
||
| 68 | $ch = curl_init(); |
||
| 69 | curl_setopt($ch, CURLOPT_URL, $url); |
||
| 70 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
||
| 71 | curl_setopt($ch, CURLOPT_POST, 1); |
||
| 72 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
||
| 73 | curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); |
||
| 74 | curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); |
||
| 75 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 76 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
| 77 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
||
| 78 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||
| 79 | |||
| 80 | |||
| 81 | $output = json_decode(curl_exec($ch)); |
||
| 82 | curl_close($ch); |
||
| 83 | return $output; |
||
| 84 | } |
||
| 85 | } |
||
| 86 |