This exercise will guide you through creating an extension that reports
the number of customer accounts, websites, databases, and mail accounts
on a Plesk server; the output format will be a plain text or the text in
XML or JSON. While writing the extension, you will learn how to do the
following:
- Use custom authentication (call PHP files bypassing controllers).
- Access Plesk entities through XML API.
We assume that the extension ID is plesk-stats, and that you start
with the code inside the ex3 directory. This code is partly written by
us to help you focus only on certain areas. Additionally, we have
populated the directory with media content necessary for the exercise.
To see the completed exercise, examine the ex3complete directory.
Step 1. Set up custom authentication.
The extension we are going to write will consist of the form which the
administrators will use to set up the data output format, and the
endpoint form where users will request the statistics. As the statistics
is secure data, we should set up access control to deliver the results
only to certain users. The two ways on how to do this are possible:
-
Determine the user type - administrator, reseller, or customer and
restrict access basing on this type. This is accomplished by creating
the
pm_Session
class instance and using its boolean methods
isClient(),
isReseller(),
and
isAdmin() .$session = new pm_Session(); $client = $session->getClient(); if ($client->isAdmin()) { }
-
Write your own authentication method.
As we assume that the statistics web service will be used by third-party
applications, we will write a custom authentication method.
Start with defining a secret token authToken in our post-installation
script and saving it to the key-value…