Internet

You are currently browsing the articles from KomKid.Net matching the category Internet.

Centralized Log ภาคที่ 1 : NTP

ติดตั้ง NTP (Network Time Protocol)
ตาม พรบ.ว่าด้วยการกระทำผิดเกี่ยวกับคอมพิวเตอร์ พ.ศ. 2550 กำหนดให้ ต้องตั้งนาฬิกาของอุปกรณ์บริการทุกชนิดให้ตรงกับเวลาอ้างอิงสากล (Stratum 0) โดยผิดพลาดไม่เกิน 10 มิลลิวินาที
1.ติดตั้ง apt-get install ntp (ที่ Log Server และ Server อื่น ๆ)
2.ตั้งค่า Log Server (/etc/ntp.conf)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

#statistics loopstats peerstats clockstats
#filegen loopstats file loopstats type day enable
#filegen peerstats file peerstats type day enable
#filegen clockstats file clockstats type day enable

# You do need to talk to an NTP server or two (or three).
server 203.185.69.60 dynamic
server time.navy.mi.th dynamic
server time.nist.gov dynamic
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
broadcastdelay 0.008
keys /etc/ntp/keys

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestric$
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
#restrict -4 default kod notrap nomodify nopeer noquery
restrict default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
#restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

3. ตั้งค่า Server อื่น ๆ ที่เป็น linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

#statistics loopstats peerstats clockstats
#filegen loopstats file loopstats type day enable
#filegen peerstats file peerstats type day enable
#filegen clockstats file clockstats type day enable

# You do need to talk to an NTP server or two (or three). (192.168.0.251 is Log Server)
server 192.168.0.251

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
#restrict -4 default kod notrap nomodify nopeer noquery
#restrict -6 default kod notrap nomodify nopeer noquery
restrict default ignore

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
#restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated. (192.168.0.251 is Log Server)
restrict 192.168.0.251 mask 255.255.255.255 nomodify notrap noquery

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

ทดสอบ

# ntpq -pn
# ntpdc
ntpdc>sysinfo

3. ตั้งค่าเครื่องอื่น ๆ ที่เป็น Windows โดยใช้ regedit.exe (save เป็น . reg แล้ว double click)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config]
"AnnounceFlags"=dword:00000005
"MaxNegPhaseCorrection"=dword:00000e10
"MaxPosPhaseCorrection"=dword:00000e10
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters]
"NtpServer"="192.168.0.251,0x1"
"Type"="NTP"
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient]
"SpecialPollInterval"=dword:00000384
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer]
"Enabled"=dword:00000001

restart service w32time

:\>net stop w32time
:\>net start w32time

ทดสอบ

:\>net time
:\>net time /querysntp

Written by Komkid on November 22nd, 2009 with no comments.
Read more articles on Admin and Internet and Networking and Ubuntu.

GeSHi Language Aliases

ทั้ง phpBB ของที่ทำงานและ wordpress ของที่นี่ ต่างก็ใช้ Syntax Hilight ของ GeSHi
โดย phpBB เป็น phpBB3.0.5 ติดตั้ง mod bbGeSHi 0.7.5
และ wordpress ใช้ plugin wp-syntax.0.9.8
เวลาใช้มักจะลืมตัวย่อของภาษาอยู่เรื่อย ก็เลยต้อง list ไว้กันลืมซะหน่อย
ABAP – abap
Actionscript – actionscript
ADA – ada
Apache Log – apache
AppleScript – applescript
APT sources.list
ASM (m68k) – asm
ASM (pic16) – asm
ASM (x86) – asm
ASM (z80) – asm
ASP – asp
AutoIT – autoit
Backus-Naur form
Bash – bash
Basic4GL
BlitzBasic – blitzbasic
Brainfuck – bnf
C – c
C for Macs – c_mac
C# – cpp
C++ – csharp
C++ (with QT) – cpp-qt
CAD DCL – caddcl
CadLisp – cadlisp
CFDG – cfdg
CIL / MSIL
COBOL
ColdFusion – cfm
CSS – css
D – d
Delphi – delphi
Diff File Format – diff
DIV – div
DOS – dos
DOT language – dot
Eiffel – eiffel
Fortran – fortran
FourJ’s Genero – genero
FreeBasic – freebasic
GetText
glSlang
GML – gml
gnuplot
Groovy – groovy
Haskell – haskell
HQ9+
HTML – html, html4strict
INI (Config Files) – ini
Inno – inno
INTERCAL
IO – io
Java – java
Java 5 – java5
Javascript – javascript, js
KiXtart
KLone C & C++
LaTeX – latex
Lisp – lisp
LOLcode
LotusScript
LScript
Lua – lua
Make – m68k
mIRC – mirc
MXML
MySQL – mysql
NSIS – nsis
Objective C – objc
OCaml – Ocaml-brief, ocaml
OpenOffice BASIC – oobas
Oracle 8 & 11 SQL – oracle8
Pascal – pascal
Perl – perl
PHP – Php-brief, php
Pixel Bender
PL/SQL – plsql
POV-Ray
PowerShell
Progress (OpenEdge ABL)
Prolog
ProvideX
Python – python
Q(uick)BASIC – qbasic
robots.txt – robots
Ruby – ruby
Ruby on Rails – rails
SAS – sas
Scala
Scheme – scheme
Scilab
SDLBasic – sdlbasic
Smalltalk – smalltalk
Smarty – smarty
SQL – sql
T-SQL – tsql
TCL – tcl
thinBasic – thinbasic
TypoScript
Uno IDL
VB.NET – vbnet
Verilog
VHDL – vhdl
VIM Script
Visual BASIC – vb
Visual Fox Pro – visualfoxpro
Visual Prolog
Whitespace
Winbatch – winbatch
Windows Registry Files – reg
X++ – xpp (มี X++ ของ Axapta ด้วย)
XML – xml, xsl
Xorg.conf

