Tag Archives: PHP

SMF 2.0 with PHP 7

SMF does not officially support running version 2.0.x with PHP 7.0.  This is due to PHP removing the mysql library in favor of more secure MySQLi library.  To get around this if you have root access to your server, you could manually build in the old mysql library functions.  Or you know, build compatibility functions.  I’m releasing this as a proof of concept that this works, I highly suggest migrating all code toMySQLi functions rather than using this, but it provides a simple path that allows you to upgrade PHP and enough time to migrate your code base over.

In $sourcedir/Subs-Db-mysql.php Find:

Add before this:

Now find:

Replace with:

In $sourcedir/Subs-Compat.php at the end before ?> add:

 

This should allow SMF to run just fine.  These are all the functions SMF calls from it’s database abstraction layer and thus should work.  Anyone using mysql functions outside of SMF’s database abstraction layer may need to add in additional functions.

Read More

iRedMail on Nginx

This is my experiment to get iRedMail to work with Nginx. In the end I got everything to work other than awstats, although with some caveats. I don’t like awstats very much and it seemed quite troublesome to get it setup. There is a mode to run awstats in that lets it just generate static files, which to me seem to be a better solution. I did testing only on Debian 6.0.7, although it should also work in Ubuntu just fine. It was also limited testing on brand new VMs.

So I am starting out with a brand new Debian 6.0.7 system. First things first we setup our hosts and hostname file. For my test environment I used mail.debian.test as my test environment. Then I grabbed the latest iRedMail which happened to be 0.8.3 at the time of writing this. I did this via wget in a ssh session. I had to install bzip2 to “tar -xf” it, so a quick “apt-get install bzip2” resolved that. I then ran the iRedMail installer and let it complete.

Now to stop apache services for good:

Optionally we can run “apt-get remove apache2” to get rid of apache binaries as well.

Now, I needed Nginx and php5-fpm (as I prefer fpm). This takes a little work as Debian 6.0.7 doesn’t have it in its default sources. This would have been easier on Ubuntu.

What I did her is first install nginx and curl. Then I added dotdeb to the sources list, added its key and then updated my sources. Finally I was able to install fpm.
Now that the applications are in place, I need to write their configuration files. Here is the list of files I will be using:
Nginx’s iRedMail site configuration file
php5’s FPM iRedMail web pool file
iRedMail init.d file to launch the iredadmin pyton webservice

During additional testing I uploaded the files and just used curl to put them into place. The init.d script is borrowed from the web (exactly where I can’t remember as I used bites and pieces from multiple places). However I don’t feel the need to write out or explain in great detail all off the changes.

You will need to modify the nginx file (/etc/nginx/sites-available/iRedMail) to contain the correct domain. As well you will need an additional dns enter for iredadmin.domain.tld (in my case iredadmin.debian.test). If this is your only/first ssl site or you prefer it to be default you will need to adjust the ssl section. I added comments to explain that. Nginx expects a default website and if none exist it won’t start.

As for the additional domain, I tried my best, but it seems there is no way to have the perl script to be aware its in a sub directory and pass the correct urls to its output templates. Although the template has the capability to do a homepath variable, this seems to be set from ctx in perl which from my limited knowledge I don’t believe is changeable via environment/server variables. I also didn’t see a way to change that in any setting. Hopefully the iRedMail developers can make this change in future versions.
The good news is the iRedMail developers had foresight to setup the script to run very smoothly as a stanalone python web server via a cgi socket. So no additional work to make that run is needed. I had hoped to use the iredapd service to launch this, but it appears to crash and fail horribly. So I setup a second instance to do this.

Now just a little more work to activate the new service, link the file as a live nginx site and restart some services.

Thats it. Now when I hit mail.debian.test I get the webmail portal. When I access iredadmin.debian.test I get the admin portal. phpmyadmin is also setup on mail.debian.test/phpmyadmin

Setting this up for Ubuntu should be easier, as 12.04 has php5-fpm in its packages so there is no need to add in the dotdeb resources. Everything else would be the same for it.

