Protected: My Standard Firewall in CentOS Web Server (iptables)

Administration, Info.Tech, Linux System Administration Enter your password to view comments.

This post is password protected. To view it please enter your password below:


Visual C# Upload File/Image via PHP with Squid-Cache in the Network

Info.Tech, Linux System Administration, PHP, Software Development, Visual C# View Comments

Today, I’ve been developing an oDesk-like activity monitoring application but for local network for my company, Innermax Support, and I came across with a problem of an errors:

  • An exception occurred during a WebClient request.
  • The remote server returned an error: (417) Expectation failed.

And during my search in Google — from forums, MSDN and other developers’ resources — they face same problem. The common issue was the 100-Continue problem passing to a network with squid-cache. So there’s a websites that I combined their codes and luckily it works. Just forgot the URLs, I can’t credit thank-you’s to them.. hehehe!

The setup is like this… there’s a firewall which has squid-cache in the local network and my server where I will upload my file/image is at the other network with public IP address. I will directly upload the file/image to my server using the assigned public IP address via PHP script.

Here’s my code to solve the problems;

public void uploadFile()
{
    try
    {
        // decleration of webclient
        ServicePointManager.Expect100Continue = false;
        System.Net.WebClient webby = new System.Net.WebClient();

        //initiate credentials
        webby.UseDefaultCredentials = false;
        webby.Credentials = new NetworkCredential("anonymous", "");

        //add headers
        webby.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.832)");
        webby.Headers.Add("Content-Type", "binary/octet-stream");

        //initiate upload file
        Byte[] result = webby.UploadFile("http://120.0.0.1/upload.php", "POST", @filename);

        string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
        MessageBox.Show(s);
        webby.Dispose();
    }
    catch (Exception)
    {
        // do nothing...
        MessageBox.Show("Upload failed!");
    }
}

So far, it works fine with me and satisfied of my solution. Hope this will help your problem too… :)

Outsourcing in the Philippines: InnerMax Support

Administration, Info.Tech, Learn New Things, Linux System Administration, Personal, PHP, Web Development View Comments

InnerMax SupportI’ve crossed  a good outsourcing firm in the Philippines, Innermax Support specializes in Web Development, Web Designing, SEO Services, Data Entry, Social Media Marketing, Inbound Phone Support, Outbound Phone Support.

They are comparatively new to the industry, but with their management along with all their agent’s combined knowledge, skills, and significantly valuable experiences; they surely can consistently turn every single task, great or small, highly distinguished more than any clients could wish for.

  • Innermax Support provides high quality services
  • Takes your business outsourcing to a new level with more leads and sales
  • Endows with the best services way beyond your desired results and expectations
  • Has assigned the best agents that fit every campaign you asked to be dealt with.
  • Gladly welcomes high level of engagement with the corporate stakeholders at your company.

Expect Quality Services

  • Exceptional results and return on assets
  • They never fail to keep our eyes peeled towards particular outcomes and circumstances of your campaign and in most instances; they most likely notice any sorts of any diversities and take action before such gets out of hand.
  • They are firmly committed to quality service and accommodation.
  • They are very knowledgeable by every inch and corners from tiniest to most immense aspects about e- marketing.
  • They never would hesitate to establish bountiful relationship and develop harmonious companionship with their valuable clients.
  • They live by the virtue of courteous and respectful demeanor to each of their clients.
  • They never would leave their clients oblivious about any current status of the relayed tasks.
  • And above all. They walk what they talk.

HowTo? .htaccess SEO-friendly URL

Administration, Info.Tech, Linux System Administration, PHP, Web Development View Comments

Today, its my 3rd time I created a SEO-friendly URL for a website… and its been a year since my last setup and forgot the procedure.. So I’m writing it down to my blog to remind me what I did… this time, I used different method coz I’m getting lazy using regex. hehehehe…

I used .htaccess generator at www.myseotool.com and upload to the server.. I tested it out.. and it seems it won’t work…

I search for the solution and I found the solution of Eddie Ringle about his experience too. So I edited my httpd.conf , since I’m also the system/server administrator, I have full access on the server, and change from;

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

to

<Directory />
  Options FollowSymLinks
  AllowOverride All
</Directory>

then save httpd.conf new changes. Then restart httpd or apache. then I tested it out..

wallah! it works!

MySQL 5.5 changing data folder

Administration, Info.Tech, Operating Systems View Comments

Today, I’m having problem with my MySQL. I bought new computer and want to transfer my databases from my old PC (using winXP) to new PC which is using windows 7. When I copied all my databases from data folder from my old computer and paste it to my new PC at “C:\Program Files\MySQL\MySQL Server 5.5\Data”, and restart the MySQL, I can’t see my databases. I found a solution from www.fossplanet.com and here’s the step (I slightly modified the step since i have different problem…)

  1. create folder in “C:\MySQLData”
  2. copy all files from “C:\Users\All Users\MySQL\MySQL Server 5.5\data” to “C:\MySQLData”
  3. go to RUN and type services.msc and stop MySQL service
  4. at “C:\Program Files\MySQL\MySQL Server 5.5″ — edit the my.ini and change the datadir value to your new MySQL data folder which is “C:/MySQLData/”
  5. after changing the datadir, at Services window (services.msc) start again your MySQL
  6. then cast command in MySQL CLI “show databases” and you should get your migrated databases showing… :)

 

