== Beispiel-Code ==
<source lang="php"><?php class CPanelProv extends Provisioning { protected $name = "cPanel"; protected $short = "cpanel"; protected $lang; protected $options = Array(); public function Config($id, $product = true) { $this->loadOptions($id, $product); if (isset($_POST['url'])) { $res = $this->Call("listpkgs", [], $_POST); if (!$res) { die('<div class="alert alert-danger"><b>Fehler!</b> Keine Verbindung zum Server möglich.Eventuell SSL-Zertifikat prüfen.</div>'); } if (!empty($res->cpanelresult->error)) { die('<div class="alert alert-danger"><b>Fehler!</b> ' .htmlentities($res->cpanelresult->error) . '</div>'); } $pkgs = $res->data->pkg; if (count($pkgs) == 0) { die('<div class="alert alert-warning">Es existieren keine Angebote in cPanel.</div>'); } $html = '<div class="form-group"><label>Angebot</label><select data-setting="plan" class="form-control prov_settings">'; foreach ($pkgs as $p) { $p = $p->name; if (!empty($this->getOption("plan")) && $this->getOption("plan") == $p) { $html .= "<option selected='selected'>$p</option>"; } else { $html .= "<option>$p</option>"; } } $html .= "</select></div>"; die($html); } ob_start();?> <div class="row"> <input style="opacity: 0;position: absolute;"> <input type="password" style="opacity: 0;position: absolute;"> <div class="col-md-4"> <div class="form-group"> <label>WHM-URL</label> <input type="text" data-setting="url" value="<?=$this->getOption("url");?>" placeholder="https://webspacepanel.de:2087" class="form-control prov_settings" /> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>WHM-Benutzer</label> <input type="text" data-setting="user" value="<?=$this->getOption("user");?>" placeholder="root" class="form-control prov_settings" /> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>WHM-Passwort</label> <input type="password" data-setting="password" value="<?=$this->getOption("password");?>" placeholder="L957fZviq6" class="form-control prov_settings" /> </div> </div> </div> <a href="#" id="check_conn" class="btn btn-default btn-block">Daten vom Server abrufen</a> <script> var doing = false; function request(){ if(doing) return; doing = !doing; $("#check_conn").html('<i class="fa fa-spin fa-spinner"></i> Daten werden abgerufen...'); $.post("?p=<?php if ($product) {?>product_<?php }?>hosting&id=<?=$_GET['id'];?>&module=cpanel", { url: $("[data-setting=url]").val(), user: $("[data-setting=user]").val(), password: $("[data-setting=password]").val(), "csrf_token": "<?=CSRF::raw(); ?>", }, function(r){ doing = false; $("#check_conn").html('Daten vom Server abrufen'); $("#server_conf").html(r); }); } <?php if (!empty($this->getOption("url"))) { echo 'request();'; } ?> $("#check_conn").click(function(e){ e.preventDefault(); request(); }); </script> <br /><div id="server_conf"></div> <?php $res = ob_get_contents(); ob_end_clean(); return $res; } private function Call($func, $data = [], $opt = false) { if (!is_array($opt)) { $opt = $this->options; } $data = is_array($data) && count($data) > 0 ? "&" . http_build_query($data) : ""; $ch = curl_init(rtrim($opt["url"], "/") . "/json-api/" . $func . "?api.version=1" . $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: Basic " . base64_encode($opt["user"] . ":" . $opt["password"]) . "\n\r", ]); $res = json_decode(curl_exec($ch)); curl_close($ch); return is_object($res) ? $res : false; } public function Create($id) { global $sec; $this->loadOptions($id); $res = $this->Call("createacct", [ "username" => "web$id", "domain" => "$id.web", "password" => $pwd = $sec->generatePassword(16, false, "lud"), "plan" => $this->getOption("plan"), ]); if ($res->metadata->result) { return [true, [ "password" => $pwd, ]]; } else { return [false, $res->metadata->reason]; } } public function Delete($id) { $this->loadOptions($id); $res = $this->Call("removeacct", [ "username" => "web$id", ]); if ($res->metadata->result) { return [true]; } else { return [false, $res->metadata->reason]; } } public function Output($id, $task = "") { global $pars, $raw_cfg, $CFG; $this->loadOptions($id); ob_start(); $org = $this->getOption("url"); $host = array_shift(explode(":", rtrim(substr(array_pop(explode(":", $org, 2)), 2), "/"))); $url = "https://$host:2083/"; ?> <div class="row"> <div class="col-md-6"> <div class="panel panel-default"> <div class="panel-heading">cPanel-Zugangsdaten</div> <div class="panel-body"> <b>URL:</b> <a target="_blank" href="<?=$url;?>"><?=$url;?></a><br /> <b>Benutzername:</b> web<?=$id;?><br /> <b>Passwort:</b> <?=$this->getData("password"); ?></a> </div> </div> </div> <div class="col-md-6"> <div class="panel panel-default"> <div class="panel-heading">FTP-Zugangsdaten</div> <div class="panel-body"> <b>Host:</b> <?=$host; ?><br /> <b>Benutzername:</b> web<?=$id;?><br /> <b>Passwort:</b> <?=$this->getData("password");?> </div> </div> </div> </div> <?php $res = ob_get_contents(); ob_end_clean(); return $res; } public function Suspend($id, $do = "") { $this->loadOptions($id); $res = $this->Call($do . "suspendacct", [ "user" => "web$id", ]); if ($res->metadata->result) { return [true]; } else { return [false, $res->metadata->reason]; } } public function Unsuspend($id) { return $this->Suspend($id, "un"); } public function ChangePackage($id) { $this->loadOptions($id); $res = $this->Call("changepackage", [ "user" => "web$id", "pkg" => $this->getOption("plan"), ]); if ($res->metadata->result) { return [true]; } else { return [false, $res->metadata->reason]; } } public function AllEmailVariables() { return Array( "url", ); } public function EmailVariables($id) { global $raw_cfg; $this->loadOptions($id); $u = $this->getClient($id); return Array( "url" => $raw_cfg['PAGEURL'] . "/hosting/" . $id, ); }}</source>