This repository has been archived by the owner on May 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpanel.php
68 lines (51 loc) · 1.87 KB
/
cpanel.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
<?php
set_time_limit(60);
# random number for cookie file
$rand = rand(1,1000000);
$post_data['login_theme'] = 'cpanel';
$post_data['goto_uri'] = '/';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
curl_init('http://'.$server.'.heliohost.org:2082/login');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
// get request information
$getinfo = curl_getinfo($curl_connection);
$info = explode("post_login", $getinfo['url']);
if(isset($info[1])) {
// Success
session_start();
$_SESSION['username'] = $post_data['user'];
$_SESSION['password'] = $post_data['pass'];
$_SESSION['server'] = $server;
if (isset($_POST['remember']) && (!isset($_COOKIE['username']) || $_COOKIE['username'] == '')) {
setcookie ("Username", $user_name, time() + 1209600); // Two Weeks
setcookie ("Password", $user_pass, time() + 1209600); // Two Weeks
setcookie ("Server", $server, time() + 1209600); // Two Weeks
}
header('location:../');
}else{
// Fail
header("location:/heliopanel/login/?error=1");
}
// For debugging purposes:
// echo curl_errno($curl_connection) . '-' .
// curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
?>