Aici veti gasi detalii tehnice despre cum se pot realiza configurari software+ hardware.
Here you can find tehnical details about software/hardware configuration.

sâmbătă, 10 decembrie 2011

FreeBSD Qmail install

cd /usr/ports/mail/qmail
make config
make install

#TcpServer

cd /usr/ports/sysutils/ucspi-tcp
make install clean

#Daemontools
cd /usr/ports/sysutils/daemontools
make install clean
echo 'svscan_enable="YES"' >> /etc/rc.conf


#vpopmail
cd /usr/ports/mail/vpopmail
make install clean -DWITH_DOMAIN_QUOTAS -DWITH_SPAMASSASSIN SPAM_THRESHOLD=10

#courierimap
cd /usr/ports/mail/courier-imap
make config
make install clean

#qmailadmin

cd /usr/ports/mail/qmailadmin
make all install clean CGIBINDIR=www/cgi-bin-dist WEBDATADIR=www/data-dist


#qmail-scanner
cd /usr/ports/mail/qmail-scanner
make install

#$clamav
cd /usr/ports/security/clamav
make install

#vqadmin
cd /usr/ports/mail/vqadmin/
make install

#maildrop install
pkg install maildrop

luni, 5 decembrie 2011

Linux Commands

FIND TEXT
Find some text in folder files
grep --color=auto -nH 'text_to_find' *

Find some text in folder and subfolder files
grep -r --color=auto -nH 'text_to_find' *
================================================

To generate a file with custom size:

# dd if=/dev/zero of=output.dat  bs=1024  count=10240
or
# dd if=/dev/zero of=output.dat  bs=1M  count=10
 
 ============================================== 
 Copy BSD Disk to another
 
 dd if=/dev/ad0 of=/dev/da0 bs=1M
 
If you not have all disk in same plece you can try to make a dump over SSH
 
dump -C16 -b64 -0uanL -h0 -f - /    | gzip -2 | ssh -c blowfish user@host.com dd of=filename.dump.gz 
 
To restore you can try:
mount first partition
mount /dev/ad1s1a /tmp/root #(ad1 is the backup disk) 
  
ssh -c blowfish usr@host.com gzcat root.dump.gz | (cd /tmp/root && restore -ruf -)
 
 ================================================
 #!/bin/bash
count=99
if [ $count -eq 100 ]
then
  echo "Count is 100"
elif [ $count -gt 100 ]
then
  echo "Count is greater than 100"
else
  echo "Count is less than 100"
fi
================================================= 
show listen port by process
 
netstat -tupln
=================================================
show linux open files
 
lsof /dev/sda1
=================================================
show port listen by process

lsof -i :22
================================================= 
Scan all ports with nmap
 
nmap -P0 -vv -sS -ff -r -n -p 1-65535 SERVER_IP_HERE
================================================= 
List apache modules

apachectl -t -D DUMP_MODULES
 
 
=================================================
 
Show open files by process
 
 watch 'lsof -u apache | sort | uniq -c | sort -n'
 watch 'lsof -u apache | awk '\''{print $2}'\'' | sort | uniq -c | sort -n'
 

vineri, 28 octombrie 2011

Copy BSD Partition to other disk

Source pastition: /dev/ad0s1a
Destination partition: /dev/ad1s1a

dd if=/dev/ad0s1a conv=notrunc,noerror,sync bs=64k | dd of=/dev/ad1s1a bs=64k
fsck /dev/ad1s1a

===================================================================

Backup disk over SSH:

Backup
dd if=/dev/ada0 | gzip -1 - | ssh user@hostname dd of=image.gz

Restore
ssh user@hostname dd if=image.gz | gunzip -1 - | dd of=/dev/ada0

luni, 19 septembrie 2011

Html Redirect

One of the most requested items we get is "How do I make an html redirect page".


Strangely enough this is one of the easiest things to accomplish, but then anything is easy when you know how to do it!



Here's the code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>


Code Description:



<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"> is the part that actually does the redirecting.


The number preceding the url (in this case zero) tells the browser the number of seconds to wait before redirecting to the new url.


You could set this to 5 and add some optional text to your page - something like:


