Author Topic: replace quota area with logged in user specific php code  (Read 8194 times)

Offline johnwayne

  • Jr. Member
  • **
  • Posts: 21
replace quota area with logged in user specific php code
« on: October 19, 2015, 04:39:24 AM »
I run roundcube on accounts with unlimited storage without root access, meaning no values to access for account usage. I have written php that opens the imap folders and returns a total. instead of showing usage "unlimited" in the lower left, I would like to be able to have my php code be run for the logged in user, to report the total usage for the account.

my initial thought is some addition to the login screen code that passes the username and password entries also to a bit of code accessed by that area of the interface, thereafter directing it to the php code to measure the account, passing along the variables of the username and password entered at login. also because of the overhead consumed by measuring the account, that the php action in that area only be run at login, not with each refresh by the interface.

alternatively, if the login could pass the info to the php which could populate a user specific html, and pass to the area in the interface where quota is displayed, allow an iframe or such to retrieve the then populated user specific html page to display in that area. then the system refresh would just be grabbing the html result page every time, and I could add in a button to re-run the php on demand.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,850
Re: replace quota area with logged in user specific php code
« Reply #1 on: October 19, 2015, 05:36:02 AM »
I think the best way would be to write a plugin which uses the 'quota' hook (see http://trac.roundcube.net/wiki/Plugin_Hooks#quota) then you can alter the displayed quota info any way you like.

Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline johnwayne

  • Jr. Member
  • **
  • Posts: 21
Re: replace quota area with logged in user specific php code
« Reply #2 on: October 19, 2015, 04:08:55 PM »
excellent point. but rather than write a plugin that tries at the same quota data that does not exist due to the setup, how would I go about changing where that part of the interface looks for quota values? if it would check for values within a file on the site root instead of values at the storage - I'd be golden.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,850
Re: replace quota area with logged in user specific php code
« Reply #3 on: October 20, 2015, 02:42:04 AM »
thats what i am saying you can change where it looks for quota info by creating a plugin which is attached to that hook. you can make it look for the info where ever you want.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline johnwayne

  • Jr. Member
  • **
  • Posts: 21
Re: replace quota area with logged in user specific php code
« Reply #4 on: October 20, 2015, 09:21:01 PM »
@JohnDoh do you have any folks you'd recommend for writing custom plugins? i wouldnt be opposed to paying something for the build and sharing my php code i wrote. i need this to happen faster than brute trial & error on my part.

Offline johnwayne

  • Jr. Member
  • **
  • Posts: 21
Re: replace quota area with logged in user specific php code
« Reply #5 on: October 20, 2015, 11:44:07 PM »
my roundcube is version 1.1
in /program/lib/Roundcube/rcube_imap.php
line 3089 - 3096
Code: [Select]
    public function get_quota($folder = null)
    {
        if ($this->get_capability('QUOTA') && $this->check_connection()) {
            return $this->conn->getQuota($folder);
        }

        return false;
    }
could this be edited to retrieve values from my php page instead of reaching the imap server?

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,850
Re: replace quota area with logged in user specific php code
« Reply #6 on: October 21, 2015, 01:01:13 PM »
try the attached example plugin file.

you need to add your custom code to it obv.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline johnwayne

  • Jr. Member
  • **
  • Posts: 21
Re: replace quota area with logged in user specific php code
« Reply #7 on: November 10, 2015, 04:44:43 AM »
@JohnDoh that solution works VERY well!! Thank you for that!

the resulting issue is that my code is run at each and every folder change - which can cause a major slowdown for the user experience. So I'm back to figuring out how to work some routine into the submission of the login to populate values in a temporary file, which this plugin can then grab its values from. Yes, grabbing the usage at each login is sufficient, it does not have to update each folder change.

Actually, the temporary file populated at login via the login values, would have to be designated to the account holder, and the plugin for the custom_quota know to grab the values for the logged in account. There is of course more than one user per this roundcube install. Perhaps adding some variable to the MySQL database associated with this roundcube install, and using it.

Thanks,
johnwayne
« Last Edit: November 10, 2015, 04:51:35 AM by johnwayne »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,850
Re: replace quota area with logged in user specific php code
« Reply #8 on: November 10, 2015, 01:27:25 PM »
I'd say it was better to save it to the session rather than a file. Its still a ugly solution though because it means that most of the time the quota display wll be wrong - as it was caculated once at login but never updated to reflact things done by the user during the session. Really I do not think you'll get a nice clean solution unless you enable quotas on your IMAP server and let those manage it.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,878
    • SKaero - Custom Roundcube development
Re: replace quota area with logged in user specific php code
« Reply #9 on: November 10, 2015, 08:32:55 PM »
If you have a script that figures out the quota maybe its best to build a cron that figures out the quota every 15 minutes or so and then updates a database that Roundcube can pull off of. That way you can offload the work from runtime and still make sure the quotas are up to date within reason.

Offline johnwayne

  • Jr. Member
  • **
  • Posts: 21
Re: replace quota area with logged in user specific php code
« Reply #10 on: October 19, 2016, 03:20:55 AM »
@JohnDoh
i do see your point, but we're working in GBs and softcaps so a days work in an account isnt going to wildly resize the account, im not serving a large corporation.
did i ever share my code with you as promised? you did supply the means to implement it.

@SKareo
great suggestion, but just as my response to JohnDoh - the instant size of an account is not an issue, just need a periodic check. with hundreds of users, no need to put unnecessary overhead on the servers.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,878
    • SKaero - Custom Roundcube development
Re: replace quota area with logged in user specific php code
« Reply #11 on: October 19, 2016, 11:56:15 AM »
If you just need to see it, like a monthly report or something like that your only real option to get accurate numbers is to check directly and by-pass Roundcube.