2015年10月6日 星期二

windows10 WOL失效問題

關於升級到windows10之後wake on lan失效問題,請到下面連結下載Win10 Auto Installation Program的realtek driver,安裝之後問題解決,也不用像其他資料寫得要改green ethernet或者windows10的fast boot。

http://www.realtek.com.tw/Downloads/downloadsView.aspx?Langid=1&PNid=13&PFid=5&Level=5&Conn=4&DownTypeID=3&GetDown=false#1

參考資料
https://m.reddit.com/r/Windows10/comments/3f73sz/psaif_windows_10_killed_your_wol_functionality_or/

2015年10月5日 星期一

Windows server 無法下載檔案問題

前一陣子試用windows server2012,發現用IE無法下載網路上的檔案,後來發現要把IE進階安全設定關閉才行。

參考資料

google sheet array串接

googlesheet如果需要將兩個array串成一個array時,使用{array1;array2}的格式。

參考資料
忘了留

XFCE自動完成失效問題

在XFCE下ubuntu的tab自動完成失效,解決方法是修改xml file

.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml
把下面改掉
<property name=”&lt;Super&gt;Tab” type=”string” value=”switch_window_key”/>
改成這個
<property name=”&lt;Super&gt;Tab” type=”empty”/>

參考資料
https://241931348f64b1d1.wordpress.com/2012/05/04/shell-autocomplete-not-working-on-xrdp-xubuntu-12-04-xfce/

selenium

selenium get url of webpage
selenium2library 可以使用 keyword "Get Location"

另外Get Element Attribute 需要使用id name@class而非一般XPATH格式否則會有錯誤

The expression is not a legal expression

而使用Get Value獲取@href不行因為結果會是attribute而非element,會有錯誤

[object XrayWrapper [object Attr]]

當需要驗證popup windows兩者標題又相同無法switch window時,後來採取抓取button href資訊並直接go to就可以不被popup限制

參考資料
自己
http://stackoverflow.com/questions/15985339/how-do-i-get-current-url-in-selenium-webdriver-2-python

rebot

robotframework 可以使用 rebot <file1>.xml <file2>.xml來合併xml,並且合併之後log.html與report.html也會跟著update

可使用參數--name <name>來變更suite name

如用Windows寫sh script時要注意檔案格式需為UNIX,否則可能有執行上問題,錯誤訊息
' failed: Data source does not exist.Appengine/X3000001.robot

Try --help for usage information.
: not found3: script.sh:
參考資料
https://twiki.cern.ch/twiki/bin/view/EMI/RobotFrameworkAdvancedGuide#Using_the_rebot_Tool
http://stackoverflow.com/questions/25988071/combining-robot-framework-test-reports

ddwrt設定wake on lan

由於無法NAT layer-2 broadcast,所以必須使用wake on internet (255.255.255.255)發送packet NAT到主機ip並寫入arp table使得router不須透過arp request取得ip的mac address。由於arp table會在重開機時清除所以使用指令arp -s <ip> <mac>並使用cron定時寫入防止遇到device重開機。

cron指令詳如下

*/20 * * * * arp -s <ip> <mac> 代表每3分鐘寫入一次

參考資料

Apache 使用virtualbox分享資料夾做為www資料夾內容 gitweb設定


1) Power the VM down and add the shared folder with the Virtualbox Manager (never works right for me if VM is on)

2) Power on the VM and make your symbolic link to the shared folder where ever you want your web root to be:
ln -s /media/sf_share /var/www
chown -h www-data /var/www
NOTE: If your OS runs apache under the user: apache or apache2, replace www-data with that.

3) Add the user apache runs under to the group vboxsrv. Edit /etc/group and on the line that defines the vboxsrv group. Here is what my line in the group file looks like:
vboxsf:x:1001:sean,www-data
NOTE: Again, swap out www-data for the user apache runs under, if not www-data.

4) Reboot the VM.

重點是在建立soft link到www資料夾下 step 2

https://forums.virtualbox.org/viewtopic.php?f=3&t=34922

檢查link是否建立成功
http://linux.vbird.org/linux_basic/0230filesystem.php#ln

apache tool
htdigest -c 建立密碼檔
mod-avaliable and mod-enabled
使用symbolic link把avaliable link到enable下,apache啟動時會讀取enable下之所有module
gitweb需要load module如下
alias.conf
alias.load
auth_basic.load
auth_digest.load
authn_file.load
authz_default.load
authz_groupfile.load
authz_host.load
authz_user.load
autoindex.conf
autoindex.load
cgi.load
dav_fs.conf
dav_fs.load
dav.load
deflate.conf
deflate.load
dir.conf
dir.load
env.load
mime.conf
mime.load
negotiation.conf
negotiation.load
php5.conf
php5.load
reqtimeout.conf
reqtimeout.load
setenvif.conf
setenvif.load
status.conf
status.load


