├── .gitignore ├── logout.php ├── README.md ├── index.php ├── edit_email.php ├── email_accounts.php ├── login.php └── DirectAdminAPI.php /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .htaccess 3 | .htpasswd 4 | .git 5 | -------------------------------------------------------------------------------- /logout.php: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # controlpanel 2 | 3 | This is the current stage of the in-house control panel for MXroute, using the DirectAdmin API. The login system is not what I would like it to be long term, but it is a decent stand-in for a first iteration, for staging only. 4 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | getDomainList(); 12 | 13 | ?> 14 | 15 | 16 | 17 | 18 | Control Panel 19 | 20 | 21 |

Domain List

22 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /edit_email.php: -------------------------------------------------------------------------------- 1 | getEmailAccounts($domain); 14 | 15 | ?> 16 | 17 | 18 | 19 | 20 | Control Panel 21 | 22 | 23 |

Email List

24 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /email_accounts.php: -------------------------------------------------------------------------------- 1 | getEmailAccounts($domain); 14 | 15 | ?> 16 | 17 | 18 | 19 | 20 | Control Panel 21 | 22 | 23 |

Email List

24 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /login.php: -------------------------------------------------------------------------------- 1 | authenticate()) { 17 | $_SESSION['username'] = $username; 18 | $_SESSION['password'] = $password; 19 | header("Location: index.php"); 20 | exit(); 21 | } else { 22 | $loginFailed = true; 23 | $errorMessage = $directAdmin->getLastError(); 24 | } 25 | } 26 | ?> 27 | 28 | 29 | 30 | 31 | Login 32 | 33 | 34 |

Login

35 | 36 |

Login failed:

37 | 38 |
39 | 40 | 41 |
42 | 43 | 44 |
45 | 46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /DirectAdminAPI.php: -------------------------------------------------------------------------------- 1 | username = $username; 11 | $this->password = $password; 12 | $this->hostname = $hostname; 13 | $this->port = $port; 14 | } 15 | 16 | public function authenticate() { 17 | $url = "https://{$this->hostname}:{$this->port}/CMD_API_LOGIN_TEST"; 18 | 19 | $response = $this->sendRequest($url); 20 | 21 | return isset($response['error']) && $response['error'] === '0'; 22 | } 23 | 24 | public function getDomainList() { 25 | $url = "https://{$this->hostname}:{$this->port}/CMD_API_SHOW_DOMAINS"; 26 | 27 | $response = $this->sendRequest($url); 28 | 29 | if (isset($response['error']) || !isset($response['list'])) { 30 | return []; 31 | } 32 | 33 | return array_values($response['list']); 34 | } 35 | 36 | public function getEmailAccounts($domain) { 37 | $url = "https://{$this->hostname}:{$this->port}/CMD_API_POP?action=list&domain={$domain}"; 38 | 39 | $response = $this->sendRequest($url); 40 | 41 | if (isset($response['error']) || !isset($response['list'])) { 42 | return []; 43 | } 44 | 45 | return array_values($response['list']); 46 | } 47 | 48 | private function sendRequest($url) { 49 | $curl = curl_init($url); 50 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 51 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 52 | curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 53 | curl_setopt($curl, CURLOPT_USERPWD, "{$this->username}:{$this->password}"); 54 | 55 | $response = curl_exec($curl); 56 | 57 | // Check for errors and display them 58 | if (curl_errno($curl)) { 59 | $error_number = curl_errno($curl); 60 | $error_message = 'Curl error (' . $error_number . '): ' . curl_error($curl); 61 | echo $error_message; 62 | } 63 | 64 | curl_close($curl); 65 | 66 | //echo "Raw Response: " . $response; 67 | 68 | parse_str($response, $parsedResponse); 69 | return $parsedResponse; 70 | } 71 | 72 | private function parseDirectAdminResponse($response) { 73 | $result = []; 74 | 75 | parse_str($response, $result); 76 | 77 | return $result; 78 | } 79 | 80 | private $lastError; 81 | public function getLastError() { 82 | return $this->lastError; 83 | } 84 | } 85 | 86 | $directAdmin = new DirectAdminAPI($_SESSION['username'], $_SESSION['password'], 'arrow.mxrouting.net', 2222); --------------------------------------------------------------------------------