Posts

Showing posts from April, 2020

User management application using Node.js and Redis

Image
Here I created a user management application using Redis and Node.js. Here we can simply add and search through user detail records. The application consists of a few components. There is the main app.js file which controls much of the application. And I used express for Node.js with handlebars to add users, create details and search through the users.  In this adduser.handlebars file I create the "POST" method with an action that will send the information below in a post to  /user/add which will create the new user in Redis. Next in the details.handlebars file below I set everything up to handle the display of the records that are retrieved from Redis. Then I have a searchusers.handlebars file which handles the search functionality. The main.handlebars file handles the HTML output and is quite similar to any other HTML page with the interesting differentiation of how the body content is handled. The triple curly brackets tell handlebars to display the

Cron job - Daemon - Shell script to send email alert to admins when RAM utilization hits critical levels

Image
In this example I am creating a daemon to run a cron job. Cron jobs are scheduled tasks that can be setup to run in an automated fashion on particular, days, weeks or even yearly quarters. And daemons are silent processes that are running in the background constantly in an alert state ready to spring into action. First, I checked to see how much ram is free on this server at any given time. The server is an Ubuntu LAMP stack on a cloud. In this particular instance 265MB of ram are free. This command returns the exact value for comparisons and is what I will plug into my program later on: So now that I know my parameters for where I want my RAM to be running and when I want to be emailed about any alarming spikes in usage. The alerts.sh program I created below sends emails to tester@slabj.com whenever the free ram is less than or equal to 267MB. I set the threshold really low to test my script. Cool. It's working now and I got an email telling me that the RAM is low.

JWT Tokens with Node.js and Express

Image
In this example I show how to create access tokens for an application using Node.js and express. JSON Web Tokens are a standard type of token that is used widely to certify user identity by a server before sending data back to the client machine. First I sign JWT with a secret token from the client. Then the server verifies the token and reads the information if the token is valid. I also created the ability to have the tokens expire or be refreshed as is needed.  For the initial setup I just needed to make sure Node.js and express were installed and up to date. Then I added a package called nodemon to monitor for any changes and to react accordingly. To handle the authentication in a secure manner I also created a separate server for handling the main request and one that is used purely for authentication. Additionally, in a rest file I am creating the parameters for the /posts and /login requests. The application type is json hence the name JSON Web Tokens. Th

Gathering and saving eSignatures from an HTML form with Ajax, PHP & jQuery

Image
For this example I show how to create an e-signature form where users can sign a form and then the signature is sent back to the database or server. I used HTML to construct the form and javascript to do AJAX calls with jQuery and the help of PHP. Below is the Javascript code that gets the image from the first location and saves it with the use of another php file called 'save_sign.php'. Here in 'save_sign.php'  I get the image, decode it and save the signature snapshot image as a .png file in a folder I created called doc_signs. Here I have the output being reflected from the database. Every time a new signature is saved they are put in that document signature folder. So here for showing the concept, I am reflecting the signatures as they get saved right back onto the page. In a production app from here the only thing left to do is to know where the specific project wants to route the signatures. It may suffice to just save the document s

Setting up and configuring an entire email server in the cloud on Ubuntu(Linux) for a website

Image
So for this example I setup an email server in Ubuntu on a cloud for a testing website I created. The process builds upon previous examples. So for this I started with installing Apache and PHP on the virtual machine to begin the installation and configuration of all the additional components. First I installed Postfix which serves as the MTA(mail transfer agent). This is the software responsible for delivering and receiving the emails. Then I installed Dovecot as an MDA(mail delivery agent) which then more specifically delivers the emails to/from the mail server. At this point I now have an IMAP/POP3 email server and am going to install SquirrelMail on the email server to have a simple interface to manage emails on my server. Here I added postfix to the server above and below I am confirming the service status. Everything looks good for the next steps. Below I now have confirmation that Dovecot is active and running. The email server is up at this point. 

Testing TCP/UDP baseline functionality with Netcat & Curl through CLI(SSH)

Image
Here I am showing how to setup a simple Netcat listening server to test baseline functionality of TCP/UDP connections. I create a simple document and save it as technical.txt that I will send to my server I am testing. Here I create the simple document. On the server for phub.info I setup a Netcat listener at port 8888 that is ready to receive the specific document.  Now from the 'HQ-cloud-green' server I get ready to receive the document with another Netcat server. To confirm receipt of the file I open it and view the contents from the terminal. Great so now I can send messages back and forth but I want to test things a little further. I want to know how this connection port and the data being sent through it will be interpreted by browsers. With Netcat I can create a simple HTTP server to serve up content to browsers to see if my server is configured correctly. Here I pulled the data from the URL with cURL and you can see the HTML for the test page I am

Using a GPG Keychain to encrypt emails and any text messages

Image
One of the most straightforward methods for integrating PGP keys with e-mails is with Apple e-mail using GPG Keychain. You just put in your e-mail, generate a key and add your e-mail as well as a password. Now whenever you want to send a message you just tell the program to encrypt with the key of your choosing and you get the results below. Here is a test message. I select to use a key I named 'newkey'. Here is the message above encrypted with the PGP key. Now with the key configured to my e-mail all I have to do is select and choose to decrypt.