Thursday, October 20, 2016

Converting Common Numeral Systems to BASE 10


A numeral system in a way to represent or express numbers using digits or other symbols in a consistent manner.

The most widely used numeral system by people is decimal, or BASE 10.

Definitions


10^4

In the example above, the number 10 is called the BASE (or radix / root), and the number 4 is called the exponent. The exponent corresponds to the number of times the base is used as a factor (4 x 4 x 4 x 4).

Binary (0, 1) - used by logic gates in most digital circuits

To convert the binary number 1011 to decimal,

 1         0         1         1             # Your binary number
(1x2^3) + (0x2^2) + (1x2^1) + (1x2^0) # Multiply your number by the power of the base that the digit represents
   8    +    0    +    2    +    1    = 11   # Add the numbers together to get the result in BASE 10


Octal (0..7) - used often in computing

To convert the octal number 350 into decimal,

 3         5         0 # Your octal number
(3x8^2) + (5x8^1) + (0x8^0) # Multiply your number by the power of the base that the digit represents
  192   +   40    +    0    = 232 # Add the numbers together to get the result in BASE 10


Hexadecimal, hex (0..9, a..f) - used often in computing

To convert the hex number 1F20 into decimal,

 1   F      2     0 # Your hex number
(1x16^3) + (Fx16^2)  + (2x16^1) + (0x16^0) # Multiply your number by the power of the base that the digit represents
(1x16^3) + (15x16^2) + (2x16^1) + (0x16^0) # Convert the hex numbers into the decimal equivilent
4096     +  3840     +  32      +  0       = 7968 # Add the numbers together to get the result in BASE 10


Further Reading:

http://whatis.techtarget.com/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-XNOR

Online Toolbox

Converter: http://coderstoolbox.net/number/
- Does string, number, time, network, and bandwidth conversion

Sunday, October 16, 2016

Security+ Certification

I recently passed the CompTIA Security+ ce exam. I've never been much on certifications, but I decided to take this test to formalize some of my knowledge. 

About the Test

There were 72 questions and I had 90 minutes to complete the test. This was enough time to complete the test and to fully review all of the questions. A few of the questions were 'simulation' questions and the rest were multiple choice. 

To prepare, I purchased the CertMaster training, which can be bought as an add-on when you purchase your exam voucher.  https://certification.comptia.org/training/certmaster/security


The above training takes ~15 hours to complete the initial 702 practice questions. I took the initial training, reviewed concepts that I did not know, and reviewed missed questions twice before taking the test.

A Hex Upon Numerals

BASE 16

0123456789abcdef

Definition

In mathematics and computing, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F (or alternatively a, b, c, d, e, f) to represent values ten to fifteen. -- https://en.wikipedia.org/wiki/Hexadecimal

Notes

  • Hex numbers uses digits from 0..9 and A..F
  • 0xVALU  - Unix/C prefix
  • Other than 0xVALU, VALU16 is a common notation
  • Each character is the equivalent of a nibble (4 bits)

Converting hex (BASE 16) to decimal (BASE 10)

A byte can be represented as:

n·16^3 n·16^2 n·16^1 n·16^0

OR

n·4096 n·256 n·16 n·1

*Any nonzero number raised to the zero power is equal to one (i.e., n^0=1). This concludes that all nonzero numbers raised to the zero power are equivalent because they all equal 1. Note that it is any nonzero number, since 00 is undefined.

Conversion Examples

0x31 = (3·16^1)+(1·16^0) = (48) + (1) = 49
0xc9 = (12·16^1) + (9·16^0) = (192) + (9) = 201
0x1f = (1·16) + (15·1) = 31

Decimal to Hexadecimal to Binary Conversion Table

Dec Hex Bin
B10 B16  B2 
0 0 00000000
1 1 00000001
2 2 00000010
3 3 00000011
4 4 00000100
5 5 00000101
6 6 00000110
7 7 00000111
8 8 00001000
9 9 00001001
10 a 00001010
11 b 00001011
12 c 00001100
13 d 00001101
14 e 00001110
15 f 00001111
16 10 00010000
17 11 00010001
18 12 00010010
19 13 00010011
20 14 00010100

