WIP: Add Create Domain capability

This commit is contained in:
Miguel Nogueira 2019-01-30 13:39:28 +00:00
parent a8f089e3b2
commit c7bcaa2093
3 changed files with 51 additions and 16 deletions

View File

@ -25,9 +25,15 @@ class Hookmanager
private $Mailer;
private $VirtualminHandler;
// Can be overloaded by child classes in order to add new features.W
// Can be overloaded by child classes in order to add new features.
// alert types are defined by wordpress.
protected $alertTypes =
[
"subscription_created",
@ -47,11 +53,14 @@ class Hookmanager
public function __construct()
{
// TODO: Switch project to MVC structuring.
// This doesn't make much sense.
$this->Customer = new Customer();
$this->Renderview = new EmailRenderer();
$this->APITools = new ApplicationAPI();
$this->JsonHelper = new Json();
$this->VirtualminHandler = new VirtualminHandler();
$this->PackageController = new PackageController();
// Create mailer when needed
@ -105,6 +114,8 @@ class Hookmanager
}
// The response and request method is passed by the redirecting method
// KISS and DRY might not apply here
// This method choses what to do based on the request's "intent".
private function redirectAlert(Request $Request, Response $response, $intent)
{
@ -153,7 +164,7 @@ class Hookmanager
$this->JsonHelper->set
([
"status" => "fail",
"message" => "Error: Invalid alert type (Or middleman attack in-progress)",
"message" => "Error: Invalid alert type!",
"code" => 500
]);
@ -171,19 +182,24 @@ class Hookmanager
// Return POST variable list in a structured array, DRY
private function getStructuredVariableList(Request $request)
{
$PDATA = $request->getParsedBody();
$dArr = $PDATA;
return $dArr;
return $request->getParsedBody();
}
// These methods below interact directly with the Virtualmin controller.
// args should also provide email and ip, not only plan
public function EventSubscriptionCreated(Request $request, Response $response, $args)
{
return $response->write($this->getStructuredVariableList($Request))->withStatus(200);
// Creates a subscription in the database.
// This method sends information directly to the virtualmin controller.
$combinedArguments = array_merge($this->PackageController->getDefaultOptionsArray(), $this->PackageController->selectPackage($args['package']));
$this->VirtualminHandler->CreateVirtualServer($domain, $password, $combinedArguments);
}
@ -226,5 +242,10 @@ class Hookmanager
}
private function postProcessFor($domain, $password)
{
}
}

View File

@ -3,7 +3,7 @@
/*
*
* This class is part of the Application core logic, since it handles customer packages.
*
* TODO: Finish default packages
*/
class Package extends Application
{
@ -19,14 +19,14 @@ class Package extends Application
const PACKAGE_UNLIMITED = "P_UNLIMITED";
// TODO: These values are subject to change, they should be pulled from config
private $allowedPackages =
[
"P_STARTER",
"P_SMALLCOMPANY",
"P_PROFESSIONAL",
"P_ENTERPRISE",
"P_UNLIMITED"
"P_STARTER" => 0,
"P_SMALLCOMPANY" => 152017738012172,
"P_PROFESSIONAL" => 152017787812438,
"P_ENTERPRISE" => 152017803412693,
"P_UNLIMITED" => 152017828912823
];
@ -45,7 +45,7 @@ class Package extends Application
return
[
"desc" => "Created by Spacejewel Billing System",
"desc" => "Automatically created by Spacejewel Billing System",
"dir",
"unix",
"webmin",
@ -55,10 +55,23 @@ class Package extends Application
"ssl",
"spam",
"virus",
"limits-from-plan"
"limits-from-plan" // apply limits from chosen plan.
];
}
// return features for each $package in an array format
public function selectPackage($package)
{
if (array_key_exists($package, $this->allowedPackages))
{
return
[
"--plan" => $this->allowedPackages[$package]
];
}
}
}

View File

@ -22,6 +22,7 @@ class VirtualminHandler
// Creates a domain with the specified password. The username will be the domain with the .tld removed.
// The features array will be populated when the method is exposed with the correct package name provided.
// Note: the features array contains the numerical ID of the chosen plan.
public function CreateVirtualServer($DomainName, $Password, Array $Features = [])
{
return $this->virtualmin->create($DomainName, $Password, $Features);