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!

[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..

install and configure subversion (SVN)

Info.Tech, Linux System Administration View Comments

I keep this guidelines because I find it very useful which I think we need it in our project development as a team in Project CollabHQ. I’m getting tired synchronizing always my files in my local PC between published files after other team members updated the files in the server.


To install subversion on CentOS you need to have the RMForge custom repository enabled (read my “Add the RPMForge custom repository to CentOS” post about how to do this), and then issue the following command:

sudo yum install subversion

This will check for any dependencies and then prompt you to install those and subversion itself. Type in "y" and <enter> to install these.

Unfortunately it doesn’t set up anything else after installing the necessary files, so you need to add a subversion user and set up the repositories etc yourself. If we decide to call the subversion user “svn” then you add them like so:

sudo /usr/sbin/useradd svn
sudo passwd svn

And then change to the subversion user like so:

su svn

Change to the svn user's directory and then create a "repositories" directory like so:

cd
mkdir repositories

And now create your project's repository. For example, if we had a project called "myproject" you would do this:

cd repositories
svnadmin create myproject

There will now be a “myproject” directory containing the following:

-rw-rw-r-- 1 svn svn  229 Nov 21 16:58 README.txt
drwxrwxr-x 2 svn svn 1024 Nov 21 16:58 conf
drwxrwsr-x 6 svn svn 1024 Nov 21 16:58 db
-r--r--r-- 1 svn svn    2 Nov 21 16:58 format
drwxrwxr-x 2 svn svn 1024 Nov 21 16:58 hooks
drwxrwxr-x 2 svn svn 1024 Nov 21 16:58 locks

You need to edit “myproject/conf/svnserve.conf” and uncomment the following lines:

auth-access = write
password-db = passwd

and edit the password file “myproject/conf/passwd” adding a new user and password. Note that the password is stored in plain text. In the following example we have a user called “john” whose password is “foobar123″:

[users]
john = foobar123

And finally, as the svn user, start the subversion daemon like so:

svnserve -d -r /home/svn/repositories

You can now connect to the subversion repository at e.g. svn://svn@hostname/myproject

You can add additional repositories under this user using the “svnadmin create” command and then access them at svn://[userame]@[hostname]/[project name]

Other reference at http://wiki.centos.org/HowTos/Subversion

Article by: http://www.electrictoolbox.com/install-subversion-centos/

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