Archive

Archive for the ‘Info.Tech’ Category

Algorithm: Graphic Sort

August 8th, 2010

Graphic Sort

Graphic Sort

Today, I created different kinds of sorting.

  1. Bubble sort
  2. Selection sort
  3. Insertion sort
  4. Quick sort

Yet, my Quick sort does not work properly… And I have 6 more sorting method to go… :(

Download: Graphic Sorting (18) (demo executable file)

Download Source Code: Sooooooon… :P

Thanks to: http://www.cs.oswego.edu/~mohammad/classes/csc241/samples/sort/Sort2-E.html

Camilo III Info.Tech, Software Development, dev-C++

VLSM Table

July 31st, 2010
Comments Off

Variable Length Subnet Mask Table

Prefix Add-on Octet Hosts Subnet
/30 +4 4th byte 2 255.255.255.252
/29 +8 4th byte 6 255.255.255.248
/28 +16 4th byte 14 255.255.255.240
/27 +32 4th byte 30 255.255.255.224
/26 +64 4th byte 62 255.255.255.192
/25 +128 4th byte 126 255.255.255.128
/24 +1 3rd byte 254 255.255.255.0
/23 +2 3rd byte 510 255.255.254.0
/22 +4 3rd byte 1022 255.255.252.0
/21 +8 3rd byte 2046 255.255.248.0
/20 +16 3rd byte 4094 255.255.240.0
/19 +32 3rd byte 8190 255.255.224.0
/18 +64 3rd byte 16382 255.255.192.0
/17 +128 3rd byte 32766 255.255.128.0
/16 +1 2nd byte 65534 255.255.0.0

Download PDF file: Variable Length Subnet Mask Table (36)

Camilo III Administration, Cisco: Network Administration, Info.Tech

dev-C++ : Bubble Sort with Graphic Plotting

July 24th, 2010
Comments Off

I’m having difficulties in creating good programming algorithm with C++. I find its very difficult. Somehow, I would like to share my accomplishment in creating this program, Bubble Sort with Graphic Plotting. But first, what is bubble sort?

Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements “bubble” to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort.

Below is the demo, source codes and libraries needed…

If you have better algorithm solutions, if you don’t mind, can you email it to me… Like to see how others solve the problem.

Camilo III Info.Tech, Software Development, dev-C++

IPTABLES – Logging and dropping traffic in a single rule

July 15th, 2010

Many people who are familiar with IPCHAINS (the predecessor to IPTABLES) are familiar with the ability to simply tack on a ‘-l’ to also log rules which match that rule. In IPTABLES this is not done the same way and no such option exists.

To accomplish the same task in IPTABLES you could simply put a identical rule with a LOG action before every drop rule, but that will fill your script with copies of the same rule and force updates in multiple locations. This is therefore not an ideal solution.

The cleanest method of accomplishing this is to create a new chain which does both the LOG and DROP for you. The following IPTABLES rules will create a LOGDROP chain.

# Create the LOGDROP chain
 iptables -N LOGDROP > /dev/null 2> /dev/null
 iptables -F LOGDROP
 iptables -A LOGDROP -j LOG --log-prefix "LOGDROP "
 iptables -A LOGDROP -j DROP

The first rule in this set creates the new chain. The output is sent to /dev/null because if you attempt to run this twice on the same system, you will get an error saying the chain already exists. It’s up to you if you want to see that message or not.

The second rule flushes the contents of the chain, again, so that if you run it twice on the same system you don’t have duplicate rules in the chain.

The third rule LOGS the traffic with the added “LOGDROP” prefix and the fourth rule DROPs the traffic

What this now means is that you can easily log and drop traffic or even log and accept traffic (with minor modifications to the above), by creating a rule such as this:

# Log and drop all connections to the HTTP port
 iptables -A INPUT -p tcp --dport 80 -j LOGDROP

As you can see, you now simply use the LOGDROP target in order to log and drop any traffic you want. You must ensure that you define the LOGDROP target BEFORE you attempt to use it in a rule.

If anyone has any comments or corrections for this, please let me know using the comment system below.

Article From: http://www.techbytes.ca/techbyte136.html

Camilo III Info.Tech, Operating Systems

Generating SSL certificates using OpenSSL

May 10th, 2010
Comments Off

Based on Centos Wiki on HowTo SSL – http://wiki.centos.org/HowTos/Https

I simplified the procedure to create a bash script. Here’s the code;

#!/bin/bash
umask 077

echo ""
if [ $# -eq 0 ] ; then
 echo $"Usage: `basename $0` <DOMAIN_NAME> [...]"
 echo ""
 exit 0
fi

for target in $@ ; do

 keyFile=${target}.key
 crtFile=${target}.crt
 csrFile=${target}.csr

 echo $keyFile
 echo $crtFile
 echo $csrFile

 # Generate private key
 openssl genrsa -out $keyFile 1024 

 # Generate CSR
 openssl req -new -key $keyFile -out $csrFile

 echo ""
 echo "Please enter the number of days which SSL Certificate will be valid:"
 read DAYS
 echo ""

 # Generate Self Signed Key
 openssl x509 -req -days $DAYS -in $csrFile -signkey $keyFile -out $crtFile
done

Or download the script below…

Download: gencert (9) bash script

How to add gencert command to your system:

  1. Download the gencert bash script
  2. Extract the file
  3. chmod u+x gencert
  4. then copy the gencert file to /bin/
  5. Wallaah! You’re done!

Camilo III Administration, Info.Tech, Operating Systems

CEntOS: Securing FTP (vsftpd) and SSH

May 8th, 2010

SECURING FTP

Use chroot_local_user=YES then the vsftpd.chroot_list becomes a list of users to NOT chroot. So… you said chroot ALL users but ftpuser.

Notice the commented out lines.
In /etc/vsftpd/vsftpd.conf:
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

edited /etc/vsftpd.chroot_list:
add users only that DO NOT NOT NOT NOT get chrooted.

use /sbin/nologin
edited /etc/passwd entry for ftpuser:
ftpuser:X:#:#:FTP User Account:/home/ftpuser/./:/sbin/nologin

————

chroot_local_user=YES
chroot_list_enable=YES
means that by default ALL users get chrooted except users in the file

chroot_local_user=NO
chroot_list_enable=YES
means that by default ONLY users in the file get chrooted.

See the difference?

Article by: JordanH

SECURING SSH

Edit /etc/ssh/sshd_config and at the bottom of the file, add these lines…

# Allowed users to login SSH
#AllowUsers root user002

# Disallow users in logging in at SSH
#DenyUsers user001

Camilo III Administration, Info.Tech, Operating Systems , , ,

Prototype POS System – Transparent GUI

April 23rd, 2010
Comments Off

POS System – Transparent GUI

My article is about a prototype POS system for grocery stores or 24 hours mini marts using Transparency graphical user interface.

Transparency in MS Visual C# works similar to chroma keys in Adobe After Effects or Premiere. All you have to do is set a color key to make it transparent.

  1. As you create a form as Form1, go to Form1 properties and set TransparencyKey to Black.
  2. Then set your Backcolor of your form to Black.
  3. In Photoshop or any image editing tools, create an GUI or layout design then save as PNG format.
  4. In Form1 properties, set BackgroundImage and select the PNG image you created from Photoshop or other image editing tools.
  5. Set also the FormBorderStyle to None and Opacity to 95%.
  6. Then run your project. You’ll see the transparency works well. :)

See my sample source code.

Prototype POS System - Transparent GUI (17)

 

 

 

Camilo III Info.Tech, Software Development, Visual C#

Visual C#: Detect Conflict Schedule

January 18th, 2010
Screenshot

Screenshot

It seems a lot of people are searching about solving conflict schedule. So I decided to create a sample. Below is the core code of checking conflict schedule…

// sample conflict detection (defined) [start]
DateTime d = new DateTime(2010, 1, 13);
richTextBox1.Text = DateTime.Now.ToLongDateString() + ” = ” + d.ToLongDateString() + “\n”;
if (DateTime.Now.CompareTo(d) > 0)
{
richTextBox1.Text += “true\n” + DateTime.Now.CompareTo(d).ToString();
}
else
{
richTextBox1.Text += “false\n” + DateTime.Now.CompareTo(d).ToString();
}
richTextBox1.Text += “\n\n”;
DateTime dx = DateTime.Now;
//MessageBox.Show(dx.Hour.ToString());
DateTime[] dt = new DateTime[4];
// enrolled schedule
dt[0] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 8, 0, 0);
dt[1] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 9, 0, 0);
// adding new schedule
dt[2] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 9, 0, 0);
dt[3] = new DateTime(int.Parse(dx.Year.ToString()), int.Parse(dx.Month.ToString()), int.Parse(dx.Day.ToString()), 10, 0, 0);
// checking schedule conflict
if (((dt[0].CompareTo(dt[2]) < 0) && (dt[1].CompareTo(dt[2]) > 0)) || (dt[0].ToShortTimeString() == dt[2].ToShortTimeString()))
{
richTextBox1.Text += dt[0].ToShortTimeString() + ” – ” + dt[1].ToShortTimeString() + ” against ” + dt[2].ToShortTimeString() + ” – ” + dt[3].ToShortTimeString() + “\nResult: CONFLICT”;
}
else
{
richTextBox1.Text += dt[0].ToShortTimeString() + ” – ” + dt[1].ToShortTimeString() + ” against ” + dt[2].ToShortTimeString() + ” – ” + dt[3].ToShortTimeString() + “\nResult: NO CONFLICT”;
}
// sample conflict detection (defined) [end]

