Monday, December 17, 2012

Find Files By Date

If you need a specific date range, than consider using the find command.

In this example find files modified between 15 December 2012 and 16 December 2012, in /var directory:
 
touch --date "2012-12-15" /tmp/start
touch --date "2012-12-16" /tmp/end
find /var -type f -newer /tmp/start -not -newer /tmp/end

Thursday, December 13, 2012

Forcing qmail to process the queue

Run this command:

kill -ALRM `ps ax | grep qmail-send | grep -v grep | awk '{print $1}'`

Adjusting qmail queue time / lifetime

if you want to adjust how long e-mails will spend in the qmail queue before they're bounced, simple set the queuelifetime:

# echo "86400" > /var/qmail/control/queuelifetime
# /etc/init.d/qmail restart


The above example is for 1 day (qmail needs the time length in seconds). Just take the days and multiply by 86,400 seconds to get your result.

Monday, November 19, 2012

Delete Documents From Solr Index By Query

If you simply want to delete documents from your Solr index by using the web interface, here's a code snippet that lets you do so:

http://localhost:8080/solr/update?stream.body=<delete><query>id:XXXXX</query></delete>&commit=true

This lets you delete documents where the id field matches XXXXX.
If you want to delete items that matches more than one field, just add another query:

http://localhost:8983/solr/update?stream.body=<delete><query>id:XXXXX</query><query>entitytype:YourContent</query></delete>&commit=true

If you want to delete all items in the index, just use this query:

<delete><query>*:*</query></delete>

Source: http://blog.dileno.com/archive/201106/delete-documents-from-solr-index-by-query/

Tuesday, November 13, 2012

Old Version MediaWiki & PHP 5.3

when you use old version of MediaWiki and PHP 5.3, you should see this error:


PHP Parse error:  syntax error, unexpected T_NAMESPACE, expecting T_STRING 


You must change only the Namspace calss with MWNamespace:

go to your MediaWiki root directory (please make a backup first) and run this command:

find -name "*.php" -exec sed -i 's/Namespace::/MWNamespace::/g' {} \;

Wednesday, October 31, 2012

Youtube Video's thumbnail in not showing when sharing to FaceBook

After posting the thumbnail-less link to my page for the hundredth time, I decided to try sharing the link via the Facebook App on my Mobile Phone. When I did, I noticed a that the app added a suffix to my original link "&sns=fb".

I tried it and it worked...first try. I'm hoping it works when I try to post our next weekly video.

Try the following steps. I hope they work for you, too!

1) On the YouTube video page, click "Share" - be sure to select "Long Link".

2) Copy the link and paste it into your Notepad program.

http://www.youtube.com/watch?v=ABCdefGHik

3) Add "&sns=fb" to the end of the link.

http://www.youtube.com/watch?ABCdefGHik&sns=fb 

4) Copy your new link and paste it into your Facebook status.

5) Cross your fingers.



Another  solution:

Go here and enter the URL https://developers.facebook.com/tools/debug
It will force it to refresh the cache for the given URL.

Tuesday, October 30, 2012

How to select and generate locales on Ubuntu

For those of you who are used to running "dpkg-reconfigure locales" on Debian to select and generate locales you may be a bit disappointed at the seemingly broken way it is done under Ubuntu.

When I say broken "dpkg-reconfigure locales" does not yield an interface that allows you to select and deselect locales. It simply generates the locales mentioned in "/var/lib/locales/supported.d/local" file.

Therefore if you want to generate a bunch of locales you will need to add them to this file and re-run:

dpkg-reconfigure locales

NOTE: One locale per line.


For a list of valid locales you can search through "/usr/share/i18n/SUPPORTED".

Source: Here

Monday, October 29, 2012

TYPO3 - Lock file could not be created

Create the directory ./typo3temp/locks/ and make it writable for the user your Apache is running with.

Wednesday, October 24, 2012

Setup curl to permanently use a proxy

Curl will look for a .curlrc file in your home folder when it starts.


You can create (or edit) this file and add this line:

proxy = yourproxy.com:8080

Setting HTTP Proxy for SVN

Edit the servers file

/etc/.subversion/servers

and set the proxy server and port.

Uncomment and change the lines necessary:

[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
http-proxy-host = yourproxy.server.com
http-proxy-port = 8080

# http-proxy-username = defaultusername
# http-proxy-password = defaultpassword
# http-compression = no
# http-auth-types = basic;digest;negotiate
# No http-timeout, so just use the builtin default.
# No neon-debug-mask, so neon debugging is disabled.
# ssl-authority-files = /path/to/CAcert.pem;/path/to/CAcert2.pem


If you get some error like this:

svn: /etc/.subversion/servers: 148: Option expected

then it means that you have a space at the start of the property which you have un-commented. Make sure that there is no space in the beginning of the property in the servers file.

Tuesday, September 11, 2012

Update mysql table records, which contain umlaut

Use your database and run this MySQL command for your desired Table:

UPDATE YOUR_TABLE SET YOUR_FIELD = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(YOUR_FIELD,'ä','ae'),'Ä','Ae'),'ö','oe'),'Ö','Oe'),'ü','ue'),'Ü','Ue');

Rename files- & directories-name which contains umlaut

I would like to change the file name, which contains umlaut, with normal characters:

For example: ü with ue or Ä with Ae.

Here is my commands:

for i in `find -name '*ü*'`; do mv $i `echo $i | sed 's/ü/ue/'`; done
or
for i in `find -name '*Ä*'`; do mv $i `echo $i | sed 's/Ä/Ae/'`; done

