2010年11月23日 星期二

jQuery find

在表單(form)中如果有動態表格(table)的話,要找到表格內的動態元素的笨方法是
$("#formid").children("table:last").children("tbody").children("tr")[0].children("td")[0].children("select");

為了避免這種蠢斃了的情況
jQuery很貼心的給了我們find(大心)
上面的笨句子就可以改成
$("#formid").children("table:last").find("select");

世界整個變美好了(茶)

2010年11月17日 星期三

visual studio 2010 要求驗證

我在用vs2010時,它臨時的網頁伺服器一直叫我驗證
雖然可以在IE設定裡調成預設使用window驗證
可是在使用服務參考時就行不通了
找了老半天,在website的起始選項裡的起始選項
底下的伺服器有個選項是「NTLM驗證」
把它勾掉後就不會再要求驗證了
我的平台是win7 64bit,vs2010是32bit
不知道是不是這個原因??

--
一開始灌好vs2010
寫好hello world,按下run
結果完全不理我= =
網頁跳不出來

原來是因為我的預設瀏覽器是firefox的關係...
套句曹老師的話
真是爛透了

2010年10月14日 星期四

vsftp設定

我在vsftpd.conf多加了幾個設定
local_umask=002
pasv_enable=YES
pasv_min_port=xxxxxx
pasv_max_port=xxxxxx
chroot_local_user=YES
user_config_dir=/etc/vsftpd/userconf

大部分的指令網路都查的到
而最後一條指令是設定個別user的conf檔存放位置

例如要把user1的家目錄指定到網頁資料夾可以這樣寫
vi /etc/vsftpd/userconf/user1

local_root=/var/www/html

這樣user1一登入便會進到html資料夾內
而且我有設定chroot_local_user=YES
所以user1也無法離開根目錄亂逛囉!

另外如果要使用xinetd管理vsftp
vsftp有寫好的設定檔供使用
cp /usr/share/doc/vsftpd-2.0.5/vsftpd.xinetd /etc/xinetd.d/vsftpd

存好後將disable改為no
另外要注意的是要將vsftp的主動模式(stand alone)關掉
我就是沒有關所以一直不成功...
vi /etc/vsftpd/vsftpd.conf

listen=NO
可以開始使用囉
--
參考網頁
http://www.linuxpk.com/5831.html
http://itnewsvendor.appspot.com/2071040-rhel5_xinetd_%E6%96%B9%E5%BC%8F.html
http://linux.vbird.org/linux_server/0410vsftpd.php#server_vsftpd.conf

timestamp to date

moodle在mdl_log檔中的time是使用unix timestamp
為了調資料時讓人看的懂可以使用mysql的函式
FROM_UNIXTIME(unix_timestamp)

預設輸出是長降子
mysql> SELECT FROM_UNIXTIME(1196440219);
-> '2007-11-30 10:30:19'

後面也可以加參數指定格式囉

--
參考網頁
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_from-unixtime

2010年10月5日 星期二

/etc/rc.d/rc.sysinit: line 648: fsck:command not found

電源失敗後出現的致命訊息
因為開機都會執行fsck,而在/sbin裡卻找不到fsck了!!
這...應該是死定了!!
google過沒有找到什麼好方法
只好拿liveCD試看看
liveCD開完機後自動就將所有的硬碟都mount起來了
還好資料都還在,可以趕快進行備份

2010年7月15日 星期四

kernel: EXT3-fs error (device dm-4): ext3_lookup: unlinked inode 58079497 in dir #58073509

昨天要下班前發現架設的網站登不進去,第一個想到的是table的錯誤,但事情不是憨人想的那麼簡單,repaire table後情況依舊。查看log檔才知道是檔案系統出錯了,導致磁碟變成read only,所以session檔寫不進硬碟,造成無法登入的情況。

