Monday, October 29, 2012

fog and openstack

.fog config file

:default:
:openstack_auth_url: http://192.168.1.113:35357/v2.0/tokens
:openstack_username: admin
:openstack_api_key: admin
:openstack_tenant: admin

Wednesday, October 10, 2012

SSH hang on expecting SSH2_MSG_KEX_DH_GEX_GROUP

This solved it for me:
http://www.snailbook.com/faq/mtu-mismatch.auto.html
"You probably have an MTU/fragmentation problem. For each network interface on both client and server set the MTU to 576, eg ifconfig eth0 mtu 576"

If 576 doesn't work try 1000.

Node.js and Express Application Tools


  • Git for version control (Heroku dependency)

  • Jade for templating

  • Stylus for CSS preprocessing

  • Redis for session storage

  • MongoDB for campaign storage

  • Mongoose, a MongoDB ORM

  • Passport for authentication

  • Jake, like Make, but for Javascript

  • Make for running tests. (I hope to use only Make or Jake but ran into issues getting Mocha to run with Jake)

  • Mocha for testing

  • JSHint for code linting

  • Docco for documentation

Wednesday, September 26, 2012

ubuntu 10.04 upstart use other user instead of root

example
exec su -s /bin/sh -c 'exec "$0" "$@" > /tmp/easypaas.log 2>&1' ubuntu -- /home/ubuntu/cloudfoundry/vcap/dev_setup/bin/vcap_dev start

Saturday, September 1, 2012

Postfix bounces email handler by python script

#!/usr/bin/python
# -*- coding: utf-8 -*-
# export PYTHONIOENCODING=utf-8
import MySQLdb
import string
import email
from cStringIO import StringIO
from email import message_from_string
from flufl.bounce import scan_message
import re, sys, os

class DB:
conn = None

def connect(self):
self.conn = MySQLdb.connect(host='10.0.0.1', user='xx_rw', passwd='123456', db='xxx', use_unicode=True, charset="utf8")

def query(self, sql, string):
try:
cursor = self.conn.cursor()
cursor.execute(sql,string)
except (AttributeError, MySQLdb.OperationalError):
self.connect()
cursor = self.conn.cursor()
cursor.execute(sql,string)
return cursor


def main():
db = DB()
sender=sys.argv[2]
recipient=sys.argv[1]
email_input = sys.stdin.readlines()
parser = email.FeedParser.FeedParser()
msg = None
for msg_line in email_input:
msg = parser.feed(msg_line)
msg = parser.close()

#filter_recipient = scan_message(message_from_string(string.join(message, ' ')))
filter_recipient = scan_message(msg)
if (len(filter_recipient)>0):
db.query("""INSERT INTO email_bounces (`sender`, `recipient`) VALUES(%s, %s)""", (filter_recipient, recipient))

if __name__ == "__main__":
main()

Tuesday, August 28, 2012

Wednesday, August 15, 2012

how to start with non-master branch?

What about renaming the "initial master", i.e.:

git init
git add .
git commit -m "intial checkin"
git branch -m non-master-branch

Wednesday, August 8, 2012

Is there any PHP function to convert current age to date?


before or on today - 18 years
after today - 19 years

before or on today - 50 years
after today - 51 years

dob <= (today -18 years) and dob > (today - 51 years)

$lower = date('Y-m-d', strtotime('today -18 years'));
$upper = date('Y-m-d', strtotime('today -51 years'));
$query = "SELECT FirstName FROM users WHERE dob >= '$lower' AND dob < '$upper';";


Note that if you plan on dates before 1970 (52-ish), you should likely use DateTime instead of date and sttrtotime (I actually only use DateTime in actual code, but date/strtotime make for much briefer examples).

An example of 85 years ago with DateTime:


$d = new DateTime('today -85 years');
$s = $d->format('Y-m-d'); //1927-06-03 as of 3 June 2012

Monday, July 30, 2012

Access Join多个表


