顯示具有 OpenVPN 標籤的文章。 顯示所有文章
顯示具有 OpenVPN 標籤的文章。 顯示所有文章

2007年8月30日 星期四

OpenVPN 用戶端使用帳號/密碼的驗證方式

OpenVPN 是屬於 SSL VPN 應用的類型,用戶端需有經由主機簽署的憑證才可以連線,這樣雖然安全但對一些可能會隨時更換機器的用戶而言,卻不是很方便。

這篇文章是以帳號/密碼為主要的登入方式,用戶不需在更換機器後還要向主機重新申請憑證的往返程序。

如果還不了解什麼是 OpenVPN,請參考這篇文章 [轉]OpenVPN中文概述 。

在繼續下述的安裝說明,請先閱讀這篇文章 Install OpenVPN on CentOS 4.4 ,因為以下步驟是延續該文章的進階設定。

作者:A-Lang (alang[dot]hsu[at]gmail[dot]com)

1. 檢查包含的套件有 mysql, mysql-devel, pam_mysql, 如尚未安裝請利用 yum 或網站 rpm.pbone.net 搜尋.
因為找不到相應 CentOS 4 的 pam_mysql 版本, 用 Google 搜尋到最新版的 source rpm , 再進行編譯安裝.
# wget http://www.lfarkas.org/linux/packages/centos/5/SRPMS/pam_mysql-0.7RC1-0.src.rpm
# rpmbuild --rebuild pam_mysql-0.7RC1-0.src.rpm
# rpm -Uvh /usr/src/redhat/RPMS/i386/pam_mysql-*.rpm

2. 建立資料庫管理 VPN 的登入帳號
# mysql -u root -p
mysql> create database vpndb;
mysql> use vpndb;
mysql> CREATE TABLE vpnuser (
-> name char(20) NOT NULL,
-> password char(128) default NULL,
-> active int(10) NOT NULL DEFAULT 1,
-> PRIMARY KEY (name)
-> );
mysql> insert into vpnuser (name,password) values('vpn','vpn');

3. 新增一個檔案 /etc/pam.d/openvpn, 內容如下。
auth sufficient pam_mysql.so user=dbuser passwd=dbpass host=localhost db=vpndb
table=vpnuser usercolumn=name passwdcolumn=password
where=active=1 sqllog=0 crypt=0
account required pam_mysql.so user=dbuser passwd=dbpass host=localhost db=vpndb
table=vpnuser usercolumn=name passwdcolumn=password
where=active=1 sqllog=0 crypt=0
說明:
dbuser -- 可存取 vpndb 的帳戶
dbpass -- 同上的密碼
crypt(0) -- Used to decide to use MySQL's PASSWORD() function or crypt()
0 = No encryption. Passwords in database in plaintext. NOT recommended!
1 = Use crypt
2 = Use MySQL PASSWORD() function

4. 測試 pam_mysql 是否正常運作
# saslauthd -a pam
# testsaslauthd -u vpn -p vpn -s openvpn
0: OK "Success."

5. 防止 Dos 的惡意攻擊, 請建立 "HMAC firewall"。
# cd /etc/openvpn/easy-rsa
# openvpn --genkey --secret keys/ta.key
# cd /etc/openvpn
# cp easy-rsa/keys/ta.key ./

6. 修改 OpenVPN 設定檔
# vi /etc/openvpn/server.conf
# For authentication by user/pass
tls-auth ta.key 0
plugin ./openvpn-auth-pam.so openvpn
client-cert-not-required
username-as-common-name

以上是依據這篇 Install OpenVPN on CentOS 4.4 所提及 server.conf 的內容,為使能以 user/pass 方式登入,需再補充的項目。

# cd /etc/openvpn
# cp /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so ./

7. 啟動或重啟 OpenVPN 服務
# service openvpn start

8. 製作用戶端的安裝套件
基本上將用戶端需要的設定檔及 ca.crt,ta.key 憑證檔打包進安裝檔, 用戶在安裝後即可連線。
請參考文件 http://openvpn.se/files/howto/openvpn-howto_roll_your_own_installation_package-Rev1.1.html



Error: Failed build dependencies:
cyrus-sasl-devel is needed by pam_mysql-0.7RC1-0.i386
Answer:
yum install cyrus-sasl-devel

Error:
0: NO "authentication failed"
Answer: crypt 請改用 0, 編者使用 2 也就是 MySQL 的加密函數 password() 但始終無法驗證成功。


