Posts

Showing posts from 2008

Apache:400 Bad request

Error message in Browser- Bad Request Your browser sent a request that this server could not understand. Apache/2.2.0 (Fedora) Server at 10.129.150.205 Port 80 Entry in Apache Error Log- [Wed Dec 17 13:15:23 2008] [error] [client 10.129.150.205] ModSecurity: Access denied with code 400 (phase 2). Pattern match "^[\\\\d\\\\.]+$" at REQUEST_HEADERS:Host. [id "960017"] [msg "Host header is a numeric IP address"] [severity "CRITICAL"] [hostname "10.129.150.205"] [uri "/"] [unique_id "Qi9cCgqBls0AACJ-VCgAAAAF"] Solution- Check "/etc/httpd/modsecurity.d" directory and modify file "modsecurity_crs_21_protocol_anomalies.conf " modsecurity_crs_21_protocol_anomalies.conf ---------------------------------------------------------------- # # Check that the host header is not an IP address # SecRule REQUEST_HEADERS:Host "^[\d\.]+$" "deny,log,auditlog,status:400,msg:'Host header is a numeric ...

Run SQL query from shell prompt

mysql -u user -p -e 'SQL Query' database Where, -u : Specify mysql database user name -p : Prompt for password -e : Execute sql query database : Specify database name To list all database, enter: $ mysql -u replicant -p -e 'show databases;' To list count all rows, enter: $ mysql -u replicant -p -e 'SELECT COUNT(*) FROM remote_logs' Sample output: Enter password: +----------+ | count(*) | +----------+ | 471 | +----------+ Tell mysql to display output a page at a time, by using more or less pager: $ mysql --pager=/usr/bin/less -u replicant -p -e 'SELECT COUNT(*) FROM remote_logs' Redirect out to a file: $ mysql -u replicant -p 'PassWord' -e 'SELECT COUNT(*) FROM quotes' remote_logs > sql.output.txta To avoid password prompt just create ~/my.cnf file: [client] # for local server #host=localhost host=10.128.150.205 user=replicant password=myPassword [mysql] pager=/usr/bin/less

Html performance

HTML is a very flexible language. It never generates errors, and often provides many different ways to accomplish a single task. For example, a list item can be specified as <LI>description or <LI>description</LI>. The only difference is the closing </LI> tag, but it might be biggest mistake. If these tags don't close, the browser renders pages just fine. But if tags are closed then it will render the pages even faster. Take a look at the following code segment: <P>Here is a list of names: <UL> <LI>Kanpur <LI>Jhanshi <LI>Lucknow <LI>Pune <LI>Bangalore </UL> In above example, the <P> and <LI> items are included without their closing counterparts. When parsing such HTML code, the browser needs to look ahead to find out where the paragraph or list item ends. The following code generates the same output in a more efficient method: <P>Here is a list of names :</P> <UL> <LI>Kanpu...

Mysql Prompts

You can change the prompt on the MySQL command-line tool to show user name, time, current database or many other useful facts. mysql> prompt \R:\m:\s> PROMPT set to '\R:\m:\s>' 11:46:16>show tables; +----------------------+ | Tables_in_wordpress | +----------------------+ | wp_categories | | wp_comments | | wp_linkcategories | +---------------------+ 9 rows in set (0.00 sec) 11:46:24> If you specify the prompt command with no argument, mysql resets the prompt to the default of mysql> . The prompt command reconfigures the default mysql> prompt. The string for defining the prompt can contain the following special sequences: Option Description \c A counter that increments for each statement you issue \D The full current date \d The default database \h The server host \l The current delimiter (new in 5.0.25) \m Minutes of the current...

isset for javascript

