Yii CModel validate预定义列表

  • boolean : CBooleanValidator 的别名, 确保属性的值是CBooleanValidator::trueValue 或CBooleanValidator::falseValue .

  • captcha : CCaptchaValidator 的别名,确保了特性的值等于 CAPTCHA 显示出来的验证码.

  • compare : CCompareValidator 的别名, 确保了特性的值等于另一个特性或常量.

  • email : CEmailValidator 的别名,确保了特性的值是一个有效的电邮地址.

  • default : CDefaultValueValidator 的别名, 为特性指派了一个默认值.

  • exist : CExistValidator 的别名, 确保属性值存在于指定的数据表字段中.

  • file : CFileValidator 的别名, 确保了特性包含了一个上传文件的名称.

  • filter : CFilterValidator 的别名, 使用一个filter转换属性.

  • in : CRangeValidator 的别名, 确保了特性出现在一个预订的值列表里.

  • length : CStringValidator 的别名, 确保了特性的长度在指定的范围内.

  • match : CRegularExpressionValidator 的别名, 确保了特性匹配一个正则表达式.

  • numerical : CNumberValidator 的别名, 确保了特性是一个有效的数字.

  • required : CRequiredValidator 的别名, 确保了特性不为空.

  • type : CTypeValidator 的别名, 确保了特性为指定的数据类型.

  • unique : CUniqueValidator 的别名, 确保了特性在数据表字段中是唯一的.

  • url : CUrlValidator 的别名, 确保了特性是一个有效的路径.

关键词: yii framework , 框架 , yii

项目开发时,函数和方法的简写还是要不得

当项目变得庞大时函数方法就开始多起来,如果在命名上不给予实际意义上的区分,后果会很惨,到最后自己都搞不清是什么意思,用在什么地方。
尽管命名看起来很长,但你会发现很有意义,特别要加上注释说明!


关键词: 方法 , 函数 , 项目开发

is_null() ,empty(),unset() 区别详解

empty() & Co, Special Values
gettype() empty() is_null() isSet() (bool)
$x = ""; string true false true false
$x = null; NULL true true false false
var $x; (not set) NULL true true false false
$x = array(); array true false true false
$x = false; boolean true false true false
$x = 15; integer false false true true
$x = 1; integer false false true true
$x = 0; integer true false true false
$x = -1; integer false false true true
$x = "15"; string false false true true
$x = "1"; string false false true true
$x = "0"; string true false true false
$x = "-1"; string false false true true
$x = "foo"; string false false true true
$x = "true"; string false false true true
$x = "false"; string false false true true

关键词: unset , empty , is_null , php

OpenVZ Debian/Ubuntu服务器安装 OpenVPN

wget http://www.putdispenserhere.com/wp-content/uploads/openvpninstall.sh
chmod +x openvpninstall.sh
./openvpninstall.sh
#!/bin/bash
# Interactive OpenVPN install script on a OpenVZ VPS
# Tested on Debian 5, 6, and Ubuntu 10.10
# 2011 v1.5
# Author Denis D. - Modified by Commander Waffles
# http://bluemodule.com/software/openvpn-install-script-for-openvz-vps/
# http://www.putdispenserhere.com/openvpn-debianubuntu-setup-script-for-openvz/

echo "################################################"
echo "Interactive OpenVPN Install Script for OpenVZ VPS Machines v1.5"
echo "by Denis D. http://www.bluemodule.com"
echo "Modified by Commander Waffles http://www.putdispenserhere.com"
echo "Should work on various deb-based Linux distos."
echo "Tested on Debian 5, 6, and Ubuntu 10.10"
echo
echo "Make sure to message your provider and have them enable"
echo "TUN, IPtables, and NAT modules prior to setting up OpenVPN."
echo
echo "You need to set up the server before creating more client keys."
echo "A separate client keyset is required per connection or machine."
echo "When creating certificated you can put \".\" to skip a field for all fields" 
echo "except for \"Common Name\" and password fields."
echo "################################################"
echo
echo
echo "################################################"
echo "Select on option:"
echo "1) Set up new OpenVPN server AND create one client"
echo "2) Create additional clients"
echo "################################################"
read x
if test $x -eq 1; then
	echo "Specify server port number that you want the server to use (eg. 1194 to use OpenVPN defaults or 53 for Captive Portal bypassing - make sure you're not running bind or named):"
	read p
	echo "Enter client username that you want to create (eg. client1):"
	read c

