Udgivet i

Search text files with grep

How to use the grep tool

The grep tool is built into the operating system, so you don’t need to install it.

The simplest syntax to find a string in a single file using the grep command is:
grep ‘searched-word’ filename

By default, the search with grep is case sensitive.

Let’s gradually add the most useful options to our search.

1. Make the search case-insensitive with the "-i" option:
grep -i 'searched-word' filename
2. Search recursively in all files in a given directory with the "-r" option:
grep -ir 'searched-word' '/directory'
3. Search whole words only with the "-w" option:
grep -irw 'searched-word' '/directory'
4. Print the line numbers in which the searched word was found with the "-n" option:
grep -irwn 'searched-word' '/directory'
5. Search for multiple words syntax:
grep -ir 'word1|word2|word3' '/directory'

Many other useful grep options can be found in the official Grep Manual.

Udgivet i

Bloker Eric Jones fra din WPForms kontakt

Der er en berygtet spammer, der går under pseudonymet “Eric Jones”.
De er i stand til at omgå Google captcha og sende hyppige beskeder til WordPress (og sandsynligvis andre) kontaktformularer.
Hvis du bruger WPForms som jeg gør, så kan du gøre brug af denne enkle, gratis løsning, der burde blokere Eric Jones spam.
Den er afhængig af en simpel kendsgerning, som nemt kan ændres til enhver tid: spammeren bruger altid den samme e-mail.
WPForms understøtter tilfældigvis sortlister til felter, så der er vores løsning!

1. Gå til din WPForms-administratorside.
2. Rediger din kontaktformular.
3. Klik på “Feltindstillinger” til venstre under felter, der allerede skulle være åbne.
4. Klik på dit e-mail-felt
5. Åbn fanen Avanceret til venstre
6. Under Tilladelsesliste / Afvisningsliste skal du vælge Afvisningsliste
7. Et nyt felt skal dukke op. Indsæt “eric.jones.z.mail@gmail.com” og seneste “ericjonesonline@outlook.com” i den.
8. Gem din formular

Det er det! Det er en måde, du kan blokere Eric Jones på.
Der er andre måder, men de fleste af dem koster penge eller er lidt smarte.

Udgivet i

perl: warning: Setting locale failed

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = (unset)
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:

Solution;

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Udgivet i

Windows 7 – never Launch Startup Repair

Do this command:

bcdedit /set {current} bootstatuspolicy ignoreallfailures

Similar is

bcdedit /set {default} bootstatuspolicy ignoreallfailures

They can be the same if you are booted into the default load, so default would equal current.

For more information, the relevant Google search is “disable Windows Error Recovery” (minus the quotes).

Udgivet i

Swap area in OpenSUSE

First create an 1Gigabyte file.

opensuse:~# dd if=/dev/zero of=/swap   bs=1024 count=1000000
1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB) copied, 28.7256 s, 35.6 MB/s

DD command to create the 1G file basically writing “0” into the file swap_1 in the “/” file system.

Create SWAP area

opensuse:~ # mkswap /swap
Setting up swapspace version 1, size = 999996 KiB
no label, UUID=4aada58e-d6f7-4053-adf1-8d4c79122d36

That sets up the file as a swap area.

Now, we’ll simply enable the swapfile, so that the system can start paging physical memory pages onto it.

opensuse:~ # swapon /swap

The system should now have an additional 1Gigabyte of swap area. Check it.

opensuse:~ # free -tom
total       used       free     shared    buffers     cached
Mem:           998        973         24          0         20        795
Swap:         1716          0       1716
Total:        2714        973       1741

We now have 1.7Gigabytes of swap area.

To confirm the swap areas we have

opensuse:~ # swapon -s
Filename                                Type            Size    Used    Priority
/dev/mapper/system-swap                 partition       757752  0       -1
/swap                                      file            999992  0       -2

To make it permanent, we need to add an entry to the /etc/fstab file.:

/swap       swap                 swap       defaults              0 0

Where /swap is our new swap file and it instructs the system to mount it at system startup as a swap area.

Udgivet i

Secure AXIGEN against brute-force with Fail2Ban [Linux]

Fail2Ban (http://wikipedia.org/wiki/Fail2ban) protects your server against intruders who try brute force to guess passwords.
Enables you to monitor standard services such as SSH, Apache, etc..

Furthermore, AXIGEN can be secured against password attacks.

The following steps are necessary:
The steps may differ depending on your distribution.

Step 1: Install Fail2Ban
Step 2: Create a shell script:

#!/bin/bash
# $1 - log file to be used
LOG_AXI="/var/opt/axigen/log/everything.txt"
if [ -z "$1" ]
 then
 LOG_SEC=/var/opt/axigen/log/secure.txt
 else
 LOG_SEC="$1"
 fi
tail --retry --follow=name "$LOG_AXI" | while read l
 do
 timestamp=$(date '+%d-%m-%Y %T')
 case "$l" in
 *"Authentication error"*|*"could not authenticate user"*|*"error authenticating user"*) sid=$(echo "$l" | awk '{print $6}')
 if [ -n "$sid" ]
 then
 con_ip=$(grep -m 1 $sid "$LOG_AXI" | awk '{print $NF}' | sed 's/\[//g;s/:.*$//g')
 if [ -n "$con_ip" ]
 then
 echo "$timestamp $l from $con_ip" >> "$LOG_SEC"
 fi
 fi
 ;;
 esac
 done

