Computer Magic
Software Design Just For You
 
 

Drive clone in Linux with dd

February 3rd, 2014

Simple way to clone drives in Linux.

Assume drive sda is the source, and sdb is the destination.

dd if=/dev/sda of=/dev/sdb & PID=$!; which kill -USR1 $PID;

& runs dd in the background.
PID=$! gets the last process id (of the dd command)
Which runs the command every second or two.
Kill -USR1 tells dd to print its progress.

Wildcard SSL Certificates in CPanel – How to put multiple sub domains on the same IP

May 3rd, 2011

ИконописиконографияКартиниA while ago I bought a wildcard SSL certificate so that I could use one certificate on multiple sub domains. This works great when each sub domain is on a separate server or if each sub domain has a separate IP.

As an example, we have several servers. Each server gets its own name. Something like server1.cmagic.biz, server2.cmagic.biz, server3.cmagic.biz.

If you setup a whole new server, it will have it’s own IP address. With a wild card certificate, you can setup CPanel on each server and use the same certificate for all three instead of having to purchase 3 separate certificates.

The tricky part is when you want to use the same certificate on more than one sub domain on the same server without using extra IPs.

The easy way to do this would be to setup another static IP for the new sub domain. In many cases though, this is a real waste and can be a technical roadblock to using SSL.

If you have followed the news on the facebook session hack, you know that SSL is a really good thing for keeping your sites secure. It is a waste though to have to setup a new IP every time you setup a new sub domain.

For example, one CPanel account can have www.cmagic.biz, payments.cmagic.biz, portal.cmagic.biz, and school.cmagic.biz.

Each sub domain serves it’s own purpose, but having 4 different IP’s so each one can use the SSL certificate is a waste if they are all on the same server and same account.

To setup a wildcard certificate so that you can share the same IP, you follow the same rules as if you were installing a standard SSL cert. Your main site will need its own static IP. After you get the wild card certificate issued, install it normally on the main website (e.g. use www.cmagic.biz as the host). This can be done in the WHM or in the CPanel interface (if it is enabled for you).

Once that is done, make sure to use CPanel to create each sub domain.

At this point, should be able to go to each subdomain using http. Once you switch it to https though, you will see the main site instead (e.g. payments.cmagic.biz will show www.cmagic.biz instead if using SSL). To get apache to direct things properly, you can add a virtual host entry to your HTTP.CONF file.

The easiest way to do this is to use the WHM (yes, you will need admin support for this) and use the Apache Include Editor (Service Configuration -> Apache Configuration -> Include Editor).

Under the Post VirtualHost Include section, paste the following and put your information for EACH subdomain in (e.g. your site name, your home directory, etc…). Once you save that and restart apache, your site can have multiple subdomains that all use the wildcard SSL certificate and the same IP and you don’t have to get too tricky. Using the WHM this way allows you to avoid command line editing and such.


ServerName subdomain.examplesite.com
ServerAlias www.subdomain.examplesite.com
DocumentRoot /home/example/public_html/subdomain
ServerAdmin websubdomain@examplesite.com
## User example # Needed for Cpanel::ApacheConf
UseCanonicalName On
UserDir subdomain

suPHP_UserGroup example example


php4_admin_value open_basedir “/home/example:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp”
php5_admin_value open_basedir “/home/example:/usr/lib/php:/usr/local/lib/php:/tmp”



php_admin_value open_basedir “/home/example:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp”


php_admin_value open_basedir “/home/example:/usr/lib/php:/usr/local/lib/php:/tmp”


php_admin_value open_basedir “/home/example:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp”


SuexecUserGroup example example

CustomLog /usr/local/apache/domlogs/subdomain.examplesite.com combined
CustomLog /usr/local/apache/domlogs/subdomain.examplesite.com-bytes_log “%{%s}t %I .\n%{%s}t %O .”
ScriptAlias /cgi-bin/ /home/example/public_html/subdomain/cgi-bin/
SSLEngine on
SSLCertificateFile /etc/ssl/certs/examplesite.com.crt
SSLCertificateKeyFile /etc/ssl/private/examplesite.com.key
SSLCACertificateFile /etc/ssl/certs/examplesite.com.cabundle
CustomLog /usr/local/apache/domlogs/examplesite.com-ssl_log combined
SetEnvIf User-Agent “.*MSIE.*” nokeepalive ssl-unclean-shutdown

Cpanel and custom Apache or PHP modules

September 1st, 2010

холови гарнитуриRecently I had to recompile PHP to add additional support for modules not listed in the CPanel easyapache config options. CPanel has thought of most things even if they haven’t created a nice GUI interface for them yet.

In this case, you can add custom parameters to add to your apache or PHP compile.

By adding entries to the appropriate file, easyapache will pick them up when you use it’s wizard to rebuild your web stack.

For Apache 1.3.x — /var/cpanel/easy/apache/rawopts/Apache1
For Apache 2.0.x — /var/cpanel/easy/apache/rawopts/Apache2
For Apache 2.2.x — /var/cpanel/easy/apache/rawopts/Apache2_2
For all PHP 4.x versions — /var/cpanel/easy/apache/rawopts/all_php4
For all PHP 5.x versions — /var/cpanel/easy/apache/rawopts/all_php5
For Mod_suPHP — /var/cpanel/easy/apache/rawopts/all_suphp
For a specific PHP Version — /var/cpanel/easy/apache/rawopts/PHP-X.X.X

For example, to add LDAP support to PHP5, you would do the following…
echo “–with-ldap” >> /var/cpanel/easy/apache/rawopts/all_php5
echo “–with-ldap-sasl” >> /var/cpanel/easy/apache/rawopts/all_php5

Next time you rebuild Apache/PHP5, it will include LDAP and LDAPS modules.

The documentation on this is at: http://docs.cpanel.net/twiki/bin/view/EasyApache3/CustomConfigureFlags

Intro to Relational Databases

December 28th, 2009

A database is just a series of one or more tables. Each table is a separate and distinct entity. What makes a database “relational” is the ability to define relationships between one table and another. In some db systems (mssql), you can actually tell the system that there is a relationship. In others (mysql) you don’t have to define it. In either case, the nature of the relationships don’t change.

How relationships are defined
To setup a relationship, you just need a field on each table that matches. The field can be a number, a string, just about any field that isn’t a text field (cause they use pointers internally, that’s another lesson).

Student Table

  • Student ID
  • Social Security Number
  • Student Name

Government Table

  • Social Sec Number
  • Name

In the example above, there are two tables. One is a government table with your social sec number. The school table would be an example of your enrollment info at college. They assign their own student ID in an attempt to expose your ssn less, but they still use it to match up with govt information. Using this analogy you could match against the two tables using the ssn field. That would be the relational field. The key is to keep the info in the two fields matching.

One to One
A one to one relationship is like husband and wife. There is one in each table. A husbands table, and a wives table. Keep in mind that there are two tables involved, so it is very possible to have one in the first table with no corresponding item in the other. The key here is that when there is a match, it will only be one record on each side that matches. A more appropriate analogy would be with a table for men and a table for women and use a field to indicate the couple. Also, the previous example above using the ssn number is a good example of a one to one relationship.

Men

  • manID
  • Name
  • CoupleID

Women

  • womenID
  • Name
  • CoupleID

In this example, you can have a list of men and women. When you want them to be a couple, set the couple id field to the same number on both sides. Then you can pull a report of married couples. We will assume that anyone with a couple id of 0 is single, and that anyone with an id > 0 is a couple. You could use null values here too for single, but to make things easy we will use 0 (some db systems require you to deal with nulls differently and I don’t want to confuse things).

To get a list of single men:
Select * from men where `coupleid`=0
Same for women, just change the table name:
select * from women where `coupleid` = 0

To get a list of couples, you do what we call a join. This creates a merge of the two tables based on your criteria. There right, left, and inner joins. We won’t worry about all the differences right now.
select men.manid, men.name, women.womenid., women.name, men.coupleid from men, women where men.coupleid=women.coupleid

This will look like the following:
1 | Bob Smith | 3 | Sandy Smith | 1
It will create a temporary table (recordset) in memory that you can use in your code (PHP?) the same way as any other query. The joined information contains the elements you asked for from both tables.

Notice that after the SELECT you use table.column notation to avoid any confusion since both tables may have similar column names. After the where statement is where we indicate how to join the tables. We specify that the coupleid column is the one that needs to match. The database will only return records when that field matches.

