3/27/08

Talk to asterisk with Asterisk-java

I just found the java way to talk to my trixbox. With Asterisk-java you can handle call from asterisk server via the FastAGI protocal, use the Manager api to connect to Asterisk server, send action and handle event. Last the Live api instead of using actions and events like the Manager api it use active domain objects (live objects) that represent Asterisk concepts like a channel or an extension.

more example on tutorial page.

3/26/08

Adding ip address on trixbox[without X]

On Ubuntu, to manage ip address of the box in console, we need to edit /etc/network/interfaces. By default ubuntu is set to using dhcp as you will see.

auto eth0
iface eth0 inet dhcp

changing "dhcp" to "static" and add network information
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

will change the box to use static ip address. Adding more ip address on this interface can be done by add script below to the same "interfaces" file.[note that we have :1 after eth0]
auto eth0:1
iface eth0:1 inet static
address 192.168.1.109
netmask 255.255.255.0
broadcast 192.168.1.255

Trixbox use centos. Like other redhat family, it has system-config-network utility or if you want to play with the configuration file, adding ip address is done by create new file in /etc/sysconfig/network-scripts like in mycase. I have external static ip address define in ifcfg-eth0.
[trixbox1.localdomain ~]# cd /etc/sysconfig/network-scripts
[trixbox1.localdomain network-scripts]# ls ifcfg-eth0
ifcfg-eth0
[trixbox1.localdomain network-scripts]#

