May 2014 Archives

PHP RePOST data

user-pic
Vote 0 Votes

Recieve POST and RePOST data to somewhere. Similar to POST redirection.

$ch = curl_init('http://yourhost.com/post.php');
$postdata = file_get_contents("php://input");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);

Apache mod_bw

user-pic
Vote 0 Votes

Apache Bandwidth Mod
wget http://ivn.cl/files/source/mod_bw-0.92.tgz
tar zxf mod_bw-0.92.tgz
apxs -i -a -c mod_bw.c
or
apxs2 -i -a -c mod_bw.c

httpd.conf 加入 config
例: 來自 192.168.0.0/16 不限速, 最大連線數 50, 其他 share 1M Bytes/s (8Mbps), 最大連線數 100,
all 一定要放在最後, 順序有差, 若放在前面, 就會先 match 到而套用設定
mod_bw 的限速都是 by IP group 的, 並非 per IP, 即某 IP group 共用指定頻寬及最大連線數
BandWidthModule On
ForceBandWidthModule On
BandWidth 192.168.0.0/16 0
BandWidth all 1000000
MaxConnection 192.168.0.0/16 50
MaxConnection all 100 # 超過此數目, 會回應 503: Service Temporarily Unavailable
IP 欄位, 可以用 USER AGENT(支援 RE), 例如 "u:^Mozilla/5(.*)" "u:wget"
若再加入以下可以用 http://yourhost/modbw 看簡單的統計
<location /modbw>
SetHandler modbw-handler
</location>

ref. mod_bw v0.92 Readme

Google Geocoding API (地址轉經緯度或經緯度轉地址) 限制只有 2500 筆 (per ip, per day)
實測大概在 2510-2550 筆查詢後就會被鎖
達到上限後會返回
{
"error_message" : "You have exceeded your daily request quota for this API.",
"results" : [],
"status" : "OVER_QUERY_LIMIT"
}

PHP mb_send_mail

user-pic
Vote 0 Votes

PHP mb_send_mail
Subject and message are automatically encoded,
to and additional_headers are not automatically encoded.

mb_send_mail 比 mail 好用很多, 主旨及本文會自動依 mbstring.internal_encoding 處理編碼
但是當 to and additional_headers 有包含 multi-byte 時, multi-byte 部份要用 mb_encode_mimeheader 處理過才會正常
e.g.
$to=mb_encode_mimeheader("王大頭")." <foo@test.com>";
$additional_headers="From: ".mb_encode_mimeheader("王小頭")." <bar@test.com>\nContent-Type: text/plain; charset=UTF-8";
mb_send_mail($to,$subject,$message,$additional_headers);

pinglog

user-pic
Vote 0 Votes

Pinglog is a Windows ping wraper that output with timestamp.
它會呼叫原本的 ping, 輸出時會帶出時間, 並產生 Log, 之前叫 pingtest, 此版在 Log 檔名加上 IP

C:\>pinglog 8.8.8.8
2014-05-12 10:50:11 Pinging 8.8.8.8 with 32 bytes of data:
2014-05-12 10:50:11 Reply from 8.8.8.8: bytes=32 time=4ms TTL=52
2014-05-12 10:50:12 Reply from 8.8.8.8: bytes=32 time=4ms TTL=52
2014-05-12 10:50:13 Reply from 8.8.8.8: bytes=32 time=4ms TTL=52
2014-05-12 10:50:14 Reply from 8.8.8.8: bytes=32 time=4ms TTL=52
2014-05-12 10:50:14 Ping statistics for 8.8.8.8:
2014-05-12 10:50:14 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
2014-05-12 10:50:14 Approximate round trip times in milli-seconds:
2014-05-12 10:50:14 Minimum = 4ms, Maximum = 4ms, Average = 4ms

Log File: pinglog-8.8.8.8-20140512105011.log

OpenMandriva Linux

user-pic
Vote 0 Votes

OpenMandriva 算是 Mandriva Linux 的社群分支, 另一個分支是 Mageia
(更早之前叫 Mandrake Linux)
跟 RedHat/CentOS 相同都是用 RPM 套件管理系統(urpmi,urpme,urpmf,urpmq)

剛裝好預設的 /etc/urpmi/urpmi.cfg 是空的, 需先 add media
urpmi.addmedia --distrib --mirrorlist http://downloads.openmandriva.org/mirrors/openmandriva.2014.0.x86_64.list

systemctl

user-pic
Vote 0 Votes

在比較新的 Linux, Service Manager 已用 systemctl 取代舊的 chkconfig, service

chkconfig --list = systemctl list-units or systemctl list-unit-files
chkconfig sshd on = systemctl enable sshd.service
chkconfig sshd off = systemctl disable sshd.service
service sshd start = systemctl start sshd.service
service sshd stop = systemctl stop sshd.service
service sshd restart = systemctl restart sshd.service
service sshd status = systemctl status sshd.service

SSH VPN

user-pic
Vote 0 Votes

man ssh /VPN 可以找到相關說明
使用前需設定 sshd_config
PermitTunnel yes
PermitRootLogin yes
可以在 local 及 remote 建立 interface tun0, 也可以綁 IP, 跑路由
這個 Script sshtun.sh 可以跟遠端主機建立 SSH VPN tunnel,
default route 走遠端的 IP 出去, 遠端主機需開啟 ip_forward 及 NAT 設定

Old CentOS ISOs

user-pic
Vote 0 Votes

About this Archive

This page is an archive of entries from May 2014 listed from newest to oldest.

April 2014 is the previous archive.

June 2014 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives