diskspace plugin mod for Multi-User with Linux Quota

das329717

Member
May 25, 2018
928
0
16
Hello all,
here is my diskspace plugin modification to support a Multi-User environment with Linux Quota.
I don't know if is the proper way to do this, but is my first try.

1 ) Linux user need a quota.

2 ) ruTorrent & diskspace plugin need a modification.

* /var/www/rutorrent/conf/users/xxx/config.php
Add this line with the linux username.
Code: [Select]
$quotaUser = 'xxx';
* /var/www/rutorrent/plugins/diskspace/action.php
Execute the modification if quotaUser exist, else use the original diskspace plugin.
Code:
<?php
require_once( &#39;../../php/util.php&#39; );

if (isset($quotaUser)) {
cachedEcho(&#39;{ total: &#39;.shell_exec("/usr/sbin/repquota -u /home | grep ^".$quotaUser." | awk &#39;{print \$4*1024}&#39;").&#39;, free: &#39;.shell_exec("/usr/sbin/repquota -u /home | grep ^".$quotaUser." | awk &#39;{print (\$4-\$3)*1024}&#39;").&#39; }&#39;,"application/json");
} else {
cachedEcho(&#39;{ total: &#39;.disk_total_space($topDirectory).&#39;, free: &#39;.disk_free_space($topDirectory).&#39; }&#39;,"application/json");
}
?>

have fun and thank sam.
 

dsouvik215

Member
May 25, 2018
896
0
16
just to be clear, this does nothing to fix the bug which causes quotas to crash/lock up rtorrent.

All this does is display quota space.
 

das329717

Member
May 25, 2018
928
0
16
this does nothing to fix the bug which causes quotas to crash/lock up rtorrent.
Shell returns result with a line break at the end. You need something like

$total = trim(shell_exec("/usr/sbin/repquota -u / | /bin/grep ^".$quotaUser." | awk '{printf \$4*1024}'"));
$free = trim(shell_exec("/usr/sbin/repquota -u / | /bin/grep ^".$quotaUser." | awk '{printf (\$4-\$3)*1024}'"));
 

somus1735

Member
May 25, 2018
833
0
16
you could use sudo.


something like:
Code:
www-data ALL=(rtuser1, rtuser2, rtuser3, rtuser3) NOPASSWD: /usr/bin/quota

then
Code:
sudo -u rtuser1 quota
 

dsouvik215

Member
May 25, 2018
896
0
16
alright, its working, security is gay. undecided.gif

[root@www ~]# grep apache /etc/sudoers
## allow apache to run repquota
apache ALL=(root) NOPASSWD: /usr/sbin/repquota
[root@www ~]# grep requiretty /etc/sudoers
#Defaults requiretty
[root@www ~]#

[root@www public_html]# grep quotaUser conf/users/testguy/config.php
$quotaUser = 'testguy';

[root@www diskspace]# cat action.php
<?php
require_once( '../../php/util.php' );
if (isset($quotaUser)) {
$total = shell_exec("/usr/bin/sudo /usr/sbin/repquota -u / | /bin/grep ^".$quotaUser." | /bin/awk '{printf \$4*1024}'");
$free = shell_exec("/usr/bin/sudo /usr/sbin/repquota -u / | /bin/grep ^".$quotaUser." | /bin/awk '{printf (\$4-\$3)*1024}'");
cachedEcho('{ total: '.$total.', free: '.$free.' }',"application/json");
} else {
cachedEcho('{ total: '.disk_total_space($topDirectory).', free: '.disk_free_space($topDirectory).' }',"application/json");
}

?>
 

das329717

Member
May 25, 2018
928
0
16
alright, its working, security is gay. undecided.gif

[root@www ~]# grep apache /etc/sudoers
## allow apache to run repquota
apache ALL=(root) NOPASSWD: /usr/sbin/repquota
[root@www ~]# grep requiretty /etc/sudoers
#Defaults requiretty
[root@www ~]#

[root@www public_html]# grep quotaUser conf/users/testguy/config.php
$quotaUser = 'testguy';

[root@www diskspace]# cat action.php
<?php
require_once( '../../php/util.php' );
if (isset($quotaUser)) {
$total = shell_exec("/usr/bin/sudo /usr/sbin/repquota -u / | /bin/grep ^".$quotaUser." | /bin/awk '{printf \$4*1024}'");
$free = shell_exec("/usr/bin/sudo /usr/sbin/repquota -u / | /bin/grep ^".$quotaUser." | /bin/awk '{printf (\$4-\$3)*1024}'");
cachedEcho('{ total: '.$total.', free: '.$free.' }',"application/json");
} else {
cachedEcho('{ total: '.disk_total_space($topDirectory).', free: '.disk_free_space($topDirectory).' }',"application/json");
}

?>
 

somus1735

Member
May 25, 2018
833
0
16
low space killer

grep RPC2-testuser /etc/httpd/conf.d/scgi.conf
SCGIMount /RPC2-testuser 127.0.0.1:5098

crontab -l|grep quota
* * * * * /root/process-rtorrent-quota.pl > /dev/null 2>&1

cat /root/process-rtorrent-quota.pl
#!/usr/bin/perl
#
# process rtorrent quota
#

$http_scgi_conf = "/etc/httpd/conf.d/scgi.conf";
$quota_drive = "/";
$percent_kill = "0.95";

open(FILE, "/usr/sbin/repquota -u $quota_drive |");
while(<FILE>) {
#testguy -- 361448 5242880 5242880 19 0 0
if ( /^([\w-]+)\s+--\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+\s+\d+\s+\d+/) {
if ( $3 > 0 && $4 > 0 ) {
$user = $1;
print "valid user $user\n";
$used_space = $2;
$soft_quota = $3;
$hard_quota = $4;
# 34% = 0.344703674316406
$percent_used = ($used_space/$soft_quota);
if ( $percent_used >= $percent_kill ) {
$rpc2 = (`/bin/grep $user $http_scgi_conf | /bin/awk '{printf \$2 }'`);
system("/usr/bin/xmlrpc http://localhost/$rpc2 d.multicall '' d.stop= d.close= > /dev/null");
}
}
}
}
close(FILE);
 

dsouvik215

Member
May 25, 2018
896
0
16
After some fiddling I've made the display part of this work with rutorrent 3.6 on Ubuntu 12.04 LTS and thought I'd share the config that works for me. I agree this isn't particularly secure.

#cat /etc/sudoers
Code:
...
#Defaults requiretty
...
www-data ALL=(root) NOPASSWD: /usr/sbin/repquota
...
# grep quotaUser conf/users/testguy/config.php
$quotaUser = 'testguy';

#sudo cat /var/www/webui/plugins/diskspace/action.php
Code:
<?php
require_once( '../../php/util.php' );
if (isset($quotaUser)) {
$total = shell_exec("/usr/bin/sudo /usr/sbin/repquota -u /home | /bin/grep ^".$quotaUser." | /usr/bin/awk '{printf $4*1024}'");
$free = shell_exec("/usr/bin/sudo /usr/sbin/repquota -u /home | /bin/grep ^".$quotaUser." | /usr/bin/awk '{printf ($4-$3)*1024}'");
cachedEcho('{ "total": '.$total.', "free": '.$free.' }',"application/json");
} else {
cachedEcho('{ "total": '.disk_total_space($topDirectory).', "free": '.disk_free_space($topDirectory).' }',"application/json");
}

?>


REMEMBER to change /home to the directory that is under quota on your system.