-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathibsng.class.php
More file actions
110 lines (97 loc) · 4.06 KB
/
ibsng.class.php
File metadata and controls
110 lines (97 loc) · 4.06 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
class IBSng
{
public $error;
public $username;
public $password;
public $ip;
private $handler;
private $cookie;
private $maxredirect;
public function __construct($username, $password, $ip)
{
$this->username = $username;
$this->password = $password;
$this->ip = $ip;
$this->maxredirect = 5;
$url = $this->ip . '/IBSng/admin/';
$this->handler = curl_init();
$post_data['username'] = $username;
$post_data['password'] = $password;
curl_setopt($this->handler, CURLOPT_URL, $url);
curl_setopt($this->handler, CURLOPT_POST, true);
curl_setopt($this->handler, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($this->handler, CURLOPT_HEADER, true);
curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->handler, CURLOPT_COOKIEJAR, $this->cookie);
$mr = $this->maxredirect === null ? 5 : intval($this->maxredirect);
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($this->handler, CURLOPT_MAXREDIRS, $mr);
} else {
curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$newurl = curl_getinfo($this->handler, CURLINFO_EFFECTIVE_URL);
$rch = curl_copy_handle($this->handler);
curl_setopt($this->handler, CURLOPT_URL, $url);
curl_setopt($this->handler, CURLOPT_COOKIE, $this->cookie);
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/', $header, $matches);
$newurl = trim(array_pop($matches));
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($this->maxredirect === null) {
trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($this->handler, CURLOPT_URL, $newurl);
}
}
$output = curl_exec($this->handler);
preg_match_all('|Set-Cookie: (.*);|U', $output, $matches);
$this->cookie = implode('; ', $matches[1]);
}
public function removeUser($user_ids)
{
$url = $this->ip . '/IBSng/admin/user/del_user.php';
$post_data['user_id'] = $user_ids;
$post_data['delete'] = '1';
$post_data['delete_comment'] = '';
$post_data['delete_connection_logs'] = 'on';
$post_data['delete_audit_logs'] = 'on';
$this->handler = curl_init();
curl_setopt($this->handler, CURLOPT_URL, $url);
curl_setopt($this->handler, CURLOPT_POST, true);
curl_setopt($this->handler, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($this->handler, CURLOPT_HEADER, TRUE);
curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->handler, CURLOPT_COOKIE, $this->cookie);
curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($this->handler);
if (strpos($output, 'Deleted Successfully') !== false)
{
echo "Success<br />";
} else {
echo "Remove user error<br />";
}
}
}