Jump to content
Froxlor Forum
  • 0

Calculating Counter


Warlock

Question

Hi all,

 

I have a general question to the function which calculates the number of used FTP accounts.

 

In file lib/functions/froxlor/function.updateCounters.php, Line 176+177, there is the following:

$customer_ftps = $db->query_first('SELECT COUNT(*) AS `number_ftps` FROM `' . TABLE_FTP_USERS . '` WHERE `customerid` = "' . (int)$customer['customerid'] . '"');

$customer['ftps_used_new'] = ((int)$customer_ftps['number_ftps'] - 1);

 

Well, the first statement counts the number of entries from the ftp_users table but then, in line 177, why is this number decreased by 1?

Could somebody explain this to me?

 

Thanks in advance.

 

Best,

Manuel

Link to post
Share on other sites

7 answers to this question

Recommended Posts

Yes, this is because the counter does not count the "main"-ftp-account which is autocreated for every customer (because this account does not count to the customers contingent)

Link to post
Share on other sites

Thank you for the answer.

 

I have another issue:

My table ftp_users also grants shell login, for this purpose I have a column "shell" in the table.

I'm not sure but I think this column has existed also in the original syscp system.

The default value for this column is "/bin/false" disabling the login per ssh.

 

But in my case, I extended the scripts in the way that one can specify the shell when creating a new ftp account.

Whenever shell is different from "/bin/false/, then the user is able to login both via ftp and shell.

A also excluded the concatenation of the domain the case of an "shell-able" account.

 

Does it make sense to include this to the next froxlor release?

It would nice to have such a feature, since a lot of more experienced customers require ssh access.

Probably the name "FTP-Accounts" also needs to be changed then to FTP/SSH accounts.

 

@d00p: What do you think?

 

Best,

Manuel

Link to post
Share on other sites

 

I have prepared the patch file now, if you give your mail address, I'll send it to you.

Below is just the svn diff, however I can also produce a patch file for the patch utilty.

 

Index: lng/english.lng.php
===================================================================
--- lng/english.lng.php (revision 1255)
+++ lng/english.lng.php (working copy)
@@ -67,7 +67,7 @@
$lng['customer']['emails'] = 'E-mail-Addresses';
$lng['customer']['accounts'] = 'E-mail-Accounts';
$lng['customer']['forwarders'] = 'E-mail-Forwarders';
-$lng['customer']['ftps'] = 'FTP-Accounts';
+$lng['customer']['ftps'] = 'FTP/SSH-Accounts';
$lng['customer']['subdomains'] = 'Sub-Domain';
$lng['customer']['domains'] = 'Domain';
$lng['customer']['unlimited'] = 'unlimited';
@@ -87,7 +87,7 @@
$lng['menue']['mysql']['phpmyadmin'] = 'phpMyAdmin';
$lng['menue']['domains']['domains'] = 'Domains';
$lng['menue']['domains']['settings'] = 'Settings';
-$lng['menue']['ftp']['ftp'] = 'FTP';
+$lng['menue']['ftp']['ftp'] = 'FTP/SSH';
$lng['menue']['ftp']['accounts'] = 'Accounts';
$lng['menue']['ftp']['webftp'] = 'WebFTP';
$lng['menue']['extras']['extras'] = 'Extras';
@@ -146,7 +146,7 @@
 * FTP
 */

-$lng['ftp']['description'] = 'Here you can create and change your FTP accounts.<br />The changes are made instantly and the accounts can be used immediately.';
+$lng['ftp']['description'] = 'Here you can create and change your FTP and SSH accounts.<br />The changes are made instantly and the accounts can be used immediately. If the Shell is set to "/bin/false", access is only via FTP, else via FTP and SSH.';
$lng['ftp']['account_add'] = 'Create Account';

