Skip to content

Commit d7a063f

Browse files
authored
Create login_fromwhm.php
1 parent 123a6b4 commit d7a063f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

json-api/cpanel/login_fromwhm.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*For Verifying User through Session*/
4+
/*
5+
session_start();
6+
require_once 'db.php';
7+
$email=$SESSION["email"];
8+
$sql="SELECT * FROM users WHERE email='$email'";
9+
$query=$conn->query($sql); //Variable conn is the Database Connection
10+
//$conn= new mysqli("DBHOST","DBUSER","DBPASS","DBNAME") or die($conn->connect_error); (Stored in either functions.php or db.php)
11+
$result=$query->fetch_assoc();
12+
$user=$result['cp_username'];
13+
$hostname=$result['server'];
14+
*/
15+
16+
/*API Login Below*/
17+
$hostname="server.example.com";
18+
$user = "root";
19+
$token = "API Token or Root Password";
20+
21+
$query = "https://$hostname:2087/json-api/create_user_session?api.version=1&user=$user&service=cpaneld";
22+
23+
$curl = curl_init();
24+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
25+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
26+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
27+
28+
$header[0] = "Authorization: whm $user:$token";
29+
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
30+
curl_setopt($curl, CURLOPT_URL, $query);
31+
32+
$result = curl_exec($curl);
33+
34+
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
35+
36+
if ($http_status != 200) {
37+
//echo "[!] Error: " . $http_status . " returned\n";
38+
echo "Auto-Login Failed. Please Contact Server Administrator";
39+
} else {
40+
$json = json_decode($result, true);
41+
$login_url = $json['data']['url'];
42+
header(Location:$login_url);
43+
}
44+
curl_close($curl);
45+
?>

0 commit comments

Comments
 (0)