Page 1 of 1

[MOD] Admin package power - add domain control

Posted: Thu Feb 11, 2016 2:38 am
by jonn
If you need a package that only grants the admin power to add new web,dns,email,db and web alias domains yet allows the user the freedom to edit domains already added, then this is for you.

What this mod does.
All users that are within a package named "Managed" are restricted as follows;
Deny users the ability to add new domain under WEB,DNS,EMAIL tab without permission.
Deny users the ability to create web aliases on listed domain edit tab to create extra dns domains without permission.
Deny users the ability to create Databases under DB tab without permission.
Allow users to edit all domains added by the admin under all conditions met except the above restrictions.
----

Please note this will not survive any vestacp updates and will break your installation.
When updating vestacp check what files are being updated by vestacp and patch files with your mods as needed... always backup.

I hope vestacp in the future will have a more permanent solution in the core perhaps a flag feature (0/1) CANADDWEB=0 CANADDDNS=1 CANADDMAIL=1 CANADDALIASES=0 in the (user.conf), so when setting up packages we can give permission on each section not just how many, web,dns,email,aliases. This way we can offer free or other types of accounts fully controlled by admins which can prevent abuse or for types of subscriptions like free services based on another purchase. get my drift :)
This will only take 30 minutes to implement. Test each before proceeding to the next section

Lets start...

First lets create a package and name it "Managed".
1). If you name the package something else change the package name reference in each below.
2). Select unlimited for everything, except the backups and other things you don't want users to have on the package.

Second, lets create a test user, assign the user to the "Managed" package.

Thirdly, lets create a page with some information.
This page is what users will see when trying to add domains that are in the package named "Managed".

Code: Select all

nano /usr/local/vesta/web/templates/admin/admin_managed.html
This is a sample of what to put inside. Customize it to your liking....

Code: Select all

<div class="l-center" style="padding-top: 259px;">
<h2>Your current hosting package is <font color="#ff6701">Managed</font>.</h2>
Please submit new domain hosting requests for web, dns, email & db accounts to the admin.<br />
Limits apply based on your subscription.<br /><br />
&star; Want to add domains yourself? Upgrade to Premium domain hosting to unlock it.<br />
&star; See our website for available premium hosting packages and upgrades.
</div>
=====================================================================

Now lets edit 4 index.php files and one html file.

===== WEB
SpoilerShow
block the adding of new web domains without permission

BACKUP

Code: Select all

cp /usr/local/vesta/web/add/web/index.php /usr/local/vesta/web/add/web/index.php.backup_orig
OPEN

Code: Select all

nano /usr/local/vesta/web/add/web/index.php
FIND

Code: Select all

// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_web.html');
CHANGE TO

Code: Select all

// Display body
if ($_SESSION['user'] == 'admin' && isset($_SESSION['look'])) {

 include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_web.html');
} else {
 if ($panel[$user]['PACKAGE'] == "Managed") {
  include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/admin_managed.html');
 } else {
  include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_web.html');
 }
}
BACKUP WITH MOD

Code: Select all

cp /usr/local/vesta/web/add/web/index.php /usr/local/vesta/web/add/web/index.php.backup_mod
Test it! All good continue to next part....
===== WEB ALIASES
SpoilerShow
block the adding of domain aliases so extra DNS domains aren't created without permission.

BACKUP

Code: Select all

cp /usr/local/vesta/web/templates/user/edit_web.html /usr/local/vesta/web/templates/user/edit_web.html.backup_orig
OPEN

Code: Select all

nano /usr/local/vesta/web/templates/user/edit_web.html
FIND

Code: Select all

                                <td class="vst-text input-label">
                                    <?php print __('Aliases');?>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                <textarea size="20" class="vst-textinput" name="v_aliases"><?php if (!empty($v_aliases)) echo htmlentities($v_aliases);  ?></textarea>
								
								</td>
CHANGE TO