try{ if(variablename){ // If true // write your code here } }catch(e){ //If false // write your code here if false }

Mass Replace String in MySQL Database

Problem: I want to change url path or a string from mysql table. Solution: Do it manually? No way. There are hundreds of them! There are basically two ways - First, output the database table and use text editor's "search and replace" function. Second, use MySQL REPLACE function . Here is the SQL query to replace string in database table :- UPDATE table_name SET column_name = REPLACE ( column_name, "original_string" , "replace_string" );

Download multiple files from FTP

Problem : When we download multiple file from command line ftp, it prompt for every file. Solution: ftp> prompt ftp> mget *.* or ftp> mget

Mysql:Reset Auto increment No.

I have a database table with a auto increment column for primary key. As the records being add and delete many times, the auto increment value will keep increasing. Problem One: I want to delete all data from table. Solution: TRUNCATE table tbl_name this command will delete everything from the table and start again from 1.... DELETE just does the same but keeps the current auto_increment value.... Problem Two: If I have entered 10 records, and deleted 9th, 10th records. The next auto increment value will be 11, not 9. Solution: Run a query: ALTER TABLE tablename AUTO_INCREMENT = 1 This will reset the next auto increment value to current largest value in the auto increment column + 1. So, the auto increment value of next inserted record will start from 9. Problem Three: If I have entered 10 records, and deleted center records - 4th, 5th. I want to insert next record as 4th not 11th. Solution: Run the following query: SET insert_id = 4; INSERT INTO tablename VALUES (’blah’, ‘…’);...

Inbound connections limit in Windows XP

SYMPTOMS At a computer that is running Windows XP or Windows 2000, when you attempt to connect to another Windows XP computer, you may receive the following error message: No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept. CAUSE This behavior occurs if the computer reaches the maximum number of inbound connections that the computer can host. ALTERNATIVE SOLUTION You can configure the AutoDisconnect time by running the following command from a command prompt: net config server /autodisconnect: time_before_autodisconnect Specify the time in minutes. For more information- http://support.microsoft.com/kb/314882

Apache 403 Error

There are two causes to 403 errors with virtual hosts. 1. First, every single parent path to the virtual document root must be Readable, Writable, and Executable by the web server httpd user. The access_log will show a 403 code, but the following message is returned to the browser with no "403" string printed: Forbidden You don't have permission to access /index.html on this server. 2. The second cause is actually a configuration problem -- the problem is forgetting to allow access in the httpd.conf. In this case the access_log will show a 403 error and Aapche2 will also sometimes send a "403" in the error string to the browser: HTTP 403 / client denied by server configuration error Forbidden You don't have permission to access /index.html on this server. A tail of the error_log gives a message like this for each access attempt: [Tue Jul 25 17:58:17 2006] [error] [client 192.168.1.1] client denied by server configuration: /var/www/vhosts/prabhat/ Th...

How to Remove Spaces From string

This is javascript function to remove spaces in given string function removeSpaces(string) { return string.split(' ').join(''); }

Web Redirection

<head> <script type="text/javascript"> <!-- setTimeout('Redirect()',2000); function Redirect() { location.href='http://newdomain.com/'; } //--> </script> <html> <body> This site is no longer located here. <br /> You will be redirected in 2 seconds. Please update your bookmarks/links </body> </html>

Forgotten MySQL root password

1. Start. 2. Stop the mysqld daemon process: root@prabhat:~# /etc/init.d/mysql stop 3. Start the mysqld daemon process with the --skip-grant-tables option. : root@prabhat:~# /usr/bin/mysqld_safe --skip-grant-tables & [1] 6702 Starting mysqld daemon with databases from /var/lib/mysql mysqld_safe[6763]: started . 4. Start the mysql client with the -u root option: Note: - In Mysql server running with the --skip-grant-tables flag not require password root@prabhat:~$ mysql --user=root mysql Enter password: 5. Execute the UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; mysql> update user set Password=PASSWORD(' new-password-here ') WHERE User='root'; Query OK, 2 rows affected (0.04 sec) Rows matched: 2 Changed: 2 Warnings: 0 6. Execute the FLUSH PRIVILEGES; comman...

Run Linux shell command with nonapache user

How to install expect extension for php- Require packages- a) php-pear and php-devel- (for phpize) b) Expect and expect-devel (there is no use of extension if original language is not available) c) make (package) d) Now simply run command Pear install http://pecl.php.net/get/expect-0.2.4.tgz Or Pecl install http://pecl.php.net/get/expect-0.2.4.tgz Or you should install latest version of extension from site http://pecl.php.net/get/ e) Now add following line in /etc/php.ini ( or location of your php.ini ) file. extension = expect.so Example- function run_shell_command( $command,$username,$password ) { ini_set ("expect.timeout", 3); ini_set ("expect.loguser", "Off"); $stream = fopen ("expect://su - $username -c ' $command '","r"); // In case su not work then use this //$stream = fopen ("expect://ssh - $username@localhost ' $command '",...