| Web guides: | Thcity.com | Thai.net | Geocities | Brinkster | 1Asphost | Netfreehost | Freeservers | Lycos |
ส่วนที่ 5 : บทเรียน
Linux |
|
หากมีข้อผิดพลาด ข้อเสนอแนะ
หรือความคิดเป็นใด โปรดแจ้งทีมงาน webmaster@yonok.ac.th |
How to linux (Case study จาก Redhat 6.2 ไปถึง Redhat 9.0) บทที่ 1 : คำสั่งสำหรับผู้ใช้พื้นฐาน (Basic user command)
| ในแต่ละกลุ่มจะมีการกำหนดสิทธิได้ 3
แบบ ตัวอักษร R มาจาก Read หมายถึง อ่าน ตัวอักษร W มาจาก Write หมายถึง เขียน ตัวอักษร X มาจาก Execute หมายถึง ประมวลผล ตัวอย่างเช่น --- : ไม่มีสิทธิอะไรเลย (เลขที่ใช้คือ 0) --X : ประมวลผลได้อย่างเดียว (เลขที่ใช้คือ 1) R-- : อ่านได้อย่างเดียว (เลขที่ใช้คือ 4) RW- : อ่าน และเขียนได้ (เลขที่ใช้คือ 6) R-X : อ่าน และประมวลผลได้ (เลขที่ใช้คือ 5) RWX : อ่าน เขียน และประมวลผลได้ (เลขที่ใช้คือ 7) |
ความหมายของ RWXRWXRWX จะเห็นว่ามีอักษร 9
ตัว 3 ตัวแรกหมายถึง เจ้าของ 3 ตัวที่สองหมายถึง กลุ่ม 3 ตัวที่สามหมายถึง คนอื่น ตัวอย่างเช่น RWX------ : เจ้าของเท่านั้นที่มีสิทธิทุกอย่าง (เลขที่ใช้คือ 700) RWXRWX--- : เจ้าของ และสามาชิกกลุ่มเดียวกันมีสิทธิทุกอย่าง (เลขที่ใช้คือ 770) RWXR-XR-X : เจ้าของทำได้หมด ส่วนกลุ่มและคนอื่นอ่านและประมวลผลได้ (เลขที่ใช้คือ 755) R--R--R-- : ทุกคนอ่านได้อย่างเดียว (เลขที่ใช้คือ 444) |
Welcome to GNU Emacs, one component of a Linux-based GNU system. Get help C-h (Hold down CTRL and press h) Undo changes C-x u Exit Emacs C-x C-c Get a tutorial C-h t Use Info to read docs C-h i Ordering manuals C-h RET Activate menubar F10 or ESC ` or M-` (`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key. If you have no Meta key, you may instead type ESC followed by the character.)
ตัวอย่างคำสั่ง และการใช้งาน esc กลับไปยังโหมดคำสั่ง enter ย้ายไปยังต้นบรรทัดของบรรทัดถัดไป i ใส่ข้อความก่อนเคอร์เซอร์ a ใส่ข้อความหลังเคอร์เซอร์ A ใส่ข้อความที่ท้ายบรรทัดปัจจุบัน dd ลบบรรทัดปัจจุบันทั้งบรรทัด x ลบอักษร 1 ตัวอักษร cw เปลี่ยนข้อความ :w บันทึกแฟ้ม :q! ออกโดยไม่ เปลี่ยนแปลงใด ๆ :wq บันทึกแฟ้ม และออกจากโปรแกรม vi
eth0 Link encap:Ethernet HWaddr 00:20:18:C0:06:C4
inet addr:202.29.78.12 Bcast:202.29.78.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:673054 errors:0 dropped:0 overruns:0 frame:0
TX packets:666268 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:74892865 (71.4 Mb) TX bytes:680121131 (648.6 Mb)
Interrupt:9 Base address:0xcf00
eth0:1 Link encap:Ethernet HWaddr 00:20:18:C0:06:C4
inet addr:202.29.78.1 Bcast:202.29.78.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:9 Base address:0xcf00Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:mysql *:* LISTEN tcp 0 0 *:http *:* LISTEN tcp 0 0 *:ftp *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:smtp *:* LISTEN tcp 0 0 *:https *:* LISTEN tcp 0 0 www.isinthai.com:ssh 202.29.78.200:1225 ESTABLISHED Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 855 /var/lib/mysql/mysql.sock unix 2 [ ACC ] STREAM LISTENING 119 /dev/log unix 2 [ ] STREAM CONNECTED 3007 unix 2 [ ] STREAM CONNECTED 859
httpd (pid 2160 2159 2158 2155 2114 583 579 578 577 576 575 573) is running... mysqld (pid 446 429 427 414) is running... sendmail (pid 1700 1690) is running... sshd (pid 2970 358) is running... xinetd (pid 3923 369) is running...
Service configuration: ftp
id = ftp
flags = IPv4
socket_type = stream
Protocol (name,number) = (tcp,6)
Nice = 10
Groups = no
Bind = All addresses.
Server = /usr/sbin/vsftpd
Server argv = vsftpd
Only from: All sites
No access: No blocked sites
Logging to syslog. Facility = authpriv, level = info
Log_on_success flags = HOST PID
Log_on_failure flags = HOST
HISTSIZE=1000 SSH_CLIENT=202.29.78.100 1091 22 OLDPWD=/usr/sbin QTDIR=/usr/lib/qt3-gcc3.2 SSH_TTY=/dev/pts/0 USER=burin LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;.... : PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin MAIL=/var/spool/mail/burin PWD=/etc INPUTRC=/etc/inputrc LANG=en_US.UTF-8 HOME=/root SHLVL=2 LOGNAME=burin LESSOPEN=|/usr/bin/lesspipe.sh %s G_BROKEN_FILENAMES=1 _=/bin/env
nslookup 202.28.18.65Non-authoritative answer: 65.18.28.202.in-addr.arpa name = mars.uni.net.th. Authoritative answers can be found from: 18.28.202.in-addr.arpa nameserver = mars.uni.net.th. 18.28.202.in-addr.arpa nameserver = ns.netserv.chula.ac.th. mars.uni.net.th internet address = 202.28.18.65
nslookup www.thaiall.comName: www.thaiall.com Address: 66.150.1.141
ตัวอย่างผลของการใช้คำสั่ง
CPU states: 0.5% user, 1.3% system, 0.0% nice, 98.0% idle
Mem: 31328K av, 28872K used, 2456K free, 0K shrd, 1032K buff
Swap: 1718912K av, 2608K used, 1716304K free 16528K cached
PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND
18306 root 14 0 852 852 672 R 0 1.5 2.7 0:00 top
18229 root 1 0 1684 1536 1240 S 0 0.3 4.9 0:00 sshd
1 root 0 0 160 116 92 S 0 0.0 0.3 0:08 init
2 root 0 0 0 0 0 SW 0 0.0 0.0 0:01 kflushd
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 202.29.78.0 * 255.255.255.0 U 0 0 0 eth0 127.0.0.0 * 255.0.0.0 U 0 0 0 lo default 202.29.78.254 0.0.0.0 UG 0 0 0 eth0
# /etc/inittab # Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) #id:5:initdefault: id:3:initdefault:
traceroute to www.thai.net (203.150.13.2), 30 hops max, 38 byte packets 1 door.yonok.ac.th (202.29.78.254) 2.046 ms 1.962 ms 2.532 ms 2 202.28.29.41 (202.28.29.41) 3.703 ms 3.294 ms 3.760 ms 3 UniNet-BKK2-ATM1-0-0.700.uni.net.th (202.28.28.129) 14.185 ms 13.226 ms 14.614 ms 4 202.28.28.18 (202.28.28.18) 13.705 ms 13.227 ms 14.130 ms 5 202.47.255.2 (202.47.255.2) 13.222 ms 13.890 ms 13.210 ms 6 202.129.63.182 (202.129.63.182) 16.649 ms 14.960 ms 15.659 ms 7 juliet-vlan-2.bkk.inet-th.net (203.150.14.22) 14.817 ms 15.573 ms 15.610 ms 8 www.thai.net (203.150.13.2) 15.628 ms 14.775 ms 14.222 ms
00:00.0 Host bridge: Intel Corp. 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 03) 00:01.0 PCI bridge: Intel Corp. 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 03) 00:07.0 ISA bridge: Intel Corp. 82371AB/EB/MB PIIX4 ISA (rev 02) 00:07.1 IDE interface: Intel Corp. 82371AB/EB/MB PIIX4 IDE (rev 01) 00:07.2 USB Controller: Intel Corp. 82371AB/EB/MB PIIX4 USB (rev 01) 00:07.3 Bridge: Intel Corp. 82371AB/EB/MB PIIX4 ACPI (rev 02) 00:0f.0 PCI bridge: Digital Equipment Corporation DECchip 21152 (rev 03) 00:11.0 Ethernet controller: 3Com Corporation 3c905B 100BaseTX [Cyclone] (rev 24) 01:00.0 VGA compatible controller: ATI Technologies Inc 3D Rage Pro AGP 1X/2X (rev 5c)
#nmap -sP 202.29.78.* Starting nmap V. 3.00 ( www.insecure.org/nmap/ ) Host (202.29.78.0) seems to be a subnet broadcast address (returned 1 extra pings). Note -- the actual IP also responded. Host www.isinthai.com (202.29.78.1) appears to be up. Host course.yonok.ac.th (202.29.78.5) appears to be up. Host yonok.ac.th (202.29.78.12) appears to be up. Host w2kdhcp.yonok.ac.th (202.29.78.17) appears to be up. Host (202.29.78.31) appears to be up. Host (202.29.78.32) appears to be up. Host (202.29.78.33) appears to be up.
#nmap -sT www.yonok.ac.th (on TCP) Starting nmap V. 3.00 ( www.insecure.org/nmap/ ) Interesting ports on yonok.ac.th (202.29.78.12): (The 1590 ports scanned but not shown below are in state: closed) Port State Service 21/tcp open ftp 22/tcp open ssh 25/tcp open smtp 53/tcp open domain 80/tcp open http 109/tcp open pop-2 110/tcp open pop-3
#nmap www.yonok.ac.th -sU (on UDP) Starting nmap V. 3.00 ( www.insecure.org/nmap/ ) Interesting ports on yn1.yonok.ac.th (202.29.78.12): (The 1465 ports scanned but not shown below are in state: closed) Port State Service 53/udp open domain 111/udp open sunrpc 867/udp open unknown
#!/usr/bin/perl print"Content-type:text/html\n\n"; print"<body bgcolor=#ffffdd>"; print"<h1>This is test.</h1><br>By tester</body>";
<form action=http://www.isinthai.com/thaiall/perlcrt.pl method=post> <input type=submit value=Create_dataperl.txt> perlcrt.pl </form>หรือ จะเรียกตรง ๆ ผ่าน URL ก็ได้เช่น http://www.isinthai.com/thaiall/perlcrt.pl
#!/usr/bin/perl print"Content-type:text/html\n\n"; $filename = "/home/burin/public_html/dataperl.txt"; open(myfile,">$filename"); $dat = "3101001:Tom:Jojo:16000:A:\n"; print myfile $dat; $dat = "3101002:Naja:Rujj:5600:R:\n"; print myfile $dat; $dat = "3101003:Packman:Somsu:7000:L:\n"; print myfile $dat; $dat = "3101004:Nichole:Jaiboon:15000:A:\n"; print myfile $dat; $dat = "3101005:Suwi:Hancharn:10600:A:\n"; print myfile $dat; $dat = "3101006:Nirund:Jiva:9700:A:\n"; print myfile $dat; close(myfile); print "<body bgcolor=#ddffff>Create 6 Records and 5 Fields : Finish";
<form action=http://www.isinthai.com/thaiall/perllst.pl method=post> <input type=submit value=List_dataperl.txt> perllst.pl </form>หรือ จะเรียกตรง ๆ ผ่าน URL ก็ได้เช่น http://www.isinthai.com/thaiall/perllst.pl
#!/usr/bin/perl
print"Content-type:text/html\n\n";
$filename = "/home/burin/public_html/dataperl.txt";
print "<body bgcolor=#ddffff><pre>";
open(myfile,"<$filename");
@getrec = <myfile>;
close(myfile);
$i = 1;
foreach $rec (@getrec) {
@r = split(/:/,$rec);
print $i,$r[0]," - ",$r[1],$r[2],$r[3],$r[4],$r[5],"\n";
$i++;
}
<form action=http://www.isinthai.com/thaiall/perladd.pl method=post>Add new<br> s-id : <input type=text name=sid><br> s-name : <input type=text name=sn><br> s-surname : <input type=text name=ss><br> s-salary : <input type=text name=ssal><br> status: <input type=text name=stat><br> <input type=submit value=Add_dataperl.txt> </form>
#!/usr/bin/perl
&parse_form;
print"Content-type:text/html\n\n";
$filename = "/home/burin/public_html/dataperl.txt";
open(myfile,">>$filename");
$dat = "$config{'sid'}:$config{'sn'}:$config{'ss'}:$config{'ssal'}:$config{'stat'}:\n";
print myfile $dat;
close(myfile);
print "Add new : Finish";
exit;
sub parse_form {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$config{$name} = $value;
}
}
<form action=http://www.isinthai.com/thaiall/perldel.pl method=post>Delete record on s-id : <input type=text name=sid> <input type=submit value=Del_dataperl.txt> </form>
#!/usr/bin/perl
&parse_form;
print"Content-type:text/html\n\n";
$filename = "/home/burin/public_html/dataperl.txt";
print "<body bgcolor=#ddffff><pre>";
open(myfile,"<$filename");
@getrec = <myfile>;
close(myfile);
$i = 1;
open(myfile,">$filename");
foreach $rec (@getrec) {
@r = split(/:/,$rec);
if ($r[0] ne $config{'sid'}) {
print myfile $rec;
}
}
close(myfile);
print "Delete : Finish";
exit;
sub parse_form {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$config{$name} = $value;
}
}
ตัวอย่างโปรแกรมที่ใช้ทดสอบ
#!/usr/bin/perl
$filename = "/home/burin/public_html/testf.pl";
print"Content-type:text/html\n\n";
print"<body bgcolor=#ffffdd><pre>";
open(myfile,"$filename");
@getrec = <myfile>
close(myfile);
$i = 1;
foreach $r (@getrec) {
$r =~ s/</</g;
$r =~ s/>/>/g;
$r =~ s/"/"/g;
print $i,". ",$r,"<br>";
$i++;
}
print"<hr>";
ตัวอย่างโปรแกรมที่ใช้ทดสอบ
<?
for ($i=1;$i<=5;$i++){
echo "$i<br>";
}
?>
ตัวอย่างโปรแกรม listall.php
<?
echo "First line of the printing on screen.";
$link = mysql_connect("localhost","thaiall","some_pass");
if ($link) {
echo "Connect OK<hr>";
mysql_select_db("test",$link);
$query = "select * from testf";
$process = mysql_query($query,$link);
$i = 1;
while ($obj = mysql_fetch_object($process)) {
echo $i.$obj->fld1." - ";
echo $obj->fld2." - ";
echo $obj->fld3."<br>";
$i++;
}
mysql_close($link);
} else {
echo "Connect error";
}
?>
ตัวอย่างโปรแกรม addone.php
<?
$link = mysql_connect("localhost","thaiall","some_pass");
if ($link) {
echo "Connect OK<hr>";
mysql_select_db("test",$link);
$query = "insert into testf values('abc','def',5)";
$result = mysql_db_query("test",$query);
if (!result) {
echo "ผิดพลาด";
} else {
echo "เพิ่มเรียบร้อย";
}
mysql_close($link);
} else {
echo "Connect error";
}
?>
ตัวอย่างโปรแกรมที่ใช้ป้อนข้อมูล เตรียมส่งเข้า mysql (addmany.htm)
ข้อมูลที่ส่งเข้าจะใช้เครื่องหมาย , แยกระหว่างเขตข้อมูล และ 1 บรรทัดก็คือ 1 ระเบียน ทำให้ผู้ใช้สามารถนำข้อมูลจาก Excel มา export CSV และใช้ที่นี่ได้ <form action=addmany.php> <textarea name=manyrecord rows=6 cols=40></textarea> <input type=submit></form>
ตัวอย่างโปรแกรมที่ใช้ส่งข้อมูลเข้า Mysql (addmany.php ถูกสั่งจาก addmany.htm)
<?
$getline = preg_split("/[\s\n]+/",$manyrecord);
for ($j=0;$j<count($getline);$j++) {
$l = $j + 1;
$getfield = preg_split("/[\s,]+/",$getline[$j]);
print "$l $getfield[0] - $getfield[1] - $getfield[2]<br>";
}
$link = mysql_connect("localhost","thaiall","some_pass");
if ($link) {
echo "Connect OK<hr>";
mysql_select_db("test",$link);
for ($j=0;$j<count($getline);$j++) {
$l = $j + 1;
$getfield = preg_split("/[\s,]+/",$getline[$j]);
print "$l $getfield[0] - $getfield[1] - $getfield[2]";
$query = "insert into testf values('$getfield[0]','$getfield[1]',$getfield[2])";
$result = mysql_db_query("test",$query);
if (!$result) {
echo "ผิดพลาด";
} else {
echo "เพิ่มเรียบร้อย";
}
echo "<br>";
}
mysql_close($link);
} else {
echo "Connect error";
}
?>
Source code : mail.htm
<body>
<form action=mail.php method=get>
<input name=refer type=hidden value="http://www.isinthai.com/~php/mail.htm">
From : <input name=from value="saleman@oho.com" size=30><br>
To : <input name=to value="burin@yonok.ac.th" size=30><br>
Subject : <input name=subject value="test sendmail by isinthai.com" size=50><br>
<textarea name=message rows=5 cols=80>
Test form isinthai.com/~php/mail.htm
</textarea><br>
<input type=submit value=send>
</form>
</body>
Source code : mail.php : สำหรับรับข้อมูลเพื่อส่ง mail ออกไป (ทำหน้าที่ส่ง e-mail โดยตรง)
<body>
<font color=blue>Send mail : </font><font color=red>
<?
$lf = chr(13). chr(10);
$msg = $_GET['message'] . $lf ."IP address: " . $_SERVER["REMOTE_ADDR"];
$msg = $msg . $lf ."Service by: http://www.isinthai.com/~php/mail.htm";
// mail ("burin@yonok.ac.th","your order","want 100 car today","From: saleman@oho.com");
if ($_GET['to'] <> "burin@yonok.ac.th" || $_GET['from'] <> "saleman@oho.com") {
mail($_GET['to'],":: ".$_GET['subject'],$msg,"From : ".$_GET['from']);
echo "ok";
} else {
echo "invalid";
}
?>
</font><br><a href=<? echo $_GET['refer']; ?>><? echo $_GET['refer']; ?></a>
</body>
อีก code หนึ่ง /var/www/html/isinthai/sndform.php
ที่ใช้งานอยู่จริง
<?
$mto = $_POST["mto"];
$msubj = $_POST["msubj"];
$mfrom = $_POST["mfrom"];
$message = $_POST["message"];
$redirect = $_POST["redirect"];
if (empty($redirect)) { $redirect = "http://www.isinthai.com/isinthai/sndform.php"; }
if (empty($mto) || empty($msubj) || empty($mfrom) || empty($message)) {
echo "<body bgcolor=#ffffdd><font face=fixedsys>";
echo "<form action=sndform.php method=post>";
echo ".... To : <select name=mto size=3>";
echo "<option value=nirund@yonok.ac.th selected>ดร.นิรันดร์ จิวะสันติการ";
echo "<option value=atichart@yonok.ac.th>อติชาต หาญชาญชัย";
echo "<option value=burin@yonok.ac.th>ผู้ดูแลเครือข่าย, HW, SW, ฐานข้อมูล";
echo "</select><br>.. From : <input name=mfrom size=30> EX. yourname@hotmail.com<br>";
echo "Subject : <input name=msubj size=50> EX. Why the name is YONOK?<br>";
echo "Messages: <textarea name=message rows=10 cols=80>";
echo "</textarea> <input type=submit value=Send_mail><br>";
echo "<input name=redirect type=hidden value=http://www.isinthai.com/isinthai/sndform.php>";
echo "</form>";
$message = "hi\nthis is test\nthis is line.";
$mto = "burin@yonok.ac.th";
$msubj = "the subject";
$mfrom = "burin@thaiall.com";
} else {
$message=$message."\n\nService from http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
$message=$message."\nScript developer by webmaster@yonok.ac.th";
$message=$message."\nIP address : ".$_SERVER["REMOTE_ADDR"];
$msubj = "Subject_".$msubj;
$txtfrom = "From: ".$mfrom."\nX-Mailer: PHP/" . phpversion();
mail($mto, $msubj, $message, $txtfrom );
echo "<html><head><meta http-equiv=Refresh CONTENT='50; URL=$redirect'>";
echo "</head><body><font face=fixedsys>";
echo "Your message sending [ <b>completely</b> ]<hr color=red><pre>";
echo "From : $mfrom \n";
echo "To : $mto \n";
echo "Subject : $msubj \n";
echo "Message : $message</pre>";
}
?>
ตัวอย่างโปรแกรม lastmsg.php
<form action=http://www.isinthai.com/lock/lastmsg.php method=get>
File: <input name=file value=messages>
Line: <input name=l value=20>
Password: <input name=p type=password value=suwit>
<input type=submit value=tail>
</form><font face=fixedsys><pre>
<?
if ($_GET['p'] == "prasert") {
$x = "tail --lines=" . $_GET['l'] . " ". $_GET['file'];
echo `$x`;
}
?>
ตัวอย่างโปรแกรม /var/www/html/mail/database/index.php
<html><head><title>Username of /var/log/maillog</title></head>
<body bgcolor=gray topmargin=0 leftmargin=0><font face="fixedsys" size=0><?
$datefull = date("F d, Y");
if(date("j") < 10) {$d = date("M")." ".date("j");}else{$d = date("M j");}
echo "Today : <font color=yellow>".$datefull."</font><br>";
echo "Last login: <a href=index.php?act=total>total</a> ";
if ($_GET['act'] <> "view" && $_GET['act'] <> "total") {
echo ", <a href=index.php?act=view>today</a> ";
} else {
echo "<ol><font color=white>";
$ar = file("/var/log/maillog");
if ($_GET['act'] == "total") { $max = 0; } else { $max = count($ar) - 500; }
$j = 0;
for ($i=count($ar);$i>=$max;$i--) {
if (strpos($ar[$i],"Login user=") && _
(strpos($ar[$i],"$d") > -1 || $_GET['act'] == "total")) {
$user = stristr($ar[$i],"user=");
$uofar = substr($user,5,strpos($user," ")-5);
$found = "no";
for($k=0;$k<$j;$k++) {
if (strpos($ur[$k],"$uofar") > -1) { $found = "yes"; }
}
if ($found == "no") {
if (strpos($ar[$i],"host=yonok.ac.th") == false) {
$p="pop";
} else {
$p=" ";
}
$ur[$j] = $uofar." <font color=black>".substr($ar[$i],7,8)."</font> ".$p;
$ut[$j] = $uofar." <font color=black>".substr($ar[$i],0,6)."</font> ".$p;
$j = $j + 1;
}
}
}
for ($i=0;$i<$j;$i++) {
if ($_GET['act'] == "total") {
echo "<li>".$ut[$i];
} else {
echo "<li>".$ur[$i];
}
}
}
?>
</ol></body></html>
upload.htm ส่วนนี้เป็น html สำหรับส่งค่าให้ upload.php <body> <form enctype="multipart/form-data" method=post action=upload.php> <input type=hidden name="MAX_FILE_SIZE" value=200000> User <input type=text name=guser><br> Password <input type=password name=gpassword><br> Select file <input type=file name=upload><br> <input type=submit value=Upload> </form> <form enctype="multipart/form-data" method=post action=listfile.php> User <input type=text name=guser><br> Password <input type=password name=gpassword><br> <input type=submit value=List> </form> </body>
upload.php ทำหน้าที่ส่งแฟ้มจากเครื่องท่านเข้าไปเก็บใน server
โปรแกรมนี้เขียนได้เพราะอ่านวิธี upload จากหนังสือ PHP ของสุพิน วรรณา เล่มสีส้ม มีรูปหน้าคนครึ่งหน้า หน้า 494
แต่ได้ปรับปรุงนิดหน่อย เพื่อให้ใช้งานใน isinthai.com ขณะที่ปิด telnet หรือ ftp (เดือนพฤษภาคม 2544)
<?
include("updateinclude.php");
setupinit();
if ($upload <> "none" and $upload_size < 200000) {
echo "User: $guser<br>";
echo "Local File: $upload<br>";
echo "Name: $upload_name<br>";
echo "Size: $upload_size<br>";
echo "Type: $upload_type<br>";
copy($upload,"$fpath/$upload_name");
chmod("$fpath/$upload_name",0700);
unlink($upload);
} else {
echo "Please select file";
}
?>
uploadinclude.php ใช้ในทุกโปรแกรม เพื่อตรวจสิทธิที่จะเข้า update
ใช้ตรวจ guser และ gpassword กับแฟ้ม password.pl เพื่อตรวจว่าเป็นผู้ใช้ที่ถูกต้องหรือไม่
ในการเขียนแบบนี้ทำให้ ระบบข้อมูลถูก hack ได้ง่ายมาก แต่ต้องใช้ php เข้าไป hack
<?
function setupinit() {
global $guser,$gpassword,$fpath;
$fpath="/home/burin/public_html/$guser";
if ($guser) {
$f = fopen("$fpath/password.pl","r");
if (!feof($f)) {
$d = fgets($f,14);
fclose($f);
}
if (strlen($d) <> 13){
$d = crypt(substr($d,0,strlen($d)),$guser);
if ($d == crypt($gpassword,$guser)) {
$f = fopen("$fpath/password.pl","w");
if ($f) {
fputs($f,$d);
fclose($f);
}
}
echo "Crypt password.pl : OK $d".crypt($gpassword,$guser)."<hr>";
}
}
if ($d == crypt($gpassword,$guser)) {
echo "Welcome.. <b>$guser</b> : OK<hr>";
} else {
echo "Password invalid of $guser";
exit;
}
}
?>
listfile.php ดูรายชื่อแฟ้ม
โดยใช้ include file สำหรับตรวจ guser และ gpassword ที่เหมาะสมกับแฟ้ม password.pl
<?
include("updateinclude.php");
setupinit();
$dir_handle = opendir($fpath);
echo "<pre><font size=4 face=fixed>";
while($list = readdir($dir_handle)) {
if (substr($list,0,1) <> "." and $list <> "mail" and $list <> "bash_profile" and
$list <> "pico.save" and $list <> "password.pl") {
echo $list." - ".filesize("$fpath/$list")." Byte<br>";
}
}
closedir($dir_handle);
?>
start Mysql ด้วยคำสั่ง cd /usr/local/bin ./safe_mysqld &
ทดสอบ run Mysql ./mysql mysql>status mysql>exit
ขั้นตอนการติดตั้ง su cd /usr/local tar xfvz /home/burin/mysql-3.22.32.tar.gz ln -sf mysql-3.22.32 mysql adduser mysql chown -R mysql:root mysql-3.22.32 mysql su mysql เป็น su ก็ทำได้ พอเป็น mysql มีปัญหา ว่าไม่สามารถใช้ gcc ที่ถูก lock ตาม 9.52 cd mysql ./configure --with-charset=tis620 make su make install ./scripts/mysql_install_db cd /usr/local chown -R mysql:root var cd /etc/rc.d/init.d cp /usr/local/mysql/support-files/mysql.server mysql chmod +x mysql /sbin/chkconfig --del mysql /sbin/chkconfig --add mysql
ตัวอย่างการใช้งาน Mysql
[thaiall@www thaiall]$ mysql -u username
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 3.22.32
Type 'help' for help.
mysql> status
mysql> show databases;
mysql> use test
mysql> show tables;
mysql> create table testf (
-> fld1 char(20),
-> fld2 char(20),
-> fld3 integer(3),
-> fld4 date );
mysql> select * from testf;
mysql> insert into testf (fld1, fld2, fld3)
-> values ('tom','dang',5 );
mysql> insert into testf (fld1, fld2, fld3) value ('siri','maru',19);
mysql> select * from testf;
+------+------+------+
| fld1 | fld2 | fld3 |
+------+------+------+
| tom | dang | 5 |
| siri | maru | 19 |
+------+------+------+
2 rows in set (0.00 sec)
mysql> exit
ข้อมูลเกี่ยวกับการเพิ่มผู้ใช้
http://www.mysql.com/doc/A/d/Adding_users.html
MySQL root user, and the root user must have the insert privilege for the
mysql database and the reload administrative privilege. Also, if you have
changed the root user password, you must specify it for the mysql commands
below.
You can add new users by issuing GRANT statements:
shell> mysql --user=root -phelloisinthai
mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO monty@"%"
IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
mysql> GRANT USAGE ON *.* TO dummy@localhost;
Welcome to Academic Services Machine
,
, ;:._.-`''.
;.;'.;` _ `.
',;` ( \ ,`-.
`:.`, (_/ ;\ `-.
';: / `. `-._
`;.;' `-,/ . `-.
';;' _ `^` `.
';; ,'-' `--._ ;
': `;; ,; `. ':`,,.__,,_ /
`;`:;`;:` ,; '. ;, ';';':';;`
.,; ' '-._ `':.;
.:; ` '._ `';;,
;:` ` :'`' ',__.)
`;:;:.,...;'`'
';. '`'::'`'' .'`'
,' `';;:,..::;`'`'
, .;` `'::''`
,`;`.
academic login:
Date: 2 สิงหาคม 2544 From: webmaster@se-ed.com (Sanyapong Kridakarn) เรียนสมาชิกทุกท่าน หลังจากที่ทางซีเอ็ดให้บริการฟรีอีเมล์ และฟรีโฮมเพจมา 1 ปี ขณะนี้ก็ถึงเวลาที่ทางทีมงานขอแจ้งให้ทราบว่า จะมีการปรับปรุงเปลี่ยนแปลง เซิร์ฟเวอร์เพื่อให้สามารถให้บริการทุกท่านได้มากขึ้น และเพิ่มเติมความสามารถให้รองรับการใช้งานของทุกท่านได้มากกว่าเดิมในทุกๆ ด้าน ทุกท่านคงพอจะทราบว่า ช่วงสองเดือนที่ผ่านมา เซิร์ฟเวอร์เกิดปัญหาหลายครั้ง โดยเกิดขึ้นจากหลายสาเหตุ เช่น - พื้นที่ฮาร์ดดิสก์ 60 GB ของเซิร์ฟเวอร์เหลืออยู่ประมาณ 2 GB เท่านั้น - การถูกถล่มด้วยเมล์จำนวนมาก (mail bomb) จากสมาชิก SE-ED.net ของเราท่านหนึ่ง - ข้อจำกัดของ Linux ที่โฟลเดอร์หนึ่งจะมีไฟล์และโฟลเดอร์ได้เพียงประมาณ 32,000 โฟลเดอร์เท่านั้น ทำให้ไม่สามารถรองรับสมาชิกเพิ่มเติมได้ - ข้อจำกัดเว็บเซิร์ฟเวอร์ Apache ที่รองรับผู้ใช้พร้อมกันได้เพียง 256 ราย และทำให้เซิร์ฟเวอร์ทำงานช้ามากสำหรับผู้ใช้รายที่ 257 ขึ้นไป เมื่อคอมไพล์โปรแกรม Apache ใหม่เพื่อให้รองรับผู้ใช้ได้มากขึ้นจนกระทั่งเกิด Error โดยไม่คาดหมาย ทำให้ไม่สามารถอ่านเมล์ผ่านเว็บและเปิดเว็บเพจของสมาชิกได้ประมาณ 2 วัน - การระบาดของไวรัส Sircam - ล่าสุด ระบบไฟล์บนฮาร์ดดิสก์ของลินุกซ์เกิดขัดข้อง จนเซิร์ฟเวอร์หยุดทำงาน ต้องไปแก้ไขเครื่องถึงอินเทอร์เน็ตประเทศไทย ระบบทุกอย่างหยุดทำงาน~ 24 ชั่วโมง ต้องขออภัยทุกท่านที่เกิดปัญหาและข้อติดขัดเหล่านี้ ทีมงานจะทุ่มเทอย่างเต็มที่เพื่อให้เกิดเหตุการณ์เหล่านี้น้อยที่สุด และในกรณีที่เกิดเหตุสุดวิสัย ก็จะรีบแก้ไขให้บริการทุกอย่างกลับมาเป็นปกติอีกครั้งในเวลารวดเร็วที่สุดเท่าที่จะทำได้ ขณะนี้ทางทีมงานกำลังอัปเกรดเครื่องใหม่ และเปลี่ยนแปลงระบบปฏิบัติการที่ใช้ดังนี้ ตารางเปรียบเทียบเซิร์ฟเวอร์ใหม่และเก่า
| New Server | Current Server | |
| CPU | Dual Pentium III 933 MHz | Pentium III 650 MHz |
| Motherboard | Intel Server Board STL2 | Intel Server Board L440GX |
| Memory | 1 GB | 512 MB |
| Harddisk | 300 GB | 60 GB |
| OS | Windows 2000 Advanced Server | Redhat Linux 6.2 |
| Web server | Apache 1.3.20 for Windows | Apache 1.3.20 |
FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [-A] [host] -v Suppresses display of remote server responses. -n Suppresses auto-login upon initial connection. -i Turns off interactive prompting during multiple file transfers. -d Enables debugging. -g Disables filename globbing (see GLOB command). -s:filename Specifies a text file containing FTP commands -a Use any local interface when binding data connection. -A login as anonymous. -w:buffersize Overrides the default transfer buffer size of 4096. host Specifies the host name or IP address of the remote host to connect to.
C:\WINDOWS>ftp.exe ftp> open www.isinthai.com Connected to www.isinthai.com. 220 www.isinthai.com FTP server (Version wu-2.6.0(1) Fri Jun 23 09:17:44 EDT 2000 0) ready. User (www.isinthai.com:(none)): demo 331 Password required for demo. Password: 230 User demo logged in. ftp> lcd c:\isinthai Local directory now C:\isinthai ftp> ascii 200 Type set to A. ftp> hash Hash mark printing On (2048 bytes/hash mark). ftp> put index.html 200 PORT command successful. 150 Opening ASCII mode data connection for index.html. ######################################## 226 Transfer complete. 162886 bytes sent in 0.39 seconds (417.66 Kbytes/sec) ftp> lcd a:\ ftp> ascii ftp> put index.html ftp> put friend.htm ftp> bin ftp> put face.jpg ftp> put hello.gif ftp> put wow.doc ftp> bye 221-You have transferred 1601416xx bytes in 6 files. 221-Total traffic for this session was 160563xx bytes in 6 transfers. |
rblcheck -s orbs.dorkslayers.com $1 rblcheck -s dev.null.dk $1 rblcheck -s bl.spamcop.net $1 rblcheck -s relays.osirusoft.com $1 rblcheck -s relays.visi.com $1 rblcheck -s list.dsbl.org $1 rblcheck -s relays.ordb.org $1
202.28.18.65 not RBL filtered by orbs.dorkslayers.com 202.28.18.65 not RBL filtered by dev.null.dk 202.28.18.65 not RBL filtered by bl.spamcop.net 202.28.18.65 not RBL filtered by relays.osirusoft.com 202.28.18.65 not RBL filtered by relays.visi.com 202.28.18.65 not RBL filtered by list.dsbl.org 202.28.18.65 not RBL filtered by relays.ordb.org
8.1.1 :: /etc/login.defs- ใช้กำหนดว่าเครื่องจะมี account สูงสุดได้เท่าใด - เพราะเลขที่กำหนดประจำตัวผู้ใช้ เริ่มต้นที่ 500 UID_MIN 500 UID_MAX 60000
8.1.2 :: /etc/security/limits.conf# ใช้จำกัดสิทธิของผู้ใช้ # คำสั่งจริงมี 2 บรรทัดล่างสุด # ส่วนที่มี # เป็นคำอธิบายทั้งสิ้น #<domain> <type> <item> <value> # #Where: #<domain> can be: # - an user name # - a group name, with @group syntax # - the wildcard *, for default entry # #<type> can have the two values: # - "soft" for enforcing the soft limits # - "hard" for enforcing hard limits # #<item> can be one of the following: # - core - limits the core file size (KB) # - data - max data size (KB) # - fsize - maximum filesize (KB) # - memlock - max locked-in-memory address space (KB) # - nofile - max number of open files # - rss - max resident set size (KB) # - stack - max stack size (KB) # - cpu - max CPU time (MIN) # - nproc - max number of processes # - as - address space limit # - maxlogins - max number of logins for this user # #<domain> <type> <item> <value> #* soft core 0 #* hard rss 10000 #@student hard nproc 20 #@faculty soft nproc 20 #@faculty hard nproc 50 #ftp hard nproc 0 #@student - maxlogins 4 # # ผู้ใช้ในกลุ่ม users มีเนื้อที่ใน home directory ได้เพียง 1 Mb @users hard rss 1000 * soft core 0
8.1.3 :: /etc/lilo.conf# คู่แข่งของ /etc/grub.conf # เมื่อแก้แฟ้มนี้แล้ว ให้สั่งประมวลผล /sbin/lilo # เพื่อให้การ update แฟ้มข้างล่างนี้เป็นผล สำหรับการ boot ครั้งใหม่ # และครั้งต่อไปที่บูตเครื่องจะ default ไปที่ linux boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=50 default=linux image=/boot/vmlinuz-2.2.14-5.0 label=linux read-only root=/dev/hda5 other=/dev/hda1 label=window
8.1.5 :: /etc/crontab- ตารางเวลาการสั่งประมวลผลโปรแกรม - หากต้องการสั่งงานต้องสร้างแฟ้มในห้อง /etc/cron.daily - แฟ้มที่สร้างให้ใส่คำสั่งได้เลยเช่น /home/radius/runacct - อย่าลืมกำหนด 755 ให้แฟ้มนั้นเช่น chmod 755 runradius SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly # minute (0-59), # hour (0-23), # day of the month (1-31), # month of the year (1-12), # day of the week (0-6 with 0=Sunday)
8.1.6 :: /etc/default/useradd- ในบางเครื่องอาจกำหนดเป็นดังข้างล่างนี้จะสะดวก - และสิทธิของห้องเป็น 700 จึงต้องใช้ script _crt กำหนดสิทธิ์เป็น 705 - อีกครั้งหนึ่ง จึงจะทำให้เปิดห้องผ่าน www ได้ปลอดภัย # useradd defaults file GROUP=100 HOME=/home INACTIVE=-1 EXPIRE= #SHELL=/bin/bash SHELL=/rbin/menu SKEL=/etc/skel
8.1.7 :: /etc/inittab- ทำให้ Boot ไม่เข้า xwindows โดยแก้บรรทัดหนึ่ง - ที่อยู่ในแฟ้ม inittab เท่านั้นเอง # Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) #id:5:initdefault: id:3:initdefault:
Group 1: ควร config ได้ /etc/rc.d/rc.local :: คล้าย autoexec.bat สำหรับผม จะเพิ่มคำสั่ง ifconfig เพิ่ม ip (9.10) /etc/named.conf :: กำหนดเงื่อนไขเพิ่มเติมเรื่อง named /etc/rndc.conf :: กำหนดเงื่อนไขเพิ่มเติมเรื่อง NS control utility /etc/resolv.conf :: กำหนดว่า nameserver ตัวใดที่จะตีความ ip หรือ domain name ให้ /etc/httpd/conf/httpd.conf :: กำหนดค่าเกี่ยวกับการบริการ http เช่นกัน /etc/sysconfig/network-scripts/ifcfg-eth0 :: กำหนดค่าประกอบ card LAN /etc/security/limits.conf :: กำหนดข้อจำกัดให้กับผู้ใช้ ถ้าไม่แก้ ก็ไม่จำกัด /etc/php.ini :: กำหนดเกี่ยวกับภาษา PHP เช่น เดิม post_max_size = 8M พอไหมครับ /var/run/named :: ใน RH9 ผมต้องเปลี่ยนสิทธิ์ห้องนี้เป็น 777 จึงจะ start named สำเร็จ /etc/procmailrc :: กำหนดเงื่อนไขการกรอง e-mail เป็นด่านแรก Group 2 : ควรรู้จักไว้ /etc/crontab :: กำหนดโปรแกรมให้ประมวลผลตามช่วงเวลา แฟ้มนี้เก็บ config หลักของ crontab /etc/inittab :: กำหนดการเริ่มต้น ที่จะเข้าสู่ text mode หรือ graphic mode เป็นต้น /etc/rc.d/init.d :: ภายในห้องนี้เก็บ shell script ที่ใช้สั่ง ให้มีการทำงานเมื่อเปิดเครื่องไว้มาก /etc/named.custom :: ระบุว่า directory ที่เก็บแฟ้มเกี่ยวกับ named เก็บไว้ที่ใด /etc/login.defs :: กำหนดจำนวนเลข uid สูงสุด หรือค่าเริ่มต้นของผู้ใช้อีกหลายเรื่อง /etc/default/useradd :: กำหนดค่าเกี่ยวกับสมาชิกใหม่เมื่อใช้คำสั่ง useradd /etc/syslog.conf :: เก็บข้อกำหนดของบริการ syslog เพื่อใช้ตรวจร่องรอยของบริการต่าง ๆ แต่ใน ntsysv ต้องเปิดบริการ syslog ไว้ /etc/services :: แสดงเลข socket ทั้งหมดที่เปิดให้บริการ เลขใดมี # หมายถึงปิดบริการ /etc/protocols :: แสดงเลข protocol ทั้งหมดที่เปิดให้บริการได้ /etc/login.defs :: กำหนดหมายเลขสูงสุด และต่ำสุด สำหรับการ assign acccount ใหม่ให้กับ user /etc/skel/.bash_profile :: แฟ้มนี้ถูกคัดลอกไปให้ผู้ใช้ เพื่อเป็นค่าเริ่มต้นในการทำงาน /etc/sysconfig/hwconf :: เก็บรายละเอียด และข้อกำหนดเกี่ยวกับ hardware มักถูก update โดย kudzu /var/log :: เก็บ log ต่าง ๆ Group 3 : ไม่พบในเครื่องที่ผมลง /etc/inetd.conf :: ใช้กำหนดการเปิดปิดบริการเช่น finger หรือ telnet เป็นต้น /etc/httpd/conf/srm.conf :: กำหนดค่าเกี่ยวกับการบริการ http เช่นกัน /etc/httpd/conf/access.conf :: กำหนดค่าเกี่ยวกับการบริการ http เช่นกัน /usr/X11R6/bin/startx :: สั่ง start x windows จาก text mode