forked from lindesbs/UberspaceAccountInfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classUberspaceWebRequest.php
85 lines (65 loc) · 2.76 KB
/
classUberspaceWebRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
class classUberspaceWebRequest
{
function __construct($username, $password)
{
$this->strCookieFile="cookie_".time().".txt";
libxml_use_internal_errors(true);
setlocale(LC_ALL, 'de_DE');
$this->arrValue=array();
$this->ch=curl_init();
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_USERAGENT, "classUberspaceWebRequest");
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->strCookieFile);
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->strCookieFile);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_HEADER, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
$strUrl='https://uberspace.de/login';
$strData=sprintf("login=%s&password=%s&submit=anmelden", $username, $password);
$this->arrValue['username']=$username;
curl_setopt($this->ch, CURLOPT_URL, $strUrl);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $strData);
}
function request()
{
$this->store=curl_exec($this->ch);
$this->getData();
}
function execute($page)
{
curl_setopt($this->ch, CURLOPT_URL, $page);
$this->content=curl_exec($this->ch);
}
function close()
{
curl_close($this->ch);
if(file_exists($this->strCookieFile))
unlink($this->strCookieFile);
libxml_use_internal_errors(false);
}
function getData()
{
$this->execute('https://uberspace.de/dashboard/accountinfo?format=json');
$arrData=json_decode(trim($this->content));
$this->arrValue['guthaben']=$arrData->current_amount;
$this->arrValue['wunschpreis']=$arrData->price;
$this->arrValue['domains_webserver']=(array) $arrData->domains->web;
$this->arrValue['domains_mailserver']=(array) $arrData->domains->mail;
$this->arrValue['hostname']=$arrData->host->fqdn;
$this->arrValue['ipv4']=$arrData->host->ipv4;
$this->arrValue['username']=$arrData->login;
}
function floatval($strValue)
{
$floatValue=preg_replace("@(^[0-9]*)(\\.|,)([0-9]*)(.*)@", "\\1.\\3", $strValue);
if(!is_numeric($floatValue))
$floatValue=preg_replace("@(^[0-9]*)(.*)@", "\\1", $strValue);
if(!is_numeric($floatValue))
$floatValue=0;
return $floatValue;
}
}
?>