2014年11月7日 星期五

Firefox FoxyProxy設定

設定了shadowsocks+foxyproxy翻牆後有個問題一直很困擾我,手動設定代理伺服器後一些內網自訂的網址( ex. test.localhost 、公司內網網站 )都沒辦法同時打開

要怎麼設定讓firefox同時上牆外網站(ex. facebook)和內網網站呢?

開啟FoxyProxy介面後,代理伺服器面板:
Default => "代理伺服器細節"選擇"選擇"直接連線"
新增代理伺服器( 假設命名MyProxy ) => "代理伺服器細節"選擇"手動設定代理伺服器"(設定值依你的代理伺服器設定而異)
MyProxy => 網址樣式 =>
1. 勾選"內部IP位址不使用此代理伺服器"
2. 將你要直接連線的內網網址"增加新的網址"到黑名單中
ex.
增加新的樣式:
樣式名稱:隨便打
網址樣式:*test.localhost* (我用萬用字元,要注意最後要加*號才能讓網址下所有檔案都直連)
然後下面選擇"黑名單"
新增萬用樣式:(必加,不然牆外的網站上不去)
樣式名稱:*
網址樣式:*
然後下面選擇"白名單" (黑名單的優先權會大於白名單)

回到FoxyProxy的代理伺服器面板,上方"選擇樣式"選"根據已經定義好的樣式及優先權使用代理伺服器"

然後國內哪些網站要連就要像設routing table一樣一個一個設進去,不然連線會較慢,無法作到完全的智能翻牆。

自訂routing table
使用 https://github.com/kalecgos0616/tools/tree/master/wildcard_bypass_domain 裡面的foxyProxy_bypass.json 在FoxyProxy的網址樣式中匯入
檢查:
開百度地圖看是不是鎖定在你所在的城市,如果在國外地圖會放到最小

SSLedge Chrome套件設定不走代理的網址
如同上面Firefox FoxyProxy遇到一樣的問題,有些內網網址要怎麼不走代理:
點選SSLedge套件圖示 => 點你走的代理上的設定圖示 => ByPass(繞行) 最下面加入你要直連的網址(ex. ,*test.localhost*)




Arch Linux 的Firefox使用VLC播放rtsp串流