Step 3: Make sure that there script runs automatically, for example, /etc/inittab

Notes:
If AXIGEN writes the log file to another location, please kindly adjust the path to the variable $ LOG_AXI.
For secure.txt file a log Rotate should be established
Test the script as follows:
Start the script
Check the contents of secure.txt
Run a false login with, this should be reported as follows

18-07-2014 14:35:42 07-28 14:35:42 +0300 02 localhost IMAP:000000CC: Authentication error for user ‘user1@localdomain’: Invalid password from 192.168.1.101

Step 4: Create a new module Fail2Ban to, for example, axigen.cfg under /etc/fail2ban/filter.d
With content:

# Fail2Ban configuration file
[Definition]
failregex = from <HOST>

Step 5: Configure Fail2Ban where you expand the jail.conf under /etc/fail2ban to block the following:

[axigen]
enabled = true
filter = axigen
port = all
logpath = /var/opt/axigen/log/secure.txt
bantime = 100
maxretry = 3
banaction = iptables-allports

The maximum number of failed attempts, spell-time and path please adjust accordingly.
Then please restart fail2ban.

 

From http://www.axigenmailgate.de/forum/archive/index.php/t-935.html

Udgivet i

Block or redirect using mod_geoip

Installing mod_geoip allows you to block or redirect traffic based on the geografical location of the client using the IP-address of the client. mod_geoip for CentOS is available at the EPEL repository. If you haven’t setup the EPEL repository follow the instructions explained on their website. I asume you allready installed Apache. Download and install mod_geoip, GeoIP and the related libraries:

yum install GeoIP GeoIP-devel GeoIP-data zlib-devel mod_geoip

As MaxMind regularly update their database files you might choose to download the file manually using by a cronjob. Create a bash script which download and install the GeoLite databases. This example is base on the GeoLite version, if you have a subscription your change the according lines to download the appropiate database files:

#!/bin/bash
#Download Maxmind GeoIP databases
cd /var/lib/GeoIP
mv GeoIP.dat GeoIP.dat.old
/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
/usr/bin/wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz

Make this script executable:

chmod 750 SCRIPTNAME.SH

and edit your crontab to run this script every 3rd day of the month:

crontab -e
0 0 3 * * /PATH_TO_SCRIPT/SCRIPTNAME

Edit the configuration file /etc/httpd/conf.d/mod_geoip.confand activate the module and change the path of the database. (GeoLiteCity.dat also returns the CityNames and the geographic locations):

LoadModule geoip_module modules/mod_geoip.so
<IfModule mod_geoip.c>
  GeoIPEnable On
  GeoIPDBFile /var/lib/GeoIP.dat
</IfModule>

and restart Apache:

/ect/init.d/apache restart

Now create a .htaccess file. For example if you want to block clients from Russia and China:

SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
Deny from env=BlockCountry

If you want to redirect based on the country using mod_rewrite in combination with mod_geoip, your .htaccess file could look like this:

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(NL|BE)$
RewriteRule ^(.*)$ http://www.mydomain.com/nl/$1 [L]

For more example take a look at he website of MaxMind

Copy from http://www.linux-faqs.info/apache/block-or-redirect-using-mod-geoip

Udgivet i Skriv en kommentar

Set the PATH in Win 7 to NPM, GIT, Cordova and Android

ANDROID_HOME
C:\somewhere

JAVA_HOME
C:\somewhere

ANDROID_HOME
C:\somewhere

ANT_HOME
C:\somewhere

PATH
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%ANDROID_HOME%\tools\;%ANDROID_HOME%\platform-tools\;%JAVA_HOME%\bin\;%ANT_HOME%\bin\;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd;C:\Users\User\AppData\Roaming\npm

Udgivet i Skriv en kommentar

Android WakeLock + Cordova 3.*

Google Developer PowerManager

I Manifestet brug:

 <uses-permission android:name="android.permission.WAKE_LOCK" />

I activity*.java læg til det med tykt markeret. 

import android.os.Bundle;
import org.apache.cordova.*;
import android.view.WindowManager;
public class Tutix extends CordovaActivity
 {
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
super.onCreate(savedInstanceState);
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 // Set by <content src="index.html" /> in config.xml
 loadUrl(launchUrl);
 }
 }

Under layout:

android:keepScreenOn="true">

That’s it.

Udgivet i

Find bad sectors

You can find the bad sector by running a smart long test;

# smartctl -t long /dev/sda

You can then check the status of the long test to see if its finished, and the LBA of the first error it encountered;

# smartctl -l selftest /dev/sda
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.7.0-1-amd64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     17711         12345
# 2  Short offline       Completed without error       00%     17709         -
# 3  Short captive       Interrupted (host reset)      10%       450         -
# 4  Short captive       Interrupted (host reset)      10%       228         -

You can then overwrite the bad sector using dd;

# dd if=/dev/zero of=/dev/sda seek=12345 count=1