References




Binary is as easy as 1, 10, 11

Definition

Binary - In mathematics and digital electronics, a binary number is a number expressed in the binary numeral system or base-2 numeral system which represents numeric values using two different symbols: typically 0 (zero) and 1 (one).https://en.wikipedia.org/wiki/Binary_number

Notes

  • BASE 2 Counting method only uses 0 and 1
  • One binary digit is called a bit
  • Two digits are called a crumb, four digits are called a nibble, and eight digits are called a byte
  • Lower Case letters start with 011xxxxx
  • Upper Case letters start with 010xxxxx
  • When counting, range 0-1, carry the 1 (i.e. 00000000, 00000001, 00000010, 00000011, 00000100, 00000101, 00000110, 00000111, 00001000, 00001001, 00001010 ...)
  • 1+1=10

Converting binary (BASE 2) to decimal (BASE 10)

A byte can be represented as:

n·2^7 | n·2^6 | n·2^5 | n·2^4 | n·2^3 | n·2^2 | n·2^1 | n·2^0

OR

n·128 | n·64 | n·32 | n·16 | n·8 | n·4 | n·2 | n·1*

*Any nonzero number raised to the zero power is equal to one (i.e., n^0=1). This concludes that all nonzero numbers raised to the zero power are equivalent because they all equal 1. Note that it is any nonzero number, since 00 is undefined.

Conversion Examples

10 = 1·2^1 | 0·2^0 = 1·2 + 0·1 = 2
111 = 1·2^2 | 1·2^1 | 1·2^0 = 1·4 + 1·2 + 1·1 =7
1011 =  1·2^3 | 0·2^2 | 1·2^1 | 1·2^0 = 1·8 + 0 + 1·2 + 1 = 11

Converting binary (BASE 10) to decimal (BASE 2)

2^4 2^3 2^2 2^1 2^0
16 8 4 2 1

Use the value in the second row to count to the value--you can use each value no more than 1 time (since we count 0..1). For example, we want to convert 22 to binary. To do this we need:

(1 x 16) + (0x8) + (1x4) + (1x2) + (0x1)

10110 = 22

Letter to ASCII to Binary Character Table

LetterASCII CodeBinaryLetterASCII CodeBinary
a09701100001A06501000001
b09801100010B06601000010
c09901100011C06701000011
d10001100100D06801000100
e10101100101E06901000101
f10201100110F07001000110
g10301100111G07101000111
h10401101000H07201001000
i10501101001I07301001001
j10601101010J07401001010
k10701101011K07501001011
l10801101100L07601001100
m10901101101M07701001101
n11001101110N07801001110
o11101101111O07901001111
p11201110000P08001010000
q11301110001Q08101010001
r11401110010R08201010010
s11501110011S08301010011
t11601110100T08401010100
u11701110101U08501010101
v11801110110V08601010110
w11901110111W08701010111
x12001111000X08801011000
y12101111001Y08901011001
z12201111010Z09001011010

References 





Friday, September 30, 2016

How To Set Up the Latest MediaWiki with Lighttpd on Ubuntu 14.04

This article was originally written to provide a Technical Writing sample. 

Introduction


MediaWiki is a popular open source wiki platform that can be used for public or internal collaborative content publishing. MediaWiki is used for many of the most popular wikis on the Internet including Wikipedia, the site that the project was originally designed to serve.
In this guide, we will be setting up the latest version of MediaWiki on an Ubuntu 14.04 server. We will use the lighttpd web server to make the actual content available, php-fpm to handle dynamic processing, and mysql to store our wiki's data.

Prerequisites


