php date time compare

Compare Date Time

Compare date time now string to some time in the past. This checks if the time in the past has been longer than a month compared to the time now.

Posted in Daily Post, PHP | Tagged , , , | Leave a comment

How To Create ssh keys for Ubuntu

SSH Login

So you want to connect to your Ubuntu server with ssh using keys? Great! This is a much more secure way of connecting to your server than using password auth.

Setup

If you havn’t installed the server yet do that now.

Now that the server is installed you may want to change some of the default settings for your server, i.e. port, allowed user(s), and allowed ip(s). Depending on your specific setup you may need or want to make some other changes too.

Before we edit this file there is one thing to consider and that is if your home directory is encrypted or not. If your not sure you can do the following:

You should notice a .ecryptfs folder, if you have a encrypted home folder.

If you do then you will need to create a ssh directory outside your home directory/folder. The reason for this is once logged out, the ssh server will not have access to your encrypted home directory so it will not be able to access your keys to validate your login.

If it’s encrypted then you may want to store the ssh keys off the root of the file system. If so then do this:

If your home folder isn’t encrypted then you can create a directory to store your keys right in your home folder. To that simply do the following:

Edit SSH Config

Now that we have the server installed and have our directory setup to store our keys in we should edit our ssh server config file. There are two files you can edit to change the configuration of the server:

  • sshd_config
  • ssh_config

Each file contains a few different options that can be changed to modify how your server will handel request and connections. The one we will focus on is the “ssd_config”.

To begin will will open up the sshd_config and have a look at whats inside. So lets do that by doing the following:

Or you can use another editor of your choice!

Once opened you should have something similar to the following:

As you can see there are several different options that can be changed. If you know what your are doing here go on make the changes you need. If not then continue to follow along.

The ones I am going to worry about are as follows:

  • Port
  • ListenAddress
  • AuthorizedKeysFile
  • AllowedUsers

Port
This is the port which you will use to connect to the server.
By default it’s set to 22, you may want to change this to something other than the default to help keep intruders from guessing what port your server is on. Maybe Port 9898.

ListenAddress
This is the address that the server will listen to for connections. If your not sure you can leave this alone or if you know what ip address and port you want the server to listen on you can enter it here. i.e. ListenAddress 192.168.0.10:9898

AuthorizedKeysFile
Eariler we checked if our home directory was encrypted or not and if it was and you moved the ssh directory outside the home directory then you will want to change this to where your ssh directory is. If you followed along exactly as I did above then you might have an entry like this:

Notice the “%u” this lets the server know to look in the directory with the username that is trying to login. i.e. %u = your-username

AllowedUsers
This is a list of allowed users that our allowed to log in using the ssh server.
Enter names seperated by only a space. i.e. your-username someother-user

If you made any chages here you will need to save the file and restart the server before they will take effect.

Create The Keys

Ok now that all that stuff is out of the way we can create our keys!
Now I must mention there are a few different key types that can be made, using different algorithm. One is the “rsa” type and the other is “dsa” type. For the sake of not making this any longer than it already is I wont go into the differences of each.

For most users the a good choice is rsa with 2096 bits, which is what we are going to use. So make sure your in the directory where you want to create your keys and lets begin!

When prompted for a file name you may provide a file name for the keys i.e. my-key, or you can just press [enter] to use the default name.
You will be promted to enter a password you can just press [Enter] or enter a password for added security.

If your home directory is encrypted and you have chose to move the ssh directory outside the home directory then you will need to cp the id_rsa and id_rsa.pub files from ~/.ssh/ directory to the directory you created outside the ome directory.

Now you will need to create a key file for your key. This should be the same name as the one used on the AuthorizedKeysFile line in the sshd_config file i.e. AuthorizedKeysFile ~/.ssh/authorized_keys.

Now we need to add the public key to the key file:

Change the permissons on the file.

Now you should remove the id_rsa.pub file from the server for security and transfer the id_rsa file to your client machine.

Thats it! now you can try logging in to to your server using the key you just created! Did it work? If so Great! If not leave a comment below and I will try to help?!?!

SSH Login Config

If you have managed to get logged in and your client machine is a linux box, you may want to create a config file in you ssh directory on your client machine to make logins much easier.

This is a simple process.

Then once you have the file open, all you need to do is add a few lines to make ssh access easier. Here is an example:

You can of course add more host for more servers, like if you have a git hub account you can add that here too.

Then in the terminal all you need to do is the following:

Thats it! Hope this helped!

Posted in Linux | Tagged , , , , , | Leave a comment

