Overview
NOTE : OlsApp has to be installed on the server(s) where the user files will be stored. It cannot install on ANY REMOTE server. OlsApp should be able to access the users directories to be able to unzip and delete files when required. If you have multiple servers then you will have to install OlsApp on all the servers.
The PANELs webserver (e.g. Apache) must point to the This is the User Interface of OlsApp for the ENDUSER.
Also it is very important that apache OR your webserver should be RUNNING as the UNIX user of the LOGGED in user e.g. if user username is logging into your Control Panel and visiting OlsApp, apache should run as user username. This is necessary in order to be able to unzip the files in the users directories.
integrating 2 important files :
1) conf.php – PHP File which is the config
2) softpanel.php – a Class which will interact with your panel
NOTE : conf.php must be placed in root of project or replace old conf with new
NOTE : softpanel.php must be placed in the includes folder. e.g. /core/softpanel.php, the file will be loaded from the appropriate folder.
if you have already integrating 2 important files :
1) univarsal.php
2) softpanel.php
for softaculous app installer it supported our app just rename univarsal.php to conf.php and folow below step
NOTE : conf.php must be placed in root of project or replace old conf with new
NOTE : softpanel.php must be placed in the includes folder. e.g. /core/softpanel.php, the file will be loaded from the appropriate folder.
Understanding conf.php
conf.php is a very important configuration file of OlsApp. It contains the variables, that are required by OlsApp to work. It has the Path Definitions of OlsApp Files and also most of the Configuration of OlsApp is stored in this file. .
<?php
//////////////////////////////////////////////////////////////
//===========================================================
// conf.php
//===========================================================
if(!defined('OlsApp')){
die('Hacking Attempt');
}
$globals['path'] = '/usr/local/OlsApp'; // Where the OlsApp folder exists.
$globals['softscripts'] = '/var/OlsApp'; // Where the script packages are going to be stored
?>
Explanation of Important Variables
$globals[‘path’] – Is the Path where OlsApp CORE will reside
$globals[‘softscripts’] – Is the Path where OlsApp Script Packages will be stored
Understanding softpanel.php
This is the Main file which will act as the point of interacting with your Control Panel. Its a simple class which takes care of many important activities like Creating and Deleting Databases, the disk space available, the logged in user information, etc.
<?php
// INDEX Files need to be defined as per the Control Panel
$globals['index'] = 'index.liv.php?';
$globals['admin_index'] = 'index.php?';
//Which Panel are you ?
$globals['softpanel'] = 'panelname';
class softpanel{
var $loaded = 0;
var $unique;
var $rawdata = array();
var $user;
var $spaceremain;
var $domainroots;
var $mysql = array();
var $theme = array();
var $env;
function __construct(){
global $cpanel;
$this->theme['logout'] = '/logout/'; // Relative to the accessed URL
$this->theme['panel_url'] = '/'; // Relative to the accessed URL
// Are you a Dedicated or Virtual Server
$this->env = '';
if(defined('SOFTADMIN')) return true;
//Load the Raw Data
$this->rawdata = $this->rawdata();
//Load the Data
$this->user = $this->userdata();
$this->domainroots = $this->domainroots();
$this->spaceremain = $this->spaceremain();
//In Cpanel we are using this since further calls need to be accessed again
$this->loaded = 1;
}
// A unique string to identify the server
function unique(){
return '';
}
// If any raw data is required to be loaded first for the user info
function rawdata(){
//return $_CPANEL;
}
function userdata(){
global $loaded_scripts, $globals;
$user = array();
$user['name'] = 'app'; // Username of the account used for MySQL purposes
$user['displayname'] = 'Osman Gani';// For displaying the actual name
$user['email'] = 'email@address.com'; // Email of the account
$user['domain'] = 'domain.com'; // Primary Domain of the account
$user['homedir'] = '/home/app/';// Home Dir of the account
// Softaculous will create a DIRECTORY in this path and files in that DIRECTORY
// e.g. $this->rawdata['homedir']/.softaculous/files.php
$user['softdir'] = '/home/app/';
//To check whether the user belongs to any ACL plan and load iscripts according to plan (Version 3.4)
if(file_exists($globals['path'].'/conf/plans.acl')){
$get_user_plan = unserialize(implode('', file($globals['path'].'/conf/plans.acl')));
if(!empty($get_user_plan['users'][$user['name']])){
$temp = unserialize(implode('', file($globals['path'].'/conf/'.$get_user_plan['users'][$user['name']].'.plan')));
$loaded_scripts = $temp['scripts'];
}
}
return $user;
}
// Should return the paths of all domains under this account
function domainroots(){
$array = array();
//The Default Domain with public_html
$array['app.myweb.vip'] = '/home/app/testf';
$array['sub.app.myweb.vip'] = '/home/app/testf/sub'; // E.g. of a sub domain
return $array;
}
//The Host of the Database
function dbhost($type = 'mysql'){
return 'localhost'; // If any other host please return that!
}
//The Maximum Number of Database
function maxdb($type = 'mysql'){
return 100000; // The max number of DBs allowed to this user. If a string is given it will be assumed as Unlimited!
}
//List the databases of this user
function listdbs($type = 'mysql'){
$array = array('username_dbname1' => 'username_dbname1',
'username_dbname2' => 'username_dbname2',
// And so on
);
// If no database is there then please return an empty array!
return $array;
}
//List the MySQL database users
function listdbusers($type = 'mysql'){
$array = array('username_dbusername1' => 'username_dbusername1',
'username_dbusername2' => 'username_dbusername2',
// And so on
);
// If no database USERS are there then please return an empty array!
return $array;
}
// Number of dbs used
// If unlimited return a string
function dbsused(){
return $this->rawdata['currentMysqlDatabases'];
}
// Return the DBNAME as per the panel
// e.g if dbname is given and a prefix is required then please give it here
function dbname($dbname){
return $dbname;
}
// Return the DBUSERNAME as per the panel
// e.g if dbusername is given and a prefix is required then please give it here
function dbuser($dbuser){
return $dbuser;
}
// Check whether the Database Exists
// Return true if it exists or false it doesnt
function dbexists($dbname){
$res = mysql_query("SHOW DATABASES LIKE '$dbname'", $this->conn['conn']);
if(mysql_num_rows($res) > 0){
return true;
}
return false;
}
// Check whether the Database Exists
// Return true if it exists or false it doesnt
function dbuserexists($dbuser){
$res = mysql_query("SELECT User FROM mysql.user
WHERE User = '$dbuser'", $this->conn['conn']);
if(mysql_num_rows($res) > 0){
return true;
}
return false;
}
//This will create a Database
function createdb($dbname, $dbuser, $dbpass, $type = 'mysql'){
// This should create a Database and its user when called
return true;
}
//Delete a Database and user
function deldb($dbname, $dbuser, $type = 'mysql'){
// This should delete a Database and its user when called
return true;
}
//Shows the Disk Space Available
function spaceremain(){
// Note: 1) Should be in BYTES
// 2) If it is not numeric then SOFTACULOUS will assume as UNLIMITED space
$space = (1024*1024*1024); // e.g. of a GB
return $space;
}
// Add a CRON JOB
function addcron($min, $hour, $day, $month, $weekday, $command, $mail = ''){
return true;
}
// Deletes a CRON JOB as per the command given
function delcron($command){
return true;
}
// Lists the installation by users - Dont touch this!
function listinstallations($users = array(), $scripts_ = array(), $scriptwise = false, $outdated = false, $start = 0, $length = 0){
global $scripts;
$list = array();
$_scripts = array_keys($scripts_);
$_scripts = (is_array($_scripts) ? $_scripts : array());
// Load the users list
$_users = $this->listusers();
if(!empty($users)){
foreach($_users as $uk => $uv){
if(!in_array($uk, $users)){
unset($_users[$uk]);
}
}
}
foreach($_users as $uk => $uv){
$data = array();
if(@is_file($uv['softdir'].'/.softaculous/installations.php')){
$tmp = parseinsfile($uv['softdir'].'/.softaculous/installations.php');
$data = _unserialize($tmp);
}
if(empty($data)){
$data = array();
}
// If this user has any installations ONLY then SET
foreach($data as $dk => $dv){
// Is only OUTDated stuff required ?
if(!empty($outdated)){
// Its uptodate!
if($dv['ver'] == $scripts[$dv['sid']]['ver']){
continue;
}
}
// If particular script(s) is specified
if(!empty($_scripts)){
if(!in_array($dv['sid'], $_scripts)){
continue;
}
}
// Return scriptwise
if(!empty($scriptwise)){
$list[$dv['sid']][$uk][$dv['insid']] = $dv;
}else{
$list[$uk][$dv['sid']][$dv['insid']] = $dv;
}
}// End of FOREACH of $data
}// End of FOREACH of $_users
return $list;
}
// Lists the users details
// $starting is for usernames starting with these characters
// $limit if specified should return only that number of rows
function listusers($starting = '', $limit = 0){
$array['username']['softdir'] = '/path/to/softdir';
$array['username']['email'] = 'username@domain.com';
$array['username2']['softdir'] = '/path/to/softdir';
$array['username2']['email'] = 'username2@domain.com';
return $array;
}
}
Functions of the Softpanel Class
Here is a little bit explanation of important functions. There are enough comments in the code you downloaded.
function softpanel()
function softpanel(){
global $cpanel;
//Some Theme Settings
$this->theme['logout'] = '/logout/'; // Relative to the accessed URL
$this->theme['panel_url'] = '/'; // Relative to the accessed URL
// Are you a Dedicated or Virtual Server
$this->env = '';
if(defined('SOFTADMIN')) return true;
//Load the Raw Data
$this->rawdata = $this->rawdata();
//Load the Data
$this->user = $this->userdata();
$this->domainroots = $this->domainroots();
$this->spaceremain = $this->spaceremain();
}
This is the Contructor class.
$this->theme is an array to adjust the theme location so that you can modify the URL of static theme files.
It also loads up the variables :
$this->user – An array of the user information. See function userdata()
$this->domainroots – An array of the domains and their PATHS. See function domainroots()
$this->spaceremain – An integer of the space available. See function spaceremain()
function rawdata()
function rawdata(){
// Any data you want to load first
}
This is just a function to load any data which might be used by other functions in the class when they are called. You can put all your important data processing code here so that you dont have to reload everything again.
function userdata()
function userdata(){
$user = array();
$user['name'] = 'username'; // Username of the account used for MySQL purposes
$user['displayname'] = 'thedisplayname';// For displaying the actual name
$user['email'] = 'email@address.com'; // Email of the account
$user['domain'] = 'domain.com'; // Primary Domain of the account
$user['homedir'] = '/home/username';// Home Dir of the account
// OlsApp will create a DIRECTORY in this path and files in that DIRECTORY
// e.g. $this->rawdata['homedir']/.OlsApp/files.php
$user['softdir'] = '/home/username';
return $user;
}
You must return the array as shown in the code. It is self explanatory. $user[‘softdir’] is the path where the .OlsApp folder is created.
function domainroots()
// Should return the paths of all domains under this account
function domainroots(){
$array = array();
//The Default Domain with public_html
$array['domain.com'] = '/home/username/public_html';
$array['sub.domain.com'] = '/home/username/public_html/sub'; // E.g. of a sub domain
return $array;
}
Return value should be a array as shown above. It is of the format domain => /path/to/files/of/domain
function dbhost()
//The Host of the Database
function dbhost($type = 'mysql'){
return 'localhost'; // If any other host please return that!
}
Return value should be the MySQL host.
function maxdb()
//The Maximum Number of Database
function maxdb($type = 'mysql'){
return 100000; // The max number of DBs allowed to this user. If a string is given it will be assumed as Unlimited!
}
Return value should be the max number of DBs allowed to this user. If a string is given it will be assumed as Unlimited!
function dbsused()
// Number of dbs used
// If unlimited return a string
function dbsused(){
return $this->rawdata['currentMysqlDatabases'];
}
This function is called to CHECK whether the existing number of databases is not GREATER that or EQUAL to (>=) then the allowed number of Databases. Return value should be an int or a string.
function dbname()
// Return the DBNAME as per the panel
// e.g if dbname is given and a prefix is required then please give it here
function dbname($dbname){
return $dbname;
}
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
function dbuser()
// Return the DBUSERNAME as per the panel
// e.g if dbusername is given and a prefix is required then please give it here
function dbuser($dbuser){
return $dbuser;
}
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
function dbexists()
// Check whether the Database Exists
// Return true if it exists or false it doesnt
function dbexists($dbname){
$res = soft_mysql_query("SHOW DATABASES LIKE '$dbname'", $this->conn['conn']);
if(soft_mysql_num_rows($res) > 0){
return true;
}
return false;
}
This is a function to check whether the Database already exists or not Should return TRUE or FALSE as the case may be.
function dbuserexists()
// Check whether the Database User Exists
// Return true if it exists or false it doesnt
function dbuserexists($dbuser){
$res = soft_mysql_query("SELECT User FROM mysql.user
WHERE User = '$dbuser'", $this->conn['conn']);
if(soft_mysql_num_rows($res) > 0){
return true;
}
return false;
}
This is a function to check whether the Database USER already exists or not Should return TRUE or FALSE as the case may be.
function createdb()
//This will create a Database
function createdb($dbname, $dbuser, $dbpass, $type = 'mysql'){
// This should create a Database and its user when called
return true;
}
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.
Parameters :
- $dbname – The is value that is got from function dbname()
- $dbuser – The is value that is got from function dbuser()
- $dbpass – The is a randomly generated string that will be passed by OlsApp when createdb() is called.
function deldb()
//Delete a Database and user
function deldb($dbname, $dbuser, $type = 'mysql'){
// This should delete a Database and its user when called
return true;
}
This function should delete the DATABASE and also the Database USER.
Parameters passed :
- $dbname – The is value that is got from function dbname()
- $dbuser – The is value that is got from function dbuser()
function spaceremain()
//Shows the Disk Space Available
function spaceremain(){
// Note: 1) Should be in BYTES
// 2) If it is not numeric then OlsApp will assume as UNLIMITED space
$space = (1024*1024*1024); // e.g. of a GB
return $space;
}
Should return the space available in BYTES. If a string is returned it will be assumed that the user has unlimited space.
function addcron()
// Add a CRON JOB
function addcron($min, $hour, $day, $month, $weekday, $command, $mail = ''){
return true;
}
Add a CRON job for a script.
Parameters passed :
- $min
- $hour
- $day
- $month
- $weekday
- $command – The CRON Command itself.
function delcron()
// Deletes a CRON JOB as per the command given
function delcron($command){
return true;
}