Written by Komkid on October 4th, 2009 with no comments.
Read more articles on Admin and Internet.

noknok.in.th API #05 Direct Message

มาต่อกันด้วยการส่งตรง Message ถึงเพื่อนที่เราต้องการ

URL: http://api.noknok.sanook.com/rest/direct_message_new
Format: xml
Method(s): POST
Parameters:
* authToken (required:GET)
* message (required:POST)
* message_to (required:POST)
Return:
* Sending status (true or false)

ก็เอา code เดิมมาแก้ไข form นิดหน่อย

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$base         = 'http://api.noknok.sanook.com/rest/auth';
$query_string = 'username=komkid&password=******';
 
$url = "$base?$query_string";
 
$xml = file_get_contents($url);
$dom = new DOMDocument('1.0', 'UTF-8');
if ($dom->loadXML($xml) === false) {
   die('Parsing failed');
}
 
$res = xml_to_result($dom);
if($res["stat"] == "ok"){
  $query_string = 'authToken='.$res["authToken"];
  $str=     " Send Direct Message <br>";
  $str.=    "<form method=\"post\" action=\"http://api.noknok.sanook.com/rest/direct_message_new?$query_string\">";
  $str.=    "message : <input type=\"text\" name=\"message\"><br>";
  $str.=    "send to : <input type=\"text\" name=\"message_to\"><br>";
  $str.=    "<input type=\"submit\" value=\"send\">";
  $str.=    "</form>";
  echo $str;
}

ได้ form ดังรูป
noknok_api_direct_message_form

แล้วก็ได้ผลดังนี้

noknok_api_direct_message_ok

Written by Komkid on February 24th, 2009 with no comments.
Read more articles on Internet and Programming.

noknok.in.th API #04 Update Status

มาต่อกันด้วย การ Update Status ของเราด้วย

new
URL: http://api.noknok.sanook.com/rest/message_new
Format: XML
Method(s): GET, POST
Parameters:
* authToken (required:GET)
* message (required:POST)
Return
* Sending message data

