Monday, June 4, 2012

Extract a Single Table from a mysqldump File

First, you have to know where in your mysqldump output you want to begin your
extraction, and where you want to end it. For example for extract test1 table:


1
2
3
4
5
6
7
8
9
10
11
12
13
--
-- Table structure for table `test1`
--
...
DROP TABLE IF EXISTS `test1`;
CREATE TABLE `test1` ( ...
LOCK TABLES `test1` WRITE;
INSERT INTO `test1` VALUES (1,0,’2 ...
UNLOCK TABLES;
...
–-
–- Table structure for table `test2`
–-

As you can see, we have a line with the comment “Table structure for table `test1`”, then all of the dropping, creating, and inserting for the table, and then another comment for the next table. These two lines are perfect for grabbing all of the operations pertinent to our one table.
To extract the dump for a single table from an entire database dump, run the following from a command prompt:

$ awk '/Table structure for table `test1`/,/Table structure for table `test2`/{print}' DBDump.sql > TableDump.sql


The above command searches through the dump file, and as soon as it matches a line containing the first search string (denoted by the first set of slashes), it prints that line and every subsequent line until it encounters a line containing the second search string (denoted by the second set of slashes).

Now the TableDump.sql file contains the SQL to restore your table. One final thing: There are usually various parameters at the top of your mysqldump file that you may need to set before restoring your table, depending on the complexity of your database (i.e. disabling foreign key checks.)

Wednesday, May 16, 2012

Sendmail - DSN: User unknown

My problem is solved, when I have deleted 127.0.0.1 from the /etc/hosts.

On server must not be a line with 127.0.0.1 in /etc/hosts file.


Tuesday, April 17, 2012

Apache ModSecurity - IP Whitelist

Add this rule to ModSecurity rules:

SecRule REMOTE_ADDR "^192\.168\.2\.15$" phase:1,nolog,allow,ctl:ruleEngine=off

It means the IP 192.168.2.15 will be ignored by ModSecurity.

Don't forget to restart Apache after adding new rule.

KnowledgeTree and PHP 5.3

The KnowledgeTree doesn't work with new PHP versions. We got always deprcated and warning messages.

You should edit the file config/dmsDefaults.php (under KnowledgTree folder) and find these lines:

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

add this line below those:

error_reporting(0) ;

Source: http://tpokorra.blogspot.de/2011/03/knowledge-tree-and-php-533.html

Thursday, April 12, 2012

Install subversion 1.6 under Lenny

Add this source to /etc/apt/sources.list

deb http://archive.debian.org/debian-backports lenny-backports main contrib non-free


then run:

apt-get update

and finally:


apt-get -t lenny-backports install --reinstall subversion

Wednesday, March 21, 2012

Create a self-signed SSL Certificate

1. Generating a private key:

openssl genrsa -des3 -out www.domain.com.key 2048 (with password)

openssl genrsa  -out www.domain.com.key 2048 (without password)

2. Generating Certificate Signing Request (CSR):

openssl req -new -key www.domain.com.key -out www.domain.com.csr

give your informations:

Country Name (2 letter code) [GB]:DE

State or Province Name (full name) [Berkshire]:Hessen  

Locality Name (eg, city) [Newbury]:Wiesbaden  

Organization Name (eg, company) [My Company Ltd]: Your Company Ltd 

Organizational Unit Name (eg, section) []:IT  

Common Name (eg, your name or your server's hostname) []:www.domain.com  

Email Address []:admin@domain.com  

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []: 

3. Generating a Self-Signed Certificate

openssl x509 -req -days 365 -in www.domain.com.csr -signkey www.domain.com.key  -out www.domain.com.crt

4. Installing the Private key and Certificate in Apache configuration file:

SSLEngine On

SSLCertificateFile www.domain.com.crt

SSLCertificateKeyFile www.domain.com.key

5. Restart Apache Service

/etc/init.d/apache2 restart

 

Tuesday, January 24, 2012

Allow from IP without password prompt, and also allow from any address with password prompt

You should write in .htaccess as follows:

Order deny,allow
Deny from all
AuthName "htaccess password prompt"
AuthUserFile /Path-to-Your-Password-File/.htpasswd
AuthType Basic
Require valid-user
#Your Allowed IP Here:
Allow from XXX.XXX.XXX.XXX
Satisfy Any

Friday, January 20, 2012

Apache and Active Directory Authentication on Debian

Make sure your apache supports mod_authnz_ldap, then enable it:

a2enmod ldap
a2enmod authnz_ldap

and restart your Apache:

/etc/init.d/apache2 restart

For the first Step (finding the user) we already need access to the Active Directory. As AD won't allow anonymous acces, you need a username and a password just to do the search. This is not

your administration account! Create a new account with minimal rights.


So what is the username? Depends on your AD Layout. This should give you a pretty good hint

CN=YOUR-NAME,OU=IT Department,OU=Germany,DC=example,DC=com

here is your sample .htaccess:


# Using this to bind
AuthLDAPBindDN "CN=
YOUR-USER,OU=IT Department,DC=example,DC=com"
AuthLDAPBindPassword "
XXX"

# search user
AuthLDAPURL "ldap://
IP-DOMAIN-CONTROLLER/ou=Germany,dc=example,dc=com?sAMAccountName?sub?(objectClass=*)"
AuthType Basic
AuthName "USE YOUR WINDOWS ACCOUNT"
AuthBasicProvider ldap

# Important, otherwise "(9)Bad file descriptor: Could not open password file: (null)"
AuthUserFile /dev/null
require valid-user

you always need to specify at least one organizational unit (ou).

PS.: If your users are split into multiple OU's, your are limiting the logons to OU's from one OU. This is the case im my environment where users are split into different regions. You should use another port (3268).

AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative Off
AuthName "whateveryouwant"
AuthLDAPURL "ldap://IP-DOMAIN-CONTROLLER:3268/dc=example,dc=com?sAMAccountName?sub?(objectClass=*)"

# Using this to bind
AuthLDAPBindDN "YOUR-USER@example.com"
AuthLDAPBindPassword "XXX"
require valid-user

Friday, January 13, 2012

Fixing double-encoded UTF-8 data in MySQL

When the data has been double-encoded, you will still have funny looking characters in the database.
Here is how to fix it, in two simple steps, using the mysqldump and mysql commands:

Source Database:

mysqldump -h DB_HOST -u DB_USER -p DB_PASSWORD --opt --quote-names \
--skip-set-charset --default-character-set=latin1 DB_NAME > DB_NAME-dump.sql

Target Database: mysql -h DB_HOST -u DB_USER -p DB_PASSWORD \
--default-character-set=utf8 DB_NAME < DB_NAME-dump.sql

Friday, December 16, 2011

Debian - files list file for package `PACKAGE-NAME' is missing final newline

You have some problem in this file:

/var/lib/dpkg/info/PACKAGE-NAME.list

delete it and reinstall the package:

apt-get install PACKAGE-NAME --reinstall

Tuesday, December 13, 2011

URL based security constraint to SOLR

In /var/lib/tomcat6/webapps/solr/WEB-INF/web.xml, add the following:

Add a username/password to /var/lib/tomcat6/conf/tomcat-users.xml



and restart the tomcat:

/etc/init.d/tomcat6 restart

Monday, December 12, 2011

Memcache and TYPO3

In debian install the php5-memcache and memcached packages:

apt-get install php5-memcache memcached

add the memcache configuration lines to localconf.php:

$TYPO3_CONF_VARS['SYS']['useCachingFramework'] = '1';
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pages']['backend'] = 't3lib_cache_backend_MemcachedBackend';
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pages']['options'] = array(
'servers' => array('localhost:11211'),
);

$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pagesection']['backend'] = 't3lib_cache_backend_MemcachedBackend';
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pagesection']['options'] = array(
'servers' => array('localhost:11211'),
);

$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_hash']['backend'] = 't3lib_cache_backend_MemcachedBackend';
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_hash']['options'] = array(
'servers' => array('localhost:11211'),
);

$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pages']['frontend']= 't3lib_cache_frontend_VariableFrontend';
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_pagesection']['frontend']= 't3lib_cache_frontend_VariableFrontend';
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['cache_hash']['frontend']= 't3lib_cache_frontend_VariableFrontend';

Thursday, December 8, 2011

Typo3 Parstime

You could see the parse time for a page in source of that page by adding this line in the localconf.php:

$TYPO3_CONF_VARS["FE"]["debug"] = '1';