Nginx has always been flaky for me while doing Ipv6 services. I intended to include them but it just wasn’t playing nicely enough. Sometimes just doing [::]:80 to a listen will make it listen. Other times I have to specify it twice (and it doesn’t complain). Then again if I try it on 443 using [::]:443 nginx may not want to start at all, while it accepted [::]:80 just fine. So because of how picky it can be at times, I just opted to go with ipv4 only support here.

Read More

Pastebin rewrote

I have taken my original code I wrote for my SMF powered pastebin and rewrote this script. This was a massive rewrite from the original code and hopefully it works out well for anyone else who is looking into using it.

I wrote it so it should be plugable with different databases, user information and templating engines. The design was mostly to implant it into my mixed environment of SMF and WordPress, but also to make it robust so it could be used in other ways.

The source of the code is up on GitHub at https://github.com/jdarwood007/pastebin

Read More

SMF in WordPress

For some reason, while using WordPress and including SMF’s SSI.php, it would not detect my logged in SMF session. Baffled and almost thinking this was a SMF bug of some sorts, I began to debug this process.

Well it turns out it is sorta a SMF old PHP support issue, but the problem lies in WordPress. This is the function in WordPress wp-includes/load.php

The problem here, is that they add magic quotes to the cookie. Not quite sure why they are even doing this. But it broke adding SMF. The part in SMF which failed because of this is in SMFs Sources/Load.php in the loadUserSettings function

Because of old PHP support in SMF, its trying to combat a cookie security issue that existed below PHP 4.3.9. Now I don’t use that version, but I rather not strip out the code. The preg match was failing because it was not finding that valid string in the cookie. Since all the double quotes where escaped with a slash \.

For my code, I called in Settings.php from SMF and then did a stripslashes on the cookie. Then I included SSI.php, with the results I expected of it finding my active SMF session.

I should note because SMF uses a lot of global variables, that I had to globalize all of those before hand. I just borrowed the globals from SSI.php and put them into that scripts function.

Read More

SMF Package Manager Generator

Hello,
Originally I had wrote my original SMF Package Manager Generator a few years ago. It was sloppy coding, poor JavaScript and relied heavily on the server. Not my absolute best work, but was something I was proud on at the time from my efforts to dive into JavaScripting.

However, todays times are different. So with JQuery out there, I decided to take breaks from my projects for a couple hours for a few days and put forth a effort to rewrite this. Needless to say, I had the initial code wrote in only a few hours. My original script took me a few days alone. That didn’t count the package-info creator I made later which also took a while.

The new script attempts to rely all on JavaScripting via JQuery. It was a fun experience to build it this way. Although, because of JavaScript’s security measures, I couldn’t leave downloading the file outside of the server. So alas, I still have to process the actual download via the server. There is a work around with using Data URIs, however it didn’t provide the filename and sounds a bit flaky when the length of the url gets to be a bit long. I included both as a option though.

Oh and Its on github, because I see no reason to not share the code. Including the code I used to integrate it into my WordPress blog.

Read More

WordPress templates on non wordpress pages

I have a couple pages such as my password generate that are non wordpress templates. However I want these to be styled as if they where from my wordpress. So after some google searches, I came up with very little information. I decided to dive into the code and came up with something that works for what I need it to do and requires little code edits to any of my pages to work.

This does also require a template edit to your wordpress templates. Sadly I couldn’t avoid this, I looked around and tried to see if I could modify the_content(), however it doesn’t look very pleasant to do so. I might in the future look into doing this. If somebody has a better solution that requires no wordpress template edits, please let me know. Back on topic, I modified page.php in my template and changed:

To this line:

Next I will just dump a file I named wp-ssi.php and explain how it works at the end.

Now for all my files I add at the very top. Of course, you need to substitute the path to match yours.

As for wp-ssi.php, I will can explain more about how that works.
(more…)

Read More

Highslide for Wordpress Plugin