# get the VPS IP
ip=`grep address /etc/network/interfaces | grep -v 127.0.0.1  | awk '{print $2}'`

echo
echo "################################################"
echo "Downloading OpenVPN 2.2.0"
echo "################################################"
case $(lsb_release -is) in Debian) wget http://build.openvpn.net/downloads/releases/debian/5/openvpn_2.2.0-debian0_i386.deb;; Ubuntu) wget http://build.openvpn.net/downloads/releases/ubuntu/10.04/openvpn_2.2.0-ubuntu0_i386.deb;; *) echo "Unkown distribution";; esac

echo
echo "################################################"
echo "Downloading and Installing Dependencies"
echo "################################################"
apt-get update
apt-get install liblzo2-2 libpkcs11-helper1 openvpn-blacklist
case $(lsb_release -is) in Debian) dpkg -i openvpn_2.2.0-debian0_i386.deb;; Ubuntu) dpkg -i openvpn_2.2.0-ubuntu0_i386.deb;; *) echo "Unkown distribution";; esac

echo
echo "################################################"
echo "Creating Server Config"
echo "\"Common Name\" must be filled."
echo "Please insert : server"
echo "################################################"
cp -R /usr/share/doc/openvpn/examples/easy-rsa/ /etc/openvpn

# creating server.conf file
echo ";local $ip" > /etc/openvpn/server.conf
echo "port $p" >> /etc/openvpn/server.conf
echo "proto udp" >> /etc/openvpn/server.conf
echo "dev tun" >> /etc/openvpn/server.conf
echo "ca /etc/openvpn/keys/ca.crt" >> /etc/openvpn/server.conf
echo "cert /etc/openvpn/keys/server.crt" >> /etc/openvpn/server.conf
echo "key /etc/openvpn/keys/server.key" >> /etc/openvpn/server.conf
echo "dh /etc/openvpn/keys/dh1024.pem" >> /etc/openvpn/server.conf
echo "server 10.8.0.0 255.255.255.0" >> /etc/openvpn/server.conf
echo "ifconfig-pool-persist ipp.txt" >> /etc/openvpn/server.conf
echo "push \"redirect-gateway def1 bypass-dhcp\"" >> /etc/openvpn/server.conf
echo "push \"dhcp-option DNS 8.8.8.8\"" >> /etc/openvpn/server.conf
echo "push \"dhcp-option DNS 8.8.4.4\"" >> /etc/openvpn/server.conf
echo "keepalive 5 30" >> /etc/openvpn/server.conf
echo "comp-lzo" >> /etc/openvpn/server.conf
echo "persist-key" >> /etc/openvpn/server.conf
echo "persist-tun" >> /etc/openvpn/server.conf
echo "status openvpn-status.log" >> /etc/openvpn/server.conf
echo "verb 3" >> /etc/openvpn/server.conf

cd /etc/openvpn/easy-rsa/2.0/
. ./vars
./clean-all

echo
echo "################################################"
echo "Building Certifcate Authority"
echo "\"Common Name\" must be filled."
echo "################################################"
./build-ca

echo
echo "################################################"
echo "Building Server Certificate"
echo "\"Common Name\" must be filled."
echo "Please insert : server"
echo "################################################"
./build-key-server server
./build-dh

cp -R /etc/openvpn/easy-rsa/2.0/keys /etc/openvpn/keys

echo
echo "################################################"
echo "Starting Server"
echo "################################################"
/etc/init.d/openvpn start

echo
echo "################################################"
echo "Forwarding IPv4 and Enabling It On boot"
echo "################################################"
echo 1 > /proc/sys/net/ipv4/ip_forward
# saves ipv4 forwarding and and enables it on-boot
cat >> /etc/sysctl.conf <<END
net.ipv4.ip_forward=1
END
sysctl -p

echo
echo "################################################"
echo "Updating IPtables Routing and Enabling It On boot"
echo "################################################"
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to $ip
# saves iptables routing rules and enables them on-boot
iptables-save > /etc/iptables.conf
cat > /etc/network/if-pre-up.d/iptables <<END
#!/bin/sh
iptables-restore < /etc/iptables.conf
END
chmod +x /etc/network/if-pre-up.d/iptables