Now, I want to add new internal ip to this interface so I create a new file call "ifcfg-eth0:1" by copy from "ifcfg-eth0".
[trixbox1.localdomain network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1
[trixbox1.localdomain network-scripts]#

then modify "ifcfg-eth0:1" made it look like this.
[trixbox1.localdomain network-scripts]# cat ifcfg-eth0:1
DEVICE=eth0:1
BOOTPROTO=none
IPADDR=192.168.1.123
NETMASK=255.255.255.0
TYPE=Ethernet
[trixbox1.localdomain network-scripts]#

last restart network service and check the result.
[trixbox1.localdomain network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[trixbox1.localdomain network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:E0:4C:84:26:BB
.....

eth0:1 Link encap:Ethernet HWaddr 00:E0:4C:84:26:BB
inet addr:192.168.1.123 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:11 Base address:0xe000

lo Link encap:Local Loopback
.....

[trixbox1.localdomain network-scripts]#

3/21/08

R4FXO card Installation note

Last year I have played with trixbox for two week and leave it sit under my desk for a long time. Last week I just got a new card to play with. It's Rhino R4FXO[4 FXO ports]. My goal now is make trixbox know the card and config it properly. I start with reinstall trixbox with the almost latest version[trixbox ce 2.4.2]. Upgrade all packages[Include zaptel driver 1.4.9.2-4]

note: this zaptel driver is not work with current rhino driver in repos[for now 21/03/08]. It need to manual download the driver and install from console[more detail]

After base system is ready. Install R4FXO card.
1. Shutdown the box.
2. Put R4FXO card to the pci slot.

Boot trixbox again and run command 'genzaptelconf' to generate configuration files automatically. The config file is '/etc/zaptel.conf' and '/etc/asterisk/zapata-chanels.conf'. mine is look like this.

[trixbox1.localdomain ~]# cat /etc/asterisk/zapata-channels.conf
; Autogenerated by /usr/sbin/genzaptelconf -- do not hand edit
; Zaptel Channels Configurations (zapata.conf)
;
; This is not intended to be a complete zapata.conf. Rather, it is intended
; to be #include-d by /etc/zapata.conf that will include the global settings
;

; Span 1: Rhino RCB4FXO/1 "Rhino RCB4FXO/1" (MASTER)
;;; line="1 FXO/1/0 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 1
context=default

;;; line="2 FXO/1/1 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 2
context=default

;;; line="3 FXO/1/2 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 3
context=default

;;; line="4 FXO/1/3 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 4
context=default

[trixbox1.localdomain ~]# cat /etc/zaptel.conf
# Autogenerated by /usr/sbin/genzaptelconf -- do not hand edit
# Zaptel Configuration File
#
# This file is parsed by the Zaptel Configurator, ztcfg
#

# It must be in the module loading order


# Span 1: Rhino RCB4FXO/1 "Rhino RCB4FXO/1" (MASTER)
fxsks=1
fxsks=2
fxsks=3
fxsks=4

# Global data

loadzone = us
defaultzone = us
[trixbox1.localdomain ~]#
note that from zapata-channels.conf I have 1 group call group0 compose of channel "1","2","3" and "4". [These channels and group are used when creat trunk]

reload new configuration and see the result by 'ztcfg -vvv'.
[trixbox1.localdomain ~]# ztcfg -vvv

Zaptel Version: 1.4.9.2-
Echo Canceller: Oslec
Configuration
======================


Channel map:

Channel 01: FXS Kewlstart (Default) (Slaves: 01)
Channel 02: FXS Kewlstart (Default) (Slaves: 02)
Channel 03: FXS Kewlstart (Default) (Slaves: 03)
Channel 04: FXS Kewlstart (Default) (Slaves: 04)

4 channels to configure.

[trixbox1.localdomain ~]#
From above message all 4 channels are configured as FXS_KS signaling, that means they will act as FXO ports.

Use 'zttool' command to check status of R4FXO.

Adding these two properties in the /etc/asterisk/zapata.conf file under the [channels] section will enable busy detect on the system.
busydetect=yes
busycount=5

and that's it. next thing to do is create a zap trunk to connect outside world.

3/18/08

Shadow Text Effect on JLabel

I found the trick to create shawdow text on JLabel from java forum. Instead of use JLabel.setText() set string to JLabel, he create Image and get Graphics2D by Image.createGraphics(). Then use TextLayout draw overlapping string on that Graphics2D.
example code

        int w = 500;
int h = 120;
Font font = new Font("Lucida Bright", Font.ITALIC, 72);
String text = "Shadow Text";

BufferedImage image = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
adjustGraphics(g);

//start off all white:
g.setPaint(Color.WHITE);
g.fillRect(0, 0, w, h);

//draw "shadow" text: to be blurred next
TextLayout textLayout = new TextLayout(text, font, g.getFontRenderContext());
g.setPaint(new Color(128,128,255));
textLayout.draw(g, 15, 105);
g.dispose();

//blur the shadow: result is sorted in image2
float ninth = 1.0f / 9.0f;
float[] kernel = {ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth};
ConvolveOp op = new ConvolveOp(new Kernel(3, 3, kernel), ConvolveOp.EDGE_NO_OP, null);
BufferedImage image2 = op.filter(image,null);

//write "original" text on top of shadow
Graphics2D g2 = image2.createGraphics();
adjustGraphics(g2);
g2.setPaint(Color.BLACK);
textLayout.draw(g2, 10, 100);
....
private void adjustGraphics(Graphics2D g) {
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}


Last use JLabel.setIcon(new ImageIcon(image2)) to display text with a shadow. Lower label is created by method show here, the result is look very good to me.

3/14/08

using Class.getResource() load resource file in Eclipse

There are many ways to load resource file in java app. What sun recommended is using Class.getResource("resource_name") or Class.getResourceAsStream("resource_name") then you will get URL and InputStream respectively. If resource_name is specified without "/", it will be prepend with Class package. So resource file must be in same place[folder structure] as the Class. What I love to do is call getResource() with "/" and put resource file at the root of package. This way i can have separate resource folder. below is in Eclipse,

1. From Package explorer right click src folder->click import
2. In import dialog, Choose General->File System ->next
3. from directory:->Browse to your resource folder.
4. to folder:-> I add "resource" as a folder name under src folder. then click "Finish".

In the code, load resource with

this.getClass().getResource("/resource/buttons1.png")
or
this.getClass().getResourceAsStream("/resource/TX_Jello2.ttf")

3/9/08

tinymce_imce.patch fixing browse button not showing up

Few week ago, I get tinymce module work on my new site. When I create new content and want to add the picture. Tinymce allow me only add url for an image. Anyway I found another module called IMCE. It work together with tinymce and allow me to upload image from my computer.

After installation, I can't see browse button when click add image??? my environments is (Drupal5.7+TinyMCE5.x-1.9+TinyMCE3.0+IMCE5.x-1.0). Many post tell me to add

<?php print $closure;?>
to page.tpl.php file, that not work for me. mine already have it.

Today I found the patch from here. It work well for my case. To apply patch[I do this on my local box then upload tinymce.module and imce_set_tinymce.js to host]
pnix@pnix-a7n:drupal$ ls
imce tinymce tinymce-5.x-1.9.tar.gz
imce-5.x-1.0.tar.gz tinymce_3_0_1.zip tinymce_imce.patch
pnix@pnix-a7n:drupal_modules$ patch -p0<tinymce_imce.patch
patching file tinymce/tinymce.module
patching file imce/imce_set_tinymce.js
pnix@pnix-a7n:drupal_modules$

here is my 'insert image popup' after patch.

3/4/08

Changing partition label on Ubuntu

I found this howto from community docs while searching for rename my usb drive. Not many times you need to do this but if you want, here is the summary.

You need few programs depends on the your partition type.
mtools for fat32
ntfsprogs for ntfs
e2label for ext2 or ext3
reiserfstune for reiserfs(v3)
Install which you need by 'sudo aptitude install [program name]'

note : check your partition type by 'mount' or 'df -T'.
For me, my usb is fat32 changing label is done by

pnix@pnix-a7n:~$ sudo mlabel -i /dev/sdb ::myusbdrive
pnix@pnix-a7n:~$
upper command, I just change label to 'myusbdrive'. for other partition types, below are some examples.
sudo ntfslabel /dev/sda1 newlabel
sudo e2label /dev/sda1 newlabel
sudo reiserfstune -l newlabel /dev/sda1



update [many thanks for comment]: for ext2/ext3 you also can use tune2fs like this
sudo tune2fs -L newlabel /dev/sda1

note : may be it's need to umount device before try changing label to get it work.
To get effect for internal drive it's need reboot, for usbdrive I need just unplug/plug.

Change /dev/xxx to match your drive.