本站vpn自助注册源码
对于pptp vpn的架构,最流行的一种方法就是pptpd+freeradius+mysql,但是对于开源的vpn账户管理系统还是很少的,几乎为零,那些收费的管理系统价格高得吓人,今天在网上发现有人贡献出自己的自助注册VPN系统源码,随手收录一下。整个系统其实很简单,无非就是用php自己写几行代码就行了,下面就把代码贴出来:
?
配置文件config.php(主要是mysql的信息):
<?php $dbhost = "localhost";//mysql服务器地址 $dbport = "3306";//mysql端口 $dbname = "radius";//freeradius数据库名称 $dbuser = "radius";//freeradius数据库用户 $dbpass = "123456";//数据库密码?>
?
?
代码vpn.php:
<?php include "config.php"; function creat_user($name,$pass) { global $dbhost,$dbname,$dbuser,$dbpass; $conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ("连接数据库错误!"); mysql_select_db($dbname,$conn); $sql = "SELECT * FROM `radcheck` WHERE username='".$name."'"; $query = mysql_query($sql,$conn); $row = mysql_fetch_row($query); if ($row[1] == $name) { echo "用户名已经存在,请选择其他用户名!"; } else { $sql = "INSERT INTO radcheck (id, username, attribute, op, value) VALUES ('', '$name', 'User-Password', '==', '$pass')"; $a = mysql_query($sql,$conn); if ($a) { echo "创建账户成功!"; } else { echo "创建账户失败!"; } } mysql_close($conn);}creat_user($_POST['username'],$_POST['pwd']);?>
?
注册表单 index.html:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="expires" content="0"><meta http-equiv="pragma" content="no-cache"><title>PPTP VPN用户自助注册</title><style type="text/css"><!--body{ text-align:center; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; background:#efefef;}#login { margin-top:6%; margin-right:auto; margin-left:auto; line-height: 20px; color: #000000; width:300px; border:1px solid #336699; background:#fff;}#frmlogin{ text-align:left; margin-left:8px;}h1{ margin:0px 0px 10px 0px; padding:0px; width:100%; height:30px; line-height:30px; color:#fff; background:#336699; font-size:18px; text-align:left; text-indent:10px; font-weight:normal; font-family:arial, helvetica, sans-serif;}input{ border:1px solid #336699; height:14px; line-height:14px; width:120px;}.button{ padding-right:10px; padding-left:10px; height:22px; line-height:22px; background:#fbfbfb; color:#000; text-align:center; border-right:2px solid #999; border-left:2px solid #999; border-top:1px solid #999; border-bottom:1px solid #999; margin-right:5px; margin-left:5px;}label{ font-weight:bold; color:#336699;}#tip{ color:#ff9900;}--></style><script type="text/javascript">function validate_required(field,alerttxt){with (field) { if (value==null||value=="") {alert(alerttxt);return false} else {return true} }}function validate_email(field,alerttxt){with (field){apos=value.indexOf("@")dotpos=value.lastIndexOf(".")if (apos<1||dotpos-apos<2) {alert(alerttxt);return false}else {return true}}}function validate_username(field,alerttxt){with (field){var patrn=/^[a-zA-Z]{1,8}$/;if (!patrn.exec(field.value)) {alert(alerttxt);return false}else {return true}}}function validate_password(field,alerttxt){with (field){var patrn=/^[a-zA-Z0-9]{6,20}$/;if (!patrn.exec(field.value)) {alert(alerttxt);return false}else {return true}}}function validate_form(thisform){with (thisform) { if (validate_username(username,"Not a valid username!")==false) {username.focus();return false} if (validate_password(pwd,"Not a valid password!")==false) {pwd.focus();return false} if (validate_required(email,"Email must be filled out!")==false) {email.focus();return false} if (validate_email(email,"Not a valid e-mail address!")==false) {email.focus();return false} }}</script></head><body> <div id="login"> <h1>PPTP VPN账户注册</h1> <form action="vpn.php"onsubmit="return validate_form(this);" method="post"> <label>用户名: <input name="username" type="text" id="username" size="22" maxlength="10" /> </label><label id="tip"></label> <p> <label>密 码: <input name="pwd" type="password" id="pwd" size="24" maxlength="20" /> </label> </p> <p style="align:center; color:red"> vpn地址:vpn.31sky.net</p> <p style="align:center; color:red"> vpn管理:http://www.31sky.net/vpn/admin/</p> <p align="center"> <input name="submit" type="submit" id="btn_login" style="width:60px;background:#efefef;height:25px;line-height:25px;font-size:12px;" value="注册" /> <input name="submit2" type="reset" style="width:60px;background:#efefef;height:25px;line-height:25px;font-size:12px;" value="重置" /> </p> </form></div></body></html>
?
?
==============================
来源:http://igfw.tk/archives/2290
?