Jul 14 17:37:54 myhost kernel: Aborting journal on device dm-4.
Jul 14 17:37:54 myhost kernel: __journal_remove_journal_head: freeing b_committed_data
Jul 14 17:37:54 myhost kernel: EXT3-fs error (device dm-4): ext3_lookup: unlinked inode 58078839 in dir #58073509
Jul 14 17:37:54 myhost kernel: ext3_abort called.
Jul 14 17:37:54 myhost kernel: EXT3-fs error (device dm-4): ext3_journal_start_sb: Detected aborted journal
Jul 14 17:37:54 myhost kernel: Remounting filesystem read-only

所以咧,第一個想到要用的指令就是e2fsck
它可以下參數-a自動修復,另外要注意使用前要把partition umount,如果是根目錄壞掉的話,只好進入single user mode囉(還好我都有分割的好習慣XD)

# e2fsck -a /dev/vg_data/lv_data
我是用lvm所以磁碟路徑是長這樣@@;

會出現錯誤其實是我手賤,測試伺服器直接mount正式伺服器的data partition在跑,結果也有寫入session的關係,在測試伺服器下線還是怎樣後,新增加session檔的inode發生錯誤,系統強制將partition轉為read only,才導致這次的事件發生。
因為session其實是紀錄client的狀態,當很多client端同時上線時就有可能會造成io wait(雖然寫的檔都很小),所以這次索性將session資料夾mount到tmpfs上,以ramdisk的型式在跑或多或少可以加快速度。

# mount -t tmpfs tmpfs /session

要注意的是因為是寫在記憶體裡,重開機就不見囉!!
不過session不見也還好,沒什麼關係。
--
參考網站
http://www.centos.org/modules/newbb/viewtopic.php?topic_id=17036
http://www.hkcode.com/linux-bsd-notes/178
http://plog.longwin.com.tw/my_note-unix/2006/01/08/ram_disk_build_method

2010年7月12日 星期一

pclzip

同事之前幫moodle寫了作業打包下載功能,用的是pclzip。最近發現有幾筆產生的壓縮檔並沒有乖乖的在指定的位置!?於是按照課號查找,發現打包下載的連結並未出現在網頁上,而那幾筆在錯誤位址的壓縮檔,下載下來後無法解開(壓縮檔破損),且打包檔案也有缺少。
上網查了一下,在做create時可以加入參數PCLZIP_OPT_NO_COMPRESSION,以不加壓方式打包即可。
以網路上的範例來做修改
include_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
$v_list = $archive->create('data/file.txt,data/text.txt',
     PCLZIP_OPT_NO_COMPRESSION,
     PCLZIP_OPT_REMOVE_PATH, 'data',
     PCLZIP_OPT_ADD_PATH, 'install');
if ($v_list == 0) {
     die("Error : ".$archive->errorInfo(true));
}
除了這點之外,最令我頭大的是若檔名含有中文,則下載下來的壓縮檔內檔名便會出現亂碼。雖然有在寫網頁的人都知道要避免使用中文檔名,但是一般使用者可是不會管你那麼多的。由於OS是linux介面,而且這邊使用的pclzip似乎沒有支援utf-8,所以才會產生亂碼的情況。這時候需要修改pclzip.lib.php的第2780行附近,function privAddFile內其中一段設定打包進壓縮檔檔案名稱的地方(按照上面的例子來說stored_filename就會是file.txt跟text.txt,因為路徑data被設定為去除了--PCLZIP_OPT_REMOVE_PATH, 'data')
    $p_header['filename'] = $p_filename;
// TBC : Removed    $p_header['stored_filename'] = $v_stored_filename;
    $p_header['stored_filename'] =
                        iconv('utf-8','big5',$p_filedescr['stored_filename']);
這樣就可以看到中文囉!

學藝不精,花了一天時間才解決問題...
--
參考網站
http://moodle.club.tw/moodle/mod/forum/discuss.php?d=1392
http://www.blueshop.com.tw/board/show.asp?subcde=BRD20091208184635ZIQ&fumcde=&PAGE=1
http://support.oss.org.tw/?q=node/147
http://itisjoe.pixnet.net/blog/post/14758894
http://modxcms.com/forums/index.php?topic=48191.0