gitolite client設定
git clone git@<ip>:<repository name>.git

以下需在repository目錄下
看狀態 git status
commit 差異文件 git commit -a
上傳 git push <remote name, default origin> <branch name/master>
加入檔案 git add <file1> <file2> ...

git remote add [<options>] <name> <url>

參考資料
同事

SVN架設

架設SVN時遇到無法commit,後來查到是因為apache user沒有該svn資料夾權限,因此將該repository資料夾chown -R apache:apache *chmod -R 664 *即可正常使用

參考資料
Can't open file '/server/svn/repo/db/txn-current-lock': Permission denied
http://stackoverflow.com/questions/960241/svn-permission-denied
svn架設
http://eric0806.blogspot.tw/2014/05/ubuntu-svn-server-with-websvn.html

openvpn server, pfsense ipsec 設定

iptables 需要將ppp設為MASQUERADE偽裝IP才有辦法連到internet

出現錯誤訊息

Options error: server and client cannot be used together

代表conf檔案內有用到不是server指令的指令

iptables restart in ubuntu

如使用ufw
sudo service ufw stop
sudo service ufw start

刪除單一chain下的規則
iptables -t nat -D POSTROUTING <number>

enable forwarding in ubuntu
echo 1 >/proc/sys/net/ipv4/ip_forward

如果要兩個網路能夠成功的達成路由﹐對方網路也必須有相應的路由設定指向本地網路才行

pfsense 內 openvpn檔案存放位置/var/etc/openvpn

traceroute
mac: traceroute
dos: tracert
linux: tracepath

terminate openvpn
sudo killall openvpn

port-share
可設一個port(通常為443)如果沒有TLS handshake則導到網頁,有則連接上openvpn server
方法是在Advanced configuration > Advanced 加上以下指令
port-share x.x.x.x 443
x.x.x.x為apache或web server的位址

pfsense 的ipsec設定可以參考下面的參考資料
因為後來看到似乎ipsec比較穩定,所以有用pfsense架設了一個ipsec VPN,到中國後才知道GFW(網路長城)的厲害啊...
總之現在就是openvpn PPTP ipsec輪著用,通常至少有一個能work

要push dns 到client時使用push "dhcp-option DNS <ip>"
如果是client端conf則使用dhcp-option DNS <ip>
可同時複數使用如增加google dns push "dhcp-option DNS 8.8.8.8"
這樣就可以同時使用local dns server與internet dns server

順帶一提,有問題的vpn是hola vpn。

2019/4/17更新
後來將VPN network與local network分開,導致兩邊無法互連問題,經過研究發現是因為設了ipv4 local network,這會導致直接優先在local route尋找而不是透過gateway轉遞。另外也須加上 push "route <local subnet> <local subnet netmask>"

參考資料
http://acman.bluenest.net/wordpress/archives/118
apache ssl (https) setting
https://www.bestvpn.com/blog/5919/how-to-hide-openvpn-traffic-an-introduction/
http://neidi.homeip.net/blog/cblog/index.php?id=414
http://kirby86a.pixnet.net/blog/post/95136568-ubuntu-12.04%E5%95%9F%E7%94%A8apache%E7%9A%84-ssl
openvpn port share
https://doc.pfsense.org/index.php/Sharing_a_Port_with_OpenVPN_and_a_Web_Server
pfsense ipsec
https://doc.pfsense.org/index.php/IPsec_for_road_warriors_in_PfSense_2.0.1_with_PSK_in_stead_of_xauth
https://www.shrew.net/download/vpn
https://doc.pfsense.org/index.php/IPsec_Road_Warrior/Mobile_Client_How-To
iptables
http://serverfault.com/questions/431593/iptables-forwarding-between-two-interface
http://askubuntu.com/questions/161551/how-to-start-stop-iptables
http://stackoverflow.com/questions/8239047/iptables-how-to-delete-postrouting-rule
http://s2.naes.tn.edu.tw/~kv/iptables.htm
https://gigenchang.wordpress.com/2014/04/19/10%E5%88%86%E9%90%98%E5%AD%B8%E6%9C%83iptables/
http://www.pcnet.idv.tw/pcnet/network/network_ip_routing.htm
pfsense存放位置
https://forum.pfsense.org/index.php?topic=13123.0
openvpn with two interface in and out
https://forums.openvpn.net/topic11033.html
https://forums.openvpn.net/topic14072.html
http://ubuntuforums.org/showthread.php?t=1606136
route
http://yinung2.blogspot.tw/2013/05/route_17.html
bridge vs routing
https://community.openvpn.net/openvpn/wiki/BridgingAndRouting
https://openvpn.net/index.php/open-source/documentation/miscellaneous/76-ethernet-bridging.html
chain using openvpn
http://serverfault.com/questions/512160/vpn-chaining-using-openvpn
dns server on openvpn
http://superuser.com/questions/637579/setting-dns-servers-using-openvpn-client-config-file
show route on mac
http://stackoverflow.com/questions/6782658/how-to-get-default-gateway-in-mac-osx
different subnet
https://blog.bobbyallen.me/2016/02/07/enabling-openvpn-clients-to-access-to-the-lan/