Code: Select all

                                <td class="vst-text input-label">
                                    <?php print __('Aliases');?>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                <?php if ($_SESSION['user'] == 'admin' && isset($_SESSION['look'])) { ?>
                                    <textarea size="20" class="vst-textinput" name="v_aliases"><?php if (!empty($v_aliases)) echo htmlentities($v_aliases);  ?></textarea>
                                    <?php  } else {
                                      if ($panel[$user]['PACKAGE'] == "Managed") { ?>
                                       <textarea size="20" class="vst-textinput" disabled><?php if (!empty($v_aliases)) echo htmlentities($v_aliases);  ?></textarea>
                                      <?php } else { ?>
                                      <textarea size="20" class="vst-textinput" name="v_aliases"><?php if (!empty($v_aliases)) echo htmlentities($v_aliases);  ?></textarea>
                                     <? }
                                     }
                                ?>
                               </td>
BACKUP WITH MOD

Code: Select all

cp /usr/local/vesta/web/templates/user/edit_web.html /usr/local/vesta/web/templates/user/edit_web.html.backup_mod
Test it! All good continue to next part...
===== MAIL
SpoilerShow
block the adding of new email domains without permission

BACKUP

Code: Select all

cp /usr/local/vesta/web/add/mail/index.php /usr/local/vesta/web/add/mail/index.php.backup_orig
OPEN

Code: Select all

nano /usr/local/vesta/web/add/mail/index.php
FIND

Code: Select all

  // Display body for mail domain
  if (empty($_GET['domain']))  {
    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
  }
  // Display body for mail account
  if (!empty($_GET['domain']))  {
    $v_domain = $_GET['domain'];
    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
  }
CHANGE TO

Code: Select all

if ($_SESSION['user'] == 'admin' && isset($_SESSION['look']) ) {

  // Display body for mail domain
  if (empty($_GET['domain']))  {
    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
  }
  // Display body for mail account
  if (!empty($_GET['domain']))  {
    $v_domain = $_GET['domain'];
    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
  }

} else {

  if ($panel[$user]['PACKAGE'] == "Managed") {

   include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/admin_managed.html');

  } else {

  // Display body for mail domain
  if (empty($_GET['domain']))  {
    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
  }
  // Display body for mail account
  if (!empty($_GET['domain']))  {
    $v_domain = $_GET['domain'];
    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
  }

 }
}
BACKUP WITH MOD

Code: Select all

cp /usr/local/vesta/web/add/mail/index.php /usr/local/vesta/web/add/mail/index.php.backup_mod
Test it! All good continue to next part...
===== DNS
SpoilerShow
block the adding of new dns domains without permission

BACKUP

Code: Select all

cp /usr/local/vesta/web/add/dns/index.php /usr/local/vesta/web/add/dns/index.php.backup_orig
OPEN

Code: Select all

nano /usr/local/vesta/web/add/dns/index.php
FIND

Code: Select all

include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
CHANGE TO

Code: Select all

    if ($_SESSION['user'] == 'admin' && isset($_SESSION['look'])) {
     include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
    } else {
     if ($panel[$user]['PACKAGE'] == "Managed") {
       include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/admin_managed.html');
     } else {
       include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_dns.html');
     }
    }
BACKUP WITH MOD

Code: Select all

cp /usr/local/vesta/web/add/dns/index.php /usr/local/vesta/web/add/dns/index.php.backup_mod
Test it! All good continue to next part...
===== DB
SpoilerShow
block the adding of new databases without permission

BACKUP

Code: Select all

cp /usr/local/vesta/web/add/db/index.php /usr/local/vesta/web/add/db/index.php.backup_orig
OPEN

Code: Select all

nano /usr/local/vesta/web/add/db/index.php
FIND

Code: Select all

// Display body
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
CHANGE TO

Code: Select all

    if ($_SESSION['user'] == 'admin' && isset($_SESSION['look'])) {
     include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
    } else {
     if ($panel[$user]['PACKAGE'] == "Managed") {
       include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/admin_managed.html');
     } else {
       include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_db.html');
     }
    }
BACKUP WITH MOD

Code: Select all

cp /usr/local/vesta/web/add/db/index.php /usr/local/vesta/web/add/db/index.php.backup_mod
=================== DONE ===================

That's it.

Now that you have backups you can revert back when every you want if something went wrong.

Hope you can make use of this quick and dirty little mod, may need some tlc and tweaking, but it worked for us today when we needed it.

Modifications, changes, suggestions will be amended to this first post.

Just remember this mod is only a temporary workaround until something permanent is made.

happy coding....