Proftpd passive mode behind firewalls

(By BT)

I could not get my Proftpd working in passive mode, whilst it was behind a firewall.

The solution seemed to be, to tell the server that it was behind a specific firewall (the MasqueradeAddress directive), that it should accept the situation(the AllowForeignAddress directive) and that it should use a number of designated ports(the PassivePorts directive).

AllowForeignAddress     on
PassivePorts 65000 65050
MasqueradeAddress 85.82.164.70

After that I only needed to forward and allow port 65000 to 65050 to the firewall host.

It should be noted, that my server is running on port 2100 due to the fact that I have more than one FTP server in house.

The other server runs perfectly in active mode, but this one is restricted to passive mode. Probably due to the fact that m0n0wall only recognizes port 21 as FTP data traffic...
Udgivet i Knowledge Base, Old Base | Skriv en kommentar

Why i dont code C , Kernighan and Ritchie style

Page 14. "The C Programming Language" By Brian W. Kernighan and Dennis M. Ritchie  1978 a simple program to read characters from STDIN:

#define EOF -1

main()
{
        int c;

        c = getchar();
        while (c != EOF)
        {
                putchar(c);
                c = getchar();
        }
}

My logic mind prefers the following:

#define EOF -1
int main(void)
{
        int c;
        for (c=0; c!= EOF; c=getchar()) { putchar(c);}
}

Simple, logic and straightforward. Who wouldnt understand that?

 ... Now with CC-Compliance!
Udgivet i Knowledge Base | Skriv en kommentar

MySQL: Getting a random roll of the dice

 CREATE TABLE dice (
d_id int(11) NOT NULL auto_increment,
roll int,
PRIMARY KEY (d_id)
);

insert into dice (roll) values (1);
insert into dice (roll) values (2);
insert into dice (roll) values (3);
insert into dice (roll) values (4);
insert into dice (roll) values (5);
insert into dice (roll) values (6);


select roll from dice order by rand() limit 1;


About the author of this programming example or tutorial:
Mike Chirico (mchirico@users.sourceforge.net) Copyright (c) 2004 (GPU Free Documentation License) Last Updated: Tue Jul 20 12:14:51 EDT 2004
Udgivet i Knowledge Base, Old Base, SQL | Skriv en kommentar

MySQL: Getting a random roll of the dice

CREATE TABLE dice (
d_id int(11) NOT NULL auto_increment,
roll int,
PRIMARY KEY (d_id)
);

insert into dice (roll) values (1);
insert into dice (roll) values (2);
insert into dice (roll) values (3);
insert into dice (roll) values (4);
insert into dice (roll) values (5);
insert into dice (roll) values (6);


select roll from dice order by rand() limit 1;


About the author of this programming example or tutorial:
Mike Chirico (mchirico@users.sourceforge.net) Copyright (c) 2004 (GPU Free Documentation License) Last Updated: Tue Jul 20 12:14:51 EDT 2004
Udgivet i Knowledge Base, Mysql | Skriv en kommentar

MySQL: MERGE: Several tables can be merged into one