/**
@@ -252,7 +252,7 @@
$lng['question']['email_reallydelete_forwarder'] = 'Do you really want to delete the forwarder %s?';
$lng['question']['extras_reallydelete'] = 'Do you really want to delete the directory protection for %s?';
$lng['question']['extras_reallydelete_pathoptions'] = 'Do you really want to delete the path options for %s?';
-$lng['question']['ftp_reallydelete'] = 'Do you really want to delete the FTP account %s?';
+$lng['question']['ftp_reallydelete'] = 'Do you really want to delete the FTP/SSH account %s?';
$lng['question']['mysql_reallydelete'] = 'Do you really want to delete the database %s? This cannot be undone!';
$lng['question']['admin_configs_reallyrebuild'] = 'Do you really want to rebuild all config files?';
$lng['question']['admin_customer_alsoremovefiles'] = 'Remove user files too?';
@@ -1498,4 +1498,7 @@
$lng['admin']['templates']['forgotpwd'] = 'Notification-mails for password-reset';
$lng['admin']['templates']['password_reset'] = 'Customer-notification for passwort-reset';

+// Added by Manuel Lamotte-Schubert
+$lng['panel']['shell'] = 'Shell';
+$lng['panel']['shellDescription'] = 'Default is "/bin/false"';
?>
Index: lng/german.lng.php
===================================================================
--- lng/german.lng.php  (revision 1255)
+++ lng/german.lng.php  (working copy)
@@ -67,7 +67,7 @@
$lng['customer']['emails'] = 'E-Mail-Adressen';
$lng['customer']['accounts'] = 'E-Mail-Konten';
$lng['customer']['forwarders'] = 'E-Mail-Weiterleitungen';
-$lng['customer']['ftps'] = 'FTP-Konten';
+$lng['customer']['ftps'] = 'FTP/SSH-Konten';
$lng['customer']['subdomains'] = 'Sub-Domain(s)';
$lng['customer']['domains'] = 'Domain(s)';
$lng['customer']['unlimited'] = 'unbegrenzt';
@@ -87,7 +87,7 @@
$lng['menue']['mysql']['phpmyadmin'] = 'phpMyAdmin';
$lng['menue']['domains']['domains'] = 'Domains';
$lng['menue']['domains']['settings'] = 'Einstellungen';
-$lng['menue']['ftp']['ftp'] = 'FTP';
+$lng['menue']['ftp']['ftp'] = 'FTP/SSH';
$lng['menue']['ftp']['accounts'] = 'Benutzerkonten';
$lng['menue']['ftp']['webftp'] = 'WebFTP';
$lng['menue']['extras']['extras'] = 'Extras';
@@ -146,7 +146,7 @@
 * FTP
 */

-$lng['ftp']['description'] = 'Hier können Sie zusätzliche FTP-Konten einrichten.<br />Die Änderungen sind sofort wirksam und die FTP-Konten sofort benutzbar.';
+$lng['ftp']['description'] = 'Hier können Sie zusätzliche FTP- und SSH-Konten einrichten.<br />Die Änderungen sind sofort wirksam und die FTP-Konten sofort benutzbar. Wird als Shell "/bin/false" festgelegt, ist der Zugriff nur per FTP möglich, ansonsten per FTP und SSH.';
$lng['ftp']['account_add'] = 'Benutzerkonto anlegen';