If you want to download the whole code, link below and enjoy… Do not practice the copy and paste! :)

Download: Detect Conflict Schedule (15)

Camilo III Info.Tech, Software Development, Visual C#

Ubuntu Professional Certification

December 18th, 2009
Comments Off
Ubuntu Girl

Ubuntu Girl

Today, I tried to answer the pre-test of UPC or the Ubuntu Professional Certification… and the result was…

Dear Camilo III,

Thank you very much for taking part in the pre-training assessment.

Your score is 9, which means that you are probably over-qualified for this course.

As a next step we suggest that you read through the Deploying Ubuntu Server Edition course overview found here: http://www.ubuntu.com/training/certificationcourses/server and then complete the corresponding online assessment.

Ubuntu Training courses are taught by Canonical-trained Ubuntu Certified Instructors. The Deploying Ubuntu Server Edition course is available through online training and classroom training, so you can can learn in the environment that suits you best.

Visit: www.ubuntu.com/training for more information.

Best regards and good luck
The Ubuntu Training Team

How flattering!! I admit it, I’m not that good… but anyway, the test is so easy.. hahahaha.. :) And one thing, I don’t have a dollars to pay the $1,600 for the Deploying Ubuntu Server Edition Certification. Its like PhP 76,800.00 in my country, that is 9 months to save my whole salary. hahahaha.. Damn! I will starved to death if I will take the exam… :P