SELECT c.equip_no, e.equip_nm, c.yc_no, y.yc_nm from (cur_data as c INNER join equip as e on e.equip_no=c.equip_no) INNER join ycp as y on y.equip_no=c.equip_no and y.yc_no=c.yc_no group by c.equip_no, c.yc_no, e.equip_nm, y.yc_nm;

Sunday, July 22, 2012

MySQL随机生成ID

随机生成ID
update www_image set user_id=(select round(round(rand(),4)*30000));

Friday, June 29, 2012

Oracle数据库监控脚本


  1. 检查实例的可用性
  2. 检查监听器的可用性
  3. 检查alert日志文件中的错误信息
  4. 在存放log文件的地方满以前清空旧的log文件
  5. 分析table和index以获得更好的性能
  6. 检查表空间的使用情况
  7. 找出无效的对象
  8. 监控用户和事务

显示服务器上的可用实例:

$ ps -ef | grep smon
oracle 21832 1 0 Feb 24 ? 19:05 ora_smon_oradb1
oracle 898 1 0 Feb 15 ? 0:00 ora_smon_oradb2
dliu 25199 19038 0 10:48:57 pts/6 0:00 grep smon
oracle 27798 1 0 05:43:54 ? 0:00 ora_smon_oradb3
oracle 28781 1 0 Mar 03 ? 0:01 ora_smon_oradb4

显示服务器上的可用监听器:

$ ps -ef | grep listener | grep -v grep
oracle 23879 1 0 Feb 24 ? 33:36 /8.1.7/bin/tnslsnr listener_db1 -inherit
oracle 27939 1 0 05:44:02 ? 0:00 /8.1.7/bin/tnslsnr listener_db2 -inherit
oracle 23536 1 0 Feb 12 ? 4:19 /8.1.7/bin/tnslsnr listener_db3 -inherit
oracle 28891 1 0 Mar 03 ? 0:01 /8.1.7/bin/tnslsnr listener_db4 -inherit

查看Oracle存档目录的文件系统使用情况

$ df -k | grep oraarch
/dev/vx/dsk/proddg/oraarch 71123968 4754872 65850768 7% /u09/oraarch

列出alert.log文件中的全部Oracle错误信息:

$ grep ORA- alert.log
ORA-00600: internal error code, arguments: [kcrrrfswda.1], [], [], [], [], []
ORA-00600: internal error code, arguments: [1881], [25860496], [25857716], []

检查Oracle实例的可用性

oratab文件中列出了服务器上的所有数据库
$ cat /var/opt/oracle/oratab
############################################################
## /var/opt/oracle/oratab                                 ##
############################################################
oradb1:/u01/app/oracle/product/8.1.7:Y
oradb2:/u01/app/oracle/product/8.1.7:Y
oradb3:/u01/app/oracle/product/8.1.7:N
oradb4:/u01/app/oracle/product/8.1.7:Y


以下的脚本检查oratab文件中列出的所有数据库,并且找出该数据库的状态(启动还是关闭)

## ckinstance.ksh ##
ORATAB=/var/opt/oracle/oratab
echo `date`
echo Oracle Database(s) Status `hostname` :
db=`egrep -i :Y|:N $ORATAB | cut -d: -f1 | grep -v # | grep -v *`
pslist=`ps -ef | grep pmon`
for i in $db ; do
echo $pslist | grep ora_pmon_$i > /dev/null 2>$1
if (( $? )); then
echo Oracle Instance - $i: Down
else
echo Oracle Instance - $i: Up
fi
done


使用以下的命令来确认该脚本是可以执行的:

$ chmod 744 ckinstance.ksh
$ ls -l ckinstance.ksh
-rwxr--r-- 1 oracle dba 657 Mar 5 22:59 ckinstance.ksh*


以下是实例可用性的报表:

Wednesday, June 27, 2012

Openstack Glance 导入ubuntu 10.04 Image

#!/bin/bash

if [ ! -f "lucid-server-cloudimg-amd64.tar.gz" ] ; then
echo "Downloading image"
wget http://cloud-images.ubuntu.com/lucid/current/lucid-server-cloudimg-amd64.tar.gz
fi

