星期日, 5月 05, 2019

PHP + JQUERY + AJAX 帳號欄位檢查

使用Ajax 前,建議你必須看得懂 Jquery語法,這樣才能方便修改




1. HTML 表單欄位 

設定欄位名稱及Javascript要抓取的ID為 account

<input name="username" class="form-control" id="account" type="text" value="" onkeyup="checkRegAcc()">
<span class="text-danger" id="msg_username"></span>

2. JQUERY Ajax 設定語法

網頁 先載入 jquery <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<!-- Ajax -->
  <script>
    $(document).ready(function(){
    checkRegAcc = function() {
    if ($('#account').val().length >= 2) {
        $.ajax({
            url: 'mag_admin_check.php',  // 判斷欄位是否存在的程式
            type: 'GET',    // 傳遞的方法
            data: {
                username: $('#account').val()
            },
            error: function(xhr) {          // 設定錯誤訊息
                alert('Ajax request 發生錯誤');
            },
            success: function(response) {   // 將回傳的訊息寫入網頁中
                $('#msg_username').html(response);
                $('#msg_username').fadeIn();
            }
        });
    } else {
        $('#msg_username').html('');
    }
};
});
</script>


3. PHP 判斷用的程式碼, 參考用,請依實際表單欄位更改

require 'config.inc.php';  // 連線資料庫

if (isset($_GET['username'])) {
    $rs = $pdo->prepare("SELECT * FROM `admin` WHERE `username`=:username");
    $rs->bindParam(':username', $_GET['username']);
    $rs->execute();
    $d = $rs->fetchObject();
 
    if ($d->username == '') {
        $ret = "此帳號可以使用";
    } else {
        $ret = "此帳號已經有人使用";
    }
    echo $ret;
}



參考資料 http://fecbob.pixnet.net/blog/post/43025230-php%28asp.net%29%2Bjquery%2Bajax%E5%B8%B3%E8%99%9F%E6%AA%A2%E6%9F%A5

















星期四, 9月 27, 2018

Plesk shows error with custom template: Template processing failed: file = /usr/local/psa/admin/conf/templates/default/domainVhostIpDefault.php

Symptoms

The following error is shown on main page of Plesk:
New configuration files for the Apache web server were not created due to the errors in configuration templates: Template processing failed: file = /usr/local/psa/admin/conf/templates/default/domainVhostIpDefault.php, error = TemplateException: Template domain/service/wordpress.php doesn't exists file: /usr/local/psa/admin/plib/Template/Processor.php line: 28 code: 0 Previous error: TemplateException: Template domain/service/wordpress.php doesn't exists file: /usr/local/psa/admin/plib/Template/Processor.php line: 28 code: 0 Previous error: Template_Exception: Template domain/service/wordpress.php doesn't exists file: /usr/local/psa/admin/plib/Template/Finder.php line: 25 code: 0. Detailed error descriptions were sent to you by email. Please resolve the issues and click here to generate broken configuration files once again or here to generate all configuration files. See the details in Configuration Troubleshooter

Cause

Corrupted or invalid /usr/local/psa/admin/conf/templates/custom/domain/domainVirtualHost.phpfile, which acts as a custom template configuration files.

Resolution

  1. Connect to the server using SSH.
  2. Create a backup of /usr/local/psa/admin/conf/templates/custom/domain/domainVirtualHost.php using the following command:
    # mv /usr/local/psa/admin/conf/templates/custom/domain/domainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/domainVirtualHost.php.backup
  3. Rebuild Apache configuration:
    Warning: Reconfiguration implies downtime, which depends on the number of domains.
    # /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
  4. If the issue persists, move all the custom templates:
    # mv /usr/local/psa/admin/conf/templates/custom /usr/local/psa/admin/conf/templates/custom_old
  5. Delete information about failed configuration:
    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -uadmin -Dpsa -Ne "delete from Configurations where status='error'"
  6. Rebuild Apache configuration:
    Warning: Reconfiguration implies downtime, which depends on the number of domains.
    # /usr/local/psa/admin/sbin/httpdmng --reconfigure-all

星期一, 2月 12, 2018

石材切斷機 STONE CUTTER CM4SB2