維護頁面時發現該頁面<embed>使用vlc( type="application/x-vlc-plugin" )播放影片(*.avi)和串流(rtsp://)
 
or
  

s
而我的Arch Linux用firefox開出現下面這個錯誤畫面:
解法:
安裝npapi-vlc-git (需先裝vlc,pacman有套件)
$ yaourt -Ss npapi-vlc-git #注意pacman找不到npapi-vlc-git這套件
aur/npapi-vlc-git 2.1.3.100.g417d246-1 (148)
    The modern VLC Mozilla plugin
yaourt太慢的話就用proxychains4 翻牆去下載安裝
# proxychains4 yaourt -S npapi-vlc-git

裝完後重開firefox,<embed>會出現這畫面:
點擊啟用VLC Web.後就能正常看影片

VLC更進階的應用(Firefox plugin API):
http://www.videolan.org/doc/play-howto/en/ch04.html



sublime sftp使用心得

1. 在電腦上開一個資料夾
2. Sublime: Project -> Add Folder to Project
3. 在左邊slide bar的資料夾上點右鍵 -> SFTP/FTP -> Map to Remote
4. 就會在資料夾下打開sftp-config.json
注意:上層資料夾不能有sftp-config.json,不然即使資料夾開在下層,點右鍵SFTP/FTP後仍會吃到上層sftp-config.json的設定
5. 設定sftp-config.json,我有更動到的設定:
"upload_on_save": true, //儲存後就上傳到遠端
"sync_down_on_open": true, // 打開檔案時自動從伺服器同步最新檔案回來
"host": "example.com", //設定ip、帳號、密碼和遠端資料夾路徑
"user": "username",
"password": "password",
"remote_path": "/example/path/",
"ignore_regexes": [
    ...  ,
    "\\.mp4", //因為遠端的影片檔較大,不將遠端的影片檔同步回來。設定檔為json字串,所以這邊正規式要跳脫兩次
    "app/storage/",  "api/storage/",  "\\.jpg",  "\\.png", "vendor/", "lib/PHPExcel/", // 避免下載Laravel套件、log和圖片
    "[\u4e00-\u9a05]",  // 避免下載中文名檔案,因sublime sftp下載中文名字的檔案會報錯
    "ssh_key_file": "C:\/Users\/x.x.x.x-project.ppk"  // 如果主機ssh需要key登入
]
6. 同步遠端檔案回本機
資料夾上點右鍵 -> SFTP/FTP -> Download Folder
7. 直接用sublime編輯本機上同步的檔案儲存後自動上傳到server

ps.
ln -s 軟連結目錄下的檔案也會下載下來
ex.
source -> /www/wwwroot/codes/source

參考連結:http://www.barryblogs.com/sublime-text2-ftp-sftp-remotefilesync/

2014年11月4日 星期二

使用tty7( ctrl+alt+F7 )登錄桌面slim出現錯誤:failed to execute login command

環境:Arch linux
桌面:enlightenment

使用tty7( ctrl+alt+F7 )登錄桌面slim出現錯誤:
failed to execute login command
http://wiki.alpinelinux.org/wiki/SLiM
https://wiki.archlinux.org/index.php/enlightenment
解法:
編輯
~/.xinitrc
加入
exec enlightenment_start  # 這台電腦的桌面是 enlightenment
必須使用tty7登錄桌面後才能遠端或透過web api 播mplayer
不然遠端console用 DISPLAY=:0 mplayer 4.mp4 會出現錯誤:
Xlib: Invalid MIT-MAGIC-COOKIE-1 key vo: couldn't open the X11 display (:0)!

2014年11月3日 星期一

Arch linux start不能開啟桌面

狀況:電腦在外接samsung的LCD螢幕(Model: S24B370H)時無法啟動桌面

http://unix.stackexchange.com/questions/33825/startx-error-when-setting-up-x-server-on-archlinux

在startx出現類似下面的錯誤:
$ startx
...
Loading extension GLX
ile at "var/log/Xorg.0.log" for addigional information.  (EE) Server terminated with error
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error

查log:
/var/log/Xorg.0.log 或 #以root執行startx
/home/user/.local/share/xorg/Xorg.0.log #以user執行startx
依錯誤提示而異
注意:
每次執行startx後Xorg.0.log是整隻檔案重寫,所以不能像apache error log用tail -f 去看他變化,只能重新打開或:edit去看新的log寫什麼

原因:沒裝主機板上顯卡驅動和設定,無須安裝samsung LCD的驅動

查主機板顯卡:
$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)
得知主機板是intel的顯卡

安裝intel顯卡driver:
extra/libva-intel-driver 1.4.1-1 [installed]
    VA-API implementation for Intel G45 and HD Graphics family
# pacman -S libva-intel-driver
安裝成功後
$ ls /usr/lib/xorg/modules/drivers
會多出 intel_drv.so*這檔案。同理,安裝nvidia driver後會這邊多出nvidia_drv.so*這檔案

啟動startx出現錯誤:
(EE) No devices detected.
Fatal server error:
no screens found

解法:
設定/etc/X11/xorg.conf
Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection

Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "AccelMethod"  "uxa"
EndSection
注意:
設定在 /etc/X11/xorg.conf.d/20-intel.conf ( 這個路徑是 pacman -S xf86-video-intel 裝完後給我的提示) 上無效

最後
$ startx 即可開啟桌面

調整登錄畫面的解析度
編輯 /etc/X11/xorg.conf  ,在 Section "Monitor" 裡面加入這行
Section "Monitor"
  Option      "PreferredMode" "1920x1080" #你要的解析度
EndSection



Arch linux pacman 安裝軟體出現錯誤

如這篇 使用mplayer播放影片 在安裝mplayer時發生錯誤

# pacman -S mplayer
error: failed retrieving file 'lirc-utils-1:0.9.1.a-3-x86_64.pkg.tar.xz' from mirrors.ustc.edu.cn : The requested URL returned error: 404 Not Found

解法:
# pacman -Syu mplayer #更新package清單和升級所有package然後安裝mplayer
先更新pacman的database,再安裝mplayer(使用pacman -Syu會更新所有安裝的程式)
# pacman -Sy
# pacman -S mplayer

遇到錯誤:
:: Import PGP key 2048R/, "Zuyi Hu <hzy068808@gmail.com>", created: 2014-03-31? [Y/n] Y
error: key "Zuyi Hu <hzy068808@gmail.com>" could not be imported
error: required key missing from keyring
error: failed to commit transaction (unexpected error)
Errors occurred, no packages were upgraded.
解法:
https://wiki.archlinux.org/index.php/Pacman-key#Cannot_import_keys
編輯/etc/pacman.conf
SigLevel = Never # 將SigLevel設定改成Never