To complete this guide, you should have access to a clean Ubuntu 14.04 server instance. On this system, you should have a non-root user configured with sudo privileges for administrative tasks. You can learn how to set this up by following our Ubuntu 14.04 initial server setup guide.
Before we install any packages, we should also log into our server with our sudo user and update our local package index.
sudo apt-get update
This will download a package list from the software repository sources that are configured on your server and update the package list with information on the newest versions of available packages and their dependencies.
Once you've taken care of all of prerequisites and updated your server, you're ready to get started with this guide.


Step One — Install MySQL


MySQL is a popular open source relational database management system (RDBMS) that is used to store and manage the data in many web applications.
In this step, we will start by downloading and installing MySQL from the official Ubuntu repositories using apt, the package tool that is used to retrieve, configure, install and remove software packages in Ubuntu. After the software has been installed, we will configure the database for our MediaWiki installation.
To install MySQL, type:
sudo apt-get install mysql-server
You will be asked to create a root (administrative) password. This should be a secure, unique password that will only be used for MySQL. Remember this password because you'll need it later.
Next, you will need to generate the directory structure that MySQL will use to store its databases and information.
sudo mysql_install_db
At this point, it's a good idea to secure MySQL. Fortunately, there is a program that will help you to improve the security of your default MySQL installation.
sudo mysql_secure_installation
This program will prompt you to implement several recommended security improvements, like removing anonymous-user accounts and test databases that can be accessed by all users.
Recommendations for mysql_secure_installation
You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
Finally, we will create a unique database and user for MediaWiki. For security reasons, it is recommended that you use one (non-root) user per database.
To do this, we will need to log in to the database.
sudo mysql -u root -p
We will then add a new database called <^>mwdb<^>, a user called <^>mwuser<^>, and we will be setting a password <^>mwpass<^>. For your installation, choose a more secure password than <^>mwpass<^>. Also, make sure you record the database, database user, and password because you'll need these to complete the MediaWiki installation.
CREATE DATABASE mwdb; CREATE USER mwuser@localhost IDENTIFIED BY 'mwpass'; GRANT index, create, select, insert, update, delete, alter, lock tables on mwdb.* TO mwuser@localhost;
These commands will create a database and a user and will grant database permissions to the user. However, you will need to tell the server to reload the grant (permission) tables before the changes take effect.
custom_prefix(mysql>) FLUSH PRIVILEGES;
Once this is done, you can exit the database using the exit command.
custom_prefix(mysql>) EXIT


Step Two — Install and Configure Lighttpd and PHP


Lighttpd is a secure and flexible open source web server that is optimized for high performance environments that we will use to display web pages to our site visitors.
In this step, we will use apt to install the lighttpd and php packages from the Ubuntu repositories. After the software is installed, we'll need to do some additional configuration to ensure that lighthttpd can utilize php-fpm.
To install lighthttpd, type:
sudo apt-get install lighttpd
This will install lighthttpd and start the service once the installation finishes. We can test the status of the server by typing your IP address into a web browser. We should see the Lighttpd placeholder page.
lighthttpd

Next, install php and php-fpm.
sudo apt-get install php5-fpm php5
We will also want to install the following packages to support the MediaWiki installation:
sudo apt-get install php5-mysql php-apc php5-intl imagemagick
Now that we've installed lighthttpd, php, and the supporting packages, we'll want to enable php in lighttpd by modifying the '/etc/php5/fpm/php.ini' file using nano, a command line text editor.
sudo nano /etc/php5/fpm/php.ini
You'll want to uncomment the cgi.fix_pathinfo=1: option by removing the ; at the beginning of the line. Make sure you save and close the file.
Next, we'll need to update the lighttpd php configuration file to use php-fpm.
sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
The configuration file should look like this:
/etc/lighttpd/conf-available/15-fastcgi-php.conf

/usr/share/doc/lighttpd-doc/fastcgi.txt.gz

http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi


Start an FastCGI server for php (needs the php5-cgi package)


