เอามาจาก debian : ทดลองติดตั้ง hylafax
ต้องมีเซิร์ฟเวอร์ที่เป็น HylaFAX แล้ว ดูวิธีติดตั้งได้จากคราวก่อน
ติดตั้ง Pyla
$ sudo aptitude install python python-tk
$ wget http://www.teamsw.it/pyla/download/pyla1.1.7.1.tgz
$ tar xfz pyla1.1.7.1.tgz
$ sudo mv pyla /usr/local
$ /usr/local/pyla/pyla.py
-> ปรับตั้งโปรแกรม
ติดตั้งเครื่องพิมพ์เทียมให้ pyla
เอามาจาก Fun with CUPS and Pyla
หลักการคือเขาใช้ perl เขียนโปรแกรมทำหน้าที่เป็น socket คอยดูว่ามีข้อมูลเข้ามาทางพอร์ต 5691 หรือเปล่า ถ้ามี ก็จะเรียกใช้โปรแกรมนี้ซึ่งจะไปเรียกใช้ pyla อีกทีนึง
สร้างโปรแกรมเรียก pyla ชื่อ pyla-print เอาใส่ไว้ใน /usr/local/bin
$ sudo vi /usr/local/bin/pyla-print
#!/usr/bin/perl
# Daniel E. Markle
# 20031114 Revision 0.1
# This program starts up a daemon which will watch for a postscript file
# coming in from CUPS, then launch pyla to send it as a fax.
# Use it with the socket://localhost:5691 URL in cups.
# Issues:
# -security, make sure only localhost can see this port, it allows anyone
# who can stream data to this port to popup pyla on your desktop
# -must be ran as the user or the window may not pop up at the right
# place, if at all
# ***CONFIGURE ME HERE
# Port to listen on, use socket://localhost: in cups
my $MY_PORT = 5691;
# Temporary file storage, this is a file not a folder
my $TMP_FILE_NAME = "/tmp/cupsfaxtemp";
# Path to pyla.py
my $PYLA_PATH = "/usr/local/pyla/pyla.py";
# Path to python binary
# use this one for Linux
my $PYTHON_PATH = "/usr/bin/python";
# use this one for OS X
#my $PYTHON_PATH = "/usr/bin/pythonw";
# ***END CONFIGURATION
# ----- You shouldn't need to touch anything beyond this point -----
use IO::Socket::INET;
# check to make sure we can use the temp file
open ( TMPFILE, ">", $TMP_FILE_NAME )
or die "Can not open temp file $TMP_FILE_NAME, " .
"check to make sure it is not owned by another user";
close ( TMPFILE );
if ( !(-e $PYLA_PATH) ) {
die "I do not see pyla at $PYLA_PATH";
}
my $data;
my $server = IO::Socket::INET->new (
LocalPort => $MY_PORT,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 1
) or die "Could not start server process";
while ( my $job = $server->accept() ) {
open ( TMPFILE, ">", $TMP_FILE_NAME );
while ( <$job> ) {
print TMPFILE $_;
}
close ( TMPFILE );
close $job;
`cat "$TMP_FILE_NAME" | "$PYTHON_PATH" "$PYLA_PATH" -i`
}
ทำให้รันได้
$ sudo chmod 755 /usr/local/bin/pyla-print
สร้างโปรแกรมที่รันเป็น daemon คอยดูซอกเก็ต ชื่อ pyla-printd เอาใส่ไว้ใน /etc/init.d
$ sudo vi /etc/init.d/pyla-printd
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/pyla-print
NAME=pyla-print
DESC="Pseudo printer for Pyla"
test -x $DAEMON || exit 0
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--background --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--oknodo
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--oknodo
sleep 1
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--background --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
ทำให้รันได้ - สั่งรันเป็น daemon และให้เริ่มรันทุกครั้งที่เปิดเครื่อง
$ sudo chmod 755 /etc/init.d/pyla-printd
$ sudo /etc/init.d/pyla-printd restart
$ sudo update-rc.d pyla-printd defaults
ติดตั้งตัวจัดการเครื่องพิมพ์
$ sudo aptitude install cupsys-client
เพิ่มเครื่องพิมพ์เทียมให้ระบบ
$ sudo lpadmin -p pseudo-pyla -E -v socket://localhost:5691
หรือตั้งชื่อให้เรียกง่ายขึ้นว่า hylafax เฉย ๆ ก็ได้
$ sudo lpadmin -p hylafax -E -v socket://localhost:5691
เมื่อทุกอย่างเรียบร้อย จะมีเครื่องพิมพ์ฃื่อ psuedo-pyla ขึ้นมา ถ้าเราพิมพ์มาที่เครื่องพิมพ์ตัวนี้ เขาจะมาเรียกใช้ pyla ให้ส่งแฟกซ์เอง
update
# vi /etc/hylafax/config.ttyS0
... RecvFileMode: 0666 ...
ปรับปรุง HylaFax Client
ปรับปรุงจากdebian: ทดลองทำ HylaFAX Client
ครั้งก่อนมีปัญหาว่า daemon ถูกรันด้วย root ใน runlevel ที่อยู่ในสถานะอักขระ (text mode) ซึ่งยังไม่มีการกำหนดค่าตัวแปรแวดล้อม $DISPLAY
แต่เวลาซอกเก็ตถูกเรียกใช้ จะถูกเรียกใช้ด้วยผู้ใช้ที่ runlevel ที่อยู่ในสถานะกราฟฟิก โดย gtk จะมาดูว่าต้องแสดงผลที่จอไหนจากตัวแปรแวดล้อม $DISPLAY นี้ ทำให้โปรแกรมตาย
ซึ่งต้องแก้ปัญหาด้วยการใช้คำสั่ง $ sudo /etc/init.d/pyla-printd restart จากเทอร์มินอล จึงจะหาย
ตอนใหม่นี้ เราจะไม่ตั้งให้เรียกจาก runlevel แล้ว แต่จะตั้งให้รันจาก gnome-session ของผู้ใช้เลย ทำให้แก้ปัญหาเรื่องต้องเริ่มเซอร์วิสใหม่ได้
แต่เพื่อป้องกันการสับสน จะขอเริ่มใหม่เลย
ต้องมีเซิร์ฟเวอร์ที่เป็น HylaFAX แล้ว ดูวิธีติดตั้งได้จากdebian: ลองติดตั้ง Hylafax
ติดตั้ง Pyla
$ sudo aptitude install python python-tk
$ wget http://www.teamsw.it/pyla/download/pyla1.1.7.1.tgz
$ tar xfz pyla1.1.7.1.tgz
$ sudo mv pyla /usr/local
$ /usr/local/pyla/pyla.py
-> ปรับตั้งโปรแกรม
ติดตั้งเครื่องพิมพ์เทียมให้ pyla
เอามาจาก Fun with CUPS and Pyla
หลักการคือเขาใช้ perl เขียนโปรแกรมทำหน้าที่เป็น socket คอยดูว่ามีข้อมูลเข้ามาทางพอร์ต 5691 หรือเปล่า ถ้ามี ก็จะเรียกใช้โปรแกรมนี้ซึ่งจะไปเรียกใช้ pyla อีกทีนึง
สร้างโปรแกรมเรียก pyla ชื่อ pyla-print เอาใส่ไว้ใน /usr/local/bin
$ sudo vi /usr/local/bin/pyla-print
#!/usr/bin/perl
# Daniel E. Markle
# 20031114 Revision 0.1
# This program starts up a daemon which will watch for a postscript file
# coming in from CUPS, then launch pyla to send it as a fax.
# Use it with the socket://localhost:5691 URL in cups.
# Issues:
# -security, make sure only localhost can see this port, it allows anyone
# who can stream data to this port to popup pyla on your desktop
# -must be ran as the user or the window may not pop up at the right
# place, if at all
# ***CONFIGURE ME HERE
# Port to listen on, use socket://localhost: in cups
my $MY_PORT = 5691;
# Temporary file storage, this is a file not a folder
my $TMP_FILE_NAME = "/tmp/cupsfaxtemp";
`touch "$TMP_FILE_NAME"; chmod 777 "$TMP_FILE_NAME"`;
# Log file storage
my $LOG_FILE_NAME = "/tmp/cupsfaxlog";
`touch "$LOG_FILE_NAME"; chmod 777 "$LOG_FILE_NAME"`;
# Path to pyla.py
my $PYLA_PATH = "/usr/local/pyla/pyla.py";
# Path to python binary
# use this one for Linux
my $PYTHON_PATH = "/usr/bin/python";
# use this one for OS X
#my $PYTHON_PATH = "/usr/bin/pythonw";
# ***END CONFIGURATION
# ----- You shouldn't need to touch anything beyond this point -----
use IO::Socket::INET;
# check to make sure we can use the temp file
open ( TMPFILE, ">", $TMP_FILE_NAME )
or die "Can not open temp file $TMP_FILE_NAME, " .
"check to make sure it is not owned by another user";
close ( TMPFILE );
if ( !(-e $PYLA_PATH) ) {
die "I do not see pyla at $PYLA_PATH";
}
my $data;
my $server = IO::Socket::INET->new (
LocalPort => $MY_PORT,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 1
) or die "Could not start server process";
while ( my $job = $server->accept() ) {
open ( TMPFILE, ">", $TMP_FILE_NAME );
while ( <$job> ) {
print TMPFILE $_;
}
close ( TMPFILE );
close $job;
`cat "$TMP_FILE_NAME" | "$PYTHON_PATH" "$PYLA_PATH" -i &> "$LOG_FILE_NAME"`;
}
ทำให้รันได้
$ sudo chmod 755 /usr/local/bin/pyla-print
ตั้งให้ gnome-sessions รัน pyla-print
ทำผ่านเมนู System -> Preferences -> Sessions
แท็บ Startup Programs กดปุ่ม Add
Name: Pyla Print Daemon Command: /usr/local/bin/pyla-print Comment: Pyla Print Daemon (start by gnome-sessions)
ล๊อกเอาต์ และ ล๊อกอิน 1 ครั้ง
จัดการให้โปรแกรมตายตอนล๊อกเอาต์
เมนู System -> Preferences -> Sessions
แท็บ Current Sessions เลือกบรรทัดที่เป็น pyla-print
เปลี่ยนปุ่ม Style เป็น Restart
เสร็จแล้ว
ติดตั้งตัวจัดการเครื่องพิมพ์
$ sudo aptitude install cupsys-client
เพิ่มเครื่องพิมพ์เทียมให้ระบบ ตั้งชื่อว่า hylafax
$ sudo lpadmin -p hylafax -E -v socket://localhost:5691
เมื่อทุกอย่างเรียบร้อย จะมีเครื่องพิมพ์ฃื่อ hylafax ขึ้นมา ถ้าเราพิมพ์มาที่เครื่องพิมพ์ตัวนี้ เขาจะมาเรียกใช้ pyla ให้ส่งแฟกซ์เอง
เพิ่มเติม
/usr/local/pyla/hylaproto.py$ sudo vi /usr/local/pyla/hylaproto.py
...
class Hylafax:
...
def getqueue(self,queue,jfmt=JFMT,view='priv'):
...
else:
retlist[-1] = retlist[-1] + l + '\n'
#wd's
retlist.sort(reverse=True)
return (1,retlist)
def callback(self,str):
...