Add all code files from IDE
This commit is contained in:
30
source/defs/Auth/Authentication.php
Normal file
30
source/defs/Auth/Authentication.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Auth
|
||||
{
|
||||
|
||||
public $AdminID;
|
||||
|
||||
private $ApiTools;
|
||||
|
||||
public function __construct($AdminID)
|
||||
{
|
||||
|
||||
$this->ApiTools = new ApplicationAPI($AdminID);
|
||||
$this->AdminID = $AdminID;
|
||||
}
|
||||
|
||||
public function Auth($key)
|
||||
{
|
||||
if ($this->ApiTools->keysMatch($key))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("FATAL: Invalid API key");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
85
source/defs/Emailer/PHPMail.php
Normal file
85
source/defs/Emailer/PHPMail.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php // THIS CLASS ENFORCES GDPR COMPLIANCE. USING A WORKAROUND FOR THIS CONSTITUTES A VIOLATION OF THE SPACEJEWEL TERMS OF SERVICE.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// This mailer won't let you mail anyone unless they are registered as a customer to prevent GDPR violation.
|
||||
// Additionally, it doesn't let you send anything else other than mandatory email (like service downtime notifications) unless
|
||||
// they explicitly provided GDPR consent
|
||||
class Emailer
|
||||
{
|
||||
private $Customer;
|
||||
|
||||
|
||||
private $CustomerEmail;
|
||||
|
||||
|
||||
private $CustomerID;
|
||||
|
||||
|
||||
private $Envelope;
|
||||
|
||||
|
||||
private $Mailer;
|
||||
|
||||
// Initialize mailer for this customer ID
|
||||
public function __construct($CustomerEmail)
|
||||
{
|
||||
|
||||
$this->Customer = new Customer();
|
||||
|
||||
// WARNIMG: Function might return wrong data, use var_dump to inspect
|
||||
$CID = $this->Customer->translateEmailToID($CustomerEmail);
|
||||
$this->CustomerId = $CID;
|
||||
// We might want to use $CID in this method, so shortening isn't feasible here
|
||||
|
||||
|
||||
if(!$this->Customer->customerExists($CustomerEmail))
|
||||
{
|
||||
// Customer doesn't exist, fail here
|
||||
throw new Exception("Fatal error! Sending an email to an unregistered person is not allowed (GDPR Error Code: #1). A customer can be registered by purchasing a subscription");
|
||||
}
|
||||
|
||||
$this->prepareMailerEnvelope();
|
||||
|
||||
}
|
||||
|
||||
private function prepareMailerEnvelope()
|
||||
{
|
||||
$config = new Config();
|
||||
|
||||
$username = $Config['mailer']['username'];
|
||||
$password = $Config['mailer']['password'];
|
||||
$hostname = $Config['mailer']['hostname'];
|
||||
$port = $Config['mailer']['port'];
|
||||
|
||||
$connStr = 'tls://' . $username . ":" . $password . "@" . $hostname . ":" . $port;
|
||||
|
||||
$this->Envelope = new ByJG\Mail\Envelope();
|
||||
|
||||
\ByJG\Mail\MailerFactory::registerMailer('smtp', \ByJG\Mail\Wrapper\PHPMailerWrapper::class);
|
||||
$this->Mailer = \ByJG\Mail\MailerFactory::create($connStr);
|
||||
|
||||
$this->Mailer->setFrom("noreply@spacejewel.ga", "Spacejewel Billing System");
|
||||
$this->Mailer->addTo($this->CustomerEmail);
|
||||
|
||||
}
|
||||
|
||||
public function addSubject($subject)
|
||||
{
|
||||
|
||||
$this->Mailer->setSubject($subject);
|
||||
|
||||
}
|
||||
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->Mailer->setBody($body);
|
||||
}
|
||||
|
||||
public function sendEnvelope()
|
||||
{
|
||||
$Mailer->send($this->Envelope);
|
||||
}
|
||||
}
|
55
source/defs/Hookmanager/Hookmanager.php
Normal file
55
source/defs/Hookmanager/Hookmanager.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
// The hookmanager is the web-exposed class that allows you to manage a user within the billing system.
|
||||
// This system takes care of CRUD operations on customers. It doesn't keep track of order but it does suspend
|
||||
// you if you don't pay.
|
||||
|
||||
class Hookmanager
|
||||
{
|
||||
|
||||
public function EventSubscriptionCreated()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function EventSubscriptionUpdated()
|
||||
{
|
||||
// Update user information if necessary
|
||||
}
|
||||
|
||||
public function EventSubscriptionCancelled()
|
||||
{
|
||||
|
||||
// Suspend user's domain name as stated on DB
|
||||
// Delete after 30 days
|
||||
|
||||
}
|
||||
|
||||
public function EventSubscriptionPaymentSuccess()
|
||||
{
|
||||
|
||||
// Renew user's subscription within billing system
|
||||
// Install hosting account if this is the user's first time and send out instructions email
|
||||
|
||||
}
|
||||
// TODO: Lenient business logic
|
||||
public function EventSubscriptionPaymentFailed()
|
||||
{
|
||||
|
||||
// Add payment strike to user account
|
||||
// After three strikes, warn user that the system has waived further attempts. Suspend their account
|
||||
// Give user an ultimatum: Pay or remain suspended
|
||||
// If user fails to pay during the next 7 days, permanently suspend their account (Reject further payments. Remove user from paddle first)
|
||||
// If payment is successful afterwards, remove all payment strikes (Success logic should execute automatically)
|
||||
|
||||
}
|
||||
|
||||
public function EventSubscriptionPaymentRefunded()
|
||||
{
|
||||
// Ban customer from billing system
|
||||
// Delete all customer data
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
64
source/defs/Package/Package.php
Normal file
64
source/defs/Package/Package.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* This class is part of the Application core logic, since it handles customer packages.
|
||||
*
|
||||
*/
|
||||
class Package extends Application
|
||||
{
|
||||
|
||||
const PACKAGE_STARTER = "P_STARTER";
|
||||
|
||||
const PACKAGE_SMALLCOMPANY = "P_SCOMPANY";
|
||||
|
||||
const PACKAGE_PROFESSIONAL = "P_PROFESSIONAL";
|
||||
|
||||
const PACKAGE_ENTERPRISE = "P_ENTERPRISE";
|
||||
|
||||
const PACKAGE_UNLIMITED = "P_UNLIMITED";
|
||||
|
||||
|
||||
|
||||
private $allowedPackages =
|
||||
[
|
||||
"P_STARTER",
|
||||
"P_SMALLCOMPANY",
|
||||
"P_PROFESSIONAL",
|
||||
"P_ENTERPRISE",
|
||||
"P_UNLIMITED"
|
||||
];
|
||||
|
||||
|
||||
private $AdminID;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->AdminID = $AdminID;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getDefaultOptionsArray()
|
||||
{
|
||||
return
|
||||
[
|
||||
|
||||
"desc" => "Created by Spacejewel Billing System",
|
||||
"dir",
|
||||
"unix",
|
||||
"webmin",
|
||||
"web",
|
||||
"dns",
|
||||
"mail",
|
||||
"ssl",
|
||||
"spam",
|
||||
"virus"
|
||||
"limits-from-plan"
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
44
source/defs/RenderEngine/Render.php
Normal file
44
source/defs/RenderEngine/Render.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class EmailRenderer
|
||||
{
|
||||
private $templateDir;
|
||||
|
||||
public $twig;
|
||||
|
||||
|
||||
public $tmeplateList = [
|
||||
|
||||
"accountBillingInformation",
|
||||
"accountCancellationNotice",
|
||||
"accountInformationUpdated",
|
||||
"accountInstallation",
|
||||
"accountRefunded",
|
||||
"accounSubscriptionPaymentFailed"
|
||||
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = new Config();
|
||||
|
||||
$loader = new Twig_Loader_Filesystem($config['templates']['templatesDirectory']);
|
||||
$this->twig = new Twig_Environment($loader);
|
||||
|
||||
}
|
||||
|
||||
public function renderTemplate($Tmpl, Array $Data)
|
||||
{
|
||||
// $Data is an associative array of data
|
||||
if(!in_array($this->templateList, $Tmpl))
|
||||
{
|
||||
throw new Exception("WARNING: Selected template not available");
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->twig->render($Tmpl, $Data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
113
source/defs/Virtualmin/Virtualmin.php
Normal file
113
source/defs/Virtualmin/Virtualmin.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
use \HnhDigital\Virtualmin as Virtualmin;
|
||||
|
||||
// This class serves as a mini wrapper to HnhDigital's wrapper class.
|
||||
// It takes the methods it needs and proxies them for applicational use.
|
||||
class VirtualminHandler
|
||||
{
|
||||
private $virtualmin;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$Config = new Config();
|
||||
|
||||
$url = $Config['vmin-url'];
|
||||
$username = $Config['username'];
|
||||
$password = $Config['password'];
|
||||
|
||||
$this->virtualmin = new Virtualmin\VirtualServersClient($url, $username, $password);
|
||||
}
|
||||
|
||||
// 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.
|
||||
public function CreateVirtualServer($DomainName, $Password, Array $Features = [])
|
||||
{
|
||||
return $this->virtualmin->create($DomainName, $Password, $Features);
|
||||
}
|
||||
|
||||
public function DeleteVirtualServer($DomainName)
|
||||
{
|
||||
|
||||
|
||||
return $this->virtualmin->delete($DomainName);
|
||||
|
||||
}
|
||||
|
||||
// NOTICE! This deletes all domain names linked to a user account. This action is IRREVERSIBLE!
|
||||
public function DeleteAllFromUser($User)
|
||||
{
|
||||
|
||||
return $this->virtualmin->deleteByUser($User);
|
||||
|
||||
}
|
||||
|
||||
public function SuspendVirtualServer($DomainName, $SuspensionReason)
|
||||
{
|
||||
// TODO: Flag account as inactive within system's database (At Hookmanager class)
|
||||
|
||||
return $this->virtualmin->suspend($DomainName, $SuspensionReason);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function DisableFeature($DomainName, $FeatureName)
|
||||
{
|
||||
|
||||
return $this->virtualmin->disableFeatureByDomain($DomainName, $FeatureName);
|
||||
|
||||
}
|
||||
|
||||
// Deattaches all features from all domains by this user
|
||||
public function DisableFeaturesByUser($Username, $Features)
|
||||
{
|
||||
|
||||
return $this->virtualmin->disableFeatureByUser($Username, $Feature);
|
||||
|
||||
}
|
||||
|
||||
public function DisableFeatureFromAllDomains($FeatureName)
|
||||
{
|
||||
|
||||
|
||||
return $this->virtualmin->disableFeatureAllDomains($Feature);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function EnableFeatureByDomain($Domain, $Feature)
|
||||
{
|
||||
|
||||
return $this->virtualmin->enableFeatureByDomain($Domain, $Feature);
|
||||
|
||||
}
|
||||
|
||||
public function enableFeatureByUser($User, $Feature)
|
||||
{
|
||||
|
||||
return $this->virtualmin->enableFeatureByUser($User, $Feature);
|
||||
|
||||
}
|
||||
|
||||
public function enableFeatureAllDomains($Feature)
|
||||
{
|
||||
|
||||
return $this->virtualmin->enableFeatureAllDomains($Feature);
|
||||
|
||||
}
|
||||
|
||||
// SPECIAL: GDPR READINESS
|
||||
|
||||
// This
|
||||
public function modifyDomain($Domain, Array $ModifiableOptions)
|
||||
{
|
||||
$optionsArr =
|
||||
[
|
||||
"domain" => $Domain
|
||||
]
|
||||
return $this->virtualmin->modifyDomain(array_merge($optionsArr, $ModifiableOptions));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user