2010年7月6日 星期二

Sorry, I was not able to successfully run APXS

最近網站效能碰到瓶頸,想說終於是該用PHP加速器了
APC、eAccelerator、XCache 中我挑了APC
在APC安裝前要先確定系統已安裝php-pear
安裝很簡單就像安裝pear的套件一樣,只是改成pecl而已
pecl install apc
若沒有意外的話會碰上
Sorry, I was not able to successfully run APXS
囧>,那是apache的應用程式相關
所以
yum install httpd-devel
就OK囉!

 --
但是我裝另外一台,就很不給面子出現
CRITICAL ERROR: We are channel://pear.php.net/apc-3.0.19
只好手動安裝
下載http://pecl.php.net/package/APC
照著document即可安裝成功。

參考網站
http://pecl.php.net/package/APC
http://pecl.php.net/bugs/bug.php?id=5942
--
20101227追加
在新機器上要裝apc時出現
error: pcre.h: No such file or directory

安裝一下吧
yum -y install pcre-devel

重新run一次即可

參考網站
http://www.centos.org/modules/newbb/viewtopic.php?topic_id=8447

2010年6月24日 星期四

ncftpput: command not found

調用crontab執行ncftpput時,發現不會動作......

You have mail in /var/spool/mail/root
系統寄信給我了 = =a

Auto-Submitted: auto-generated
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:

/root/backup.sh: line 3: ncftpput: command not found


sh 沒有支援到ncftpput指令,囧>
將指令改寫為完整路徑

/usr/local/bin/ncftpput -u..........

就可以跑囉!

參考網頁
http://www.linuxquestions.org/questions/linux-networking-3/ncftpget-problem-103795/

2010年6月21日 星期一

MySQL現階段參數值

1.點phpMyAdmin資訊
2.mysql> show variables (like '%size');

2010年6月18日 星期五

/usr/bin/dvips: ! DVI file can't be opened.

moodle內有支援tex(latex)
因為是直接調控主機內的程式,所以安裝了
tetex-latex
及其他相依程式

測試過後發現圖片出不來
檢查/etc/httpd/logs/error_log

kpathsea: Running mktexfmt latex.fmt
kpathsea: Running mktexfmt latex.fmt
fmtutil: format directory `/.texmf-var/web2c' does not exist.
fmtutil: format directory `/.texmf-var/web2c' does not exist.
This is dvips(k) 5.95a Copyright 2005 Radical Eye Software (www.radicaleye.com)
/usr/bin/dvips: ! DVI file can't be opened.
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
This is dvips(k) 5.95a Copyright 2005 Radical Eye Software (www.radicaleye.com)
/usr/bin/dvips: ! DVI file can't be opened.
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
sh: /var/www/html/moodle/filter/tex/mimetex.linux: Permission denied
kpathsea: Running mktexfmt latex.fmt
fmtutil: format directory `/.texmf-var/web2c' does not exist.
This is dvips(k) 5.95a Copyright 2005 Radical Eye Software (www.radicaleye.com)
/usr/bin/dvips: ! DVI file can't be opened.
convert: unable to open image `/backup/temp/latex/d1e56126337cd6e29b16fe759232ce90.ps': No such file or directory.

將/moodledata/temp/latex內修改權限便可以看到圖片了

2010年6月17日 星期四

Metadata file does not match checksum

當執行yum時如果出現
Metadata file does not match checksum
可以在yum.conf裡添加

http_caching=none

參考網址
http://plone.lucidsolutions.co.nz/linux/rpm/yum-metadata-file-does-not-match-checksum

2010年6月4日 星期五

PHP 取得client IP

僅作備忘用

if (!empty($_SERVER['HTTP_CLIENT_IP']))
$ip=$_SERVER['HTTP_CLIENT_IP'];
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else
$ip=$_SERVER['REMOTE_ADDR'];
原文連結

2010年6月2日 星期三

