Fetch virtualhosts fra mysql i apache

Når jeg selv har testet det af ryger min egen version online:
http://guides.printf.dk/perl-dbi.htm

Apache med virtualhosts fra en MySQL DB
Af: Jesper Noehr <spike@printf.dk> 21/01/03
Smid dette perl-kode i bunden af din httpd.conf:

<Perl>
use DBI;
my ($sth, $dbh, $sname, $sadmin, $droot, $id, $soptions);

$dbh = DBI->connect("DBI:mysql:apache","USERNAME","PASSWORD");
$sth = $dbh->prepare("SELECT * FROM vhosts");
$sth->execute();

while (($id,$sname,$droot,$sadmin,$sdomain,$soptions) = $sth->fetchrow_array()) {
    #warn "+PERL DEBUG+ Addded name: $sname.$sdomain root: $droot admin: $sadmin\n";
    push @{$VirtualHost{'*'}}, {
        ServerName       => "$sname.$sdomain",
        ServerAdmin      => $sadmin,
        DocumentRoot     => "/home/customers/$sdomain/$droot",
        ErrorLog         => "/home/customers/$sdomain/log/httpd-error.log",
        TransferLog      => "/home/customers/$sdomain/log/httpd-access.log",
  Directory	 => {
        "/home/customers/$sdomain/$droot" => {
          Options => $soptions,
             	       },
          },
    };
}
$sth->finish();
$dbh->disconnect();
</Perl>

Yderlige opsaetning:

Du skal lave en database i din MySQL med navnet 'apache', og tabellen 'vhosts', ellers kan du vel selv rette det til.
Felterne skal vaere 5 varchars paa 255, hhv. 'sname','droot','sadmin','sdomain','soptions'.
Navnene giver vel sig selv. 'sdomain' dog er det felt som virtualhostet hoerer til. Jeg bruger det i mit PHP frontend, og der hvor den placerer logfilerne.
Min opsaetning placerer logfilerne i ``/home/customers/<sdomain>/log/'', saa jeg kan lave webalizer stats paa dem.
BEMAERK: Dette kode kraever at du har mod_perl compilet til din apache. En let maade at goere det paa en FreeBSD er `pkg_add -r mod_perl`.
Den vil oven i koebet saette din apache op til at bruge det. :-)
Held og lykke med det.

$Id: perl-dbi.htm,v 1.3 2003/02/22 21:55:35 spike Exp $

 

Udgivet i Apache, Knowledge Base, Old Base | Skriv en kommentar

htaccess password

AuthName "-- Clasified area --"
AuthType Basic
AuthUserFile /data/www/htpasswd
require user dinuser

password filen laver du med /sti/til/apache/htpasswd -c .htpasswd dinuser

 

Udgivet i Apache, Knowledge Base, Old Base | Skriv en kommentar

Custom 404 i apache

Tilfoej:
ErrorDocument 404 /404.html

Til httpd.conf , enten i selve filen eller i et virtualhosts statement. Kan efter sigende ogsaa placeres i .htaccess.

Filen skal her ligge i webroden af det aktuelle domaene.

Ellers kan det nævnes at der er gode eksempler og forklaringer i httpd.conf filen.

Udgivet i Apache, Knowledge Base, Old Base | Skriv en kommentar

Checking if someone is online with ICQ in PHP

<?php
        // ***
        // ICQ tjek funktion
        // ***
        function icq_test($uin) {
                $arr = file( "http://online.mirabilis.com/scripts/online.dll?icq=$uin&img=1");
                    $len = strlen($arr[1]);
                    if ($len == 96) {
                        return  "<b><font color=\"#00FF00\">Online</font></b>";
                } elseif ($len == 83) {
                        return  "<b><font color=\"#FF4040\">Offline</font></b>";
                } elseif ($len == 1) {
                        return  "<b><font color=\"#FF4040\">Offline</font></b>";
                } else {
                        return  "Status ukendt";
                }
        }
?

 

Udgivet i Knowledge Base, Old Base, PHP, Programmering | Skriv en kommentar

Sessions i php

session_start();

if ( $_SESSION[“nick”] != “”)

Udgivet i Knowledge Base, Old Base, PHP, Programmering | Skriv en kommentar

Mål bandwidth troughput

http://freshmeat.net/redir/iperf/30604/url_tgz/iperf-1.7.0-source.tar.gz

root@chilibeans:~/iperf-1.7.0# iperf -s -c localhost
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 64.0 KByte (default)
------------------------------------------------------------
[  6] local 127.0.0.1 port 5001 connected with 127.0.0.1 port 1952

[ ID] Interval       Transfer     Bandwidth
[  6]  0.0-10.0 sec   482 MBytes   404 Mbits/sec




root@chilibeans:~# iperf -c localhost
------------------------------------------------------------
Client connecting to localhost, TCP port 5001
TCP window size: 64.0 KByte (default)
------------------------------------------------------------
[  5] local 127.0.0.1 port 1952 connected with 127.0.0.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  5]  0.0-10.0 sec   482 MBytes   404 Mbits/sec

 

Udgivet i Knowledge Base, Networking, Old Base | Skriv en kommentar

Configuring TCP/IP Client on Linux

The interface

eth0           : The interface want to configure
10.1.1.2       : The IP of the interface
255.255.255.0  : The netmask of the interface
 
ifconfig eth0 10.1.1.2 netmask 255.255.255.0 up

The gateway

10.1.1.1       : Name of gateway

route add default gateway 10.1.1.1

The DNS

10.1.1.1       : The DNS server

echo nameserver 10.1.1.1 > /etc/resolv.conf



Now your net should be running!
Udgivet i Knowledge Base, Linux | Skriv en kommentar

Keeping up2date with deamons

Apache

http://httpd.apache.org/lists.html#http-announce

Udgivet i Apache, Knowledge Base, Links, Old Base | Skriv en kommentar

DECSystem 5100 running ultrix password recovery

i mounted /usr and got access to ‘vi’ and also ‘passwd’ changed the root pass and logged in. Here is a short guide on how to do when or if the problem arises for somebody else:

How to recover root password on Utrix 4.4 or DECsystem 5100, proberly works on other systems as well.

Boot the system, when the fsck begins (harddisk checking) press ctrl+c (might be names ‘code’ instead of ‘ctrl’ if your on a vt420 terminal)

You will now be granted with a root promt in singelmode, now type ‘mount /usr’ and then ‘passwd’ you will now be asked for the password you want to set to be roots, type it in, afterwards it will ask you to repeat, do that to.

Now type reboot and log in with your new password.

Udgivet i Knowledge Base, Old Base, Retro hardware | Skriv en kommentar

SQL Queries

Insert data:

insert into TabelName (`Var1`, `Var2`, `Var2`) values ('Content1','Content2','Content2');

Delete data:
delete from TabelName where Var1='Content1';

Update data:
update Tabelname set Var1='More Content' where Var1='Content1';

Queries:
select * from Tablename;
  Show all rows from Tablename

select * from Tablename where Var1='Content';
  Show all rows from Tablename where Var1 contais "Content"

select Var1,Var2 from Tablename where ID<20;
  Show Var1 and Var2 from Tablename with ID lower than 20

select distinct Var1 from TabelName 
  Show all values of Var1 from tablenames except clones

select title from content  where title like "%crac%" and type="dictionary";
   Show all values of content where title containts the letter 'crac' and type is 'dictionary'
Udgivet i Knowledge Base | Skriv en kommentar