Sunday, May 29, 2011

Firefox 4 change: input type image only submits x and y, not name when clicked. Keyboard as before

Firefox 4.0 beta — as well as IE and Opera — do not send name/value for input type=”image”; only .x and .y coordinates are sent.

Note, this is when clicking the input image with a mouse. When navigating using keyboard, focusing on it, and pressing enter, then the name does get submitted.

If you need to use an image button as a submit button in a form then you have to pass a hidden value to process the form.

EX:





then in test.php page

isset($_post['passvalue'])

{

process the request

}



?>







Firefox 4 change: input type image only submits x and y, not name when clicked. Keyboard as before

Firefox 4.0 beta — as well as IE and Opera — do not send name/value for input type=”image”; only .x and .y coordinates are sent.

Note, this is when clicking the input image with a mouse. When navigating using keyboard, focusing on it, and pressing enter, then the name does get submitted.

If you need to use an image button as a submit button



Firefox 4 change: input type image only submits x and y, not name when clicked. Keyboard as before

Firefox 4.0 beta — as well as IE and Opera — do not send name/value for input type=”image”; only .x and .y coordinates are sent.

Note, this is when clicking the input image with a mouse. When navigating using keyboard, focusing on it, and pressing enter, then the name does get submitted.

If you need to use an image button as a submit button in a form then you have to pass hidden value



Sunday, May 15, 2011

How to set windows look and feel in JFrame GUI in java

public static void main(String[] args) {
try
{

UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception e) { }

new SwingApplication(); //Create and show the GUI.
}

Monday, May 2, 2011

Linux Commands

tar Commands

1. Creating an uncompressed tar achieve.

tar cvf filename.tar filename/foldername


In the above command:
  • c – create a new archive
  • v – verbosely list files which are processed.
  • f – following is the archive file name
ex:

tar cvf abc.tar myfile.txt
tar cvf pqr.tar myfolder

2.
Creating a tar gzipped archieve using option cvzf


To use gzip compression on the tar archive, use the z option as follows.

tar cvzf filename.tar.gz dirname/

tar cvzf filename.tar.gz filename

In the above command

  • c – create a new archive
  • v – verbosely list files which are processed.
  • f – following is the archive file name
  • z– filter the archive through gzip
ex:

tar cvzf filename.tar.gz filename.txt

3. Extracting (untar) a file using tar command

tar xvf filename.tar

In the above command

  • x – extract files from archive.
  • v – verbosely list files which are processed.
  • f – following is the archive file name

ex:

tar xvf filename.tar

4. Extracting a gziped tar achieve.

tar xvfz filename.tar.gz

In the above command
  • x – extract files from archive.
  • v – verbosely list files which are processed.
  • f – following is the archive file name
  • z- uncompressing a gzipped tar achieve.

tail Command

Example 1:

tail mytextfile.txt
-  The above command list the last 10 lines of the file "mytextfile.txt"

tail mytextfile.txt -n 100

- The above command list last 100 lines of the file "mytextfile.txt"

tail -f mytextfile.txt 
- The above command displays the last 10 lines and then update the file as new lines are being added
- This is a very useful command to watch log files in realtime

tail -f access.log | grep 127.0.0.2

- The above command can use to filter the output of the file

Monday, March 21, 2011

X startup failed in Fedora 10

When I install fedora 10 in my PC it does not show the X start up. It performs the text mode installation.

Cause:
* If the graphic card is not support or can not be auto detected the installer goes to the text mode.

Solution:
* You can try the xdriver=vesa to force graphical install using the VESA graphics driver.

* To do this you have to edit boot option.

*Press tab button and enter xdriver=vesa

Monday, March 7, 2011

ldap_bind(): Unable to bind to server: Protocol error

Note that you have to specify the protocol version prior to making a call to ldap_bind, when the server is expecting LDAP protocol version 3. If you do not, you will receive a warning and fail to bind, such as:

ldap_bind(): Unable to bind to server: Protocol error

In order to avoid this, make this call:

ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
?>

Where $ds is the result returned by ldap_connect(...);

Solved PHP LDAP error - Fatal error: Call to undefined function ldap_connect()

Solution

1. find the php.ini file in apache bin folder

2. In php.ini, enable setting extension=php_ldap.dll
- find the line with this setting
- remove the comment-indicating semicolon in front of it
- save php.ini
- restart apache

User authentication with LDAP server sample code

ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapconfig['host'] = xxx.xxx.xxx.xxx';// IP Address
$ldapconfig['port'] = 389; //port(default port is 389)
$ldapconfig['basedn'] ='dc=yyy,dc=yy';

$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);

//$dn="uid=".$username.",ou=people,".$ldapconfig['basedn'];
$dn="uid=".charith.",".$ldapconfig['basedn'];
$password='yourdullaa';

if ($bind=ldap_bind($ds, $dn, $password))
{
echo("Login correct");
}
else
{

echo("Unable to bind to server.
");


}

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();

}

}



}
}