if [ ! -f "lucid-server-cloudimg-amd64.img" ] ; then
echo "Extracting image"
tar xfzv lucid-server-cloudimg-amd64.tar.gz
fi

echo "Uploading kernel"
RVAL=`glance add name="ubuntu-lucid-kernel" is_public=true container_format=aki disk_format=aki < lucid-server-cloudimg-amd64-vmlinuz-virtual`
KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`

echo "Uploading image"
glance add name="ubuntu-lucid" is_public=true container_format=ami kernel_id=$KERNEL_ID disk_format=ami < lucid-server-cloudimg-amd64.img

Wednesday, June 20, 2012

Python and Linux Command

import commands
out = commands.getoutput("ls")
print out

Wednesday, June 13, 2012

MySQL调优

1, 查看MySQL服务器配置信息
mysql> show variables;

2, 查看MySQL服务器运行的各种状态值
mysql> show global status;

3, 慢查询
mysql> show variables like '%slow%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| log_slow_queries | OFF |
| slow_launch_time | 2 |
+------------------+-------+
mysql> show global status like '%slow%';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| Slow_launch_threads | 0 |
| Slow_queries | 279 |
+---------------------+-------+


配置中关闭了记录慢查询(最好是打开,方便优化),超过2秒即为慢查询,一共有279条慢查询
4, 连接数
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 500 |
+-----------------+-------+

mysql> show global status like 'max_used_connections';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 498 |
+----------------------+-------+

设置的最大连接数是500,而响应的连接数是498
max_used_connections / max_connections * 100% = 99.6% (理想值 ≈ 85%)

5, key_buffer_size
key_buffer_size是对MyISAM表性能影响最大的一个参数, 不过数据库中多为Innodb
mysql> show variables like 'key_buffer_size';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| key_buffer_size | 67108864 |
+-----------------+----------+

mysql> show global status like 'key_read%';
+-------------------+----------+
| Variable_name | Value |
+-------------------+----------+
| Key_read_requests | 25629497 |
| Key_reads | 66071 |
+-------------------+----------+

一共有25629497个索引读取请求,有66071个请求在内存中没有找到直接从硬盘读取索引,计算索引未命中缓存的概率:
key_cache_miss_rate = Key_reads / Key_read_requests * 100% =0.27%
需要适当加大key_buffer_size
mysql> show global status like 'key_blocks_u%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Key_blocks_unused | 10285 |
| Key_blocks_used | 47705 |
+-------------------+-------+

Key_blocks_unused表示未使用的缓存簇(blocks)数,Key_blocks_used表示曾经用到的最大的blocks数
Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% ≈ 18% (理想值 ≈ 80%)

Friday, June 1, 2012

nagios 3 + ndoutils-1.5 问题

环境: CentOS 6 ,Nagios3.2 , ndoutils-1.5.
错误

Feb 28 19:04:37 monitor nagios: ndomod: Successfully connected to data sink. 0
queued items to flush.
Feb 28 19:04:37 monitor nagios: Event broker module
'/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
Feb 28 19:04:37 monitor nagios: Finished daemonizing... (New PID=3160)
Feb 28 19:04:37 monitor ndo2db-3x: Error: queue send error.


需要设置

kernel.msgmax = 131072000
kernel.msgmnb = 131072000
kernel.msgmni = 65536000


中文问题解决:
设置为UTF-8
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
default-character-set = utf8
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

Saturday, April 28, 2012

Selenium IDE 如何触发onblur

使用 fireEvent

优化MySQL语句的十个建议

1.他的力气没使对地方

我们要遵循的一个准则就是如果你要优化代码时,应该先找出瓶颈在哪。然而Silverton先生的力气没有用对地方。我认为60%的优化是基于清楚理解SQL和数据库基础的。你需要知道join和子查询的区别,列索引,以及如何将数据规范化等等。另外的35%的优化是需要清楚数据库选择时的性能表现,例如COUNT(*)可能很快也可能很慢,要看你选用什么数据库引擎。还有一些其他要考虑的因素,例如数据库在什么时候不用缓存,什么时候存在硬盘上而不存在内存中,什么时候数据库创建临时表等等。剩下的5%就很少会有人碰到了,但Silverton先生恰好在这上面花了大量的时间。我从来就没用过SQL_SAMLL_RESULT。

2.很好的问题,但是很糟糕的解决方法

Silverton先生提出了一些很好的问题。MySQL针对长度可变的列如TEXT或BLOB,将会使用动态行格式(dynamic row format),这意味着排序将在硬盘上进行。我们的方法不是要回避这些数据类型,而是将这些数据类型从原来的表中分离开,放入另外一个表中。下面的schema可以说明这个想法:

CREATE TABLE posts (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
author_id int UNSIGNED NOT NULL,
created timestamp NOT NULL,
PRIMARY KEY(id)
);

CREATE TABLE posts_data (
post_id int UNSIGNED NOT NULL.
body text,
PRIMARY KEY(post_id)
);


3. 有点匪夷所思……

他的许多建议都是让人非常吃惊的,譬如“移除不必要的括号”。你这样写SELECT * FROM posts WHERE (author_id = 5 AND published = 1),还是这样写SELECT * FROM posts WHERE author_id = 5 AND published = 1 ,都不重要。任何比较好的DBMS都会自动进行识别做出处理。这种细节就好像C语言中是i++快些还是++i快些。真的,如果你把精力都花在这上面了,那就不用写代码了。

Monday, April 23, 2012

acpi绑定Thinkpad Hotkey

/etc/acpi/default.sh
ibm)
case "$action" in
hotkey)
case "$value" in
00001008)
logger "TouchPage toggle"
export DISPLAY=":0.0"
/home/fred/bin/keys/fn/touchpad.sh
;;
*) log_unhandled $* ;;
esac
;;
esac
;;

Thursday, April 19, 2012

Monday, April 16, 2012

使用convert裁剪图片

裁剪掉图片底部20px高度:
convert trim_oneside.gif -gravity South -chop 0x20 trim_south.gif

Friday, April 13, 2012

使用SSH压缩让网络传输更慢

mbailey@modu1:~/vm$ scp -r r03 modu4:vm/
Ubuntu 64-bit-f001.vmdk 7% 147MB 8.1MB/s 03:54 ETA


mbailey@modu1:~/vm$ scp -r -o 'Compression no' r03 modu4:vm/
Ubuntu 64-bit-f001.vmdk 100% 2048MB 28.1MB/s 01:13 ETA


所以我推荐 ssh+rsync。

Ant build.xml
























Thursday, April 12, 2012

在App Engine上使用bottle框架

application: my-bottle-app\
version: 1
runtime: python
api_version: 1

handlers:
- url: /styles
static_dir: styles

- url: /.*
script: main.py

from framework import bottle
from framework.bottle import route, template, request, error, debug
from google.appengine.ext.webapp.util import run_wsgi_app

@route('/')
def DisplayForm():
message = 'Hello World'
output = template('templates/home', data = message)
return output

def main():
debug(True)
run_wsgi_app(bottle.default_app())

@error(403)
def Error403(code):
return 'Get your codes right dude, you caused some error!'

@error(404)
def Error404(code):
return 'Stop cowboy, what are you trying to find?'

if __name__=="__main__":
main()

Friday, April 6, 2012

批量下载某个网站 0001.jpg 到 0999.jpg 图片的shell脚本

for i in {1..999}; do curl -L -O http://baidu.com/images/pic_$(printf "%0.4d" $i).jpg; done

Monday, April 2, 2012

Linux版本Google Chrome更改字体方法

在Linux下的Google自然可以通过设置更改字体,不过不能选择像“sans-serif”,“monospace”这样的字体。

你需要用编辑器手工编辑 .config/google-chrome/Default/Preferences

"webkit": {
"webprefs": {
"global": {
"fixed_font_family": "monospace",
"sansserif_font_family": "sans-serif",
"serif_font_family": "serif",
"standard_font_family": "sans-serif"
},
"uses_universal_detector": true
}
}

dejavu是我一直使用的字体。

Wednesday, March 14, 2012

在哪里找Google Chrome播放的Flv缓存

这里只是 Linux上的方法

  1. 先找到PID
    ps ax | grep -i chrome | grep -i flash  

  2. 再找到文件
    file /proc/Flash_Plugin_PID/fd/* | grep -i deleted
    或者
    lsof -p Flash_plugin_pid | grep -i deleted

  3. 拷贝文件 /proc/[pid]/fd/[fileno] 到 recovered_file.flv

Monday, March 12, 2012

Telnet到AIX字符界面显示问题

先 [cci]export TERM=VT100[/cci] 再登录。
如果是SSH连接。[cci]export TERM=xterm[/cci]

Friday, March 9, 2012

KVM install windows 2003 guest


qemu-system-i386 -m 1024 -cdrom images/Windows\ Server\ 2003\ SP2.ISO -drive file=win2003.img,cache=writeback,boot=on -fda virtio-win-1.1.16.vfd -boot d -nographic -vnc :0


安装到提示重新启动的时候,必须去掉 boot=on,不然装不上,windows 2008没有这个问题。

Thursday, March 1, 2012

scp太慢了

在转移5G文件到新服务器时用scp只有60k,换用rsync+ssh,4M速度!
[cc]rsync -ave ssh greendome:/home/ftp/pub/ /home/ftp/pub/[/cc]

[cc]$ rsync -avz -e "ssh -i /home/thisuser/cron/thishost-rsync-key" remoteuser@remotehost:/remote/dir /this/dir/[cc]

Tuesday, February 28, 2012

内网服务器使用SSH端口转发访问外网



很多使用我们不能在内网防火墙中的服务器上使用yum等工具,不过我们可以使用SSH来映射本地端口到服务器完成。

在你的笔记本电脑上使用以下Python(twisted)来做一个代理,当然你也可以用nodejs,Perl,或者直接用Squid等。

from twisted.web import proxy, http
from twisted.internet import reactor


class ProxyFactory(http.HTTPFactory):

    def buildProtocol(self, addr):
        return proxy.Proxy()


reactor.listenTCP(8080, ProxyFactory())
reactor.run()

 

然后把这个8080端口映射到内网服务器上的8083端口上

ssh -g -R 8083:localhost:8080 remote-server

最后在内网服务器上使用代理

export http_proxy="http://localhost:8083"

Wednesday, February 22, 2012

Increase A VMware Disk Size (VMDK) Formatted As Linux LVM


3) Partitioning the unalloced space


Once you've changed the disk's size, either boot up your VM again, or restart if it was still running. Linux needs to boot with the new disk, so it can see you've added (unallocated) disk space.

Once you've booted again, you can check if the extra space can be seen on the disk.
lb02.lab.mojah.be ~ $ fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         391     3036285   8e  Linux LVM

So the server can now see the 10GB hard disk. Let's create a partition, by start fdisk for the /dev/sda device.
lb02.lab.mojah.be ~ $ fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
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): n

Now enter 'n', to create a new partition.
Command action
e   extended
p   primary partition (1-4)
p

Now choose "p" to create a new primary partition. Please note, your system can only have 4 primary partitions on this disk! If you've already reached this limit, create an extended partition.
Partition number (1-4): 3

Choose your partition number. Since I already had /dev/sda1 and /dev/sda2, the logical number would be 3.
First cylinder (392-1305, default 392): <enter>
Using default value 392
Last cylinder or +size or +sizeM or +sizeK (392-1305, default 1305): <enter>
Using default value 1305

Note; the cylinder values will vary on your system. It should be safe to just hint enter, as fdisk will give you a default value for the first and last cylinder (and for this, it will use the newly added diskspace).
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Now type t to change the partition type. When prompted, enter the number of the partition you've just created in the previous steps. When you're asked to enter the "Hex code", enter 8e, and confirm by hitting enter.
Command (m for help): w

Once you get back to the main command within fdisk, type w to write your partitions to the disk. You'll get a message about the kernel still using the old partition table, and to reboot to use the new table. Please obey kindly, and reboot the virtual machine.

After you've rebooted, you can see the newly created partition with fdisk.
lb02.lab.mojah.be ~ $ fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         391     3036285   8e  Linux LVM
/dev/sda3             392        1305     7341705   8e  Linux LVM

3) Extend your Logical Volume with the new partition


Now, create the physical volume as a basis for your LVM. Please replace /dev/sda3 with the newly created partition.
lb02.lab.mojah.be ~ $ pvcreate /dev/sda3
Physical volume "/dev/sda3″ successfully created

Now find out how your Volume Group is called.
lb02.lab.mojah.be ~ $ vgdisplay
--- Volume group ---
VG Name               VolGroup00
...

Let's extend that Volume Group by adding the newly created physical volume to it.
lb02.lab.mojah.be ~ $ vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00″ successfully extended

With pvscan, we can see our newly added physical volume, and the usable space (7GB in this case).
lb02.lab.mojah.be ~ $ pvscan
PV /dev/sda2   VG VolGroup00   lvm2 [2.88 GB / 0    free]
PV /dev/sda3   VG VolGroup00   lvm2 [7.00 GB / 7.00 GB free]
Total: 2 [9.88 GB] / in use: 2 [9.88 GB] / in no VG: 0 [0   ]

Now we can extend Logical Volume (as opposed to the Physical Volume we added to the group earlier). The command is "lvextend /dev/VolGroupxx /dev/sdXX".
lb02.lab.mojah.be ~ $ lvextend /dev/VolGroup00/LogVol00 /dev/sda3
Extending logical volume LogVol00 to 9.38 GB
Logical volume LogVol00 successfully resized

If you're running this on Ubuntu, use the following.
lb02.lab.mojah.be ~ $ lvextend /dev/mapper/vg-name /dev/sda3

All that remains now, it to resize the file system to the volume group, so we can use the space. Replace the path to the correct /dev device if you're on ubuntu/debian like systems.
lb02.lab.mojah.be ~ $ resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2457600 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2457600 blocks long.

And we're good to go!
lb02.lab.mojah.be ~ $ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 9.1G 1.8G  6.9G  21% /
/dev/sda1              99M   18M   77M  19% /boot
tmpfs                 125M     0  125M   0% /dev/shm

Monday, January 30, 2012

Filezilla 3.5.3 连接VsFTPd TLS问题

Response arg: error:1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher

/etc/vsftpd/vsftpd.conf
ssl_ciphers=HIGH

原因是
The default is DES-CBC3-SHA which seems that is not supported anymore by FileZilla

Wednesday, January 18, 2012

MySQL regex_replace Function

[cc lang='mysql' ]
DELIMITER $$
CREATE FUNCTION `regex_replace`(pattern VARCHAR(1000),replacement VARCHAR(1000),original VARCHAR(1000))

RETURNS VARCHAR(1000)
DETERMINISTIC
BEGIN
DECLARE temp VARCHAR(1000);
DECLARE ch VARCHAR(1);
DECLARE i INT;
SET i = 1;
SET temp = '';
IF original REGEXP pattern THEN
loop_label: LOOP
IF i>CHAR_LENGTH(original) THEN
LEAVE loop_label;
END IF;
SET ch = SUBSTRING(original,i,1);
IF NOT ch REGEXP pattern THEN
SET temp = CONCAT(temp,ch);
ELSE
SET temp = CONCAT(temp,replacement);
END IF;
SET i=i+1;
END LOOP;
ELSE
SET temp = original;
END IF;
RETURN temp;
END$$
DELIMITER ;

[/cc]

Friday, January 6, 2012

FreeBSD PF 防火墙简单配置

oif="em0"
block in
pass out
pass in on $oif proto tcp to ($oif) port = 5631
pass in on $oif proto tcp from 192.168.0.0/24 to ($oif) port = 3128
pass in on $oif proto tcp to ($oif) port = 80