Camilo III Administration, Info.Tech, Operating Systems

Visual C#: Retrieving Image (BLOB) from MySQL database

December 14th, 2009
Comments Off

I’ve been searching an article about storing and retrieving an image (BLOB data type) from MySQL database. Somehow, I only found the retrieving process but I created the storing process using PHP… :)

You may download my works, link provided below…

  • idsystem_database.sql.zip – the dump file of MySQL database; import this SQL file before running the project
  • the rest of the files are the project sample files

-> retrieveImg_public.zip (49) or http://camilord.kagayan.com/my.files/retrieveImg_public.zip

For the credits, Thanks to Markusek Peter…

MySqlConnection myConnection = new MySqlConnection(myConnString);

string testQuery = “SELECT sp.studePhoto, s.firstName, s.lastName

FROM students AS s, student_photos AS sp WHERE s.id = sp.studentID”;
MySqlCommand myCommand = new MySqlCommand(testQuery, myConnection);

myConnection.Open();
MySqlDataReader myReader = myCommand.ExecuteReader();

FileStream fs; // Writes the BLOB to a file (*.jpg).

BinaryWriter bw; // Streams the BLOB to the FileStream object.

int bufferSize = 100; // Size of the BLOB buffer.

// The BLOB byte[] buffer to be filled by GetBytes.

byte[] outbyte = new byte[bufferSize];
long retval; // The bytes returned from GetBytes.
long startIndex = 0; // The starting position in the BLOB output.

while (myReader.Read())
{
DateTime tmp = new DateTime();
tmp = DateTime.Now;
// Create a file to hold the output.
string filename = camilordMD5(tmp.ToLongDateString().ToString() + tmp.ToLongTimeString().ToString()) + “.jpg”;

string dest = Directory.GetCurrentDirectory() + “/” + filename;
fs = new FileStream(dest, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);

// Reset the starting byte for the new BLOB.
startIndex = 0;
// Read the bytes into outbyte[] and retain the number of bytes returned.

//myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
retval =(long) myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
lblName.Text = myReader.GetString(1) + ” ” + myReader.GetString(2);

// Continue reading and writing while there are bytes beyond the size of the buffer.
while (retval == bufferSize)
{
bw.Write(outbyte);
bw.Flush();

// Reposition the start index to the end of the last buffer and fill thebuffer.
startIndex += bufferSize;
retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);

}

pictureBox1.ImageLocation = Directory.GetCurrentDirectory() + “/test.jpg”;
//pictureBox1.Image = retval;

// Write the remaining buffer.

bw.Write(outbyte, 0, (int)retval – 1);
bw.Flush();

// Close the output file.
bw.Close();
fs.Close();
}

Camilo III Info.Tech, Software Development, Visual C#