Create Aptana Studio Desktop Entry

Create Unity Desktop Entry File

Need a desktop entry file for Aptana Studio? Is the icon HUGE?
If you want to be able to find Aptana Studio in the dash and pin it to the launcher then you will need a desktop entry file.

You can create a desktop entry file for any application, and change the icon thats displayed for that application with teh desktop entry file.

Let’s start by creating the desktop entry file. Open up the terminal and enter the following commands:

What we have done is changed into the directory where the desktop entry files are located, created a new entry and changed the permission on that file.

Open it up!

Now lets open that file with your faviorte editor. I am using vim, you may use whatever you like!

After you have opened up the desktop entry file you will need to enter some information about your application. All information is entered in {key => value} pairs.

What goes inside?

Since I am creating one for Aptana Studio here is what it might look like:

So that’s about it. As you can see it’s pretty simple file, the main thing to notice in this file is the Exec. This lets Linux know where the application executable file is located at. The other values are helpful but not necessary.

Hope this was helpful!

Posted in Linux | Tagged , , , | Leave a comment

php Facebook wall feed with jQuery push and Masonry

Have you ever wanted to create a wall feed for your social site just like what facebook has? If you have then here it is!

This wall feed uses jQuery Ajax to send and recive post for the wall. I also have decided to use jQuery Masonry for the wall feed to lay out the post on the page, this allows for a much cleaner look and feel. This also allows for each box to be a different size while maintaing the same spacing around each box, just like you would see on google plus page.

And since I am such a big fan of Codeigniter and the MVC style I will be using codeigniter agin for this project. Dont worry though you can easily take this code and use it in your exsiting project!

To begin we will need to create a database to hold all our wall post and user info and friends. We will want be able to view any post our friends may have posted so we have created a friends table too.

Wall Feed Database Code

Copy the database code below and import it into your MySQL :

Now that you have the database tables created we can begin to create the rest of the files needed for the wall feed.

Wall Feed Controller

The wall feed controller is what will allow our jQuery script to send a request to, to get more content to be shown on the the wall feed. Let’s begin by creating a file labeled “wall.php” in our controllers directory. Again this file will contain the logic needed to fetch and return more content to be displayed on our wall.

wall.php

Inside the wall.php file create a new class called wall as shown below. This is the start of our controller.

Next we will start by adding in the code needed to process the Ajax request, handel the logic and loading our wall model, we haven’t created this file yet but we will later. We will also add a proprerty to hold the user id of the logged in user from the database.

Now I havent built a mechanizm for getting the user id, insted I just assined one above and that will be the id of the user in the database. I will leave you to creating your own mechanizm for retrieving the user id.

Now sticking to the MVC approch we know that we can allow users access to the controllers with a url, i.e. (http://somesite.co/controller/function/) So for our Wall controller we will simply create a index function that will handel request to this controller from the browser by serving up our wall page.

Lets do that now!

Now that we are loading our view file to display our wall feed content, we need to create that file. This file will contain all our jQuery code, Ajax calls and html to show the user the wall feed. We will also provide a textarea for the user to enter text to update there wall.

The next file we are creating is called “wall_feed.php” and will be located in the views directory of our application folder. This file will be loaded by the function we just created in the code block above:

Now that we have the controller built we can move onto the model. The model will take care of all our database stuff.
This file should be labeled wall_model.php and be located in your models directory if your using codeigniter.

“wall_model.php”

Now I now I am not going into much detail on exactly whats taken place in each of these files, but ther should be alot of code hints with in the code to give you a pretty good idea of whats happening.

Next we need to create the view file which is the file that will contain all our jQuery and html. We call this wall_feed.php

“wall_feed.php”

Next we will create another file to show full post, if you have noticed we have limited post length to a set amount of characters and if the post is longer we add a “Read More” link to the post. This allows are users to view the full post.

Here is the full_post.php file

So there it is if you like it, hate or have any questions about this script just leave a reply below. Also if you just want download this enitre script you can do that here Facebook Wall Feed Script

Posted in Codeigniter, facebook, jquery, PHP | Tagged , , , , , | Leave a comment

Very Simple php login

This isn’t pretty I know and I will probably clean this up and add to it. It literally took me less than 5 minutes to write this. I just wanted to create a very simple and basic authentication/login system just to show how easy it is to get started creating a login in php.

So here goes it!

The index.php file:

The auth.php file:

More on this as I get time to do so. Leave your comments below, maybe some ideas on what should be included? I will leave that to you (the reader). Thanks!

Posted in Uncategorized | Leave a comment