——————-

thanks to:

Rolando A. Edwards
MySQL DBA (SCMDBA)

Load Balancing in Windows XP

Administration, Info.Tech, Operating Systems View Comments

I have an small office in my house and got two internet connections. Yet I want both connections will be used. So I found a solution to tweak the system. So here’s what we will do;

Requirements:

  1. 2 NICs
  2. REGEDIT

Guidelines:

Go to start menu and select RUN, then type “regedit” and a Registry Editor will appear. Go to “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters” and right click and mouse over to NEW then select DWORD value. Name the DWORD entity to RandomAdapter and change the value to 1 to make the selection of NICs randomly.

 


System Key: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters]
Value Name: RandomAdapter
Data Type: REG_DWORD (DWORD Value)
Value Data: (0 = disabled, 1 = enabled)

 

Reference: http://www.pctools.com/guides/registry/detail/951/

[Linux] Count Files and Delete Old Files

Administration, Info.Tech, Linux System Administration View Comments

Here’s the command to count the files inside a specific directory under linux environment:

ls -1 <target path> | wc -l

Here’s the command to delete all files older then 60 days within specific directory:

find <target path> -mtime +60 -type f -exec rm -rf {} \;

 

It help a lot for file management combined with cron jobs.

[Rackspace] Backup web server files to Cloud Files using PHP API

Administration, Info.Tech, Linux System Administration, PHP, Web Development View Comments

My latest task if to enhance our backup system that we currently have which all our backups are stored in the same server. Today, I managed to create an API integration to Rackspace Cloud Files and to transfer the generated backups of the web server to Cloud Files. Below is the guide for those who are having trouble using the API.

HowTo:

  1. Download the Cloud Files API – https://github.com/rackspace/php-cloudfiles/tree
  2. Follow the steps in extracting the API files to your server, http://cloudfiles.rackspacecloud.com/index.php/PHP_API_Installation
  3. And you may start creating php script, read http://docs.rackspacecloud.com/files/api/cf-devguide-latest.pdf

Possible Problems you will encounter:

PHP Fatal error:  Uncaught exception 'BadContentTypeException' with message 'Required Content-Type not set ...

Solution:

  • Install the PHP PECL FileInfo
# yum -y install php-devel php-pecl php-pear

// if "sh: make: command not found" error OR "ERROR: `make' failed" occur, groupinstall the Development Tools.
# yum -y groupinstall "Development Tools"

// install fileinfo
# pecl install fileinfo
# service httpd restart

if still occurs, last resort is upgrade your php to php 5.3

  • Upgrade your PHP to 5.3

first, remove the current installed php and php-common

# yum -y erase php php-common

then install the PHP v5.3

# yum -y install php53 php53-devel php-mysql php-gd php-pecl php-pear php-common
#service httpd restart

and that’s it.. your php script should be running…

for my scenario:

[root@server backups]# ls
backup.logs                          mysql_03262011_0155.tar.gz  mysql_04042011_0155.tar.gz  mysql_04132011_0155.tar.gz  WebFiles_04-06-2011.tar.gz
backup.mail                          mysql_03272011_0155.tar.gz  mysql_04052011_0155.tar.gz  mysql_04142011_0155.tar.gz  WebFiles_04-13-2011.tar.gz
backupSQL.script                     mysql_03282011_0155.tar.gz  mysql_04062011_0155.tar.gz  mysql_04152011_0155.tar.gz  WebFiles_04-20-2011.tar.gz
backupSQL.script.11082010            mysql_03292011_0155.tar.gz  mysql_04072011_0155.tar.gz  mysql_04162011_0155.tar.gz  cronjobs.txt
backup.web                           mysql_03302011_0155.tar.gz  mysql_04082011_0155.tar.gz  mysql_04172011_0155.tar.gz  init.cdn.script
backupWEB.script                     mysql_03312011_0155.tar.gz  mysql_04092011_0155.tar.gz  mysql_04182011_0155.tar.gz  monthly.2011
cdn.backup.php                       mysql_04012011_0155.tar.gz  mysql_04102011_0155.tar.gz  mysql_04192011_0155.tar.gz  scripts
mysql_03242011_0155.tar.gz  mysql_04022011_0155.tar.gz  mysql_04112011_0155.tar.gz  mysql_04202011_0155.tar.gz
mysql_03252011_0155.tar.gz  mysql_04032011_0155.tar.gz  mysql_04122011_0155.tar.gz  WebFiles_03-30-2011.tar.gz

These files are my backup files, so I created a PHP script named cdn.backup.php, with initializer named init.cdn.script to upload the backup files to Cloud files. If I execute my script, this is the output:

[root@server backups]# ./init.cdn.script
. . . . . . . . . . . . . Uploadeding mysql_04202011_0155.tar.gz...
SQL backup completed!
. . . . . . . . . . . . . . . . . . . . Uploadeding WebFiles_04-20-2011.tar.gz...
Web files backup completed!