echo
echo "################################################"
echo "Building certificate for client $c"
echo "\"Common Name\" must be filled."
echo "Please insert like same cert : $c"
echo "################################################"
./build-key $c

echo "client" > /etc/openvpn/keys/$c.ovpn
echo "dev tun" >> /etc/openvpn/keys/$c.ovpn
echo "proto udp" >> /etc/openvpn/keys/$c.ovpn
echo "remote $ip $p" >> /etc/openvpn/keys/$c.ovpn
echo "resolv-retry infinite" >> /etc/openvpn/keys/$c.ovpn
echo "nobind" >> /etc/openvpn/keys/$c.ovpn
echo "persist-key" >> /etc/openvpn/keys/$c.ovpn
echo "persist-tun" >> /etc/openvpn/keys/$c.ovpn
echo "ca ca.crt" >> /etc/openvpn/keys/$c.ovpn
echo "cert $c.crt" >> /etc/openvpn/keys/$c.ovpn
echo "key $c.key" >> /etc/openvpn/keys/$c.ovpn
echo "comp-lzo" >> /etc/openvpn/keys/$c.ovpn
echo "verb 3" >> /etc/openvpn/keys/$c.ovpn

cp /etc/openvpn/easy-rsa/2.0/keys/$c.crt /etc/openvpn/keys
cp /etc/openvpn/easy-rsa/2.0/keys/$c.key /etc/openvpn/keys

cd /etc/openvpn/keys/
tar -czf clientkeys.tgz ca.crt $c.crt $c.key $c.ovpn

echo
echo "################################################"
echo "One client keyset for $c generated."
echo "To connect:"
echo "1) Download /etc/openvpn/keys/clientkeys.tgz using a client such as WinSCP/FileZilla."
echo "2) Create a folder named VPN in C:\Program Files\OpenVPN\config directory."
echo "3) Extract the contents of clientkeys.tgz to the VPN folder."
echo "4) Start openvpn-gui, right click the tray icon and click Connect on your client name."
echo "To generate additonal client keysets, run the script again with option #2."
echo "################################################"


# runs this if option 2 is selected
elif test $x -eq 2; then
	echo "Enter client username that you want to create (eg. client2):"
	read c
	
ip=`grep address /etc/network/interfaces | grep -v 127.0.0.1  | awk '{print $2}'`
p=`grep -n 'port' /etc/openvpn/server.conf | cut -d' ' -f2`

echo
echo "################################################"
echo "Building certificate for client $c"
echo "\"Common Name\" must be filled."
echo "Please insert like same cert : $c"
echo "################################################"
cd /etc/openvpn/easy-rsa/2.0
source ./vars
./vars
./build-key $c

echo "client" > /etc/openvpn/keys/$c.ovpn
echo "dev tun" >> /etc/openvpn/keys/$c.ovpn
echo "proto udp" >> /etc/openvpn/keys/$c.ovpn
echo "remote $ip $p" >> /etc/openvpn/keys/$c.ovpn
echo "resolv-retry infinite" >> /etc/openvpn/keys/$c.ovpn
echo "nobind" >> /etc/openvpn/keys/$c.ovpn
echo "persist-key" >> /etc/openvpn/keys/$c.ovpn
echo "persist-tun" >> /etc/openvpn/keys/$c.ovpn
echo "ca ca.crt" >> /etc/openvpn/keys/$c.ovpn
echo "cert $c.crt" >> /etc/openvpn/keys/$c.ovpn
echo "key $c.key" >> /etc/openvpn/keys/$c.ovpn
echo "comp-lzo" >> /etc/openvpn/keys/$c.ovpn
echo "verb 3" >> /etc/openvpn/keys/$c.ovpn

cp /etc/openvpn/easy-rsa/2.0/keys/$c.crt /etc/openvpn/keys
cp /etc/openvpn/easy-rsa/2.0/keys/$c.key /etc/openvpn/keys

cd /etc/openvpn/keys/
tar -czf clientkeys.tgz ca.crt $c.crt $c.key $c.ovpn

echo
echo "################################################"
echo "One client keyset for $c generated."
echo "To connect:"
echo "1) Download /etc/openvpn/keys/clientkeys.tgz using a client such as WinSCP/FileZilla."
echo "2) Create a folder named VPN in C:\Program Files\OpenVPN\config directory."
echo "3) Extract the contents of clientkeys.tgz to the VPN folder."
echo "4) Start openvpn-gui, right click the tray icon and click Connect on your client name."
echo "################################################"