CREATE TABLE log_01 (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE log_02 (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MyISAM;

CREATE TABLE log_summary (
pkey int(11) NOT NULL auto_increment,
a int,
b varchar(12),
timeEnter timestamp(14),
PRIMARY KEY (pkey)
) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;

mysql> insert into log_01 (a,b) values (1,'log1');
mysql> insert into log_02 (a,b) values (1,'log2');

mysql> select * from log_summary;
select * from log_summary;
+------+------+------+---------------------+
| pkey | a | b | timeEnter |
+------+------+------+---------------------+
| 1 | 1 | log1 | 2004-04-16 11:59:55 |
| 1 | 1 | log2 | 2004-04-16 12:00:08 |
+------+------+------+---------------------+
2 rows in set (0.00 sec)

Reference:
http://dev.mysql.com/doc/mysql/en/MERGE.html


About the author of this programming example or tutorial:
Mike Chirico (mchirico@users.sourceforge.net) Copyright (c) 2004 (GPU Free Documentation License) Last Updated: Tue Jul 20 12:14:51 EDT 2004
Udgivet i Knowledge Base, Old Base, SQL | Skriv en kommentar

Mysql transactions

 Transactions: Not all table types support transactions. BDB and INNODB type do support transactions.
Assuming the server has NOT been started with --skip-bdb or --skip-innodb the following should work:

mysql> create table tran_test (a int, b int) type = InnoDB;
mysql> begin;
mysql> insert into tran_test (a,b) values (1,2);

mysql> select * from tran_test;
select * from tran_test;
+------+------+
| a | b |
+------+------+
| 1 | 2 |
+------+------+
1 row in set (0.00 sec)

mysql> rollback;

mysql> select * from tran_test;
select * from tran_test;
Empty set (0.00 sec)


Summary: rollback undoes everything and commit will save.

About the author of this programming example or tutorial:
Mike Chirico (mchirico@users.sourceforge.net) Copyright (c) 2004 (GPU Free Documentation License) Last Updated: Tue Jul 20 12:14:51 EDT 2004
Udgivet i Knowledge Base, Old Base, SQL | Skriv en kommentar

Check om en streng kun indeholder bogstaver og mellemrum

function IsAlpha($char)
{
        if (preg_match("/[a-z;A-Z]/",$char))
        { return true; }
        else if (in_array(htmlentities($char),explode(" ","æ &Aelig; ø Ø å Å")))
        { return true; }
        else if ($char == " ")
        { return true; }
        else
        { return false; }
}

function StripSigns($string)
{
        for ($i=0; $i<=strlen($string); $i++)
        {
                if (IsAlpha($string[$i]))
                {
                        $str=$str.htmlentities($string[$i]);
                }
        }
        return $str;
}


print StripSigns("Søren 23423"#%¤#!%!#¤ Peter");

Vil returnere Søren Peter
Udgivet i Knowledge Base, Shellscript | Skriv en kommentar

Mysql show status information on table / show create

Show status information on a table. Note, if the database was started
with --safe-show-database or --skip-show-database some of these commands
may not work. Note the "\G" option may provide a nicer format.

Show the create statement:

mysql> show create table dupTest\G
show create table dupTest\G
*************************** 1. row ***************************
Table: dupTest
Create Table: CREATE TABLE `dupTest` (
`pkey` int(11) NOT NULL auto_increment,
`a` int(11) default NULL,
`b` int(11) default NULL,
`c` int(11) default NULL,
`timeEnter` timestamp NOT NULL,
PRIMARY KEY (`pkey`),
UNIQUE KEY `a` (`a`,`b`)
) TYPE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)


About the author of this programming example or tutorial:
Mike Chirico (mchirico@users.sourceforge.net) Copyright (c) 2004 (GPU Free Documentation License) Last Updated: Tue Jul 20 12:14:51 EDT 2004
Udgivet i Knowledge Base, Old Base, SQL | Skriv en kommentar

Mysql Clean up binary log files

Clean up binary log files. For a default install they may be in
/usr/local/var/
with names ending in -bin.000001,-bin.000002,..


mysql> reset master;
reset master;
Query OK, 0 rows affected (0.02 sec)

See (TIP 24:) details working with binary log files and (TIP 25:) explains
how to setup logging.

About the author of this programming example or tutorial:
Mike Chirico (mchirico@users.sourceforge.net) Copyright (c) 2004 (GPU Free Documentation License) Last Updated: Tue Jul 20 12:14:51 EDT 2004
Udgivet i Knowledge Base, Mysql | Skriv en kommentar

How to create and use temporary tables in MySQL?

The temporary tables could be very useful in some cases
to keep temporary data. The most important thing that
should be know for temporary tables is that they will
be deleted when the current client disconnects

You could try to create such a temporary table

CREATE TEMPORARY TABLE MyTemporaryTable SELECT * FROM MyRealTable WHERE id<10;
Udgivet i Knowledge Base, Old Base, SQL | Skriv en kommentar