суббота, 23 февраля 2008 г.

add zone

#domain# - example.com

1. open
/etc/namedb/zones/
#domain#.zone

2. find
#domain#. IN SOA ns.#domain#. root.#domain#. (
2008012101
10800
3600
604800
86400 )

3. edit 2008012101 to curent date and version in date (for example, 2008012102, 2008012103, 2008022301)

4. add new zone
newzone IN A 10.10.10.10
www.newzone IN A 10.10.10.10

5.
verify the changes by the eyes :)

6. /etc/rc.d/named stop

7. /etc/rc.d/named start

вторник, 19 февраля 2008 г.

phpbb2 проблема с кодировкой

open file includes/db.php

#
#-----[ FIND ]------------------------------------------
#
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
#
#-----[ AFTER, ADD ]------------------------------------------
#
mysql_query("SET NAMES cp1251");
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM

четверг, 14 февраля 2008 г.

mod_auth_mysql & .htaccess

1. install (FreeBSD)
# cd /usr/ports && make search key="mod_auth_mysql"
select port for your version apache&mysql

# cd /usr/ports/www/mod_auth_mysqlxxx


# make install clean

2. configure
edit httpd.conf (uncomment LoadModule auth_mysql_module libexec/apache22/mod_auth_mysql.so)

create DB&tables (source)
#
# Table structure for table `host_info`
#
# the fields created, updated, and isadmin are not needed by the module!
# they may help you creating a php-htpasswd frontend
#

CREATE TABLE host_info (
id int(14) NOT NULL auto_increment,
host char(255) NOT NULL default '',
host_group int(14) NOT NULL default '0',
created timestamp(14) NOT NULL,
updated timestamp(14) NOT NULL,
PRIMARY KEY (id),
KEY host (host)
) TYPE=MyISAM PACK_KEYS=1;
# --------------------------------------------------------

#
# Table structure for table `user_group`
#

CREATE TABLE user_group (
id int(14) NOT NULL auto_increment,
user_name char(50) NOT NULL default '',
user_group char(20) NOT NULL default '',
host_group int(14) default NULL,
created timestamp(14) NOT NULL,
updated timestamp(14) NOT NULL,
PRIMARY KEY (id),
KEY host_group (host_group),
KEY user_group (user_group)
) TYPE=MyISAM PACK_KEYS=1;
# --------------------------------------------------------

#
# Table structure for table `user_info`
#

CREATE TABLE user_info (
id int(14) NOT NULL auto_increment,
user_name char(30) NOT NULL default '',
user_passwd char(120) NOT NULL default '',
host_group int(14) NOT NULL default '0',
created timestamp(14) NOT NULL,
updated timestamp(14) NOT NULL,
isadmin tinyint(4) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY user_name (user_name,host_group)
) TYPE=MyISAM PACK_KEYS=1;

create .htaccess (source)

AuthName "Protected Area"

#!! If you use this module with apache 2.2.x you
#!! need to uncomment following line !
AuthBasicAuthoritative Off

AuthType Basic

AuthMySQLHost localhost
AuthMySQLUser user
AuthMySQLPassword passwd
AuthMySQLDB dbname
# AuthMySQLPort 3306

#AuthMySQLUserTable user_info
#AuthMySQLTableUserName user_name
#AuthMySQLTableUserPasswd user_passwd
#AuthMySQLTableUserHostGroup host_group

# AuthMySQLHostTable host_info
# AuthMySQLTableHostName host
# AuthMySQLTableHostHostGroup host_group

# AuthMySQLGroupTable user_group
# AuthMySQLTableGroupName user_name
# AuthMySQLTableGroupGroupName user_group
# AuthMySQLTableGroupHostGroup host_group

# AuthMySQLUserQueryCondition 1 // rev 1.8
# AuthMySQLGroupQueryCondition 1 // rev 1.8

AuthMySQLAuthoritative On
AuthMySQLKeepAlive Off
AuthMySQLEnable On
AuthMySQLVirtualHost Off

# AuthMySQLClientUseSSL On // rev 1.10
# AuthMySQLClientCert "full_path/client-cert.pem" // rev 1.10
# AuthMySQLClientKey "full_path/client-key.pem" // rev 1.10
# AuthMySQLClientCA "full_path/cacert.pem" // rev 1.10
# AuthMySQLClientCipher "" // rev 1.10
# AuthMySQLClientVerifyCert Off // rev 1.10

require valid-user

edit this .htaccess for your parameters

fill tables with data (source)
minimum example
insert into host_info(id,host,hostgroup)
values ( null, "www.foo.com", 1 );

insert into host_info(id,host,hostgroup)
values ( null, "www.bar.com", 2 );

insert into user_info (id, user_name,user_passwd, host_group)
values (null,"myself", encrypt("secret"),1);

insert into user_info (id, user_name,user_passwd, host_group)
values (null,"myself", encrypt("password"),2);

restart apache
# apache2 restart

see error logs (no errors)

3. work

username - $_SERVER["PHP_AUTH_USER"]
password - $_SERVER["PHP_AUTH_PW"]


official site

пятница, 8 февраля 2008 г.

Mount new hdd (Fedora)

Doing the Work

Once your drive is plugged, detected by the system bios and you are booted into your system open a terminal and type: su --login

  1. Finding the hard disk devices your computer sees attached.
  2. [root@quetzalcoatl ~]# fdisk -l

    Disk /dev/hda: 20.8 GB, 20847697920 bytes
    16 heads, 63 sectors/track, 40395 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes

    Device Boot Start End Blocks Id System
    /dev/hda1 * 1 1016 512032+ 83 Linux
    /dev/hda2 1017 5079 2047752 82 Linux swap / Solaris
    /dev/hda3 5080 40395 17799264 83 Linux

    Disk /dev/hdb: 120.0 GB, 120034123776 bytes
    16 heads, 63 sectors/track, 232581 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes

    Device Boot Start End Blocks Id System
    /dev/hdb1 1 232581 117220792+ 83 Linux

    Disk /dev/hdi: 250.0 GB, 250059350016 bytes
    255 heads, 63 sectors/track, 30401 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/hdi1 1 30401 244196001 83 Linux

    Disk /dev/hdj: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/hdj1 1 9729 78148161 83 Linux

    Disk /dev/hdk: 120.0 GB, 120034123776 bytes
    16 heads, 63 sectors/track, 232581 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes

    Device Boot Start End Blocks Id System
    /dev/hdk1 * 1 232576 117218241 83 Linux

    Disk /dev/hdl: 251.0 GB, 251000193024 bytes
    255 heads, 63 sectors/track, 30515 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Disk /dev/hdl doesn't contain a valid partition table


  3. At the bottom we see: "Disk /dev/hdl doesn't contain a valid partition table", this is what we are looking for, now we can create the partitions. For this example, we're taking a 250GB Maxtor hard disk and using the entire space as one large partition. If you want more than one partition on your new disk you can alter this when you choose the size of your new partitions using +sizeM (megabytes) or +sizeK (Kilobytes).
  4. [root@quetzalcoatl ~]# fdisk /dev/hdl
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel. Changes will remain in memory only,
    until you decide to write them. After that, of course, the previous
    content won't be recoverable.


    The number of cylinders for this disk is set to 30515.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)
    Command (m for help): m
    Command action
    a toggle a bootable flag
    b edit bsd disklabel
    c toggle the dos compatibility flag
    d delete a partition
    l list known partition types
    m print this menu
    n add a new partition
    o create a new empty DOS partition table
    p print the partition table
    q quit without saving changes
    s create a new empty Sun disklabel
    t change a partition's system id
    u change display/entry units
    v verify the partition table
    w write table to disk and exit
    x extra functionality (experts only)

    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-30515, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-30515, default 30515):
    Using default value 30515

    Command (m for help):
  5. Now that we've created the partition scheme we'd like, we need to write the changes to the disk partition table.
  6. Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@quetzalcoatl ~]#
  7. Now we need to create a filesystem on the new partition. For this howto we will use the native linux filesystem (ext3 or type 83). Make note of the superblock backups for this new disk in case an fsck is required and the main journal is corrupted or missing. You can point fsck to a backup superblock provided you thought ahead and recorded them.
  8. [root@quetzalcoatl ~]# mkfs.ext3 /dev/hdl1
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    30654464 inodes, 61277926 blocks
    3063896 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=0
    1871 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872


    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done

    This filesystem will be automatically checked every 24 mounts or
    180 days, whichever comes first. Use tune2fs -c or -i to override.
    [root@quetzalcoatl ~]#
  9. Mounting the new disk on /mnt/250GB so we can put data on it and use it normally. First, we create the directory with the mkdir command. Second we mount the disk device into our newly created directory /mnt/250GB as read/write. Note: if you have trouble with directory permissions or not being allowed to write to the directory see: man chmod | man chown.
  10. [root@quetzalcoatl ~]# mkdir /mnt/250GB && mount -t ext3 /dev/hdl1 /mnt/250GB rw
    [root@quetzalcoatl ~]#
  11. Setting your drive up to automount on boot. For this we'll edit the /etc/fstab file and add in the appropriate line save/exit. We'll then tell the system to execute the fstab file with: mount -a and finally we'll use: df -h to verify that the disk is indeed mounted and the system sees it where we expect.
  12. [root@quetzalcoatl ~]# nano /etc/fstab
    # This file is edited by fstab-sync - see 'man fstab-sync' for details
    LABEL=/1 / ext3 defaults 1 1
    LABEL=/boot1 /boot ext3 defaults 1 2
    none /dev/pts devpts gid=5,mode=620 0 0
    none /dev/shm tmpfs defaults 0 0
    none /proc proc defaults 0 0
    none /sys sysfs defaults 0 0
    LABEL=SWAP-hda2 swap swap defaults 0 0
    /dev/hdb1 /mnt/hdb120 ext3 rw
    /dev/hdi1 /mnt/hdi250 ext3 rw
    /dev/hdj1 /mnt/hdj80 ext3 rw
    /dev/hdk1 /mnt/hdk120 ext3 rw
    /dev/hdl1 /mnt/hdl250 ext3 rw
    /dev/fd0 /media/floppy1 auto pamconsole,exec,noauto,utf8,managed 0 0
    /dev/hdd /media/cdrom auto pamconsole,exec,noauto,managed 0 0
    /dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
    [root@quetzalcoatl ~]# mount -a
    [root@quetzalcoatl ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/hda3 17G 15G 1.8G 90% /
    /dev/hda1 485M 52M 408M 12% /boot
    none 506M 0 506M 0% /dev/shm
    /dev/hdb1 111G 97G 8.3G 93% /mnt/hdb120
    /dev/hdi1 230G 216G 2.6G 99% /mnt/hdi250
    /dev/hdj1 74G 67G 2.8G 97% /mnt/hdj80
    /dev/hdk1 111G 100G 4.9G 96% /mnt/hdk120
    /dev/hdl1 231G 188M 219G 1% /mnt/hdl250
    [root@quetzalcoatl ~]#

пятница, 1 февраля 2008 г.

Drupal Search without temporaty tables

Many drupal lovers getting trouble at godaddy for search module.
when user try to search they will get error message as not able to create temporary tables.
Here is the code snippets for search hack:
File: search.module
Function name: do_search
Replace the function with the following code. Please backup your copy before applying the code.
-----------------------------------------
function do_search($keywords, $type, $join1 = '', $where1 = '1', $arguments1 = array(), $select2 = 'i.relevance AS score', $join2 = '', $arguments2 = array(), $sort_parameters = 'ORDER BY score DESC') {
$query = search_parse_query($keywords);

if ($query[2] == '') {
form_set_error('keys', t('You must include at least one positive keyword with %count characters or more.', array('%count' => variable_get('minimum_word_size', 3))));
}
if ($query === NULL || $query[0] == '' || $query[2] == '') {
return array();
}

// First pass: select all possible matching sids, doing a simple index-based OR matching on the keywords.
// 'matches' is used to reject those items that cannot possibly match the query.
$conditions = $where1 .' AND ('. $query[2] .") AND i.type = '%s'";
$arguments = array_merge($arguments1, $query[3], array($type, $query[4]));

//----G // Temporary table not allowed in godaddy hosting.

//$result = db_query_temporary("SELECT i.type, i.sid, SUM(i.score * t.count) AS relevance, COUNT(*) AS matches FROM {search_index} i INNER JOIN {search_total} t ON i.word = t.word $join1 WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d", $arguments, 'temp_search_sids');

$result = db_query("CREATE TABLE IF NOT EXISTS temp_search_sids SELECT i.type, i.sid, SUM(i.score * t.count) AS relevance, COUNT(*) AS matches FROM {search_index} i INNER JOIN {search_total} t ON i.word = t.word $join1 WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d", $arguments);

// Calculate maximum relevance, to normalize it
$normalize = db_result(db_query('SELECT MAX(relevance) FROM temp_search_sids'));
if (!$normalize) {
return array();
}
$select2 = str_replace('i.relevance', '('. (1.0 / $normalize) .' * i.relevance)', $select2);

// Second pass: only keep items that match the complicated keywords conditions (phrase search, negative keywords, ...)
$conditions = '('. $query[0] .')';
$arguments = array_merge($arguments2, $query[1]);
//----G // Temporary table not allowed in godaddy hosting.
//$result = db_query_temporary("SELECT i.type, i.sid, $select2 FROM temp_search_sids i INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type $join2 WHERE $conditions $sort_parameters", $arguments, 'temp_search_results');

$result = db_query("CREATE TABLE IF NOT EXISTS temp_search_results SELECT i.type, i.sid, $select2 FROM temp_search_sids i INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type $join2 WHERE $conditions $sort_parameters", $arguments);

if (($count = db_result(db_query('SELECT COUNT(*) FROM temp_search_results'))) == 0) {
return array();
}
$count_query = "SELECT $count";

// Do actual search query
$result = pager_query("SELECT * FROM temp_search_results", 10, 0, $count_query);
$results = array();
while ($item = db_fetch_object($result)) {
$results[] = $item;
}
//----G // Temporary table not allowed in godaddy hosting.
db_query('DELETE LOW_PRIORITY FROM temp_search_sids');
db_query('DELETE LOW_PRIORITY FROM temp_search_results');
return $results;
}
-----------------------------------

Search Table Structure:

CREATE TABLE `temp_search_results` (
`type` varchar(16) default NULL,
`sid` int(10) unsigned NOT NULL default '0',
`score` double default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `temp_search_sids` (
`type` varchar(16) default NULL,
`sid` int(10) unsigned NOT NULL default '0',
`relevance` double default NULL,
`matches` bigint(21) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


-----------------------------------
It is better to create the search tables in advace before hacking the code.

source