Larry Brouwer

…just my technology sandbox …for my personal amusement only!

Browsing Posts published by Larry Brouwer

PHP Random Key Generator

No comments

Yesterday, I needed a way to generate a random alpha-numeric key of various lengths using PHP for a project that I’m currently working on. I didn’t find any built-in functions, so after some Googling, I decided to implement my own version.

    private function generateRandomKey($len)
    {
        $chars = array('1','2','3','4','5','6','7','8','9','0',
        'a','b','c','d','e','f','g','h','i','j','k','l','m',
        'n','o','p','q','r','s','t','u','v','w','x','y','z',
        'A','B','C','D','E','F','G','H','I','J','K','L','M',
        'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
        $min = 0;
        $max = sizeof($chars)-1;
        $key = "";

        for ($i=0;$i<$len;$i++) {
            $key .= $chars[mt_rand($min,$max)];
        }
        return $key;
    }

Let me know if anyone has a better suggestion?

While installing some demo software today, I had to create a self-signed SSL certificate for IIS7. This is a relatively easy thing to do within the IIS7 Manager. However, the certificate that IIS7 generates is only for the machine that it is running on. I need a certificate that has my custom web site domain name on it. As it turns out, Microsoft has eliminated this capability within IIS7, so the easiest way to accomplish this is to use the selfssl tool from IIS6.

It took me a while to figure out, but after some Googling (with much trial and error), here’s what I came up with.

I found a post, Self-Signed Certificates on IIS7, that I used to create and install the certificate.

First, I opened IIS7 Manager, and found the Web Site ID for my web application.

Second, I downloaded, IIS 6 Resources Kit Tools, and installed just the selfssl tool.

Third, I opened an Administrator command prompt and navigated to the selfssl location: C:\Program Files (x86)\IIS Resources\SelfSSL

Fourth, I executed the following command:

selfssl /N:CN=www.larrybrouwer.com /V:10 95 /S:6 /P:8443

That completes the configuration on the Server.

Now, on the client, open Internet Explorer with Administrator privileges.

Second, navigate to the secured site. Bypass the security warnings.

Third, view the certificate and Install it to the “Trusted Root Certification Authorities”, “Local Computer”.

Done!

So far, I’ve installed three (3) open source shopping carts; PrestaShop, OpenCart, and TomatoCart. All of these packages have been developed with PHP and MySQL technologies. This morning I’ve decided to see if there are any open source ecommerce packages written in a Microsoft .NET environment.

My first search lead me to the Microsoft Web Gallery. From there, I found nopCommerce. It looks like a reasonable package, so I’ve decided to install it and see what it looks like.

I wanted to first look at the documentation, however, it’s not free! I decided to download the product and install it anyway. I have two (2) choices for installing. The first way is to use the Microsoft Web Platform Installer. The second way is to manually download and install it. I’m choosing the latter, as I want to be sure to get the complete package with source code.

I then navigated to the nopCommerce download page, downloaded the latest release (v1.90 at the time of this writing) and extracted the Visual Studio solution to my development workstation. I opened the solution with Visual Studio, and realized that I didn’t “unblock” the downloaded zip file prior to extracting the solution to my hard drive. So I deleted the solution files, used Microsoft file explorer to change the properties to “Unblock” the zip file prior to extracting the files. I then re-extracted the files to my development environment and re-opened project with Visual Studio 2010. Much better now! No security warnings.

Next, I rebuilt the application and after verifying that it executed a clean build, I took the contents of the “NopCommerceStore” folder and copied to the “www\nopCommerce” folder on my development Web Server. I then added the new application using IIS7 Manager, and binded it to port 8004. I then opened the server’s firewall port.

I browsed to the nopCommerce Web Site, and immediately got the following error:

Server Error in ‘/’ Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized attribute ‘targetFramework’. Note that attribute names are case-sensitive.

Source Error:

Line 26: 			<error statusCode="404" redirect="filenotfound.htm"/>
Line 27: 		</customErrors>
Line 28: 		<compilation debug="true" targetFramework="4.0">
Line 29: 			<expressionBuilders>
Line 30: 				<add expressionPrefix="NopResources" type="NopSolutions.NopCommerce.BusinessLogic.Localization.NopResourceExpressionBuilder, Nop.BusinessLogic"/>

Source File: C:\Data\www\nopCommerce\web.config    Line: 28


Version Information: Microsoft .NET Framework Version:2.0.50727.4206; ASP.NET Version:2.0.50727.4209

 

My initial thoughts were that the Application Pool wasn’t set to the proper .NET Framework, so I used IIS7 Manager and changed it from .NET Framework v2.0.50727 to v4.0.30319. I then restarted the Application Pool, and the application is now loading fine.

I followed the installation instructions, and created a new Microsoft SQL Server schema and user. The only problem I encountered here was that I forgot to include the database instance name in the SQL Server name field. The format is “SERVER\INSTANCENAME”. Other than that, the installation process was a breeze.

After the installation was complete, I was able to browse to the home page and log into the application. From there, I was able to get into the administration section and begin configuring it.

I next renamed the existing “robots.txt” to “robots.txt.orig” and replaced it with the following to prevent spidering of my demo site:

# go away
User-agent: *
Disallow: /

I’ll keep updating this post as I continue exploring nopCommerce.

You’re welcome to visit my nopCommerce demo site here. It will be up and running while I’m developing at my desk during the day. If you would like help with your installation, just get in contact with me. I’m always happy to help out!

Updates:

One of the first modification that I did was to download the Five colour theme pack for front-end themes. To install the themes, simply extract the files from the download and drop them into the “APP_Themes” folder.

I’m continuing my evaluation of open source ecommerce packages by installing TomatoCart. TomatoCart was chosen as the second runner-up of the 2010 Open Source Awards as published by Packt Publishing.

I began my TomatoCart installation by reviewing the tomato Cart documentation WiKi. The wiki has many uncompleted links, but I managed to find the TomatoCart User Guide, which covered the basics needed to get the software installed.

I downloaded the current version, TomatoCart v1.1.3, and saved it to my “install\tomatocart” folder. I then created a new “tomatocart” folder under my “www” root folder and copied the contents of the “gtrunk2” folder from the downloaded file there.

I then went into Windows IIS7 Manager and created a new Web Site at port 8003. I also added an additional binding for my local IP address of 192.10.11.21. Lastly, I opened my firewall port at 8003.

I then browsed to the site’s install URL, 192.10.11.21:8003/install, and followed the installation procedure. I soon realized that I needed to create a new MySQL database schema and user, so I logged into MySQL Workbench, and created both. I make sure that the user only has privileges to it’s own schema, and that it can only log in locally to the server. I gave the user total rights to it’s “tomatocart” schema.

I continued with the installation, entering all the database information requested. I chose the MySQL – InnoDB (Transaction-Safe) database type. Upon hitting the “Continue” button, the import ran for a few seconds and then bombed with the following error:

 

There was a problem importing the database. The following error had occured:

1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘type = innodb’ at line 1; alter table toc_weight_classes_rules type = innodb

Please verify the connection parameters and try again.

 

I then logged into MySQL Workbench and entered the “alter table” SQL statement. It has a syntax error. Upon looking up the correct syntax, it should be “alter table toc_weight_classes_rules engine = innodb;”. I executed the code, and it works fine.

I next tracked down the offending code that produced the bug by searching for it in the installation folder using the grepwin explorer tool. I located the problem code in the “install\rpc.php” file. I changed the code from “type = innodb” to “engine = innodb”, saved the file, then dropped the “tomatocart” schema and re-created it. I then re-ran the installation, and the tables loaded fine.

I continued with the installation and completed it with no additional problems. I next renamed the “install” directory to prevent it from being run again.

I next renamed the existing “robots.txt” to “robots.txt.orig” and replaced it with the following to prevent spidering of my demo site:

# go away
User-agent: *
Disallow: /

I’ve completed the installation, and now I need to begin configuring it. So, apart from the minor bug, it was a pretty easy installation.

I’ll keep updating this post as I continue working with TomatoCart.

As always, you’re welcome to view my TomatoCart demo site here. It will be available while I’m working during the day. If you should need any help with your installation, send me an email. I’d be happy to help you out! Have fun!

Update on 3/2/2011

While attempting to add a new product with a “variant”, I got the following error message:

“Error: There was a problem performing the action.”

Upon further research, I discovered that “STRICT_TRANS_TABLES” needed to be removed from the sql-mode parameter in the my.ini startup file.

Today, I’m attempting to install OpenCart, an open source ecommerce package. OpenCart was chosen as the runner-up of the 2010 Open Source Awards as published by Packt Publishing.

I first looked through the OpenCart Online Documentation. The most current stable release as of this writing is OpenCart v1.4.9.3. OpenCart requires PHP, and MySQL. I currently have both installed on my Windows Server 2008 platform. It should also work fine running  under Windows IIS 7.

As a side note, the OpenCart Tools section outlines some great suggestions for free tools. I use some of them, like Jing, others I’m excited to check out.

Installation is pretty straight forward. First, download the software. I usually download to an install directory whereby I can easily start over if necessary. I then used MySQL Workbench to create an “opencart” schema and user.

Next, I created a root folder for the opencart Web Site application to reside. I then copied the contents from the “install\opencart\upload” folder to the “www\opencart” folder.

I then went into the IIS7 Manager and added the new Web Site to port 8002. I also added a binding for the local IP address “192.10.11.21”. I then opened port 8002 on the firewall.

At this point, I pointed my browser to the OpenCart Web Site and with through the installation instructions. This was a simple one step process of entering the database connection and admin account credentials. The last step is to delete the installation folder. I was unable to do this as it was in use. So I shut down the Web Server, renamed the folder, then started it back up again.

The installation should now be complete, however, when I browse to the site, it still attempts to take me to the installation page. After looking at the index.php file, I’ve noticed that it’s looking for a variable ‘DIR_APPLICATION’. This variable should be defined in the config.php file. However, when I look at the config.php file, it’s empty. So there is a problem with the installation.

I immediately think it’s a permission problem. After doing some Googling, I found several posts discussing similar issues, but nothing that definitively solving the problem. I then Googled on ‘ii7 php file permissions’ and the first result answered my question. To implement the solution, I created a “temp” folder under my “www” folder, and then altered the PHP.ini file’s “upload_tmp_dir” variable to point to the new temp file location. I then used file explorer and gave IIS_IUSRS; Read; Write’; List folder contents; Read & execute permissions to the “www” folder and sub-folders. To the “temp” folder, I gave IIS_IUSRS; Full control.

Using MySQL Workbench, I dropped and recreated the “opencart” schema. Using IIS7 Manager, I stopped the Web Service, and deleted the contents of the opencart folder and re-copied the contents back from the install\upload folder. I then re-started the Web Server, and re-ran the installation. This time, it worked fine, and the installation was complete.

After confirming I was able to browse the site, I created a robots.txt file in the root directory to prevent this site from being spidered by Google’s WebBot. Here’s the file:

# go away
User-agent: *
Disallow: /

 

My next hurdle was gaining access to the site administration. The username and password I provided upon installation didn’t seem to work. So I went into MySQL Workbench and looked at the “user” table, in my case the “oc_user” table. I ran a quick update as follows:

use opencart;
update oc_user set password=md5('admin')

That fixed it! I am now able to get signed on to the system. I then began to configure it. That was easy!

I’ll update this post with additional findings as I continue to work with OpenCart.

You’re welcome to view my OpenCart demo site here. It will most likely only be available during the day when I’m at my desk working. If you should need help with your installation, drop me a line. I’d be happy to assist you! Good luck!

Here’s a list of free stuff I’ve installed on my development workstation. I will keep updating this post as I go along.

FileZilla

CC Cleaner

Defraggler

Notepad++

Jing

Screenhunter

Navicat MySQL Lite

SQLyog

WinMerge

Fiddler

I’ve been creating a new Web Site for one of my clients, Clear Lake Auto Service, using WordPress, and the client is wanting to see statistics regarding Web Site traffic. My first thought is to add Google Analytics to the site. Here are the steps I took to get analytics up and running for him.

First, I logged into the WordPress site, and installed the Google Analytics for WordPress v4.0.9.

Second, I created a new Google Analytics account under his Google mail id.

Third, I activated the WordPress plugin, selecting his new account. The plugin automatically verified the Account and Profile to use.

Forth, added my email account as an Administrator to the profile.

That’s it!

I’ve been using Windows Live Writer to create my blog posts, and I’ve just stumbled upon the plugins site for Live Writer, here. I’ll add more to this post as I get more experience with them.

I’ve installed the following plug-ins:

Insert Code for Windows Live Writer

Code Snippet plugin for Windows Live Writer

Today, I discovered that my SmarterMail is acting up again. When I attempted to check my emails, I get a really nice aspx error page.

My first thought is that someone has hacked my mail system, and is sending out spam again. I’ve had this problem before, and outlined the steps I undertook in order fix the problem in my post entitled, SmarterMail Security Lockdown Prodecures.

I shut down the SmarterMail Service and started looking at the mail logs, and event logs. I can see the out of memory errors, but I still don’t know what’s causing the problems.

I then restarted the SmarterMail Service and logged into my account to look at the reports being generated. There is nothing in the reports that are out of the ordinary.

My next thought was to see if I could check out what the overall network traffic looks like. I did a Google search on “network traffic monitor open source”, and I stumbled upon ntop. I installed the demo version, ntop v4.0.3. I wasn’t able to get ntop to work. After some additional research I discovered ntop-extra, but that has been discontinued. I uninstalled ntop and looked for something else.

I next installed, WireShark v1.4.3. After running the program for over an hour, I didn’t see suspicious network traffic. However, I did notice that the SmarterMail MailService.exe program was taking up to 45% CPU and ever increasing amounts of memory (now at 78MB).

At this point, I decided it was time to upgrade to the latest release of SmarterMail. I followed the upgrade instructions by first backing up the data files, then uninstalling the software, then running the installation program.

I am now running SmarterMail v7.4.3995. I will update this post if I continue to have problems. Otherwise, consider this issue resolved for now!

2011-01-14 – Update

The MailService.exe is still gobbling up lots of memory. I’ve verified that the mail system isn’t sending out spam emails, so I’m now looking into possible memory leak issues. I installed the Microsoft Windows SDK for Windows 7 and .NET Framework 4 debugging tools to see if I can spot any problems.

This morning, I’m working on installing open source ecommerce packages on my Windows Server 2008 box. This is mainly for experimental and learning purposes.

The first package I choose to install is PrestaShop. PrestaShop was chosen as the winner of the 2010 Open Source Awards as published by Packt Publishing.

My first step was to read through the most current PrestaShop User Guide. The most current stable version as of this writing is PrestaShop v.1.3.5. PrestaShop uses a MySql Database, so my first task is to install the current release of MySql (5.5.8) on my Windows 2008 server.

Since I’m not currently using MySql on a daily basis, I also made sure all of my workstation components (i.e. workbench, connector, etc.) are also up to date.

I ran into a glitch installing MySql. The Configuration Wizard has an identified bug in it as reported to the MySql Bug database as, Bug #59038 mysql.user.authentication_string column causes configuration wizard to fail. To overcome this bug, I executed the following command from the MySql Workbench:

use mysql;
alter table
    user change authentication_string authentication_string text null;

I then clicked on the re-try for the Wizard and it completed normally. After this, I ran the following commands:

use mysql;
update user set authentication_string = '' where authentication_string is null;
alter table user change authentication_string authentication_string text not null;
 
I then installed PHP 5.2.17 using the IIS7 Web Platform Installer.
I then downloaded PrestaShop and extracted the files to my server.
I then added the website in IIS7 and started the website binding it to port 8001.
I then opened the firewall on port 8001.
I then opened a browser tab on my workstation and navigated to the website.
I then followed the installation instructions.
 
At the “DATABASE CONFIGURATION” section, I logged into MySQL Workbench, and created a new user account, and database schema’s.
 
At the “E-MAIL DELIVERY SET-UP” section, it allows you to enter the SMTP server information. I currently do not have the SMTP service installed. So, at this point, I used the “Add Features Wizard” on the “Initial Configuration Tools” window to install the SMTP Server.
 
*** After many attempts at getting email to work, I’ve decided to move on for now and come back to this issue later.
 
After the database was successfully created, I then selected the Shop name, Default country, and attempted to upload a logo. But this action was not successful. There are most likely permission problems being encountered.
 
In IIS7, I configured a PrestaShop Application Pool giving it Integrated pipeline mode, and a NetworkService for an Identity. I then went to the root directory for the application, and modified the security adding “NETWORK SERVICE” and giving it full control.
 
**If my Webserver were running Server 2008 R2, then I could more easily use the ApplicationPoolIdentity for an Identity, and then specify “AppPool\PrestaShop” when alter security.
 
Ran into serious problems with continuing the installation as I couldn’t get past the database screen. I ran into a post, Prestashop, Cant continue with installation!, and abandoned the installation wizard and opted to execute the sql script to manually create an admin user and go from there.
 
This didn’t help much as I was unable to log into the admin site. I suspected that the encrypted password wasn’t being generated properly, so I found another post, Prestashop, Password encryption. pSQL function. This post has a php script in it that can be used to generate an encrypted password.
 
I attempted to run the php script from a command prompt, however, I got a php error, “The application has failed to start because MSVCR71.DLL was not found. Re-installing the application may fix the problem.”. I found a post entitled, PHP on Windows: workaround for a command-line error (MSVCR71.DLL is missing). I didn’t install the .Net Framework 1.1 on my server as I already had msvcr71.dll on a Windows XP workstation. So I copied the file from “C:\Windows\Microsoft.NET\Framework\v1.1.4322” on my XP machine to “C:\Windows\syswow64” on my Windows 2008 Server. This solved the problem, and I was now able to run the script.
 
Next, I had to get the proper “COOKIE_KEY” for my PrestaShop installation to re-create the encrypted password accurately. This string is found under the prestashop\config\config.inc.php file. Just to confirm, this string is indeed much different than the string used to generate the original user outlined above.
 
So, basically, the php code necessary to generate the password is:
 
<?phpecho md5("xae0u0c9kzEGgPFJWgGtgJa8PG1STZubGmeI57482nPwmzTkEowdbBth"."admin");?> 

where, the first long string came from the “COOKIE_KEY” and the second part is my actual password. The command to execute the php is:
 
"C:\Program Files (x86)\PHP\php.exe" -f .\password.php

This resulted in the output string “a170cb24882e45992cd42259e6579502”, which I then used in a sql update statement. I was then able to log into the admin section of the database! What a use of my day!
 

Manual Setup of PrestaShop

Now that I’m able to log into my demo PrestaShop site, I need to start configuring it!
 
First thing is to add a robots.txt file into the root directory! Here’s the file:
 
# go awayUser-agent: *Disallow: /

I then logged into the shop and set the home time zone, the default currency, the default country, etc. This was a little more difficult than I first thought it would be. However, most of the problems I encountered were due to the Windows and PHP environment settings. Once I ironed those out, everything else went fine.

 
I’ll keep updating this post with additional details as I continue to explore PrestaShop.
 
You’re welcome to view my PrestaShop demo site here. It will most likely only be available during the day when I’m at work. If you should need help with your installation, drop me a line. I’d be happy to help you out! Take care!