"Please wait while we redirect you to our new site".


That's it! Just copy the code, save it (i.e. save as index.html) and your html redirect will work perfectly.








source

miercuri, 7 septembrie 2011

Mysql update from another table

1. Open up phpmyadmin or similar database editor
2. view the sql query below

Code (sql)

UPDATE updatefrom p, updateto pp
SET pp.last_name = p.last_name
WHERE pp.visid = p.id

Lets say we have 2 tables one named main and one named updateto and one named updatefrom, In the first line we assign variables to these t tables (p and pp) from there we can call column names using this format table.columname. If we had first_name and last_name in both tables and wanted to update the “updateto” table with the info from “updatefrom” this is how you would write it.

If you need to update multiple rows in same query :


Code (sql)

UPDATE updatefrom p, updateto pp
SET pp.last_name = p.last_name,
pp.first_name = p.first_name
WHERE pp.visid = p.id

vineri, 2 septembrie 2011

mysql commands

This is a list of handy MySQL commands that I use time and time again. At the bottom are statements, clauses, and functions you can use in MySQL. Below that are PHP and Perl API functions you can use to interface with MySQL. To use those you will need to build PHP with MySQL functionality. To use MySQL with Perl you will need to use the Perl modules DBI and DBD::mysql.

Below when you see # it means from the unix shell. When you see mysql> it means from a MySQL prompt after logging into MySQL.
To login (from unix shell) use -h only if needed.

# [mysql dir]/bin/mysql -h hostname -u root -p
Create a database on the sql server.

mysql> create database [databasename];
List all databases on the sql server.

mysql> show databases;
Switch to a database.

mysql> use [db name];
To see all the tables in the db.

mysql> show tables;
To see database's field formats.

mysql> describe [table name];
To delete a db.

mysql> drop database [database name];
To delete a table.

mysql> drop table [table name];
Show all data in a table.

mysql> SELECT * FROM [table name];
Returns the columns and column information pertaining to the designated table.

mysql> show columns from [table name];
Show certain selected rows with the value "whatever".

mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";
Show all records containing the name "Bob" AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';
Show all records not containing the name "Bob" AND the phone number '3444444' order by the phone_number field.

mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;
Show all records starting with the letters 'bob' AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';
Show all records starting with the letters 'bob' AND the phone number '3444444' limit to records 1 through 5.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444' limit 1,5;
Use a regular expression to find records. Use "REGEXP BINARY" to force case-sensitivity. This finds any record beginning with a.

mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";
Show unique records.

mysql> SELECT DISTINCT [column name] FROM [table name];
Show selected records sorted in an ascending (asc) or descending (desc).

mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
Return number of rows.

mysql> SELECT COUNT(*) FROM [table name];
Sum column.

mysql> SELECT SUM(*) FROM [table name];
Join tables on common columns.

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;
Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password'));
mysql> flush privileges;
Change a users password from unix shell.

# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'
Change a users password from MySQL prompt. Login as root. Set the password. Update privs.

# mysql -u root -p
mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');
mysql> flush privileges;
Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
Set a root password if there is on root password.

# mysqladmin -u root password newpassword
Update a root password.

# mysqladmin -u root -p oldpassword newpassword
Allow the user "bob" to connect to the server from localhost using the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by 'passwd';
mysql> flush privileges;
Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;

or

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;
To update info already in a table.

mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';
Delete a row(s) from a table.

mysql> DELETE from [table name] where [field name] = 'whatever';
Update database permissions/privilages.

mysql> flush privileges;
Delete a column.

mysql> alter table [table name] drop column [column name];
Add a new column to db.

mysql> alter table [table name] add column [new column name] varchar (20);
Change column name.

mysql> alter table [table name] change [old column name] [new column name] varchar (50);
Make a unique column so you get no dupes.

mysql> alter table [table name] add unique ([column name]);
Make a column bigger.

mysql> alter table [table name] modify [column name] VARCHAR(3);
Delete unique from table.

mysql> alter table [table name] drop index [colmn name];
Load a CSV file into a table.

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);
Dump all databases for backup. Backup file is sql commands to recreate all db's.

# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql
Dump a table from a database.

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql
Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql
Create Table Example 1.

mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));
Create Table Example 2.

mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default 'bato');


source

Copy one database to other (new)

mysqldump -u root -p -v db1 | mysql -u root -p db2 and two times enter pass 

vineri, 10 iunie 2011

Openvpn network with tap (bridge mode)

In this configuration all clients are in bridge.
This config is without encryption.

Before you start you need to generate ca.crt, server.crt, server.key, dh1024.pem and clients keys and certificates


#Begin server.conf

local x.x.x.x
port 1194
proto udp
dev tap
server-bridge 192.168.100.10 255.255.255.0 192.168.100.129 192.168.100.254
ca /usr/local/etc/keys/ca.crt
cert /usr/local/etc/keys/server.crt
key /usr/local/etc/keys/server.key # This file should be kept secret
dh /usr/local/etc/keys/dh1024.pem
# Don't put this in the keys directory unless user nobody can read it
#crl-verify /usr/local/etc/keys/crl.pem

#Make sure this is your tunnel address pool
#server 10.10.101.0 255.255.255.0
ifconfig-pool-persist ipp.txt
#This is the route to push to the client, add more if necessary

#push "dhcp-option DNS 10.0.0.2"
keepalive 10 120
#cipher BF-CBC #Blowfish encryption
cipher none
###comp-lzo
user nobody
group nobody
persist-key
persist-tun
client-to-client
status openvpn-status.log
verb 6
mute 20
#client-config-dir /usr/local/etc/openvpn/ccd
ping-restart 0

=====================================================

cat ipp.txt

1.example.com,10.10.101.8
2.example.com,10.10.101.12
3.example.com,10.10.101.16
4.example.com,10.10.101.20
5.example.com,10.10.101.24
6.example.com,10.10.101.28
7.example.com,10.10.101.32
8.example.com,10.10.101.36
9.example.com,10.10.101.40
10.example.com,10.10.101.44
11.example.com,10.10.101.48

===============================================================
===============================================================
CLIENT SIDE


client
dev tap
proto udp
remote x.x.x.x 1194 #server ip address
resolv-retry infinite
nobind
persist-key
persist-tun
ca /tmp/openvpncl/ca.crt
cert /tmp/openvpncl/client.crt
key /tmp/openvpncl/client.key
#comp-lzo
ping-restart 0
cipher none

Openvpn network with tun

SERVER SIDE

Before you start you need to generate ca.crt, server.crt, server.key, dh1024.pem and clients keys and certificates


#Begin server.conf
local x.x.x.x (server ip address)
port 1194
proto tcp
dev tun

ca /usr/local/etc/keys/ca.crt
cert /usr/local/etc/keys/server.crt
key /usr/local/etc/keys/server.key # This file should be kept secret
dh /usr/local/etc/keys/dh1024.pem
# Don't put this in the keys directory unless user nobody can read it
#crl-verify /usr/local/etc/keys/crl.pem

#Make sure this is your tunnel address pool
server 10.10.101.0 255.255.255.0
ifconfig-pool-persist ipp.txt
#This is the route to push to the client, add more if necessary
push "route 192.168.101.0 255.255.255.0"
push "route 192.168.102.0 255.255.255.0"
push "route 192.168.103.0 255.255.255.0"
push "route 192.168.104.0 255.255.255.0"
push "route 192.168.105.0 255.255.255.0"
push "route 192.168.106.0 255.255.255.0"
push "route 192.168.107.0 255.255.255.0"
push "route 192.168.108.0 255.255.255.0"
push "route 192.168.109.0 255.255.255.0"
push "route 192.168.110.0 255.255.255.0"
push "route 192.168.111.0 255.255.255.0"
push "route 192.168.112.0 255.255.255.0"