關閉ctrl注音符號快速輸入



參考資料
http://answers.microsoft.com/zh-hant/windows/forum/windows_8-ime/%E5%9C%A8-windows-8/ad2e85c3-6863-4865-a614-2c8b9f36ebe3?auth=1

git ssh id_rsa key

使用robot framework sshlibrary時,遇到錯誤訊息SSHException: No existing session原先以為是alise沒設好,後來發現是因為我的ssh id_rsa key有變動造成。

解決方法
使用root權限再跑一次即可

另外將ssh id_rsa.pub放到要連線的server~/.ssh/authorized_keys即可之後連線不需要輸入密碼(使用者名稱仍需要)

cp <path to id_rsa.pub> ~/.ssh/authorized_keys

如使用puttygen.exe,因為格式與openSSH不同,需在puttygen裡作轉換,並且public key的格式也需照框框內的內容貼上到authorized_keys,而非使用download public key的檔案。

另外也需要在ssh server上將權限設成可執行rwx------
chmod 700 ~/.ssh/authorized_keys
可用 ls -l 指令檢查
private key則需要600,不過一般都一定可以讀取所以不容易出錯

參考資料
自己
同事
authenticate agent
http://stackoverflow.com/questions/6832248/paramiko-no-existing-session-exception
authorized_keys
http://stackoverflow.com/questions/7260/how-do-i-setup-public-key-authentication
https://www.debian-administration.org/article/530/SSH_with_authentication_key_instead_of_password
puttygen.exe
http://blog.faq-book.com/?p=1444
chmod
http://unix.stackexchange.com/questions/36540/why-am-i-still-getting-a-password-prompt-with-ssh-with-public-key-authentication
ssh key on pi
https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
pfsense ssh key
https://doc.pfsense.org/index.php/HOWTO_enable_SSH_access

xcopy

xcopy使用時來源與目的地不須加最後的 \
如 xcopy c:\source c:\destination 而非  xcopy c:\source\ c:\destination\
如設錯會在有空格需用雙引號""時將來源與目的地連在一起
另外 /xd 用於例外目錄, /xf 則是例外檔案可使用*等符號

windows7 會遇到 My Documents 資料夾 access denied 存取被拒,是因為安全性因素 My Documents設為連結,需用PATH變數如
xcopy "%USERPROFILE%\Documents" "F:\New Folder" /s /e /i

參考來源
自己
https://social.technet.microsoft.com/Forums/en-US/f6f7968e-dd99-4d46-b4e5-1307e2187b21/using-robocopy-with-a-large-xf-exclusion-list
https://technet.microsoft.com/en-us/library/cc733145.aspx
http://serverfault.com/questions/430268/how-do-i-use-robocopy-to-exclude-all-subfolders-under-a-chosen-folder
http://stackoverflow.com/questions/12875842/folder-names-with-spaces-in-xcopy-doesnt-work

Winodws boot fail 0xc0000098 pciidex.sys

windows開機時出現錯誤訊息0xc0000098 pciidex.sys無法載入。後來看了許多方法,比較有用的是使用Gparted備份除windows以外的資料夾再將資料倒回到新安裝的windows。但是還是有很多問題如檔案系統異常,圖示消失等,最後是還原到前一個備份點。

原因可能是在windows update的時候異常關機。

試過的方法有
bootrec /rebuildbcd
copy system32 files
windows system recovery windows修復開機
copy C:\Windows\System32\config
都無效,供參考
不過如果是其他的問題可能可以參考上面的方法處理