and the following command for the directories:
for i in `find -type d -name '*Ä*'`; do mv $i `echo $i | sed 's/Ä/Ae/'`; done


Wednesday, September 5, 2012

Bash script - Delete characters before or after a pettern from string

I have this string:

MyString="This is a Test. Isn't it? Yes, it is."

I want to delete all characters after "?":

echo $MyString | sed -e 's/?.*//g'

the result is: This is a Test. Isn't it

now I want to delete all characters before "a":

echo $MyString | sed -e 's/.*a//g'

Resut: Test. Isn't it? Yes, it is.




Bash script - Removing duplicated lines from file

Run this command:

awk '!x[$0]++' source.txt > target.txt

Wednesday, August 22, 2012

Using PHP/oci8 to Connect to Oracle Remote DB

With this short PHP script, you can see how I connect to a remote Oracle DB:



<?php

//Connect String
$db="(DESCRIPTION=

     (ADDRESS_LIST=

       (ADDRESS=(PROTOCOL=TCP)

         (HOST=REMOTE_DB_IP)(PORT=XXXX)

       )

     )

       (CONNECT_DATA=(SID=ORACLE_SID))

 )";

//Connect to DB
$conn = oci_connect('USERNAME','PASSWORD',$db); 


//Run a sample query
$s = oci_parse($conn, 'select * from DB_TABLE');

oci_execute($s);

oci_fetch_all($s, $res);

echo "<pre>\n";

var_dump($res);

echo "</pre>\n";


//Close DB Connection
oci_close($conn);


?>


Installing OCI8 On Debian

OCI8 is an extension for providing APIs to Oracle database management system. You need Apache, PHP and Oracle Instant Client.

Register and Download Oracle Instant Client. Choose your platform compatibility (in my case x64), if the package not compatible with your platform then installation process will failed. At least, we just need Basic and SDK. Then put on /opt/oracle or whatever directory did you liked:

mkdir /oracle_client
mkdir /opt/oracle
cd /opt/oracle


 unzip instantclient-basic-linux.x64-11.2.0.3.0.zip
 unzip instantclient-sdk-linux.x64-11.2.0.3.0.zip
 mv /opt/instantclient_11_2/* /oracle_client/

 Create symbolic links for dinamic library and Add instant client to system ld:

cd /oracle_client
ln -s libclntsh.so.11.1 libclntsh.so
ln -s libocci.so.11.1 libocci.so

Compiling OCI8 and enter instantclient,/oracle_client when you are prompted:

pecl install oci8

Enable oci8 extension on php.ini or add it to php Conf:

vim /etc/php5/conf.d/oci8.ini 

and add this line to file:

extension=oci8.so

then restart apache2 web server.

/etc/init.d/apache2 restart

Then check phpinfo() and the successfull installation should be :



When you get this error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/oci8.so' - libaio.so.1: cannot open shared object file: No such file or directory in Unknown on line 0

you should install libaio:

apt-get install libaio1

Tuesday, August 21, 2012

Get an IP address out of fail2ban jail

Removes an iptables rule created by fail2ban. This example shows how to remove a rule for an IP from the fail2ban-apache chain. Can be used for any service monitored by fail2ban:

 iptables -D fail2ban-apache -s IP_ADDRESS_TO_SET_BE_FREE -j DROP


or remove from fail2ban-SSH jail:

 iptables -D fail2ban-SSH -s IP_ADDRESS_TO_SET_BE_FREE -j DROP

Monday, August 20, 2012

Resize a VirtualBox hard disk (.VDI) in Linux

I would recommend backing up your current vdi file before doing this!

Run this command in terminal:

VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB
 
Example:

VBoxManage modifyhd MyWindows7.vdi --resize 20000

It resizes your hard disk to 20GB. Start your guest machine and resize the partition with your suitable tool. (for example: Gparted for Linux or Windows Partition Manager for windows)

Wednesday, August 8, 2012

Block a message by a specific email SUBJECT - PLESK


Custom filter rules can be defined in /etc/mail/spamassassin/local.cf, for example:

header CUSTOM_SUPERSPAM Subject =~ /.*spam subject.*/i
describe CUSTOM_SUPERSPAM Superspam messages
score CUSTOM_SUPERSPAM 100.0

The first string defines the match rule. A regular expression is used in 'header' to check the message's subject.
The second string describes the filter.
And the third string defines how much scores should spamassassin set to the matching message.

You can find more info on writing custom rules for spamassassin in Mail::SpamAssassin::Conf manual page:

# man Mail::SpamAssassin::Conf

Source: http://kb.parallels.com/en/1038


Friday, July 27, 2012

Piwik 1.8 and import log

In Piwik 1.8 you can import the raw apache logs into piwik from command line:

%PIWIK-ROOT%/misc/log-analytics/import_logs.py --url=http://YOUR-PIWIK-URL LogFileName.log   --show-progress --idsite=1

mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to database 'information_schema' when using LOCK TABLES

This error occurs when making MySQL dump:

mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to database 'information_schema' when using LOCK TABLES 

To solve this problem, add this parameter to mysqldump command:

 --single-transaction

Friday, July 20, 2012

Plesk - Autoresponder in Cron job

This command could be in cronjob for automtic on/off autoresponder:

for activating:

/usr/local/psa/bin/mail  -u YOUR@EMAIL.COM -autostatus true -autoname AUTORESPONSE-NAME -autorsp true


for deactivating:

 /usr/local/psa/bin/mail  -u YOUR@EMAIL.COM -autostatus false -autoname AUTORESPONSE-NAME -autorsp false

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