#push "dhcp-option DNS 10.0.0.2"
keepalive 10 120
cipher BF-CBC #Blowfish encryption
comp-lzo
user nobody
group nobody
persist-key
persist-tun
client-to-client
status openvpn-status.log
verb 6
mute 20
client-config-dir /usr/local/etc/openvpn/ccd
route 192.168.102.0 255.255.255.0
route 192.168.103.0 255.255.255.0
route 192.168.104.0 255.255.255.0
route 192.168.105.0 255.255.255.0
route 192.168.106.0 255.255.255.0
route 192.168.107.0 255.255.255.0
route 192.168.108.0 255.255.255.0
route 192.168.109.0 255.255.255.0
route 192.168.110.0 255.255.255.0
route 192.168.111.0 255.255.255.0
route 192.168.112.0 255.255.255.0



============================================================
cat ipp.txt

1.example.com,10.10.101.8
2.example.com,10.10.101.12
3.example.com,10.10.101.16
4.example.com,10.10.101.20
5.example.com,10.10.101.24
6.example.com,10.10.101.28
7.example.com,10.10.101.32
8.example.com,10.10.101.36
9.example.com,10.10.101.40
10.example.com,10.10.101.44
11.example.com,10.10.101.48

========================================================
# cd /usr/local/etc/openvpn/ccd
# ls

1.example.com
2.example.com
3.example.com
4.example.com
5.example.com
6.example.com
7.example.com
8.example.com
9.example.com
10.example.com
11.example.com


# cat 1.example.com
iroute 192.168.102.0 255.255.255.0
#
# cat 2.example.com
iroute 192.168.103.0 255.255.255.0
#
.......

===============================================================
===============================================================
CLIENT SIDE


client
dev tun
proto tcp
remote x.x.x.x 1194 (Server address)
resolv-retry infinite
nobind
persist-key
persist-tun
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
ca /tmp/openvpncl/ca.crt
cert /tmp/openvpncl/client.crt
key /tmp/openvpncl/client.key
comp-lzo

FreeBSD Qmail Install

cd /usr/ports/mail/qmail
make config
make install

#TcpServer

cd /usr/ports/sysutils/ucspi-tcp
make install clean

#Daemontools
cd /usr/ports/sysutils/daemontools
make install clean
echo 'svscan_enable="YES"' >> /etc/rc.conf


#vpopmail
cd /usr/ports/mail/vpopmail
make install clean -DWITH_DOMAIN_QUOTAS -DWITH_SPAMASSASSIN SPAM_THRESHOLD=10

#courierimap
cd /usr/ports/mail/courier-imap
make config
make install clean

#qmailadmin

cd /usr/ports/mail/qmailadmin
make all install clean CGIBINDIR=www/cgi-bin-dist WEBDATADIR=www/data-dist


#qmail-scanner
cd /usr/ports/mail/qmail-scanner
make install

#$clamav
cd /usr/ports/security/clamav
make install

#vqadmin
cd /usr/ports/mail/vqadmin/
make install

miercuri, 1 iunie 2011

To Recreate Qmail's Queue

To Recreate Qmail's Queue

1. Log in to your server using SSH.
2. Type su -.
3. Enter the password for the root user on your server.
4. At the command prompt, stop Qmail by typing /etc/init.d/qmail stop.
cd /var/qmail/queue
rm -rf info intd local mess remote todo

mkdir mess

for i in `seq 0 22`; do
mkdir -p mess/$i
done

cp -r mess info
cp -r mess intd
cp -r mess local
cp -r mess remote
cp -r mess todo

chmod -R 750 mess todo
chown -R qmailq:qmail mess todo

chmod -R 700 info intd local remote
chown -R qmailq:qmail intd
chown -R qmails:qmail info local remote

5. Then, type the following:
6. Start Qmail by typing /etc/init.d/qmail start.

luni, 28 martie 2011

Extract mail addreses from files or downloaded site

======================================
grep -Eiorh '([[:alnum:]_.]+@[[:alnum:]_]+?\.[[:alpha:].]{2,6})' ./ > emails.txt
======================================

This makes grep find all email addresses and write them to file emails.txt in the current dir.
-E makes grep use extended regular expressions
-i does a case-insensitive match
-o makes grep return only the matching part of the line and not the whole line
-r makes grep look files recursively
-h stops grep from outputting the filename where the match was found

with the r parameter and the source file as ./ grep will go through all the files in the current directory and sub directories. The weird looking string in the line is the regular expression which looks for emails.

Map


Visitor Map