參考連結:
http://bbs.chinaunix.net/viewthread.php?tid=513004&extra=page%3D1

Install OpenVPN on CentOS 4.4

Install OpenVPN on CentOS 4.4

What's OpenVPN:
OpenVPN is a full-featured SSL VPN which implements OSI layer 2 or 3 secure network extension using the industry standard SSL/TLS protocol, supports flexible client authentication methods based on certificates, smart cards, and/or username/password credentials, and allows user or group-specific access control policies using firewall rules applied to the VPN virtual interface. OpenVPN is not a web application proxy and does not operate through a web browser.

OpenVPN 2.0 expands on the capabilities of OpenVPN 1.x by offering a scalable client/server mode, allowing multiple clients to connect to a single OpenVPN server process over a single TCP or UDP port.


Author: A-Lang (alang[dot]hsu[at]gmail[dot]com)

Our System Environment:
Server>
OS : CentOS Linux V4.4/kernel 2.6.9-34.0.2.EL
Real IP : 192.168.10.10
VPN IP : 10.8.0.1

Client>
OS : Windows XP Home
Real IP : 192.168.0.163(dhcp mode)
VPN IP : 10.8.0.x (server assigned)

Reference Document:
http://www.study-area.org/tips/openvpn.html

==============
For Server
==============
1. Download package files
#wget http://openvpn.net/release/openvpn-2.0.9.tar.gz
#wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm

2. Install package
#rpmbuild --rebuild lzo-1.08-4.rf.src.rpm
#rpm -Uvh /usr/src/redhat/RPMS/i386/lzo-*.rpm

#rpmbuild -tb openvpn-2.0.9.tar.gz
#rpm -Uvh /usr/src/redhat/RPMS/i386/openvpn-2.0.9-1.i386.rpm


Error:
Failed build dependencies:
autoconf is needed by lzo-1.08-4.rf.i386
Answer:
yum install autoconf.noarch
--
Error:
Failed build dependencies:
pam-devel is needed by openvpn-2.0.9-1.i386
Answer:
yum install pam-devel

3. Copy the sample configuration files
#cp -r /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
#cp /usr/share/doc/openvpn-2.0.9/sample-config-files/server.conf /etc/openvpn/

4. Configure the CA
#cd /etc/openvpn/easy-rsa/
#vi vars
export KEY_COUNTRY=TW
export KEY_PROVINCE=Taiwan
export KEY_CITY=Hsinchu
export KEY_ORG="ALANGVPN"
export KEY_EMAIL="vpn@myvpn.ca.mail"

#. ./vars
#./clean-all