鑽石鋸片尺寸 最大直徑: 110mm x 1 mm x 20mm * 鑽石鋸片另購
 能力
 (最大切割深度)
 34 mm (使用 110mm (4-3/8") 鑽石鋸片時) 
 31.5 mm (使用 105mm (4") 鑽石鋸片時)
 輸入功率 1,320 W
 無負載轉速 11,500 /min.
 尺寸 (L x H) 204mm ( 8-1/32") x 157mm (6-3/16")
 重量 (不含電線) 2.8 kg (6.2 lbs.)      
 標準附件 套筒板手x1, 扳手x1, 橡膠連接器x1, 水管x1, 乙烯軟管x1

一次只能最多切割20mm,超過需分次切割,避免電動機過載損壞。
切割混擬土 磁磚 石材或畫線時務必澆水

星期二, 1月 23, 2018

資料庫隱碼攻擊( SQL Injection )

分析 Log 內的特徵碼
與資料庫有關的語法
-- , %20-- , 'or'='or' ..... 等

星期一, 6月 19, 2017

install php 5.5 opcache on Centos 5.11

Oh, I've already got answer to my question :) Add it here, maybe, someone else will use it.
Initially I installed php using such command
# yum --enablerepo=remi,remi-php55 install php-pecl-apc php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
Now I just ADDED missing extension with this command
# yum --enablerepo=remi,remi-php55 install php-opcache
And it worked!!! phpinfo() shows needed module :)

星期二, 4月 25, 2017

Centos 5.X 升級更新問題

CentOS 5.X 己經停止支援了,所以各大 Mirror Site 都砍掉這些檔案

主要還是 yum update 不能用了, 像是


# yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. /
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/5/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
這時候就要修改 mirror 檔案, mark 掉所有 mirrorlist 的地方, 改從 valut 抓檔案

#vi /etc/yum.repos.d/CentOS-Base.repo , mark 掉所有 mirrorlist=

分別加上
baseurl=http://vault.centos.org/5.11/os/$basearch
baseurl=http://vault.centos.org/5.11/updates/$basearch
baseurl=http://vault.centos.org/5.11/extras/$basearch
baseurl=http://vault.centos.org/5.11/centosplus/$basearch
baseurl=http://vault.centos.org/5.11/contrib/$basearch

硬改 5.11 應該也沒有什麼關係,反正也不會再升級或是進版了

資料來源:https://blog.richliu.com/2017/04/26/2142/centos-5-x-%E5%8D%87%E7%B4%9A%E6%9B%B4%E6%96%B0%E5%95%8F%E9%A1%8C

星期二, 3月 28, 2017

Linux top 指令 說明

 PID USER      PR   NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
28163 root      18   0  4220  968  444 R 47.4  0.0   0:00.24 fuser
28164 root      18   0  4220  972  444 R 47.4  0.0   0:00.24 fuser
28165 root      18   0  4220  968  444 R 47.4  0.0   0:00.24 fuser
28162 root      17   0  4220  968  444 R 45.4  0.0   0:00.23 fuser


PID — 進程id
USER — 進程所有者
PR — 進程優先順序
NI — nice值。負值表示高優先順序,正值表示低優先順序
VIRT — 進程使用的虛擬記憶體總量,單位kb。VIRT=SWAP+RES
RES — 進程使用的、未被換出的實體記憶體大小,單位kb。RES=CODE+DATA
SHR — 共用記憶體大小,單位kb
S — 進程狀態。D=不可中斷的睡眠狀態 R=運行 S=睡眠 T=跟蹤/停止 Z=僵屍進程
%CPU — 上次更新到現在的CPU時間佔用百分比
%MEM — 進程使用的實體記憶體百分比
TIME+ — 進程使用的CPU時間總計,單位1/100秒
COMMAND — 進程名稱(命令名/命令行)

星期四, 3月 16, 2017

linux 刪除當前目錄下 檔案為空的指令


find . -type f -empty -exec rm {} \;

星期三, 3月 01, 2017

Linux fuser 造成主機系統負載過高,網站開啟不了的解決方式

Cause

The script plesk-php-cleanuper contains a string ' ! -execdir fuser {} \\ ', which opens every file in the/var/lib/php/session directory and checks that it is not used by a working process and can be deleted. However, the maximum number of open files is set to 1024 by default.

fuser是一個UNIX命令,用於顯示哪些進程正在使用指定的文件,文件系統或unix套接字,find命令用於查找Unix或Linux系統上的文件


1. 使用 ps aux | grep 'fuser' 指令查出, fuser 所使用的pid號


2. 再使用 kill -9 8352 強制停止該程序。 8352 是fuser pid號

3. 如果網站還是無法正常顯示重新啟動 httpd

#/etc/init.d/httpd restart


問題產生原因如下 :

PHP Session Cleanup failing

https://support.plesk.com/hc/en-us/articles/213947925-PHP-Session-Cleanup-failing




星期一, 2月 27, 2017

Linux convmv 轉換編碼指令 將 big5轉換成 utf8

這隻主要是隻 Perl script, 該做 轉換/備份/測試/偵測環境 等等, 都寫的蠻完整的.

convmv 轉換編碼指令

  • convmv -f big5 -t utf-8 -r --notest *
  • -f big5: 從 Big5 編碼轉換 (不過標準應該是要寫 big5-eten, 但是我測試 big5 也可以動. :P)
  • -t utf-8: 轉換編碼到 UTF-8
  • -r: 遞迴的將目錄下的所有檔名都做轉換
  • --notest: 如果不下這個, 一切動作都只是測試, 會直接將轉換前和轉換後的檔名列給你看, 這加下去, 才會實際轉換檔名.
  • *: 所有檔案

其他參數

  • --list : 列出所有可用的編碼
  • --unescape : 轉換檔名中 %xx 這種 16 進位的編碼 (mv "./a%20x.jpg" "./a x.jpg")
  • --lower : 將所有檔名都轉小寫(ex: convmv --lower LOWER.txt)
  • --upper : 將所有檔名都轉大寫
  • -i : 互動模式, 轉換前會先經過 y/n 確認
  • 更多詳細可 man convmv 或 convmv --help, 除此之外, 可以另外再搭配 rename 做些其他應用~ 
資料來源 https://blog.longwin.com.tw/2008/07/convmv_utf8_big5_convert_linux_2008/

星期二, 9月 27, 2016

Error on Home page: New configuration files for the Apache web server were not created

Symptoms
There is an error message on the Home page or in Domains > example.com page:
New configuration files for the Apache web server were not created due to the errors in configuration templates: Template processing failed: file = /usr/local/psa/admin/conf/templates/default/domainForwarding.php, error = Template_Exception: No data. file: /usr/local/psa/admin/plib/Template/Processor.php line: 27 code: 0 Previous error: Template_Variable_Exception: No data. file: /usr/local/psa/admin/plib/Template/Variable/AbstractCachedData.php line: 65 code: 0. The error message containing the detailed error descriptions was sent to you by e-mail. Please resolve the issues and click here to generate broken configuration files once again or here to generate all configuration files.
There are one or more entries in Configurations table with error status:
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ne"select * from Configurations where status='error'\G"

Cause

Entries for several domains are absent in psa database.

Resolution

Get the affected domain name:
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ne"select name from domains where id in (select objectId from Configurations where status='error')"
Reconfigure domain name in question:
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain example.com
If some configurations still need to be fixed, run the following:
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin psa -Ne"delete from Configurations where status='error' \G" 

星期四, 9月 22, 2016

我的服務器有防火牆保護,如何為ProFTPd的配置被動端口範圍?

這陣子使用 Sublime vsftp 來上傳資料,但總是被伺服器端的防火牆拒絕,調整一下防火牆的設定讓系統也能接受被動式連線。

我的服務器有防火牆保護,如何為ProFTPd的配置被動端口範圍?

  • 應用到:
  • 12.5的Plesk為Linux
  • 的Plesk 12.0適用於Linux
  • 的Plesk 11.0適用於Linux
  • 的Plesk 11.5適用於Linux

解決方案

PassivePorts用於指令/etc/proftpd.conf文件來指定被動端口範圍把該指令置入,Global容器,如下所示:
<Global>
.....
.....
PassivePorts 57000 58000
</Global>
查看ProFTPd的文檔了解更多有關PassivePorts指令的信息:http://proftpd.org/docs/directives/linked/config_ref_PassivePorts.html。
接下來,在應該中系統-加載ip_conntrack_ftp模塊:
# /sbin/modprobe ip_conntrack_ftp
# lsmod | grep conntrack_ftp
nf_conntrack_ftp       13696  0
nf_conntrack           61684  1 nf_conntrack_ftp
同時,應通過以下方式配置iptables:
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
如果服務器有NAT,還需則加載ip_nat_ftp模塊:
# /sbin/modprobe ip_nat_ftp
要想在系統啟動後保留修改,把請該模塊添加至/etc/sysconfig/iptables-config的IPTABLES_MODULES行(空格隔開)。

星期五, 7月 15, 2016

惡意攻擊 Apache 連線滿載,造成記憶體爆滿

今天早上發現網頁開啟不了,查看伺服器狀態,發現預設的連線數已滿載,記憶體要耗盡。
Apache Status 即時記錄中,發現有個來自羅馬尼亞的IP持續使用POST方式發送連線需求。
重新啟動 Apache 後,利用iptable 擋掉這個 IP



 下圖可看到 產生四千多筆連線。



重新調整 apache httpd.conf 設定如下

<IfModule prefork.c>
StartServers       5
MinSpareServers    10
MaxSpareServers    20
ServerLimit       1500
MaxClients        1450
MaxRequestsPerChild  4000
</IfModule>

編輯 iptable 限制單一IP 最大的連線數為100個

#vi /etc/sysconfig/iptables

-A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 100 -j REJECT --reject-with tcp-reset

希望以上作法能有效抵擋惡意攻擊~~~

星期三, 5月 11, 2016

原木料整理

之前從這堆雜木中整理出六塊檜木(紅檜)原木,這次花時間特別去整理,

主要還是希望有個乾淨舒適的木作空間,

因為個人是絕對無法忍受雜亂的環境,再者很重要的一點是,混亂的環境容易造成工安意外。

二手檜木拆除紀錄

去年碰巧朋友買了一家中古房屋,打算要整個拆除重新新建房子,所以提供裡面的東西給有需要的人。

這間房子已經五十多年了,裡面的裝潢很多是用檜木當材料。(去料去漆後跟新的沒多太多差異)

據當地人說屋主在以前是醫生所以家境比較富有,佔地約一百坪。

對喜歡木做的我來說,二手木料檜木是我很喜歡的木頭之一,從去年中左右一直到今年初

花了很多時間慢慢拆下這些二手木料,拍了一些照片當作回憶紀錄。

車檜木聚寶盆

很多年前父親從海邊撿了數量相當多的木頭,大部分是樟木也有一些是檜木,前些日子搬了兩塊原木

請朋友送到三義去車聚寶盆,總共車製了四顆,花費約三千七百元。

車璇後的作品質感很好,將其中一顆送給親人當作新居落成的賀禮


DEWALT 得偉 DC988 18V充電震動電鑽 配一電一充

雖然已經有買了Bosch的插電用電鑽,但還是需要一隻不需要插電而能快速更換鑽頭的電鑽 個人對得偉的機器有很高的評價,上網找了二手機器,看網路資料貨品是從大陸進來 電鑽跟電池是分開寄送的,主機到貨後表面有些生鏽,先用砂紙去鏽後再拆機件做內部齒輪 油更換,測試過得偉的機器好用又有力。 商品入手價 $2550
型號:DC988

1.外殼為高強度工程塑,極為堅固耐用
2.電鑽/電動螺絲刀兩用,雙向無級調速
3.高扭矩馬達,最高扭矩可達65扭米
4.使用鑽頭最大直徑13mm
5.得偉專利分三種鑽速:0-450轉/分鐘、0-1450轉/分鐘、0-2000轉/分鐘
6.衝擊率:34000次/分
7.可以設定22檔扭力調節,使上螺絲的時候不會造成螺絲鬆緊不一的情況
8.本電鑽的夾頭也是採用自鎖夾頭,設計非常精巧,只要用手就可以把任何鑽頭之類的配件牢固夾緊,根本不費力,那是低階工具無法比擬的
9.握把手感舒適,完全符合人體工學設計;
10.電子刹車;
11.配原裝快速充電器,保證了充電的品質及電池的使用壽命,充電時間僅為50~90分鐘(因電池而異)。
12.配充電電池;
13.帶強力衝擊功能,可以鑽牆、鑽鋼板、鑽木。




空壓機

因沒太多預算,在網路上找了一台大陸製的空壓機做木工常常需要清理桌面上的木屑,這時空壓機就非常好用
另外如果你常用釘槍來工作,需要空壓機來提供氣體壓力
空壓機在打氣時,發出的噪音其實也蠻吵的,如果空間許可,將它裝到離工作
較遠的地方會是比較好的選擇。

如果在太吵雜的環境,對做木工是種干擾。
如果下次換機器,會考慮高檔的,聲音不要太大,儲氣桶大些,可以不需要一直打氣,
有個車行朋友推薦買機車店那種尺寸雙汽缸的二手貨,大約兩萬上下。

使用感受:堪用但品質不夠好(使用過後覺得便宜沒好貨,請買台灣製的)
機器規格:2馬力 10公升




Bosch 手提砂輪機

    手提砂輪機是很早期就購入的工具,可調速使用上會比較安全。

    使用上還是需要注意安全,如果轉速過快,機器還是會拿不穩。
    是屬於比較多用途的工具,雖然是大陸製,但品質還是很不錯。

    入手價是 $1800元


輸入功率:720W

空載速率:2800~9300rpm

軸心螺紋:M10

適用磨 / 切片-直徑:100mm/4"

適用橡膠磨盤-直徑:100mm/4"

無電源線重量:1.5kg

附件:保護蓋、板手、輔助把手

製造國家:中國



電動刨木機

   買這款機器,覺得有點後悔,大陸製的商品使用上很笨重,

   用過 Bosch 的刨木機一經比較,功能效能都無法比,

   買來至今只開過三次機,使用機會也不多。

   打算暫時冷藏,也許有一天會再用到也說不定。