(ผ่านไปไม่กี่วัน URL เปลี่ยนซะแล้ว จาก http://api.noknok.in.th/rest/ เป็น http://api.noknok.sanook.com/rest)

ซึ่งคราวนี้จะต้องส่งแบบ POST เพราะฉะันั้นก็ต้องสร้าง FORM ไว้ส่ง
ก็เอาแบบง่าย ๆ นะครับ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$base         = 'http://api.noknok.sanook.com/rest/auth';
$query_string = 'username=komkid&password=******';
 
$url = $base.'?'.$query_string;
 
$xml = file_get_contents($url);
$dom = new DOMDocument('1.0', 'UTF-8');
if ($dom->loadXML($xml) === false) {
   die('Parsing failed');
}
 
$res = xml_to_result($dom);
if($res[stat] == 'ok'){
    $query_string = 'authToken='.$res[authToken];
    $str=<<<FORM
    Update Status <br>
    <form method="post" action="http://api.noknok.sanook.com/rest/message_new?$query_string">
    message : <input type="text" name="message"><br>
    <input type="submit" value="update">
    </form>

    FORM;
    echo $str;
}

noknok_update_status
ได้ผลดังรูป
noknok_update_status_ok

อ้อ อย่าลืมตั้งค่า Encoding เป็น UTF8 ด้วยนะครับ

Introduction
API Protocol
* Representational_State_Transfer(REST)
* HTTP Requests: Post and GET
Data Format
* XML, *Json, *RSS,*ATOM
Encoding
* UTF8

Written by Komkid on February 23rd, 2009 with no comments.
Read more articles on Internet and Programming.

noknok.in.th API #03 Profile

มาต่อกันด้วย Profile ครับท่าน

URL: http://api.noknok.in.th/rest/profile
Format: xml
Method(s): GET
Parameters:
* authToken (required)
Return:
* User’s profile data

เริ่มด้วยการลองคลิกเข้าไปแบบตอนที่ Authen แต่คราวนี้กลับได้ผลดังรูป
noknok_api_profile_fail

แสดงว่าต้องเริ่มสื่อสารกันเป็นจริงเป็นจังแล้วล่ะ
ตามคู่มือที่เค้าบอกก็คือ format ของการสื่อสารกัน ก็คือ xml
ดังนั้นก็เลยต้องเลือกวิธีที่จะใช้ ซึ่งผมเลือกใช้ DOM ก็จัดการหา function มาใช้งานสำหรับดึงค่าจาก xml มาใช้

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function xml_to_result($dom) {
   $root = $dom->firstChild;
   foreach($root->attributes as $attr) $res[$attr->name] = $attr->value;
   $node = $root->firstChild;
   $i = 0;
   while($node) {
      switch($node->nodeName) {
         case 'Result':
         $subnode = $node->firstChild;
         while($subnode) {
            $subnodes = $subnode->childNodes;
            foreach($subnodes as $n) {
               if($n->hasChildNodes()) {
                  foreach($n->childNodes as $cn) $res[$i][$subnode->nodeName][$n->nodeName]=trim($cn->nodeValue);
               } else $res[$i][$subnode->nodeName]=trim($n->nodeValue);
            }
            $subnode = $subnode->nextSibling;
         }
         break;
         default:
         $res[$node->nodeName] = trim($node->nodeValue);
         $i--;
         break;
      }
      $i++;
      $node = $node->nextSibling;
   }
   return $res;
}

จากนั้นก็ทำการ authen ก่อน เพราะเจ้า profile นี่มันต้องการ authToken ซึ่งจะได้มาจากเจ้า auth อีกที ดังนี้

1
2
3
4
5
6
7
$base         = 'http://api.noknok.in.th/rest/auth';
$query_string = 'username=komkid&password=******';

$url = "$base?$query_string";

$xml = file_get_contents($url);
echo $xml;

ซึ่งก็ได้ผลดังนี้
noknok_api_profile_ok

แล้วก็ตามด้วยการขอดู profile ด้วย code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$base         = 'http://api.noknok.in.th/rest/auth';
$query_string = 'username=komkid&password=******';

$url = "$base?$query_string";

$xml = file_get_contents($url);
$dom = new DOMDocument('1.0', 'UTF-8');
if ($dom->loadXML($xml) === false) {
   die('Parsing failed');
}

$res = xml_to_result($dom);
if($res["stat"] == "ok"){
    $base         = 'http://api.noknok.in.th/rest/profile';
    $query_string = 'authToken='.$res["authToken"];

    $url = "$base?$query_string";
    $xml = file_get_contents($url);
    echo $xml;
}

ซึ่งก็ได้ผลดังรูปครับ
noknok_api_profile_result

หรือจะจัดรูปแบบในการแสดงผลซะหน่อยด้วย code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$base         = 'http://api.noknok.in.th/rest/auth';
$query_string = 'username=komkid&password=******';

$url = "$base?$query_string";

$xml = file_get_contents($url);
$dom = new DOMDocument('1.0', 'UTF-8');
if ($dom->loadXML($xml) === false) {
   die('Parsing failed');
}

$res = xml_to_result($dom);
if($res["stat"] == "ok"){
    $base         = 'http://api.noknok.in.th/rest/profile';
    $query_string = 'authToken='.$res["authToken"];

    $url = "$base?$query_string";
    $xml = file_get_contents($url);
   
    $dom = new DOMDocument('1.0', 'UTF-8');
    if ($dom->loadXML($xml) === false) {
       die('Parsing failed');
    }

    $res = xml_to_result($dom);
    echo "name : ".$res["name"]."<br>";
    echo "story: ".$res["story"]."<br>";
    echo "homepage : ".$res["homepage"]."<br>";
    echo "image : <img src=".$res["profile_image_url"].">";
}

ก็ได้ผลดังรูป
noknok_api_profile_show

Written by Komkid on February 19th, 2009 with no comments.
Read more articles on Internet and Programming.

« Older articles

Newer articles »