5. Build the root CA
#./build-ca
......++++++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [TW]:
State or Province Name (full name) [TAIWAN]:
Locality Name (eg, city) [HSINCHU]:
Organization Name (eg, company) [ALANGVPN]:
Organizational Unit Name (eg, section) []:linux
Common Name (eg, your name or your server's hostname) []:VPN
Email Address [vpn@myvpn.ca.mail]:

6. Build the server key and crt
#./build-key-server ovpnsrv1
Generating a 1024 bit RSA private key
.....++++++
........................++++++
writing new private key to 'ovpnsrv1.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [TW]:
State or Province Name (full name) [TAIWAN]:
Locality Name (eg, city) [HSINCHU]:
Organization Name (eg, company) [ALANGVPN]:
Organizational Unit Name (eg, section) []:linux
Common Name (eg, your name or your server's hostname) []:VPN
Email Address [vpn@myvpn.ca.mail]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'TW'
stateOrProvinceName :PRINTABLE:'TAIWAN'
localityName :PRINTABLE:'HSINCHU'
organizationName :PRINTABLE:'ALANGVPN'
organizationalUnitName:PRINTABLE:'linux'
commonName :PRINTABLE:'VPN'
emailAddress :IA5STRING:'vpn@myvpn.ca.mail'
Certificate is to be certified until Jun 27 05:21:29 2017 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

7. Build the Diffie Hellman parameters
#./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
..........

8. Install the CA file which server request
#cp keys/ca.crt ../
#cp keys/dh1024.pem ../
#cp keys/ovpnsrv1.key ../
#cp keys/ovpnsrv1.crt ../

9. Setting the server configuration for OpenVPN
#cd ../
#vi server.conf
dev tap
;dev tun
ca ca.crt
cert ovpnsrv1.crt
key ovpnsrv1.key # This file should be kept secret

10. Startup the service
#service openvpn restart
#chkconfig openvpn on

==============
For Client
==============
1. Download and install the OpenVPN GUI for Windows
http://openvpn.se/files/install_packages/openvpn-2.0.9-gui-1.0.3-install.exe

2. Configure the CA
cmd.exe
>cd "c:Program FilesOpenVPNeasy-rsa"
>copy vars.bat.sample vars.bat
edit vars.bat
set KEY_COUNTRY=TW
set KEY_PROVINCE=TAIWAN
set KEY_CITY=HSINCHU
set KEY_ORG=ALANGVPN
set KEY_EMAIL=vpn@myvpn.ca.mail
(PS. Above must be same as the server)

3. Double-Click the file vars.bat or run this batch file with command-line to load the configuration above.

4. Build the client key and csr
>cp openssl.cnf.sample openssl.cnf
>md keys
>build-key alanghome

5. Copy the client csr file to server and then sign up the csr file with command 'sign-req' .
Copy the keys/alanghome.csr of client to the directory /etc/openvpn/easy-rsa/keys of server.
#cd /etc/openvpn/easy-rsa/
#./sign-req alanghome
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'TW'
stateOrProvinceName :PRINTABLE:'TAIWAN'
localityName :PRINTABLE:'HSINCHU'
organizationName :PRINTABLE:'ALANGVPN'
organizationalUnitName:PRINTABLE:'linux'
commonName :PRINTABLE:'alanghome'
emailAddress :IA5STRING:'vpn@myvpn.ca.mail'
Certificate is to be certified until Jun 27 06:40:48 2017 GMT (3650 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

6. Return to client, install the CA files (including alanghome.crt and ca.crt)
Copy the crt file(alanghome.crt) that server made and ca.crt of server to the directory Program Files/OpenVPN/config of client.
>cd ../config
>copy ../easy-rsakeysalanghome.key ./

7. Setting the client configuration for OpenVPN
>copy ../sample-config/client.ovpn ./
Right-Click the OpenVPN GUI icon in the bottom right-hand corner, select 'Edit Config'
dev tap
;dev tun
dev-node OpenVPN_Tap
remote 192.168.10.10 1194
ca ca.crt
cert alanghome.crt
key alanghome.key
ns-cert-type server



8. Configure the network interface for OpenVPN
Select "Control Panel" -> "Network Connection" -> "TAP-Win32#(#)"
Right-Click to rename as 'OpenVPN_Tap'



9. Startup the connection of client
In the task-bar, select "OpenVPN GUI" -> right-click "Connect"



Here you should can connect with OpenVPN server thru VPN. However general web browsing will be accomplished with direct connections that bypass the VPN.
If you want to browse web thru VPN , please continue to follow the steps below.

1. Add the following directive to the server configuration file 'server.conf'
push "redirect-gateway def1"
push "dhcp-option DNS 168.95.1.1"

2. Setting NAT routing for VPN client on server (設定NAT)
#vi /etc/openvpn/start-nat.sh
#!/bin/bash

ipt="/sbin/iptables"

# Clean the all rules (清除所有iptables)
$ipt -F
$ipt -X
$ipt -t nat -F
$ipt -t nat -X

# Enable ip_forward
echo "1" > /proc/sys/net/ipv4/ip_forward

# For NAT routing
$ipt -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
$ipt -t nat -L

#cd /etc/openvpn
#./start-nat.sh

See Also:

http://blog.chinaunix.net/u/9284/article.php?frmid=28653
http://openvpn.net/howto.html
http://openvpn.se/index.html
http://bbs.chinaunix.net/viewthread.php?tid=935322&extra=page%3D3
http://bbs.chinaunix.net/viewthread.php?tid=503434&extra=page%3D4

OpenVPN中文概述

OpenVPN中文概述

http://dev.csdn.net/article/79/79321.shtm
趣多多 譯

OpenVPN 是一個具備完全特徵的SSL VPN解決方案,能夠進行大範圍的配置操作,包括遠程訪問、站點-站點間VPN、WiFi安全及企業級遠程訪問解決方案,支持負載均衡,錯誤恢復及細粒度的訪問控制。

OpenVPN通過使用工業標準SSL/TLS協議 實現了OSI 2層及3層安全網絡擴展,支持靈活的基於證書、智能卡的客戶端認證方法,允許通過在VPN虛擬接口上應用防火牆規則實現用戶及組訪問控制策略。OpenVPN並非一個Web應用代理,也不能通過Web瀏覽器進行操作。

作為一個不錯的關於OpenVPN的概念介紹,可以參考James Ynan在Linux Fest Northwest 上2004年發表的程序註釋--理解用戶空間VPN:歷史、概念基礎及實際應用(Understanding the User-Space VPN: History, Conceptual Foundations, and Practical Usage)。也可以參考Charlie Hosner的OpenVPN及SSL VPN革命(OpenVPN and the SSL VPN Revolution)。

OpenVPN 是一個開源項目,遵從GPL許可協議。商業許可對重新發佈其基於OpenVPN的應用程序的公司也有效。獲得更多信息請聯繫info@openvpn.net。

OpenVPN 能夠運行於Linux、Windows 2000/XP及更高版本、OpenBSD、FreeBSD、NetBSD、Mac OS X及Solaris平台。
通過OpenVPN,你可以:

在任意IP局部網絡或虛擬以太網適配器上通過單個UDP或TCP端口建立隧道;

使用一或多台機器配置可裁剪的、負載均衡的VPN服務器群以處理成千上萬的來自VPN客戶端的動態連接;

能夠使用在OpenSSL庫中所提供所有的加密、認證及證書特性以保護私有網絡在Internet網絡上的數據傳輸;

使用OpenSSL庫所支持的任意加密算法、密鑰長度或HMAC數字簽名(用於數據報完整性檢查);

先把基於靜態密鑰傳統加密方法或基於證書的公鑰加密方法;

使用靜態、預先公有的密鑰或基於TLS的動態密鑰交換;

使用實時的自適配壓縮及流量整形以管理鏈路帶寬分配;

為動態公共點(如DHCP或撥號客戶端)提供隧道傳輸;

無需顯示定義防火牆規則為面向連接的防火牆提供網絡隧道傳輸;

基於NAT的網絡隧道;

通過虛擬的tap設備創建安全的以太網橋;

在Windows或Mac OS X系統上通過GUI界面控制OpenVPN。



OpenVPN與其它VPN有何區別?

OpenVPN的主要特徵包括跨平台的可移植性、優秀的穩定性、成百上千或成千上個客戶端支持的可伸展性、相對簡單的安裝過程、支持動態IP地址及NAT。

OpenVPN 提供一個設計為易於針對站點定制的可擴展的VPN框架,例如提供發佈自定義安裝包到客戶端,或通過OpenVPN插件模塊接口支持可選的認證方法(例如openvpn-auth-pam 模塊允許OpenVPN使用任意PAM認證方法認證客戶端,這種方法可以單獨使用,也可以與基於X509證書結合使用以進行認證)。

OpenVPN 提供一個管理接口,可以用於遠端控制或中央控制一個OpenVPN守護進程。管理接口也可以用於開發基於GUI或web的前端應用程序。

在Windows平台上,OpenVPN能夠使用Windows Crypto API從智能卡上讀取證書或私鑰。

OpenVPN 使用設計用於可保護被動攻擊和主動攻擊的工業強度的安全模型。OpenVPN的安全模型基於SSL/TLS進行會話認證及使用IPSec ESP協議用於基於UDP的安全隧道傳輸。OpenVPN支持X509 PKI (public key infrastructure)用於會話認證,TLS協議用於密鑰交換,OpenSSL的加密算法無關的EVP接口用於加密隧道數據,HMAC-SHA1算法用於認證隧道數據。

OpenVPN建立為可移植的, OpenVPN可以運行於Linux、Solaris、OpenBSD、FreeBSD、NetBSD、Mac OS X及Windows 2000/XP,因為OpenVPN作為用戶空間守護進程編寫而非內核模塊或對IP層的複雜變更,移植操作的簡易性是值得留意的。

OpenVPN易於使用,通常,一個隧道的建立和配置可以通過一個單獨的命令完成(無需任何必要的配置文件)。OpenVPN文檔包含了的示例進行了詳細解釋。

OpenVPN 經過嚴格設計,並在不可靠的網絡中進行了強度測試。OpenVPN的一個主要的設計目標就是在正常操作和錯誤恢復情況下IP層都能夠快速響應。這意味著如果IP層斷開5分鐘,當它再次恢復時,隧道流量能夠立即恢復,即使動態密鑰交換在這期間已經過期。

OpenVPN 有著健壯的模塊設計。所有加密都由OpenSSL庫處理,所有IP隧道功能都由TUN/TAP虛擬網絡驅動提供。

模塊化的好處是顯而易見的,例如,OpenVPN可以與新版本的OpenSSL庫動態鏈接並立即能夠使用其在新版本中所提供的新功能。例如,當OpenVPN基於最後版本的OpenSSL(0.9.7)編譯時,它能夠使用新的加密算法,如AES-256(高級加載標準,256位密鑰),以及OpenSSL特定目的的硬件加速器優化加密、解密及認證性能的加密引擎功能。

同樣地,OpenVPN的用戶空間設計易於移植到任何包含TUN/TAP虛擬網絡驅動的OS中。

OpenVPN 運行速度很快,在Pentium II 266MHz機器上運行Redhat 7.2 ,使用基於TLS的認證方法,Blowfish加密算法,SHA1 用於隧道數據認證,當隧道傳輸一個巨大的,經過預先壓縮文件的FTP會話時,OpenVPN達到了每秒(CPU時間,包括內核及用戶態時間)1.455MB的收/發傳輸速度。

OpenVPN提供了用於控制VPN隧道的安全參數的選項,同時提供了用於保證服務器本身安全的選項,例如—chroot用於限制OpenVPN守護進程能夠訪問的文件系統部分,--user 及—group選項用於降低守護進程在初始化之後的優先級,--mlock用於確認密鑰原始內容及隧道數據從不被分頁到磁盤上,從而避免被後期恢復。

為什麼先把TLS作為OpenVPN的根本認證及密鑰協商協議呢?TLS是SSL協議族的最後成果,最初由Netscape開發用於他們最初的安全web瀏覽器。多年來,TLS及其SSL前身已經在web上得到了廣泛應用,並得到了深入的弱點分析。這些分析使得它不斷被加強,從而形成如今的協議,SSL/TLS被認為是最強壯及最成熟的安全協議之一。因此,我們相信TLS是作為VPN產品認證及密鑰交換機制的極好的先把。

OpenVPN 支持IPSec或PPTP嗎?
目前被廣泛應用的VPN實現中有三個主流:SSL、IPSec及PPTP。OpenVPN是一個SSL VPN,因此並不與IPSec、L2TP或PPTP兼容。
IPSec協議設計為內核空間IP棧的修正,不同的操作系統需要其自身的IPSec實現。
相對而言,OpenVPN的用戶空間實現允許跨操作系統及處理器體系、防火牆及NAT友好操作、動態地址支持、多協議支持(包括協議橋接)的移植。
優點與缺點並存,OpenVPN的主要優點在於可移植、易於配置及與NAT和動態地址兼容。OpenVPN的安裝和使用與其它安全相關的守護進程軟件,例如SSH相似。
由於歷史因素,IPSecr的優點在於獲得了眾多廠商的支持,雖然OpenVPN也逐漸開始致力於硬件設備的支持。
PPTP協議的優點在於其在Windows平台預裝了客戶端,密碼分析專家已經透露了其安全弱點。

OpenVPN符合標準嗎?
作為一個用戶空間VPN守護進程,OpenVPN與SSL/TLS、RSA證書及X509 PKI、NAT、DHCP及TUN/TAP兼容。
OpenVPN與IPSec、IKE、PPTP或L2TP並不兼容。

OpenVPN 隧道能夠基於TCP連接傳輸嗎?
是的,OpenVPN 1.5以上版本均支持基於TCP連接的隧道傳輸。

我是否能夠使用web瀏覽器作為OpenVPN客戶端?
不可以,雖然OpenVPN使用SSL/TLS協議用於安全傳輸,OpenVPN並不是一個Web應用代理。它是一個OSI 2層或3層Internet網絡隧道解決方案,要求OpenVPN同時安裝於客戶端和服務器端。


編譯OpenVPN
OpenVPN 在Linux或BSD系列系統中很容易通過源碼編譯。而在Windows上編譯則比較複雜,你可以在OpenVPN下載站中找到預編譯的安裝包。


OpenVPN 的編譯:
基於OpenSSL 加密及SSL庫(版本0.9.6或更高),可以提供基於證書的認證、公鑰加密、基於TLS的動態密鑰交換;
只基於OpenSSL加密庫,可以提供基於靜態密鑰的傳統加密和認證;
不基於OpenSSL,只提供未加密的UDP隧道。
OpenVPN也可以與LZO實時加密庫鏈接。OpenVPN支持自適配壓縮,這意味著它可以在隧道數據流能夠被壓縮時進行鏈路壓縮。
OpenVPN完全運行於用戶空間,除了在Windows、Linux及BSD系列系統上需要TUN/TAP虛擬網絡驅動外,不需要其它任何特殊的內核組件。

捐助OpenVPN項目
請考慮捐助OpenVPN項目。OpenVPN是GPL協議下一個完全由社區支持的成果,你的捐助對我們大有幫助,它可以確保OpenVPN的持續開發,包括保持最高安全性,維持一個嚴格的測試程序,添加新特性,改善文檔及提供技術支持。

OpenVPN web status - Use PHP

以網頁顯示 OpenVPN 目前連線的狀況,用 PHP 撰寫。

預覽圖:



步驟一:將這一行加入 /etc/openvpn/server.conf

management localhost 7505

步驟二:新增 vpnstat.php,並置於網站可存取目錄內,內容如下:

=============================================
<?php

// OpenVPN (php-based) web status script
//
// This script has been released to the public domain by Pablo Hoffman
// on February 28, 2007.
//
// Original location:
// http://pablohoffman.com/software/vpnstatus/vpnstatus.txt

// Configuration values --------
$vpn_name = "My VPN";
$vpn_host = "localhost";
$vpn_port = 7505;
// -----------------------------

$fp = fsockopen($vpn_host, $vpn_port, $errno, $errstr, 30);

if (!$fp) {
echo "$errstr ($errno)<br />";
exit;
}

fwrite($fp, "status");
sleep(1);
fwrite($fp, "quit");
sleep(1);

$clients = array();

$inclients = $inrouting = false;

while (!feof($fp)) {

$line = fgets($fp, 128);

if (substr($line, 0, 13) == "ROUTING TABLE") {
$inclients = false;
}

if ($inclients) {
$cdata = split(',', $line);
$clines[$cdata[1]] = array($cdata[2], $cdata[3], $cdata[4]);
}

if (substr($line, 0, 11) == "Common Name") {$inclients = true;}

if (substr($line, 0, 12) == "GLOBAL STATS") {$inrouting = false;}

if ($inrouting) {
$routedata = split(',', $line);
array_push($clients, array_merge($routedata, $clines[$routedata[2]]));
}

if (substr($line, 0, 15) == "Virtual Address") {$inrouting = true;}

}

$headers = array('VPN Address', 'Name', 'Real Address', 'Last Act', 'Recv', 'Sent', 'Connected Since');

$tdalign = array('left', 'left', 'left', 'left', 'right', 'right', 'left');

/* DEBUGprint "<pre>";
print_r($headers);
print_r($clients);
print_r($clines);
print_r($routedata);
print "</pre>";
*/

fclose($fp);

?>
<!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>
<title><?php echo $vpn_name ?> status</title>
<meta equiv="'refresh'" content="'300'">
<style type="text/css">

body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
background-color: #E5EAF0;
}

h1 {
color: green;
font-size: 24px;
text-align: center;
padding-bottom: 0;margin-bottom: 0;
}

p.info {
text-align: center;
font-size: 12px;
}

.status0 {
background: #ebb;
}

.status1 {
background: lime;
}

table {
#border: medium solid maroon;
margin: 0 auto;border-collapse: collapse;
}

th {
background: maroon;
color: white;
}

tr {
border-bottom: 1px solid silver;
}

td {
padding: 0px 10px 0px 10px;
}

</style>
</head>
<body>
<table>
<tr>
<?php
foreach ($headers as $th) {
?>
<th><?php echo $th?></th>
<?php
}
?>
</tr>
<?php
foreach ($clients as $client) {
$client[3] = date ('Y-m-d H:i', strtotime($client[3]));
$client[6] = date ('Y-m-d H:i', strtotime($client[6]));
$client[4] = number_format($client[4], 0, '', '.');
$client[5] = number_format($client[5], 0, '', '.');
$client[2] = preg_replace('/(.*):.*/', '$1', $client[2]);
$i = 0;
?>
<tr>
<?php
foreach ($client as $td) {
?>
<td align="'<?php">'><?php echo $td?></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
<p class="'info'">This page gets reloaded every 5 min.<br />Last update:
<b><?php echo date ("Y-m-d H:i:s") ?></b>
</p>
</body>
</html>
================================================