Call to undefined function mssql_connect() in

這不是什麼新聞了...
網路上都在流傳把php_mssql.dll及ntwdblib.dll複製到system32底下重開阿帕契便行了
しかぁぁぁぁぁぁし
事情沒有憨人想的那麼簡單...就是找不到function!!
我把那二個檔案能貼的地方都去貼一貼,還是一樣...
突然!! 想到我是灌win7 64bit耶...
把檔案貼到SysWOW64重開apache........
好了=..=

//
時代在進步,搜尋出來的資料也要找新一點的才行XD

Spreadsheet_Excel_Writer

安裝依附套件OLE
http://pear.php.net/package/OLE/download
pear install OLE-1.0.0RC1
安裝
http://pear.php.net/package/Spreadsheet_Excel_Writer/download
pear install Spreadsheet_Excel_Writer-0.9.2

PHP Warning: PHP Startup: Unable to load dynamic library 'C:/AppServ\php5\ext\php_exif.dll'

灌完appserv後想說裝個pear,點了go-pear.bat後卻出現mbstring.dll錯誤及標題錯誤。
其實是因為exif是依附在mbstring上,要先inclue mbstring才能include exif,所以在php.ini裡把mbstring拉到exif前面去就可以囉!

參考網頁:
http://blog.yam.com/koli09/article/20020227

2010年5月26日 星期三

linux 指令

lspci--查看匯流排、網卡等裝置型號

2010年5月19日 星期三

linux rsync備份至不同機器

target(被丟的)
# vi /etc/rsyncd.conf
    [mch1]
path = /backup
auth users = tatsumilk
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
read only = no
# vi /etc/rsyncd.secrets
tatsumilk:1234567

# chmod 600 /etc/rsyncd.secrets
重要!不然會auth failed

# rsync --daemon

initiator(丟人的)
# vi /home/.../rsyncd.secrets
1234567

# rsync -av --password-file=/home/.../rsyncd.secrets /send tatsumilk@targetIP::mch1

如果上面沒有改權限則會出現下面訊息
@ERROR: auth failed on module mch1
rsync error: error starting client-server protocol (code 5) at main.c(1383) [sender=2.6.9]

參考網頁
http://www.csie.nctu.edu.tw/~tsaiwn/course/introcs/history/linux/linux.tnc.edu.tw/techdoc/rsync.htm

linux moodle 使用套件

php-common-5.1.6-3.7.fc6
php-odbc-5.1.6-3.7.fc6
php-cli-5.1.6-3.7.fc6
php-pgsql-5.1.6-3.7.fc6
php-mbstring-5.1.6-3.7.fc6
php-pdo-5.1.6-3.7.fc6
php-5.1.6-3.7.fc6
php-gd-5.1.6-3.7.fc6
php-xmlrpc-5.1.6-3.7.fc6
php-ldap-5.1.6-3.7.fc6
php-mysql-5.1.6-3.7.fc6

httpd-2.2.6-1.fc6
system-config-httpd-1.4.1-1.fc6
httpd-manual-2.2.6-1.fc6

libdbi-dbd-mysql-0.8.1a-1.2.2
mod_auth_mysql-3.0.0-3.1
mysql-server-5.0.27-1.fc6
mysql-connector-odbc-3.51.12-2.2
mysql-5.0.27-1.fc6
mysql-devel-5.0.27-1.fc6
php-mysql-5.1.6-3.7.fc6
mysql-bench-5.0.27-1.fc6

linux phpMyAdmin

fedora剛灌好是沒有附phpMyAdmin
# yum install phpMyAdmin
因為習慣用web介面所以/etc/phpMyAdmin/config.inc.php裡用預設即可
# vi /etc/httpd/conf.d/phpMyAdmin.conf

# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

order deny,allow
deny from all
allow from 127.0.0.1
allow from ::1
allow from all


# This directory does not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#

Order Deny,Allow
Deny from All
Allow from all

換成IP是比較保險,不過寫all就可以連上去了