else
echo "Invalid selection, quitting."
exit
fi
openvpninstall.zip



关键词: openvpn , vps , vpn , linux , 服务器

buyvm Debian/Ubuntu OpenVZ一键安装PPTP (vpn)教程

wget http://www.putdispenserhere.com/wp-content/uploads/pptpinstall.sh
chmod +x pptpinstall.sh
./pptpinstall.sh

#!/bin/bash
# Interactive PoPToP install script on a OpenVZ VPS
# Tested on Debian 5, 6, and Ubuntu 11.04
# 2011 v1.1
# Author: Commander Waffles
# http://www.putdispenserhere.com/pptp-debian-ubuntu-openvz-setup-script/

echo "######################################################"
echo "Interactive PoPToP Install Script for OpenVZ VPS"
echo "by Commander Waffles http://www.putdispenserhere.com"
echo "Should work on various deb-based Linux distos."
echo "Tested on Debian 5, 6, and Ubuntu 11.04"
echo
echo "Make sure to message your provider and have them enable"
echo "IPtables and ppp modules prior to setting up PoPToP."
echo
echo "You need to set up the server before creating more users."
echo "A separate user is required per connection or machine."
echo "######################################################"
echo
echo
echo "######################################################"
echo "Select on option:"
echo "1) Set up new PoPToP server AND create one user"
echo "2) Create additional users"
echo "######################################################"
read x
if test $x -eq 1; then
	echo "Enter username that you want to create (eg. client1 or john):"
	read u
	echo "Specify password that you want the server to use:"
	read p

# get the VPS IP
ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`

echo
echo "######################################################"
echo "Downloading and Installing PoPToP"
echo "######################################################"
apt-get update
apt-get install pptpd

echo
echo "######################################################"
echo "Creating Server Config"
echo "######################################################"
cat > /etc/ppp/pptpd-options <<END
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
nodefaultroute
lock
nobsdcomp
END

# setting up pptpd.conf
echo "option /etc/ppp/pptpd-options" > /etc/pptpd.conf
echo "logwtmp" >> /etc/pptpd.conf
echo "localip $ip" >> /etc/pptpd.conf
echo "remoteip 10.1.0.1-100" >> /etc/pptpd.conf

# adding new user
echo "$u	*	$p	*" >> /etc/ppp/chap-secrets

echo
echo "######################################################"
echo "Forwarding IPv4 and Enabling it on boot"
echo "######################################################"
cat >> /etc/sysctl.conf <<END
net.ipv4.ip_forward=1
END
sysctl -p

echo
echo "######################################################"
echo "Updating IPtables Routing and Enabling it on boot"
echo "######################################################"
iptables -t nat -A POSTROUTING -j SNAT --to $ip
# saves iptables routing rules and enables them on-boot
iptables-save > /etc/iptables.conf

cat > /etc/network/if-pre-up.d/iptables <<END
#!/bin/sh
iptables-restore < /etc/iptables.conf
END

chmod +x /etc/network/if-pre-up.d/iptables
cat >> /etc/ppp/ip-up <<END
ifconfig ppp0 mtu 1400
END

echo
echo "######################################################"
echo "Restarting PoPToP"
echo "######################################################"
/etc/init.d/pptpd restart

echo
echo "######################################################"
echo "Server setup complete!"
echo "Connect to your VPS at $ip with these credentials:"
echo "Username:$u ##### Password: $p"
echo "######################################################"

# runs this if option 2 is selected
elif test $x -eq 2; then
	echo "Enter username that you want to create (eg. client1 or john):"
	read u
	echo "Specify password that you want the server to use:"
	read p

# get the VPS IP
ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`

# adding new user
echo "$u	*	$p	*" >> /etc/ppp/chap-secrets

echo
echo "######################################################"
echo "Addtional user added!"
echo "Connect to your VPS at $ip with these credentials:"
echo "Username:$u ##### Password: $p"
echo "######################################################"

else
echo "Invalid selection, quitting."
exit
fi
pptpinstall.zip

关键词: 代理服务器 , buyvm , vps , vpn , linux , 服务器

Total: 14123Next ›