注意:
這步會讓pacman安裝不可信任的packages

升級chromium ( chrome的測試板 )後無法執行
$ chromium
/usr/lib/chromium/chromium: /usr/lib/libpci.so.3: version `LIBPCI_3.3' not found (required by /usr/lib/chromium/chromium)
查原因:
$ pacman -Qo /usr/lib/libpci.so.3
/usr/lib/libpci.so.3 屬於 pciutils 3.2.1-1
# pacman -Ss pciutils
core/pciutils 3.3.0-1 (base) [installed: 3.2.1-1]
    PCI bus configuration space access library and tools
原來是pciutils 版本太舊,升級....
# pacman -S pciutils
解決,正常使用。
參考資料:
https://forum.manjaro.org/index.php?topic=19875.0

Arch Internet sharing(透過另一台電腦上網)

環境:
我的電腦有連兩個網路、內網(接有線eth0 or enp0s25)和外網(收無線網路wlan0 or wls1) 有個內網的設備想透過我電腦上外網去更新程式。 內網不能對外,外網可以。
我的電腦enp0s25和內網設備enp2s0(用ifconfig查該點腦是用哪個網路)連同一個無線ap,在同一個LAN

原本要外接usb無線網卡用wpa_supplicant(需另外安裝)連無線網路去更新,但是更新一下網卡就過熱段掉了。才改採用internet sharing的方法
# wpa_supplicant -i wlan0 -c <(wpa_passphrase your_SSID your_key)

參考:https://wiki.archlinux.org/index.php/Internet_sharing
我的電腦:
1. 設定固定IP - 這步我將mac網址寫在無線ap的設定上面去設定固定ip
2. 啟用封包轉發( Enable packet forwarding )
查packet forwarding 設定:
# sysctl -a | grep forward
暫時啟用packet forwarding:
# sysctl net.ipv4.ip_forward=1
如果保留這些設定在重開機後:
編輯/etc/sysctl.d/30-ipforward.conf:
net.ipv4.ip_forward=1
net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1
3. 啟用NAT
# iptables -t nat -A POSTROUTING -o internet0(能上外網的網路) -j MASQUERADE
# iptables -A FORWARD -i net0(內網的網路) -o internet0(能上外網的網路) -j ACCEPT
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
例:
# iptables -t nat -A POSTROUTING -o wls1 -j MASQUERADE
# iptables -A FORWARD -i enp0s25 -o wls1 -j ACCEPT
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

設備:
1. 設定固定ip - 將mac網址寫在無線ap的設定上面去設定固定ip
2. 設定route方向
# ip route add default via 192.168.123.100 dev eth0
例:
# ip route add default via 192.168.0.101 dev enp2s0
出現錯誤:
RTNETLINK answers: File exists
解法:
重啟網路
# ifconfig enp2s0 down
# ifconfig enp2s0 up
3. 檢查ping不ping得出去
# ping 114.114.114.114
4. ping得出去後設定DNS
/etc/resolv.conf:
nameserver 114.114.114.114

內網設備即可透過我電腦去更新程式
如:
# pacman -Syu mplayer

shan:此方法適用於linux-like的系統

更快速的方法:proxychains
假設server IP(能上外網那台):192.168.92.2
client IP(只能上內網那台):192.168.92.138
[bear@192.168.92.138 proxychains]$ ssh -NfD 9050 bear@192.168.92.2
[bear@192.168.92.138 ~]proxychains4 curl http://baidu.com
註:
server無須做任何設定,9050 port是client上proxychains.conf預設走的port
socks4     127.0.0.1 9050

client透過server上的shadowsocks上牆外網站
把server(非shadowsocks的server,是internet sharing中的server)的ss跑在0.0.0.0上
然后把client的代理配置到server的IP上
server shadowsocks的config.json配置新增:
"local_address": "0.0.0.0",
client proxychains.conf配置:
socks5  192.168.92.2 8080
最後用這些指令透過ss上網
[bear@192.168.92.138 ~] proxychains4 curl http://facebook.com
[bear@192.168.92.138 ~] proxychains4 pacman -S subversion
特別改謝shell指導

2014/11/27
上述"client透過server上的shadowsocks上牆外網站"情況在使用pacman -Sy更新時會報錯:
error: failed retrieving file 'core.db' from mirrors.163.com : Resolving timed out after 10519 milliseconds
使用iptables方法則正常

參考資料:
http://heylinux.com/archives/2933.html