2010年5月5日 星期三

550 create directory operation failed


其實事情還沒結束....
在傳輸檔案時發生了

550 create directory operation failed
不用想也知道又是SElinux了...

# vi /etc/selinux/config
設定SELINUX=disable
重開機後...終於啊...
--
參考網頁
http://blog.techippo.org/archives/351
http://www.uncle.ws/2010/04/vsftp-550-create-directory-operation-failed/

2010年5月4日 星期二

500 OOPS: cannot change directory:/home/


裝完vsftpd後
client端出現

500 OOPS: cannot change directory:/home/

google大部分是 說

setsebool ftpd_disable_trans 1
但會出現

Could not change active booleans: Invalid boolean
其實是SElinux限制住了,所以改key

setsebool -P ftp_home_dir=1
就可以囉!

--
參考網頁
http://www.rossi.url.tw/wordpress/?p=204
http://wiki.ubuntu.org.cn/Vsftpd%E8%99%9A%E6%8B%9F%E7%94%A8%E6%88%B7%E8%AE%BE%E7%BD%AE
http://adai0620.blog.ccidnet.com/blog-htm-do-showone-type-blog-itemid-406513-uid-68468.html

2010年4月30日 星期五

liux lvm 最大值

lvm2+linux2.6已經没有2T限制了

lvm裡VG(Volume Group, 捲軸群組)最多只可包含65534個PE(Physical Extend, PE, 實體延伸區塊),而每個PE的大小值介於8k~16G,且需為2的倍數。

若PE取最大值16G 則lvm最大可約1PB(65534 * 16G = 1,048,544G)。


參考網頁:
https://bbs.et8.net/bbs/archive/index.php/t-455273.html
http://www.novell.com/global/china/support/tids/7000032.html
http://linux.vbird.org/linux_basic/0420quota.php#the_pv

2010年4月28日 星期三

linux掛點進入單人模式,很多設定都變成read only,只要下以下指令即可

mount -n -o remount,rw

之前因為多設eth1且網段與eth0不一樣,導致開機很慢也不能登入
進入shell後下

ip link set eth1 down


關掉eth1重開即可

ps.ifconfig eth1 down只是暫時性的,無寫入系統

PHP + SQL Server

如果發生mssql_connect() [function.mssql-connect]: Unable to connect to server
是因為ntwdblib.dll的版本不符,我自身php5帶的是2000.2.8.0
除了將php.ini內extension=php_mssql.dll註解拿掉外還要做以下幾件事

1. http://www.dlldll.com/ntwdblib.dll_download.html下載ntwdblib.dll(2000.80.194.0)
2. 停止 Apache 服務(沒停止會說檔案使用中)
3. 將檔案複製到以下路徑
\windows\system32\
\php\ (php 安裝路徑)
\Apache2.2\bin\ (Apache 安裝路徑下的 bin\)
4. 啟動 Apache 服務

參考網頁:http://www.systn.com/data/news/39_hk.html
     http://www.hoyo.idv.tw/hoyoweb/document/hoyo/349.html

2010年3月17日 星期三

linux

ncftp
下載原始碼
./configure
make
make install

完成!

2010年1月18日 星期一

session_start()出現error

session_start();前面是不能帶有任何html輸出,這是大家都知道的。
但是重灌後突然發現之前的檔案有問題,出現

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at .... )
把檔案內文全刪只剩session_start();卻還是出現上述錯誤這就...
上網google後發現原來是UTF-8的BOM在做怪,只因重灌後直接用筆記本去修改結果造成寫入BOM。
用editplus->tools->preferences->files->utf-8 signature->always remove signature
再存一次檔就OK囉!

參考網頁:
http://blog.raienet.com/406
http://twpug.net/modules/smartfaq/faq.php?faqid=31
http://www.haixiait.com/article.asp?id=232
http://blog.planism.com/archives/2008/09/12/1701/%E7%94%A8-editplus-%E6%B6%88%E9%99%A4-utf-8-%E7%9A%84-bom