/**
@@ -252,7 +252,7 @@
$lng['question']['email_reallydelete_forwarder'] = 'Wollen Sie die Weiterleitung %s wirklich löschen?';
$lng['question']['extras_reallydelete'] = 'Wollen Sie den Verzeichnisschutz für %s wirklich löschen?';
$lng['question']['extras_reallydelete_pathoptions'] = 'Wollen Sie die Optionen für den Pfad %s wirklich löschen?';
-$lng['question']['ftp_reallydelete'] = 'Wollen Sie das FTP-Benutzerkonto %s wirklich löschen?';
+$lng['question']['ftp_reallydelete'] = 'Wollen Sie das FTP/SSH-Benutzerkonto %s wirklich löschen?';
$lng['question']['mysql_reallydelete'] = 'Wollen Sie die Datenbank %s wirklich löschen?<br />ACHTUNG! Alle Daten gehen unwiderruflich verloren!';
$lng['question']['admin_configs_reallyrebuild'] = 'Wollen Sie wirklich alle Konfigurationsdateien neu erstellen lassen?';
$lng['question']['admin_customer_alsoremovefiles'] = 'Auch Kunden-Daten löschen?';
@@ -1481,4 +1481,7 @@
$lng['admin']['templates']['forgotpwd'] = 'Benachrichtigungs-Mails bei Zurücksetzen des Passworts';
$lng['admin']['templates']['password_reset'] = 'Kunden-Benachrichtigung nach Zurücksetzen des Passworts';

+// Added by Manuel Lamotte-Schubert
+$lng['panel']['shell'] = 'Shell';
+$lng['panel']['shellDescription'] = 'Default ist "/bin/false" (Zugriff nur per FTP)';
?>
Index: templates/customer/ftp/accounts_edit.tpl
===================================================================
--- templates/customer/ftp/accounts_edit.tpl    (revision 1255)
+++ templates/customer/ftp/accounts_edit.tpl    (working copy)
@@ -27,6 +27,10 @@
                               <td class="main_field_display" nowrap="nowrap">{$pathSelect}</td>
                       </tr>
                       <tr>
+                                <td class="main_field_name">{$lng['panel']['shell']}:</td>
+                                <td class="main_field_display" nowrap="nowrap"><input type="text" class="text" name="ftp_shell" size="30" value="$shell"/></td>
+                        </tr>
+                       <tr>
                               <td class="main_field_name">{$lng['login']['password']}:<br /><font size="1">{$lng['ftp']['editpassdescription']}</font></td>
                               <td class="main_field_display" nowrap="nowrap"><input type="password" name="ftp_password" maxlength="50" /></td>
                       </tr>
Index: templates/customer/ftp/accounts_add.tpl
===================================================================
--- templates/customer/ftp/accounts_add.tpl     (revision 1255)
+++ templates/customer/ftp/accounts_add.tpl     (working copy)
@@ -22,6 +22,11 @@
                               <td class="main_field_display" nowrap="nowrap">{$pathSelect}</td>
                       </tr>
                       <tr>
+                                <td class="main_field_name">{$lng['panel']['shell']}:<br /><font size="1">{$lng['panel']['shellDescription']}</font></td>
+                                <td class="main_field_display" nowrap="nowrap"><input type="text" class="text" name="ftp_shell" size="30" /></td>
+                        </tr>
+
+                       <tr>
                               <td class="main_field_name">{$lng['login']['password']}:</td>
                               <td class="main_field_display" nowrap="nowrap"><input type="password" name="ftp_password" size="30" /></td>
                       </tr>
Index: templates/customer/ftp/accounts_account.tpl
===================================================================
--- templates/customer/ftp/accounts_account.tpl (revision 1255)
+++ templates/customer/ftp/accounts_account.tpl (working copy)
@@ -1,6 +1,7 @@
<tr class="" onmouseover="this.className='RowOverSelected';" onmouseout="this.className='';">
       <td class="field_name_border_left">{$row['username']}</td>
       <td class="field_name">{$row['documentroot']}</td>
+       <td class="field_name">{$row['shell']}</td>
       <td class="field_name"><a href="$filename?page=accounts&action=edit&id={$row['id']}&s=$s">{$lng['panel']['edit']}</a></td>
       <td class="field_name"><a href="$filename?page=accounts&action=delete&id={$row['id']}&s=$s">{$lng['panel']['delete']}</a></td>
</tr>
Index: templates/customer/ftp/accounts.tpl
===================================================================
--- templates/customer/ftp/accounts.tpl (revision 1255)
+++ templates/customer/ftp/accounts.tpl (working copy)
@@ -16,6 +16,7 @@
                       <tr>
                               <td class="field_display_border_left">{$lng['login']['username']}  {$arrowcode['username']}</td>
                               <td class="field_display">{$lng['panel']['path']}  {$arrowcode['homedir']}</td>
+                               <td class="field_display">{$lng['panel']['shell']}</td>
                               <td class="field_display_search" colspan="2">{$sortcode}</td>
                       </tr>
                       $accounts
Index: customer_ftp.php
===================================================================
--- customer_ftp.php    (revision 1255)
+++ customer_ftp.php    (working copy)
@@ -49,7 +49,7 @@
                       'homedir' => $lng['panel']['path']
               );
               $paging = new paging($userinfo, $db, TABLE_FTP_USERS, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']);
-               $result = $db->query("SELECT `id`, `username`, `homedir` FROM `" . TABLE_FTP_USERS . "` WHERE `customerid`='" . $userinfo['customerid'] . "' " . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
+               $result = $db->query("SELECT `id`, `username`, `homedir`, `shell` FROM `" . TABLE_FTP_USERS . "` WHERE `customerid`='" . $userinfo['customerid'] . "' " . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
               $paging->setEntries($db->num_rows($result));
               $sortcode = $paging->getHtmlSortCode($lng);
               $arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
@@ -146,6 +146,7 @@
                               $path = validate($_POST['path'], 'path');
                               $password = validate($_POST['ftp_password'], 'password');
                               $password = validatePassword($password);
+                               $shell = $_POST['ftp_shell'];

                               $sendinfomail = intval($_POST['sendinfomail']);
                               if($sendinfomail != 1)
@@ -166,7 +167,10 @@
                                       {
                                               standard_error('maindomainnonexist', $domain);
                                       }
-                                       $username = $ftpusername . "@" . $ftpdomain;
+                                       if($shell == '' || $shell == '/bin/false')
+                                        {
+                                                  $username = $ftpusername . "@" . $ftpdomain;
+                                        }
                               }
                               else
                               {
@@ -191,7 +195,8 @@
                               {
                                       $path = makeCorrectDir($userinfo['documentroot'] . '/' . $path);

-                                       $db->query("INSERT INTO `" . TABLE_FTP_USERS . "` (`customerid`, `username`, `password`, `homedir`, `login_enabled`, `uid`, `gid`) VALUES ('" . (int)$userinfo['customerid'] . "', '" . $db->escape($username) . "', ENCRYPT('" . $db->escape($password) . "'), '" . $db->escape($path) . "', 'y', '" . (int)$userinfo['guid'] . "', '" . (int)$userinfo['guid'] . "')");
+                                       $db->query("INSERT INTO `" . TABLE_FTP_USERS . "` (`customerid`, `username`, `password`, `homedir`, `shell`, `login_enabled`, `uid`, `gid`) VALUES ('" . (int)$userinfo['customerid'] . "', '" . $db->escape($username) . "', ENCRYPT('" . $db->escape($password) . "'), '" . $db->escape($path) . "', '" . $d
+b->escape($shell) . "', 'y', '" . (int)$userinfo['guid'] . "', '" . (int)$userinfo['guid'] . "')");
                                       $result = $db->query("SELECT `bytes_in_used` FROM `" . TABLE_FTP_QUOTATALLIES . "` WHERE `name` = '" . $userinfo['loginname'] . "'");
                                       while($row = $db->fetch_array($result))
                                       {
@@ -269,7 +274,7 @@
       elseif($action == 'edit'
              && $id != 0)
       {
-               $result = $db->query_first("SELECT `id`, `username`, `homedir`, `uid`, `gid` FROM `" . TABLE_FTP_USERS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
+               $result = $db->query_first("SELECT `id`, `username`, `homedir`, `shell`, `uid`, `gid` FROM `" . TABLE_FTP_USERS . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");

               if(isset($result['username'])
                  && $result['username'] != '')
@@ -278,6 +283,7 @@
                          && $_POST['send'] == 'send')
                       {
                               $path = validate($_POST['path'], 'path');
+                               $shell = $_POST['ftp_shell'];

                               $_setnewpass = false;
                               if(isset($_POST['ftp_password']) && $_POST['ftp_password'] != '')
@@ -315,6 +321,11 @@
                                               $log->logAction(USR_ACTION, LOG_INFO, "updated ftp-account homdir for '" . $result['username'] . "'");
                                               $db->query("UPDATE `" . TABLE_FTP_USERS . "` SET `homedir`= '" . $db->escape($path) . "' WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
                                       }
+                                       if($shell != '')
+                                       {
+                                               $log->logAction(USR_ACTION, LOG_INFO, "updated ftp-account shell for '" . $result['username'] . "'");
+                                               $db->query("UPDATE `" . TABLE_FTP_USERS . "` SET `shell`= '" . $db->escape($shell) . "' WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
+                                               }
                               }

                               redirectTo($filename, Array('page' => $page, 's' => $s));
@@ -333,6 +344,8 @@

                               $pathSelect = makePathfield($userinfo['documentroot'], $userinfo['guid'], $userinfo['guid'], $settings['panel']['pathedit'], $homedir);

+                               $shell = $result['shell'];
+
                               if($settings['customer']['ftpatdomain'] == '1')
                               {
                                       $domains = '';

 

Cheers,

Manuel

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...