-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.live.php
61 lines (50 loc) · 2.53 KB
/
index.live.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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="assets/css/main.css" media="screen" />
<?php
require 'bootstrap.php';
$cpanel = new CPANEL();
print $cpanel->header( "Change Username" );
// Retrieve the current username
$accountName = Account::name($cpanel);
require_once "/usr/local/cpanel/php/cpanel.php";
// Display the form to change the primary domain
echo '<form method="post">';
echo '<div class="form-group">';
echo '<label for="current_primary_domain">Current Username:</label>';
echo '<input type="text" id="current_primary_domain" class="form-control" value="' . $accountName . '" readonly>';
echo '</div>';
echo '<div class="form-group">';
echo '<label for="new_primary_domain">New Username:</label>';
echo '<input type="text" name="new_primary_domain" id="new_primary_domain" class="form-control">';
echo '</div>';
echo '<button type="submit" class="btn btn-primary">Change cPanel Username</button>';
echo '</form>';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['new_primary_domain'])) {
// Retrieve the new primary domain name from the form
$newPrimaryDomain = $_POST['new_primary_domain'];
// Use the proc_open to run the WHM API1 command to change the primary domain name
$whmApiCommand = "./wrapper {$accountName} {$_POST['new_primary_domain']}";
echo '<div class="alert alert-info">cPanel username is being changed from ' . $accountName . ' to ' . $newPrimaryDomain . ' please allow a few seconds for the process to complete.</div>';
$descriptorspec = array(
0 => array('pipe', 'r'), // stdin
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w') // stderr
);
$process = proc_open($whmApiCommand, $descriptorspec, $pipes);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
$exitCode = proc_close($process);
if ($exitCode === 0) {
echo '<div class="alert alert-success">Your cPanel username has been changed to ' . $newPrimaryDomain . '. You have been automatically logged out, please login with the new username.</div>';
echo "<script>document.getElementById('current_primary_domain').value='$newPrimaryDomain';</script>";
} else {
echo '<div class="alert alert-danger">Failed to change the primary domain name: ' . $stderr . '</div>';
}
}
// TODO
// https://developers.whmcs.com/api-reference/updateclientproduct/
echo $cpanel->footer();
$cpanel->end();