Monday, February 21, 2011

Disable ssh root direct login

For security reasons it is not a good idea to allow ssh root direct login, it is better to login as another usre and then switch to root using "su" command.

To do this you need to disable root from login directly using ssh protocol, this will decrease the possibility of a hacker breaking your system, as now he will have to guess your user name and password.

1. Edit the file /etc/ssh/sshd_config

vi /etc/ssh/sshd_config

2. Locate this line with, writing this onces editing with vi or vim

:/Protocol

3. If it says

Protocol 2, 1 change it to Protocol 2

*This will enable only ssh2 which is more secure that ssh, do not do this if you need to log with a client that only support ssh, and not ssh2 protocol.

4.Next locate this line "PermitRootLogin yes" by entering this on your vi or vim editor

:/PermitRootLogin yes

and change it to no

PermitRootLogin no
4. Then save the file using shift+zz

5. Now restart the ssh service.

/etc/init.d/sshd restart

Monday, February 14, 2011

Sending emails from the localhost in php

Following article describes how to send an email from local host using XAMPP , WAMP or any other PHP servers. You have to do the following configurations in php.ini file in your local server.

1.Search for the attribute called "SMTP" in the php.ini file. Generally you can find the line "SMTP="localhost"". Change the localhost to smtp server name of your ISP and there is another attribute called "smtp_port" which should be set to 25.

2.) Specify the following headers and try to send the mail.

$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From: sender@sender.com’ . “\r\n”;
mail(“you@yourdomain.com”,”test subject”,”test body”,$headers);

Well that’s all, the mail is sent to “you@yourdomain.com” from the localhost.

Tuesday, January 4, 2011

MS Word to PDF converstion in C sharp

Ms Word to PDF conversion in C sharp
• 2007 Microsoft Office Add-in can be used to add the save as pdf feature to a word document.
• I used Microsoft Word 12.0 Object Library to access the word document and programmatically converted in to PDF.
• I used the bellow code to convert a MS word document to pdf.
• Related links
1. http://msdn.microsoft.com/en-us/library/bb412305.aspx
2. http://blogs.msdn.com/b/pranab/archive/2008/09/24/convert-office-documents-docx-pptx-pub-into-pdf-programmatically.aspx?CommentPosted=true#commentmessage


For this code to work you must have to add a reference to Microsoft.Office.Interop.World.dll (in Visual Studio 2008, There will be two versions.)

1. Version 11.0
2. Version 12.0

I used version 11.0 here



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace LK_IGen
{
class PdfConverter
{
private string ToSend;
public void wordToPdf(string sourceFile,string dFile)
{
this.ToSend = System.Configuration.ConfigurationSettings.AppSettings["SentPDF"].ToString();
String destFile=this.ToSend + dFile+".pdf";
ApplicationClass wordApplication = new ApplicationClass();

Document wordDocument = null;

object paramSourceDocPath = @sourceFile;

object paramMissing = Type.Missing;

string paramExportFilePath = destFile;
// string paramExportFilePath = @"E:\Test.pdf";

WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;

bool paramOpenAfterExport = false;

WdExportOptimizeFor paramExportOptimizeFor =

WdExportOptimizeFor.wdExportOptimizeForPrint;

WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;

int paramStartPage = 0;

int paramEndPage = 0;

WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;

bool paramIncludeDocProps = true;

bool paramKeepIRM = true;

WdExportCreateBookmarks paramCreateBookmarks =

WdExportCreateBookmarks.wdExportCreateWordBookmarks;

bool paramDocStructureTags = true;

bool paramBitmapMissingFonts = true;

bool paramUseISO19005_1 = false;

try
{

// Open the source document.

wordDocument = wordApplication.Documents.Open(

ref paramSourceDocPath, ref paramMissing, ref paramMissing,

ref paramMissing, ref paramMissing, ref paramMissing,

ref paramMissing, ref paramMissing, ref paramMissing,

ref paramMissing, ref paramMissing, ref paramMissing,

ref paramMissing, ref paramMissing, ref paramMissing,

ref paramMissing);



// Export it in the specified format.

if (wordDocument != null)

wordDocument.ExportAsFixedFormat(paramExportFilePath,

paramExportFormat, paramOpenAfterExport,

paramExportOptimizeFor, paramExportRange, paramStartPage,

paramEndPage, paramExportItem, paramIncludeDocProps,

paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,

paramBitmapMissingFonts, paramUseISO19005_1,

ref paramMissing);

}

catch (Exception ex)
{

Console.WriteLine("Error");
Console.WriteLine(ex);
Console.Read();
// Respond to the error

}

finally
{

// Close and release the Document object.

if (wordDocument != null)
{

wordDocument.Close(ref paramMissing, ref paramMissing,

ref paramMissing);

wordDocument = null;

}



// Quit Word and release the ApplicationClass object.

if (wordApplication != null)
{

wordApplication.Quit(ref paramMissing, ref paramMissing,

ref paramMissing);

wordApplication = null;

}



GC.Collect();

GC.WaitForPendingFinalizers();

GC.Collect();

GC.WaitForPendingFinalizers();

}

}



}
}

Wednesday, July 14, 2010

How to Add a file downloder to a website in PHP

1. use the following code to add file downloading funtionality to your web site.
2. To add multiple download buttons to your web site you must define seperate forms for each submit button and pass the file path as a hidden field.


$filename = $_GET['file'];

// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

// addition by Jorg Weske
$file_extension = strtolower(substr(strrchr($filename,"."),1));

if( $filename == "" )
{
echo "eLouai's Download ScriptERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath";
exit;
} elseif ( ! file_exists( $filename ) )
{
echo "eLouai's Download ScriptERROR: File not found. USE force-download.php?file=filepath";
exit;
};
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();

?>

Thursday, February 5, 2009

How to Rank high on google

You can get a good idea on how to rank high on Google by following this link

Firebug plug-in for Mozilla

Hi friends,

Firebug is a plug-in for Mozilla, which helps us to debug javascripts, edit html and CSS codes dynamically. Not only that we can change and test html and JavaScript values, like a normal programming IDE. I think it will be very useful for you.You can download the plug-in using this link https://addons.mozilla.org/en-US/firefox/addon/1843

Best regards,
Charith

Monday, February 2, 2009

A grate way to improve your English faster and more Easily

Hi all,
English is an important language because it is spoken through out the world.So this reference will helpful to improve your english knowledge.Follow the link bellow. learn english Then join to the free email course.

An error occured while completing process -java.lang.reflect.InvocationTargetException

Hi friends,
When I’m trying to build a java client to access a web service using apache axis 2 Code Generator eclipse plug-in I got an error at the point where I clicked the finish button to complete the code Generator plug-in Wizard. Finally I could find a solution to this error from the web. So I hope to share it with you. I think it will be helpfull to you too.

Solution
Simply you can solve this error by adding following jar files to eclipse plug-in directroy. These jar files can be downloaded from http://www.findjar.com/

1. backport-util-concurrent-3.1.jar

2. stax-api-1.0.1.jar

Developing a web service using Apache axis 2 eclipse plug-in

If you want to know, how to build a web service using apache axis 2 follow this link. I think this will helpfull to the people who are interested in java.