Koozali.org: home of the SME Server

SME Server PHP abstraction layer (interface class)

Offline madadam

  • *
  • 149
  • +0/-0
    • http://www.extremetourist.com
SME Server PHP abstraction layer (interface class)
« on: September 06, 2011, 04:31:26 AM »
Hi,

I want to be able to perform management tasks of my SME Server from PHP to offer an integrated service to client's that use services hosted on my server.

As yet I don't know of any PHP library that abstracts common SME Server functions. If anyone knows of one I would appreciate a heads-up.

In the meantime I've started working on my own. There seems to be a number of ways to do this (none perfect) and I thought I'd discuss it here.

The first option is only half an option as it can only be used for READING the configuration but not writing and thats by simply opening the flat-text database files at /home/e-smith/db.

The second option would be the most complex and would involve somehow integrating a PERL interpreter into PHP (not sure if it's built in or not but there are add on modules for this) and using the native SME PERL database library. Whether this would work or not I'm not even sure and hope that someone may be able to set the record straight on this.

The third option I can see is much easier but does have security implications. This involves using one of the PHP command shell commands (exec/system etc) to query the SME database and to commit changes to the database. The only problem with this is that to do so you have to grant special privileges to PHP/Apache to execute /sbin/e-smith/db by modifying the /etc/sudoers file so that the user www can be given root access (without a password) for just one command - albeit one very important and potentially dangerous command.

Does anyone know of another method that I've neglected or have any recommendations on the above? Is anyone else interested in the resulting PHP class?

Cheers,

Adam
...

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: SME Server PHP abstraction layer (interface class)
« Reply #1 on: September 06, 2011, 11:04:43 AM »
I suggest you to invest in improving/modifying the userpanels contrib.. you are just trying to re-invent the wheel

moreover, you should tell us what you are trying to achieve and why the contrib doesn't fit your needs

Offline madadam

  • *
  • 149
  • +0/-0
    • http://www.extremetourist.com
Re: SME Server PHP abstraction layer (interface class)
« Reply #2 on: September 06, 2011, 04:03:05 PM »
I suggest you to invest in improving/modifying the userpanels contrib.. you are just trying to re-invent the wheel

moreover, you should tell us what you are trying to achieve and why the contrib doesn't fit your needs

Hi Stafano,

Thank you for your reply. I think you missed a key word in my message and that was "integrated". Taking clients from a well-constructed modern AJAX style website to the more bare-bones user-panel is too jolting to most non-IT people. A high-level of integration is expected by many web users these days and when offering internet services to such clients you really need to offer an easy to use yet sophisticated environment.

There are many such systems available for other platforms including CentOS but because of SME's unique template-driven system I've not come across one that works with SME without breaking the templates. I'm a big fan of SME so prefer to stick to SME and find a way to offer some sort of basic PHP API to allow developers to build on top of SME systems.

Cheers,

Adam
...

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: SME Server PHP abstraction layer (interface class)
« Reply #3 on: September 06, 2011, 05:23:07 PM »
I think you are taking this much too lightly and have a wrong sense of the terms in this task.

I don not understand why you need PHP for that, if you are after a AJAX like interface, PHP has nothing to do with that. You could IMHO just as easily extend the whole existing framework with a javascript based library, for instance jQuery and make the code work with that. PHP has nothing to do with AJAX, it is just another server side language to code things in.

Choosing PHP would mean you will have to code a lot off things that are already coded (very well) in perl, like for instance the code to access and modify the internal configuration database.
The whole idea of AJAX based websites is that most off the logic runs client side: http://en.wikipedia.org/wiki/Ajax_%28programming%29 . If you for instance need to access the database you would have to setup a secure channel to prevent sensitive data from being intercepted to get the data using some sort of JSON based method, writing to it would be even harder.

A part from that PHP is not a very secure platform to write your code in... and yes I know SME Server does provide PHP but that is mainly as a requirement for the horde groupware packages which rely on PHP.

Although most browsers do support javascript using a AJAX based methodology you would exclude users who use the SME Server text based webbrowser from the admin console or have (explicitly) disabled javascript in their browser.
« Last Edit: September 06, 2011, 05:26:02 PM by cactus »
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline madadam

  • *
  • 149
  • +0/-0
    • http://www.extremetourist.com
Re: SME Server PHP abstraction layer (interface class)
« Reply #4 on: September 07, 2011, 03:16:15 AM »
It seems you are not listening. I am trying to provide an INTEGRATED client service which will INTEGRATE other services with some of the basic services of a Linux server such as mailbox management. I will not and a client will not accept (nor pay me) for a "solution" that jumps to another completely independent subsystem completely different in design and navigation to that offered by the user-panel.

As I said there are many such off-the-shelf systems on other platforms including CentOS, just non that will work with SME's unique template system. While SME's template system is very good and clever it's not the last word in modern modular interface design. As much as I like SME I'm really beginning to see the limitations to it unfortunately.

Adam
...

Offline madadam

  • *
  • 149
  • +0/-0
    • http://www.extremetourist.com
Re: SME Server PHP abstraction layer (interface class)
« Reply #5 on: September 07, 2011, 03:46:03 AM »
To be clear what I intend to do I'll try to explain in more simple terms.

I need a way to do some basic system administration tasks from within a website. These tasks are mostly related to user/mailbox management, most commonly creating new users/mailboxes, removing old users/mailboxes, defining new email groups and pseudonyms, setting email forwarding rules, setting vacation messages and changing user/mailbox passwords.

These are fairly basic tasks and are commonly done on management consoles such a C Panel on other Linux servers. As I already provide a number of services to my clients using our own proprietary system I would like to be able to integrate these basics tasks into the system. I have in the past tried to send clients to the SME user panels but my clients won't have a bar of it and have asked why they pay me money for such a bad system when they can get so much better elsewhere. From their perspective it's a good point.

Now SME is not really so different from other systems, at least configuration-wise - you've just got to follow the rules, you can't go around editing all the conf files etc. This isn't really so hard and there are a number of approaches that can be taken to ensure a stable system which I listed in my initial message.

Currently my preferred method is to simply have PHP send a shell command to SME's db program. Most (if not all) things can be achieved this way. To achieve this it is good programming practice to abstract this functionality in case of future changes to the way db works and in case we decide to do thing differentially. This way the code behind the web page simply puts a call into the SME management class and let's the SME management class worry about just how it goes about doing it.

I hope this is clearer for people. I have spoken to other people using SME in a web development environment and they all agree it would be great to have this functionality. Though they are more web developers and programmers than sys admins so I suspect my audience here is more slanted to sys admin. I'm a bit of both.

Adam

 
...

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: SME Server PHP abstraction layer (interface class)
« Reply #6 on: September 07, 2011, 01:55:10 PM »
Currently my preferred method is to simply have PHP send a shell command to SME's db program. Most (if not all) things can be achieved this way. To achieve this it is good programming practice to abstract this functionality in case of future changes to the way db works and in case we decide to do thing differentially. This way the code behind the web page simply puts a call into the SME management class and let's the SME management class worry about just how it goes about doing it.
I am a developer (also in web apps) first and then a sysadmin, but PHP still is a server side solution and has nothing to do with AJAX like solutions, as already stated if you like dynamic pages you will have to incorporate Javascript libraries and that can be done in perl as well as in PHP.
It seems you only focus on PHP because of your existing system and the desire of your customers not willing to use the server-manager. Perhaps you are using the wrong product to sell your customers. SME Server is not geared to webhosting solutions (only) as you seem to hint (with references to CPanel) at IMHO, SME Server is geared to be run on a server in a office as a replcament of Microsoft SBS for example.
What is the reason you choose SME Server and not plain CentOS with CPanel or your own custom solution? To me it seems you are having more trouble than it's worth to use SME Server in your used case.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline madadam

  • *
  • 149
  • +0/-0
    • http://www.extremetourist.com
Re: SME Server PHP abstraction layer (interface class)
« Reply #7 on: September 08, 2011, 04:52:32 AM »
I am a developer (also in web apps) first and then a sysadmin, but PHP still is a server side solution and has nothing to do with AJAX like solutions, as already stated if you like dynamic pages you will have to incorporate Javascript libraries and that can be done in perl as well as in PHP.
It seems you only focus on PHP because of your existing system and the desire of your customers not willing to use the server-manager. Perhaps you are using the wrong product to sell your customers. SME Server is not geared to webhosting solutions (only) as you seem to hint (with references to CPanel) at IMHO, SME Server is geared to be run on a server in a office as a replcament of Microsoft SBS for example.
What is the reason you choose SME Server and not plain CentOS with CPanel or your own custom solution? To me it seems you are having more trouble than it's worth to use SME Server in your used case.

You are right on many points except I must disagree about AJAX. The point of AJAX being the A for Asynchronous and X for XML is that aside from the client side processing it communicates with the server which sends through updates. The server processing can be done by any number of languages of course, so it's not limited to PHP. However PHP is very popular and the basis of most open-source packages and large websites like FaceBook and Twitter.

My customers are very happy with the solutions we provide but would like the additional functionality of being able to do basic mailbox admin. This really should't be a big problem. In fact using option three above it took me less than a day yesterday to write a class to do the above and put it in place.

But you're right SME Server really is best as a simple workgroup server, not a web server. But I have been using e-Smith/SME for a long time now and am a big fan. I've worked with contributors in putting together packages for SME. And the fact that SME only supports PHP 4 with the current production release is a major drawback. But security-wise SME has been rock-solid and I've never had a major security breach.

Every time I look at another OS such I feel like a cheating lover :-) I don't want to turn my back on SME as I think it's a terrific product that is largely unrecognised.

I'm not at all a fan of CPanel, it's just plain awful. I have been looking for other solutions for other services. What have you found?

Adam
...