Skip to content

Commit

Permalink
Create login_fromwhm.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ankeshanand1 authored Oct 22, 2021
1 parent 123a6b4 commit d7a063f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions json-api/cpanel/login_fromwhm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*For Verifying User through Session*/
/*
session_start();
require_once 'db.php';
$email=$SESSION["email"];
$sql="SELECT * FROM users WHERE email='$email'";
$query=$conn->query($sql); //Variable conn is the Database Connection
//$conn= new mysqli("DBHOST","DBUSER","DBPASS","DBNAME") or die($conn->connect_error); (Stored in either functions.php or db.php)
$result=$query->fetch_assoc();
$user=$result['cp_username'];
$hostname=$result['server'];
*/

/*API Login Below*/
$hostname="server.example.com";
$user = "root";
$token = "API Token or Root Password";

$query = "https://$hostname:2087/json-api/create_user_session?api.version=1&user=$user&service=cpaneld";

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);

$header[0] = "Authorization: whm $user:$token";
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_URL, $query);

$result = curl_exec($curl);

$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($http_status != 200) {
//echo "[!] Error: " . $http_status . " returned\n";
echo "Auto-Login Failed. Please Contact Server Administrator";
} else {
$json = json_decode($result, true);
$login_url = $json['data']['url'];
header(Location:$login_url);
}
curl_close($curl);
?>

0 comments on commit d7a063f

Please sign in to comment.