htpasswd Apache 2 authentication with exeption ip.

htpasswd? Hi guys, today I’m just bringing a note about htpasswd hope it will be useful for someone as this knowledge has been for me.

htpasswd is a tool for apache able to secure folders in a web directory, that means that the folder is public, but protected with password. this functionality is very useful for instance to install systems that have no internal security like Sarg the web app to read Squid logs, Munin to read servers performance, also if you want to share a folder with a friend or even when you need to secure your own web applications and you do not want to create your own security module. in the other hand; htpasswd supports several authentication methods with different security level, but I am just going to describe the basics authentication.

Now let’s stop talking and start doing; to create the password file with the first user you are supposed to execute the following command:

# htpasswd -c /home/pwww/.htpasswd-users abel

The -c option is to create the file and abel is the user. /home/pwww, could be any folder in your filesystem.

Note: I am assuming you have all the packages that are required already installed, and your Apache is running with the target folder to share with password.

After you have created one user you can add as many as you want with the following.

# htpasswd /home/pwww/.htpasswd-users raik
# htpasswd /home/pwww/.htpasswd-users shorn

As you might have noticed the command is the same but without the -c option, as this option is only to create the file.

So far the file for the authentication is created and inside we have the users with the passwords; pretty but Apache does not know about them so they are useless. to say to Apache that a file is protected with htpasswd you have find the folder that you want to share with htpasswd and create a file colled .htaccess. this file is the first thing that Apache reads when he receives a request to a folder. So we create the file and inside we add the following code:

AuthType Basic
AuthUserFile /home/pwww/.htpasswd-users
AuthName "Enter password"
Require valid-user
AuthGroupFile /dev/null

This is nice and works perfectly, but what does it means? Well it means we are going to use basics authentication. The user are going to be in /home/pwww/.htpasswd-users, AuthName is just a name so and it will appear in the authentication prompt. Require valid user is to make people use a name and passwords in the database and authGroupFile is optional for in case you have groups, that why here is pointing to /dev/null.

Now let say we want to make every one authenticate using htpasswd except for your own computer, because you do not want to put a password to access your own computer resources. Or that you have a server where the folder is running and you want the server to be able to execute a cron task on any of this URLs.

we you just have to modify a little bit your script adding this at the beginning:

Satisfy any

and this at the end of the script:

order deny,allow
deny from all
allow from 127.0.0.1

So the final file would be like this:

# permit by USER || IP
Satisfy any
AuthType Basic
AuthUserFile /etc/apache2/.htpasswd
AuthName "Enter password"
Require valid-user
AuthGroupFile /dev/null
# IP
order deny,allow
deny from all
allow from 127.0.0.1

And that’s pretty much it… cheers guys.

GPS tracking; a Business automation Solution

GPS Tracking; this is the first of a few articles about business automation solutions. I try to suggest a stable but also as affordable as possible. This can be implemented by business that might not have enough to pay for a tracking company or just do not want to do it and they want to have their own tracking system.

Tracar System image...

Tracar System

For GPS tracking there are a lot of solutions that might work for different purposes. In this case I’ll focus in feet tracking. Some companies have a few vehicles or a lot of them and they do not really know what are they doing most of the time. How much fuel have they spent? how many girlfriends is the driver visiting per month? In how many illegal recces have their cars participated? How much time are my cars IDE? and a whole lot of things that people tend to do when some resources are available without the proper control.

Well this GPS tracking article will help them to know that there are solutions out there that you can implement and that some of them are not very expensive. To implement any of this solutions you need a computer (server), a Real IP address so that your devices can see it from internet. A receptor of messages. And the GPS tracking device to be installed on what ever you want to track, a CAB, a truck, a ship, an air-plain. Check out GPS tracking picture to see how the system works. Basically the GPS tracking device contacts something (in the image the satellite) that says to it the current position and then the device sends it the receptor and the receptor to the server, the servers processes the information and stores it on a database that can be acceded from every where using a web browser.

Note: If someone is trying to sell to you a solution like this in this century that is not accessible from the web from every where; they are behind or they are not serious.
Schematic GPS tracking image

GPS tracking

Just to clarify, actually you always need a Receptor, but sometimes is more convenient for you just to rent the service to someone like a telephone company and they send it to you, so that you do not need a receptor of the data from the device directly and you do not have to pay too much at once.

It is also important for you to know how to that this schematic is just a possibility of the many ways of tracking devices, you can track basically any thing and in the way you want.

The other important part is the software that you are going to use, you can use a few software for this purpose, there are really good paid solutions, but this article is about making it cheaper so I will talk about two solutions that are currently out there for free and that you can have access to the code; OpenGTS and Traccar both of them are completely free based on java.

“OpenGTS™ (“Open GPS Tracking System”) is the first available open source project designed specifically to provide web-based GPStracking services for a “fleet” of vehicles.

OpenGTS image

OpenGTS