另外在修復控制台的命令列使用xcopy出現access denied不是權限問題而是檔案唯讀,可使用/R參數覆寫

參考資料
http://superuser.com/questions/358651/bootmgr-is-missing-usual-fixes-dont-work
Total identified Windows installations: 0
http://answers.microsoft.com/en-us/windows/forum/windows8_1-windows_install/total-identified-windows-installations-0/52359f87-de4a-41dc-b0c3-cc275e1d9fbf?auth=1
xcopy
https://support.microsoft.com/zh-tw/kb/240268

Forward PPTP server packet from Pi

這個問題花了我不少時間去處理,原因居然是因為Rasbian使用的3.18 kernel將PPTP packet視為invalid packet。不過還好後來有找到解決方法,分享給各位。

ping: sendmsg: Operation not permitted
出現以上訊息時代表iptables沒設定好,可重設iptables
# Reset/Flush iptables
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Flush end
但須注意此時已經policy設為ACCEPT,為debug使用,記得結束後要將iptables -P 設回需要的policy

PPTP forward參考設定如下

#!/bin/sh
### BEGIN INIT INFO
# Provides:         firewall.sh
# Required-Start:   $all
# Required-Stop:
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
### END INIT INFO

INTIF="你的對內介面,如brlan"

INTNET="對內介面的網段"

INTIP="PPTP server的IP"

EXTIF="對外介面,如為撥接通常為ppp0"

#Loading required stateful/NAT kernel modules...

/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_nat_irc

#below has to be loaded for pptp
/sbin/modprobe nf_nat_pptp 
/sbin/modprobe nf_conntrack_pptp 
/sbin/modprobe nf_conntrack_proto_gre 
#就是上面這三個kernel需要load,否則再怎麼設都是枉然

echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr

UNIVERSE="0.0.0.0/0"

iptables -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

iptables -A FORWARD -i $EXTIF -o $INTIF -d $INTIP -j ACCEPT

# Enable SNAT (MASQUERADE) functionality on $EXTIF
iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

#DMZ setting
iptables -t nat -A PREROUTING -i $EXTIF -p tcp -m multiport --dport 1:65535 -j DNAT --to $INTIP
iptables -t nat -A PREROUTING -i $EXTIF -p udp -m multiport --dport 1:65535 -j DNAT --to $INTIP

# PPTP PREROUTING GRE packets
iptables -t nat -A PREROUTING -i $EXTIF -p 47 -j DNAT --to $INTIP
iptables -A FORWARD -i $EXTIF -p 47 -j ACCEPT

如果不是使用DMZ的話可將DMZ setting改成--dport 1723只轉port 1723到PPTP server就好
另外如果是使用pfsense之類的firewall,INTIP為pfsense的WAN端




將script註冊為service
sudo update-rc.d <script undre /etc/init.d/> defaults
將service移除
sudo update-rc.d -f foobar remove
設定啟動相依性(如在某service啟動後啟動)
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs

2015/10/5更新
遇到一個問題是source ip被snat蓋掉。因為以前使用ddwrt時沒有遇到這個問題,因此研究了一下,發現是需要設-m state --state NEW在iptables裡對應PREROUTING的port。才能夠觸發output。否則單純用MASQUERADE是可以但是就變成snat會將source ip蓋掉變成內部ip,不是我要的。
因此上面#DMZ setting要多增加兩行
iptables -t nat -A INPUT -i $EXTIF -p udp -m state --state NEW -m multiport --dport 1:65535 -j ACCEPT
iptables -t nat -A INPUT -i $EXTIF -p tcp -m state --state NEW -m multiport --dport 1:65535 -j ACCEPT

參考資料
register service
https://mkaz.github.io/2013/07/03/run-script-at-start-on-debian/
setting linux firewall
http://www.aboutdebian.com/firewall.htm
http://www.linuxjournal.com/article/3866
PPTP forward
http://ubuntuforums.org/showthread.php?t=801207
http://www.linuxquestions.org/questions/linux-networking-3/port-forward-gre-and-pptp-using-iptables-210334/
http://serverfault.com/questions/466030/pptp-iptables-routing-issue
https://wiki.archlinux.org/index.php/PPTP_server#iptables_firewall_configuration
https://lists.debian.org/debian-firewall/2004/04/msg00103.html
http://wiki.linuxmce.org/index.php/PPTP_server
tcpdump PPTP packet
http://serverfault.com/questions/342604/how-to-sniff-request-packet-on-vpn-server
DMZ, nat preserve source ip
https://www.debian-administration.org/article/73/Port_forwarding_for_iptables_DMZ