One To Many
One to many relationships are more common in databases. This is where you have one item on the left table and 0 or more items on the right side. Think of a parent. You can have zero or more children. You can’t just create 10 fields for children names, you will find people who have 14 or 15 children. And creating that many fields wastes massive space since the average couple will have 2.5 children. It is a better solution to build a new table with information for just one child per row.

Parent

  • ParentID
  • Name

Children

  • ChildID
  • ParentID
  • Name

In this example, you have a parent with an ID. You then have another table that holds children. Each row is a child. To tell which ones are yours, you put your parentid in their parentid field. Then you can pull your kids out of the mess of children in the table. A little like picking your kid up from school.

To get your children (assuming your parentid is 1):
select * from children where ParentID=1

The key here is to make sure you know what your parent ID is. When writing code for this, you would need to track what parent you are looking at. In the example of a blog entry (parent) where you would want to view comments (children) you would want to track which blog entry you are viewing. This shouldn’t be a big issue as you are likely to have a url like the following when viewing the blog entry already:
/viewblog.php?blogid=1

The blogid=1 should be what you would use to grab comments and print them on the page:
select * from comments where blogid=1
Here it is in PHP code:
$sql = “SELECT * FROM comments WHERE blogid=” + $_GET[“blogid”];
$rs = mysql_query($sql);
while ($record = mysql_fetch_assoc($rs)) {
print $record[“comment”];
}

Many to Many
You can also do many to many relationships. This can get confusing though. Think plural wives and plural husbands at the same time. Generally this is just a really bad idea and shouldn’t be done unless there is no other way to represent the information. The linkage gets confusing and if you forget to update the linkage (relational fields) in your code somewhere it leads to trashed data. I am a firm believer in the KISS concept. The more you keep it simple, the fewer bugs you will introduce and the easier it will be to maintain later. Google many to many if you want for more information, but if you are reading this article and learning things, than stay away from many to many for now.

Crystalfontz LCD – 635 on FreeBSD and OpenSolaris

December 16th, 2009

I have recently gotten a hold of a CFA 635 LCD + Keypad device. Very slick. I was doing some work with it and wanted to use a unix OS to drive the device for some custom work. I ran into a couple minor things when getting the device setup.

1) It works great in windows, just use the USB driver from the crystalfontz website.
2) It works great in FreeBSD (v 6.3 +) but you need to load the kernel module (kldload uftdi or add uftdi_load=”YES” to the /boot/loader.conf file). See below for patch to allow examples to compile.
3) Works great in OpenSolaris if you update to the dev version. I couldn’t find the uftdi (SUNWuftdi package) in the standard 0906 install until I updated to the current dev version (b128+). I didn’t look hard though. After install reboot and you are golden.

In both unix systems, the device would be detected and light up and even get devices to show up in the /dev area. This was confusing at first because they were the wrong devices. You need the uftdi driver loaded and then it loads different/correct devices and it works like a charm.

Here is where it detected properly on my installs.
Freebsd: /dev/ttyU0
Opensolaris: /dev/term/0

I put this down because I had trouble finding this information out on the net and in the crystalfontz forums. There is lots of info for Linux/Win, but less for Unix.

FreeBSD Patch
FreeBSD is missing some entries in the termios.h file. Here are the lines you can add to your code (include/serial.h is recommended) if you are compiling the crystalfontz examples on freebsd. I used the ifndef around each so that it wouldn’t re-declare if it was present so it should be safe to put this in your code even if you are running on a system where they are defined.

#ifndef OFILL
#define OFILL 00000100
#endif
#ifndef OFDEL
#define OFDEL 00000200
#endif
#ifndef NLDLY
#define NLDLY 00001400
#endif
#ifndef TABDLY
#define TABDLY 00006000
#endif
#ifndef CRDLY
#define CRDLY 00030000
#endif
#ifndef FFDLY
#define FFDLY 00040000
#endif
#ifndef BSDLY
#define BSDLY 00100000
#endif
#ifndef VTDLY
#define VTDLY 00200000
#endif


Home | My Blog | Products | Edumed | About Us | Portfolio | Services | Location | Contact Us | Embedded Python | College Courses | Quick Scan | Web Spy | EZ Auction | Web Hosting
This page has been viewed 863141 times.

Copyright © 2005 Computer Magic And Software Design
(360) 417-6844
computermagic@hotmail.com
computer magic