To date, OpenGTS™ has been downloaded and put to use in over 110 countries around the world to track many 1000’s of vehicles/assets around all 7 Continents. The types of vehicles and assets tracked include taxis, delivery vans, trucks/trailers, farm equipment, personal vehicles, service vehicles, containers, ships, ATVs, personal tracking, cell phones, and more.

While OpenGTS™ was designed to fill the needs of an entry-level fleet tracking system, it is also very highly configurable and scalable to larger enterprises as well.”

This is how OpenGTS defines their own project, you can visit the website.

Now the other system that I have talked about is Traccar. and they define them selves as:

“Traccar is open source system for various GPS tracking devices. At the moment server supports more than 30 different protocols. Versions starting from 1.0 include embedded http server and web interface (view demo) to track devices. Traccar is written in Java and portable between different operating systems and platforms. At the moment installation packages provided for Windows, Mac OS X and Linux.”

Traccar image

Traccar

And you can get information about the project on this page.

That is what I had prepared for today. Just to say that depending  on the environment you might need a custom solution, not exactly what I have proposed. But if you know what you need or you get the right help you can implement it in your company. Enjoy, and feel free to leave any feedback or reply.

 

Symfony 2 hosting server

 Screenshot from 2013-10-08 12:34:07Symfony again! Hello, as you know I like to hit my head against the screen from time to time. So today I’m going to try to configure a server to host Symfony Aplications. The host in this case will be a virtual machine in my own computer.

Note: this post is about how to install Symfony, how to meet the requirements. if you have done this already maybe what you need is to deploy your product app. visit this link for that . And if you want to install in windows you can follow this link

My OS is a Debian testing (8) and I have a virtualbox running ready to have a lot of virtual
machines. So I have created a Debian Stable (7) Virtual Machine that will be our server for the symfony 2 applications. in this case I’m going to use Symfony 2.3.5 the latest version available on the server. I am talking to much take a look at the image of my of my VM for more information. Continue reading

Symfony 2 production environment server deploy

Symfony 2 logo

Symfony 2 logo

Symfony 2 is one of the most popular PHP frameworks and particularly my favorite. My fist time to deploy a project in production environment, I have struggled a lot. One of the most common errors you might get when you execute the prod environment is “401 Page Not found”. But, actually it is really simple to make a Sysfony 2 project work. you just have play a little bit around with it knowing what you want.

Note: This post is about how to move a bundle to production environment, if what you want to know is how to install Symfony (by meeting it’s requirements), you can go here. Also to instal Symfony in windows 8 PC with wamp server you can go here.

Note: Last update on 2014-04-09.

1. On a linux alike system Log to the project folder using the cd command

2. execute this 3 commands:

  • php app/console cache:clear --env=prod --no-debug 
  • php app/console assets:install web_directory 
  • php app/console assetic:dump web_directory

3. Promote the web server's user the owner of the cache folder, as root you should execute in Linux systems

chown www-data:www-data -R app/cache

4. Promote the web server’s user the owner of the logs folder, as root you should execute in Linux systems.

 chown www-data:www-data -R app/logs

In my case it was like this:

root@khs01wxl001:/var/www/Org# php app/console assets:install web
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
root@khs01wxl001:/var/www/Org# php app/console assets:install web
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
root@khs01wxl001:/var/www/Org# php app/console assetic:dump web
Dumping all dev assets.
Debug mode is on.

root@khs01wxl001:/var/www/Org# chown www-data:www-data -R app/cache
root@khs01wxl001:/var/www/Org# chown www-data:www-data -R app/logs
root@khs01wxl001:/var/www/Org# php app/console cache:clear --env=prod --no-debug
Clearing the cache for the prod environment with debug false
PHP Parse error:  syntax error, unexpected '$content' (T_VARIABLE) in /var/www/Org/src/Osd/RetireBundle/Controller/GeneralController.php on line 15
root@khs01wxl001:/var/www/Org# php app/console cache:clear --env=prod --no-debug
Clearing the cache for the prod environment with debug false
root@khs01wxl001:/var/www/Org# php app/console assets:install web
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
root@khs01wxl001:/var/www/Org# php app/console assetic:dump web
Dumping all dev assets.
Debug mode is on.

root@khs01wxl001:/var/www/Org# chown www-data:www-data -R app/logs
root@khs01wxl001:/var/www/Org# chown www-data:www-data -R app/cache
root@khs01wxl001:/var/www/Org#

 

Note: This update was done because of the question from César Chalén.

If you need also apache to take you directly to the default project page you just need to create a Virtual host pointing to Symfony 2’s internal web directory (if you need more detailed info about the apache virtual hosts you can see it here). Any way check out one of my virtual hosts:

<virtualhost *:80>
        ServerAdmin webmaster@localhost
        ServerName retirement.gabs.hospitals.moh.gov.bw
        DocumentRoot /var/www/Symfony/web

        <directory /var/www/Symfomy/www/web></directory>

                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

</virtualhost>

And that is it, enjoy.