fastcgi.server += ( ".php" => (( "socket" => "/var/run/php5-fpm.sock", "broken-scriptfilename" => "enable" )) ) ```
Save and exit the file.
Next, we'll need to enable the php-fpm FastCGI process manager by running the following commands:
sudo lighttpd-enable-mod fastcgi sudo lighttpd-enable-mod fastcgi-php
Finally, we'll need to reload lighttpd:
sudo service lighttpd force-reload
At this point we can confirm that php-fpm is working correctly by creating a PHP file called phpinfo.php in the lighttpd web directory.
sudo nano /var/www/phpinfo.php
Enter the following text into the file:
/var/www/phpinfo.php

Save and exit the file. Now we can load phpinfo.php in a browser by going to http://<^>server ip<^>/phpinfo.php. If you see the Server API FPM/FastCGI line, then you know that everything is working as expected.

php info

[WARNING] Warning: Before proceeding, you'll want to remove the 'phpinfo.php' file. While this file is very useful for troublshooting and debugging, it contains sensitive information that could be used to comprimise your server. <$>
sudo rm /var/www/phpinfo.php
Once you've removed the phpinfo.php file, you're ready to move on to the next step.


Step Three - Install MediaWiki


In this step, we will download, install, and configure the latest MediaWiki package.
First, we'll download the MediaWiki package:
cd /tmp sudo wget https://releases.wikimedia.org/mediawiki/1.27/mediawiki-1.27.0-rc.1.tar.gz
This will download a compressed archive file named 'mediawiki-1.27.0-rc.1.tar.gz' from wikimedia to a temporary folder.
Next, we will need to extract the file and move it to the lighthttpd web directory.
sudo tar -xvzf mediawiki-1.27.0-rc.1.tar.gz sudo mkdir /var/www/mediawiki sudo mv mediawiki-1.27.0-rc.1/* /var/www/mediawiki
Now that you've downloaded the MediaWiki files, you can proceed to the next step.


Step Four — Complete the MediaWiki Installation


Now that you have your files in place and your software is configured, you can complete the MediaWiki installation through the web interface.
To start the installer, navigate to your server's public IP address or domain name and run through the configuration wizard at 'http://<^>server ip<^>/mediawiki'. This page will tell you that the LocalSettings.php file is not found. Click on the 'Please set up the wiki first.' link and you will be guided through the wiki setup. At the end of this step, a 'LocalSettings.php' file will be generated.
Installer
First, you will be asked to select your language.

Language

Next, an environment check will run to determine if any packages are missing or if there are any configuration issues.

Env Check

The third screen will ask you to connect to a database.
  • If you have followed this guide, your database will be installed on the same server as the MediaWiki installation and you will select 'localhost' for the 'Database host'.
  • Use the database name, username, and password for the <^>mwdb<^> database that we created in step one.
  • In most cases, the 'Database table prefix' can be left blank. This prefix is usually only used if you need to share a database between multiple applications.
Database

You should use the default database settings (Storage engine: InnoDB, Database character set: Binary) as recommended by the installer.

DB Config Settings

You will then be asked to name your wiki and provide credentials for your administrator account.

Wiki Name

You will also be asked if you would like for the installer to 'Ask me more questions' or 'I'm bored already, just install the wiki'. If you choose to be asked more questions, the installer will ask you to configure several additional settings, including user permissions, copyright information, email configuration, user experience, optional extensions, image uploads, and caching.

Credentials
Once you finalize the configuration, a LocalSettings.php file will be downloaded. You will need to download the and put it in the base of your wiki installation (the same directory as index.php).

LocalSettings Download
However, it may be easier to create a LocalSettings.php file and paste the contents of the downloaded file into the LocalSettings.php file that you created:
sudo nano /var/www/mediawiki/LocalSettings.php
You should now be able to access your wiki at http://<^>server ip<^>/mediawiki/.


Conclusion


Your new MediaWiki site should now be configured and ready to use on your Ubuntu 14.04 server. Using this website, you will be able to directly publish and modify content from a web browser.