That’s it… My files has been uploaded to cloud files.

Source code:

<?php
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());

require('cloudfiles.php');

date_default_timezone_set('America/New_York');
$cfgAccount = array('user'=>'demo','keys'=>'fe01ce2a7fbac8fafaed7c982a04e229');

$auth = new CF_Authentication($cfgAccount['user'], $cfgAccount['keys']);

$auth->authenticate();

if ($auth->authenticated())
{
	$conn = new CF_Connection($auth);
	//$conn->ssl_use_cabundle();

	$container_name = "backups";

	// execute this if no container
	//$backup_obj = $conn->create_container($container_name);
	//echo $backup_obj;

	if (function_exists('systemxx'))
	{
		system("ls -t",$lines);
		foreach($lines as &$line)
		{
			echo $line . "\n\n";
		}
	}
	else
	{
		$backupSQLSent = 0;
		$backupFILESent = 0;
		$limit = date("j") - 7;
		for ($i = date("j"); $i > $limit; $i--)
		{
			$d = dir("/backups/");
			//echo "Handle: " . $d->handle . "\n";
			//echo "Path: " . $d->path . "\n";
			while (false !== ($entry = $d->read()))
			{
				//  mysql_04122011.tar.gz
				if ((preg_match("/mysql_".date("mdY")."/", $entry)) && ($backupSQLSent == 0))
				{
					$backup_obj = $conn->get_container($container_name);

					echo 'Uploadeding '.$entry."...\n";

					$tarballs = $backup_obj->create_object("cdn_".mktime()."_".$entry);
					$filename = "/backups/".$entry;

					// upload file in a hard way
					$fsize = (float) sprintf("%u", filesize($filename));
					$fp = fopen($filename, "r");
					$tarballs->write($fp, $fsize);

					// upload file in a convenience way
					//$tarballs->load_from_filename($filename);

					echo "SQL backup completed!\n";
					$backupSQLSent = 1;
				}

				// WebFiles_04-20-2011.tar.gz
				if ((preg_match("/WebFiles_".date("m-d-Y")."/",$entry)) && ($backupFILESent == 0))
				{
					$backup_obj = $conn->get_container($container_name);

                                        echo 'Uploadeding '.$entry."...\n";

                                        $tarballs = $backup_obj->create_object("cdn_".mktime()."_".$entry);
                                        $filename = "/backups/".$entry;

                                        // upload file in a hard way
                                        $fsize = (float) sprintf("%u", filesize($filename));
                                        $fp = fopen($filename, "r");
                                        $tarballs->write($fp, $fsize);

                                        // upload file in a convenience way
                                        //$tarballs->load_from_filename($filename);

					echo "Web files backup completed!\n";
                                        $backupFILESent = 1;
				}

				if (($backupFILESent == 1) && ($backupSQLSent == 1))
				{
					break;
				}
				echo ". ";
			}
			$d->close();

			// if backup sent, end loop
			if (($backupFILESent == 1) && ($backupSQLSent == 1))
			{
				break;
			}
			echo "\n";
		}
	}

}
else
{
	echo 'Unable to connect to Cloud Files!';
}

?>

Downloads:

  1. Cloud Files PHP API (78)
  2. cdn.backup.php (69)

HowTo: Reset MySQL root password

Administration, Info.Tech, Linux System Administration View Comments

This is the way to reset MySQL server password in Centos Linux, steps below:

# /etc/init.d/mysql stop
# /usr/bin/mysqld_safe --skip-grant-tables --skip-networking &
# mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = '' WHERE User = 'root';
mysql> exit

# /etc/init.d/mysql stop
# /etc/init.d/mysql start

You may also use service to start and stop the mysql.

#service mysqld start
#service mysqld stop

Linux Web Mail Server

Administration, Info.Tech, Linux System Administration View Comments

I’ve been managing web servers yet I haven’t tried setting up web mail server. Today, this is my experiment.. Below is the steps or guides from Vincent Avelino, a friend of mine in C21. The scenario is running under CentOS 5.3.

Part 1

  1. Postfix – http://wiki.centos.org/HowTos/postfix
  2. SPF – http://old.openspf.org/wizard.html
  3. DKIM/DK – http://www.howtoforge.com/postfix-dkim-with-dkim-milter-centos5.1 ; http://www.ijs.si/software/amavisd/ ; http://www.howtoforge.com/how-to-implement-domainkeys-in-postfix-using-dk-milter-centos5.1
  4. Clamav – http://www.linuxmail.info/how-to-install-clam-antivirus-centos-5/ || http://www.linuxmail.info/how-to-install-clam-antivirus-centos-4/
  5. Spamassassin – http://spamassassin.apache.org/
  6. Roundcube

Part 2

  1. DNS
  • http://www.dnswatch.info/dkim/create-dns-record
  • http://www.simpledns.com/kb.aspx?kbid=1092
  • http://palma-seo.com/setting-dkim-spf-domainkeys-dns-bind

Result and Conclusion:

Can’t proceed the experiment as of now.. too busy.. hahahaha..

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in