2020年12月25日 星期五

開發系統時檔案的權限真的要注意

 剛犯了一個好笑的錯誤,記錄一下。

之前作了一個系統,原理很簡單:

1、上傳檔案

2、讀檔寫到DB以便作長期追蹤

3、用jpgraph畫圖

4、用PHPPresentation把圖作成簡報。

上週突然要加新的圖和說明文字。這個工作很簡單,網路上找張圖再塞進去。

但說也奇怪手動執行時該圖會出現在簡報上,但用上傳檔案介面時就是不會。

唯一的差異就是一個用我的帳號執行,一個用apache帳號執行。

難道會是PHP有問題嗎?

查了一下才想到,該不會是新抓的圖不給人讀吧。

回頭看一下,果然,新圖是700權限.....

2020年11月11日 星期三

spanning tree mode rapid pvst (spanning tree 快速收斂)

用GNS3做了一個很簡單的測試。如果靠L2 switch做路徑切換,大概要斷多久。

把左下角的那一條拿掉 試了一下,大概是掉90~105秒左右。

在兩台switch都設定了這一行:

spanning tree mode rapid pvst 

還不錯,大概斷線75秒就起來了。


 

2020年11月9日 星期一

rpi3 console線異常?

之前用console無法連Pi3,baud rate調9600是亂碼,調115200什麼都出不來。一直以為是console線壞了。


但同一條線接Pi2,設定baud rate 115200又正常。

今天有空查了一下,原來是RPI3新增藍牙,造成後續一堆排擠效應的關係。

裝了Raspberry Pi OS,從gui介面開啟serial port (serial console)之後比較了一下config的差異,發現只要編輯/boot/config.txt

找到

[all]

新增下面這行 (當然還有其它解決方法但我懶得去查)

enable_uart=1

再重開Pi3,console又可以用115200快樂操作了。

2020年11月5日 星期四

PHP5 轉移至 PHP7需注意事項

 1、Too few arguments to function

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function TABLE::__construct(), 0 passed in /home/www/OM/class/class.table.php on line 

10638 and exactly 1 expected in /home/www/OM/class/class.table.php:14

原因是PHP7比較嚴謹(我猜的),所以即使是空值也要給個null

public function __construct($var_cond) => $var_cond=null

大批修改如下:

vi 

%s/$var_cond)/$var_cond=null)/g


2、mysql_xxx to mysqli_xxx

所有mysql開頭的函式請改為mysqli開頭。但有兩個要特別注意的:

mysqli_query($sql, $conn); => mysqli_query($conn,$sql);

mysql_select_db('OM',$conn); => mysqli_select_db($conn,'OM');

這兩個mysql函式的順序跟mysqli相反,記得要調整。

3、PHP Warning:  preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead 

這個很明顯,改一下就好了。但callback似乎有比較多眉角,如果要做到沒有info或warning的話,要再調整一下。

4、PHP Deprecated:  __autoload() is deprecated, use spl_autoload_register() instead

這個也是改一下就好了

5、ereg及split相關函式

ereg() 可以用 preg_match() 替代

ereg_replace() 可以用 preg_replace() 替代

eregi() 用 preg_match() i 引數替代

eregi_replace() 用 preg_replace() i 引數替代

split() 用 preg_split() 替代

spliti() 用 preg_split() 模式 ‘i’ 替代

split -> explode

split -> 因為語法有用到regular expression要改用preg_split

6、iconv()要用mb_convert_encoding取代

7、PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP

Replace

public function TSStatus($host, $queryPort)

with

public function __construct($host, $queryPort)

剩下的是環境問題:

1、php-fpm的log在/var/log/php-fpm/www-error,第一次用php-fpm的我不曉得。

2、Mariadb (MySQL)的錯誤訊息:Field `s_symptom` doesn‘t have a default value

要修改設定檔:

cd /etc/my.cnf.d

 vi mariadb-server.cnf

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION

3、mysqlimport最後要加上--local



2020年10月21日 星期三

RHEL8 firewalld tftp problem 搞掉我一天的時間...

 


https://linuxhint.com/install_tftp_server_centos7/


搞了一整天,結果是OS bug...

簡單的來說 換了RHEL8之後tftp一直不能傳,看fw會有異常的unreachable - admin prohibited filter

disable firewalld就會好,但總不能一直這樣吧....

3.106310 wan1 -- 192.168.26.26.23814 -> 192.168..100.33.69: udp 26

3.114525 wan1 -- 192.168..100.33.43341 -> 192.168.26.26.23814: udp 4

3.114943 wan1 -- 192.168.26.26 -> 192.168..100.33: icmp: host 192.168.26.26 unreachable - admin prohibited filter

8.105289 wan1 -- 192.168.26.26.23814 -> 192.168..100.33.69: udp 26

8.113544 wan1 -- 192.168..100.33.43342 -> 192.168.26.26.23814: udp 4

8.113931 wan1 -- 192.168.26.26 -> 192.168..100.33: icmp: host 192.168.26.26 unreachable - admin prohibited filter


怎麼改規則,怎麼加port都沒有效的...

/bin/firewall-cmd --permanent --zone public --add-service tftp-client

firewall-cmd --reload


sudo firewall-cmd --permanent --add-port=69/udp

sudo firewall-cmd --zone=public --add-service=tftp --permanent

firewall-cmd --reload


2020年9月22日 星期二

重新產出ssh key時的注意事項 (for ssh2.php)

 今天把ssh key重新產出了。結果一堆程式不能跑,查了很久才想到,在用ssh2.php登入設備時,id_rsa及id_rsa.pub(這個檔應該不用,但懶得試了)也會用到。

因此如果重新把ssh key產生時,記得把這兩隻key也放到程式的目錄中。

2020年9月21日 星期一

ssh免密碼認證失敗的解決方法

 ssh免密碼認證應該算是基本功了。但我的新機器就是沒有辦法免密碼認證。

明明用其它帳號都正常,但就是我自己的帳號不行。

所以簡單講一下怎麼查:

1、先把firewall開好

sudo firewall-cmd --zone=public --permanent --add-port=2222/tcp

sudo firewall-cmd --reload

2、在server上開ssh debug

/usr/sbin/sshd -d -p 2222

3、從client去登入

ssh -p 2222 user@host

4、觀察debug:

debug1: trying public key file /home/klting/.ssh/authorized_keys debug1: fd 10 clearing O_NONBLOCK Authentication refused: bad ownership or modes for directory /home/klting

看的出來是/home/klting這個目錄的權限問題。

看了一下權限是750,可能是我之前測東西改到的,用chmod改回700就正常了。

5、記得關防火牆

sudo firewall-cmd --zone=public --permanent --remove-port=2222/tcp

sudo firewall-cmd --reload

最後確認一下目前防火牆開哪些port,確認有關成功

firewall-cmd --list-all