Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/lib/panels/remote/remote.sample.php
<?php
if(!defined('SOFTACULOUS')){
die('Hacking Attempt');
}
/**
* Class customPanel. This whole class should be modified by you according to your Panel.
* Code written in the class is an example.
*/
class remote{
var $db;
// Set $auto_managedb to 1 if you do not want the user to input database name
// You will need to return the database name and database user in dbname() and dbuser() functions below
var $auto_managedb = 0;
/**
* Constructor. If you want to execute anything when customPanel class is loaded you can put it here.
* For example you can connect to mysql as shown in below example if you want.
*/
function __construct(){
// Connecting to the database with root privileges. This will be used to create database for any new installations.
// Note: This is not compulsory and just an example
$this->db = soft_mysql_connect($this->dbhost(), 'root', 'mysql');
if(!$this->db){
die('Could not establish a connection to a database.');
}
}
/**
* THIS IS JUST EXAMPLE. You can create your own functions and use it in class.
*/
/**
* Raw Load Domains. It should return the list of domains under the particular user that is logged in.
* This function is OPTIONAL and is to be used only when you do not want to add the domains in Softaculous database
* rather just load it from your database.
*
* @return array
*/
function raw_load_domains(){
$domain_name = 'example.com';
$domains = array();
$domains[$domain_name]['did'] = 1;
$domains[$domain_name]['owner'] = 'root';
$domains[$domain_name]['username'] = 'root';
$domains[$domain_name]['domain'] = $domain_name;
$domains[$domain_name]['path'] = '/home/USERNAME/public_html';
$domains[$domain_name]['protocol'] = 'ftp';
$domains[$domain_name]['port'] = 21;
$domains[$domain_name]['ftp_user'] = 'ftp_user';
$domains[$domain_name]['ftp_pass'] = 'ftp_pass';
$domains[$domain_name]['ftp_path'] = '/public_html';
$domains[$domain_name]['backup_dir'] = '/backups';
$domains[$domain_name]['data_dir'] = '/datadir';
return $domains;
}
function myquery($query, $report = 1){
$result = soft_mysql_query($query, $this->db);
if($report && !$result){
echo 'Could not make query : <br />'.$query.'
<br /><br /> MySQL ERROR :'.soft_mysql_error($this->db);
die();
}
return $result;
}
/**
* Database Host. It should return the hostname of the database.
* This function is used to connect to a database where softaculous can install scripts.
*
* @return string
*/
function dbhost($type = 'mysql'){
return '192.168.1.10';
}
/**
* The max number of databases that this user can create
* This function is used so check that user does not create more databases than users is allotted.
*
* @return int. If unlimited return a string
*/
function maxdb($type = 'mysql'){
return 1000000;
}
/**
* Number of databases used.
* This function is called to CHECK whether the existing number of databases is not GREATER that or EQUAL to (>=) than the allowed number of Databases.
*
* @return int. If unlimited return a string
*/
function dbsused(){
return 0;
}
/**
* Database Name.
* If the panel requires to modify the DB NAME that is to be created when installing a script, it has to be done here.
* Many panels e.g. cPanel accept input from users as DBNAME but create Databases like USERNAME_DBNAME.
* In such a case this function must return USERNAME_DBNAME or DBNAME
*
* @param string.
* @return string.
*/
function dbname($dbname){
return $dbname;
}
/**
* Database Username.
* If the panel requires to modify the Database USER NAME that is to be created when installing a script, it has to be done here.
* Many panels e.g. cPanel accept input from users as DBUSERNAME but create Databases like USERNAME_DBUSERNAME.
* In such a case this function must return USERNAME_DBUSERNAME OR DBUSERNAME
*
* @param string.
* @return string.
*/
function dbuser($dbuser){
return $dbuser;
}
/**
* Database User Password.
*
* @param string.
* @return string.
*/
function dbpass($dbpass = ''){
if(!empty($dbpass)) return $dbpass;
else return generateRandStr(7);
}
/**
* Check whether the specified Database Exists.
* Return true if it exists or false if it doesnt
*
* @param string.
* @return boolean.
*/
function dbexists($dbname){
return false;
}
/**
* Check whether the specified Database User Exists.
* Return true if it exists or false if it doesnt
*
* @param string.
* @return boolean.
*/
function dbuserexists($dbuser){
return false;
}
/**
* This function should create the DATABASE and also the Database USER.
* The user must also be added to the database so that the user can conduct all necessary operations on the Database.
* Return true if it is created successfully or false if there were any error
* If there are any errors while creation of database please fill in $GLOBALS['error'][] = 'The error';
* Code below is the example.
*
* @param string $dbname.
* @param string $dbuser.
* @param string $dbpass.
* @return boolean.
*/
function createdb(&$dbname, &$dbuser, &$dbpass, $type = 'mysql'){
$is_empty = $this->dbexists($dbname);
if(!empty($is_empty)) return true;
$result = $this->myquery("CREATE DATABASE ".$dbname, 0);
// Softaculous is installed on 192.168.17.131 and will be accessing the database from here
$result = $this->myquery("GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'192.168.1.26' IDENTIFIED BY '$dbpass'", 0);
$result = $this->myquery("GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'".$this->dbhost()."'
IDENTIFIED BY '$dbpass'", 0);
/* if(!$result){
$GLOBALS['error'] = 'Could not create the database';
} */
return true;
}
/**
* This function should delete the DATABASE and also the Database USER.
* Return true if it deletes the database and user successfully or false if it doesn't
* If there are any errors while deleting of database please fill in $GLOBALS['error'][] = 'The error';
* Code below is the example.
*
* @param string $dbname.
* @param string $dbuser.
* @return boolean.
*/
function deldb($dbname, $dbuser, $type = 'mysql'){
global $globals, $__settings;
$result = $this->myquery("DROP DATABASE ".$dbname, 0);
$result = $this->myquery("DROP USER '".$dbuser."'@'192.168.1.26'", 0);
$result = $this->myquery("DROP USER '".$dbuser."'@'".$this->dbhost()."'", 0);
return true;
}
/**
* Shows the Disk Space Available.
* Should return the space available in BYTES.
* If a string is returned it will be assumed that the user has unlimited space.
* Code below is the example.
*
* @return int. If a string is returned it will be assumed that the user has unlimited space.
*/
function spaceremain(){
return 'UNLIMITED';
}
/**
* Add a CRON job for a script.
* Return TRUE if cron job was added successfully else FALSE.
*
* @param string $min.
* @param string $hour.
* @param string $day.
* @param string $month.
* @param string $weekday.
* @param string $command.
* @return boolean.
*/
function addcron($min, $hour, $day, $month, $weekday, $command, $mail = ''){
// This function should create a cron job on the machine where the script will be installed.
// Certain scripts like Drupal require a cron job for certain activity.
// NOTE : This has to be created on the machine where the script will be installed and not where the Softaculous is located.
return true;
}
/**
* Delete a CRON job of an installed script.
* Return TRUE if cron job was deleted successfully else FALSE.
*
* @param string $command.
* @return boolean.
*/
function delcron($command){
return true;
}
/**
* Choose list of domains you want to exclude for the user from
* existing list of domains owned by that user
* Return array list of domains you want to blacklist with domain name as the key
*
* @param array $domains.
* @return array
*/
function blacklist_domains($domains){
$blacklist_domains = array();
return $blacklist_domains;
}
/**
* (Optional) Create a list of plans as per your control panel
* You can use this later for ACL to assign specific scripts to these plans
* Return array list of your control panel plans. Eg : Gold, Silver, Bronze
*
* @param array $cpplans.
* @return array
*/
function listcpplans(){
$cpplans = array();
return $cpplans;
}
}
?>Back to Directory