Showing posts with label Opensource. Show all posts
Showing posts with label Opensource. Show all posts

Monday, November 17, 2008

ERP on a Flash.. in a Flash

My sister is wishing for a software to help her manage the raw materials inventory of her new bakery franchise. I think I'm going to end up as her Santa this year...

Lots of ERP heavyweights abound the opensource community.. but I want something lighter. Something that can fit in a USB flash drive and delivered in a pouch -- an ERP on a Flash!

And here's my magic combo: TinyERP 4.2.2 + Ubuntu Intrepid Ibex + 2GB Imation NanoDrive.

TinyERP is included in the Ubuntu repositories -- a promise of painless installation via a series of apt-gets. PendriveLinux.com has lots of guides on how to install Linux on a USB flash drive. I favored the Ubuntu 8.10 install using the built-in USB installer. This method provides a persistence feature allowing you to save the changes on subsequent boots.

Once Ubuntu is installed and booted up, we need to issue a sudo apt-get update command in order to synchronize the package index files from their sources. But before doing that, let's edit the list of apt sources via the command sudo vi /etc/apt/sources.list. Uncomment the deb entry for the intrepid universe repository --- the TinyERP packages are contained here. Save the changes and issue the following commands to download the desired packages:

sudo apt-get update
sudo apt-get install tinyerp-server
sudo apt-get install tinyerp-client


At this point, the Postgres database server and client should be installed and two new accounts (postgres and terp) created. We still need to create the terp database and user...

sudo /etc/init.d/postgresql* restart
sudo su - postgres -c "createdb -q --encoding=UNICODE terp"
sudo su - postgres -c "createuser -q --createdb --adduser terp"

..and restart the TinyERP server.

sudo /etc/init.d/tinyerp-server restart


Press Alt-F2 and select Tiny ERP Client from the list of known applications. You can view the User Manual here .

TinyERP is re-branding itself and is now known as OpenERP.

Tuesday, April 22, 2008

OpenID login for Knowledgetree

I have replaced (not integrated) KnowledgeTree authentication with OpenID. Supporting both default and OpenID authentication requires more work and that can come later.

This is by no means final since only limited testing has been performed so far. I've decided to post this in its raw form so I can solicit comments and suggestions from the community. And besides, my blog has not been updated for awhile now..

I'll detail the procedures here. I took notes but I may have missed something. Diligence is not one of my virtues..

  • Copy login.php to login-orig.php (save original, let's modify login.php)
  • Change template ktcore/login -> ktcore/openid
  • Copy ./templates/ktcore/login.smarty to openid.smarty
    - change invocation of stylesheet kt-login.css -> kt-openid.css
    - change the Username prompt label to OpenID
    - add class="openid" to input tag for username
    - change name="username" to name="openid_url"
    - remove the password input field

  • Download the OpenID logo
  • Upload logo as openid-bg.png to ./resources/graphics
  • Copy ./resources/css/kt-login.css to kt-openid.css
  • Add input.openid to kt-openid.css, as follows:
    input.openid {
    border: 1px solid #666;
    width: 232px;
    background: url(../graphics/openid-bg.png) no-repeat;
    padding-left: 18px;
    }
Note the OpenID logo in the input field. This is implemented by the input.openid section of the stylesheet. I also changed the input field name to openid_url in conformance to OpenID specifications. I'm using Verisign PIP as OpenID Identity Provider and the Seatbelt browser plug-in kicks in only when openid_url is used as identifier.

I installed version 2.x.x of the PHP OpenID Library, as follows:
  • Create the directory ./thirdparty/OpenID
  • Copy the file common.php found in the examples directory. Also copy the Auth directory from the library.
  • Add the following functions to common.php
    function fixslashes($s) {
    return get_magic_quotes_gpc() ? stripslashes($s) : $s;
    }

    function normOpenIDUrl($oid_url) {
    $claimed_id = strtolower (fixslashes($oid_url));
    $has_scheme = preg_match ('#^https\://#', $claimed_id) === 1;
    $has_scheme = $has_scheme || preg_match ('#^http\://#', $claimed_id) === 1;
    $has_tslash = preg_match ('#/$#', $claimed_id) === 1;
    return (($has_scheme?'':'http://') . $claimed_id . ($has_tslash?'':'/'));
    }
  • Overwrite the original functions in common.php with these
    function getReturnTo() {
    return sprintf("%s://%s:%s/login.php",
    getScheme(), $_SERVER['SERVER_NAME'],
    $_SERVER['SERVER_PORT']);
    }

    function getTrustRoot() {
    return sprintf("%s://%s:%s/",
    getScheme(), $_SERVER['SERVER_NAME'],
    $_SERVER['SERVER_PORT']);
    }
  • Change config/dmsDefaults.php to include the library in the path..
    $KTInit->prependPath(KT_DIR . '/thirdparty/OpenID');
The rest of the changes are in login.php, the source of which can be found here.

I've disabled automatic sign-up so make sure to create an OpenID account with Administrator privileges before you apply the changes. To prevent duplicate accounts, the usernames are OpenID URLs in normalized form (with leading http:// and trailing /). Thus, the username http://pipoltek.blogspot.com/ applies to any of the following acceptable OpenID identity URLs:
  • pipoltek.blogspot.com
  • http://pipoltek.blogspot.com
  • http://pipoltek.blogspot.com/
I've successfully authenticated using my OpenID accounts from Blogspot, Technorati and Verisign PIP. However, I had login failures using my Yahoo OpenID and a delegate identity URL.

My testbed:
  • VMWare Server version 1.0.4.56528
  • KnowledgeTree OSS 3.4.2 VM Appliance from rPath
  • Microsoft Windows XP Home Service Pack 2
  • Mozilla Firefox 2.0.0.14

Monday, January 21, 2008

A Tcl Web Service client for KnowledgeTree Document Management System

Sometime last year, I dabbled with KnowledgeTree's web services and (somehow I've forgotten why) I ended up with a Tcl client to perform a document upload.

Before I lose this chunk of code or forget about it altogether (and it happens a lot), I decided to post it here:


package require SOAP
package require http
package require TclCurl

set prx "http://192.168.211.128/ktwebservice/webservice.php"
set url "http://192.168.211.128/ktwebservice/upload.php"
set usr "admin"
set pas "admin"
set ipa "any"

set upf "upload-me.txt"
set typ "multipart/form-data"

proc log_it { chn msg } {
set stm [clock format [clock seconds] -format "%Y/%m/%d %H:%M:%S %a"]
puts $chn "$stm : $msg"
}

SOAP::create kt_login \
-proxy $prx \
-params { "username" "string" "password" "string" "ip" "string"} \
-name login
SOAP::create kt_add_document \
-proxy $prx \
-params { "session_id" "string" "folder_id" "int" "title" "string" "filename" "string" \
"documentype" "string" "tempfilename" "string" } \
-name add_document
SOAP::create kt_logout \
-proxy $prx \
-params { "session_id" "string"} \
-name logout

set log "debug.log"

if { [catch {open $log a} out] } {
puts stderr "Error: $out"
set out "stderr"
}

set rsp [kt_login $usr $pas $ipa]
set sta [lindex $rsp 1]
set ses [lindex $rsp 3]
log_it $out "Login: status ($sta); session ($ses)"

set opt "session_id $ses action A"
set crl [curl::init]
set rsp [$crl configure -url $url -bodyvar rsp -post 1 \
-httppost [list name "file1" file $upf contenttype $typ] \
-httppost [list name "session_id" contents $ses] \
-httppost [list name "action" contents A] \
-httppost [list name "output" contents php] \
]
catch { $crl perform } curlErrorNumber
if { $curlErrorNumber != 0 } {
error [curl::easystrerror $curlErrorNumber]
}
$crl cleanup

log_it $out "Upload: response ($rsp)"

set ps1 [string first "\"tmp_name\";s:" $rsp 0]
set ps2 [string first ":\"" $rsp [expr $ps1 + 12]]
set ps3 [string first "\";s:5:\"error\"" $rsp 0]
set tmp [string range $rsp [expr $ps2 + 2] [expr $ps3 - 1]]

# Define folder where to upload files
set fld 1;
set ttl "My Document";
set doc "Default"

set rsp [kt_add_document $ses $fld $ttl $upf $doc $tmp]
log_it $out "Add Document: response ($rsp)"

set rsp [kt_logout $ses]
log_it $out "Logout: response ($rsp)"

close $out

The upload facility is implemented by upload.php and returns a response coming out of php's serialize() function. I've mangled upload.php to return a response in xml or json format. The code changes are posted in the Knowledgetree community forum here.

The above Tcl code digests the php's serialize() output.

For xml output, here are the relevant changes:

set crl [curl::init]
set rsp [$crl configure -url $url -bodyvar xml -post 1 \
-httppost [list name "file1" file $upf contenttype $typ] \
-httppost [list name "session_id" contents $ses] \
-httppost [list name "action" contents A] \
-httppost [list name "output" contents xml] \
]
...
set top [dom parse $xml]
set sel [$top selectNodes /results/uploads/document/tmp_name/text()]
set tmp [$sel nodeValue]
$top delete

And for json..

set rsp [$crl configure -url $url -bodyvar rsp -post 1 \
-httppost [list name "file1" file $upf contenttype $typ] \
-httppost [list name "session_id" contents $ses] \
-httppost [list name "action" contents A] \
-httppost [list name "output" contents json] \
]
...
set ps1 [string first "\"tmp_name\":\"" $rsp 0]
set ps2 [string first "\",\"error\"" $rsp 0]
set tmp [string range $rsp [expr $ps1 + 12] [expr $ps2 - 1]]

Check the contents of debug.log for any errors. A successful operation produces this output:

Tuesday, December 4, 2007

Postgres on Cygwin

I'm working on a project that requires database support and I decided to use Postgres on Cygwin. I encountered mild difficulty (and lots of confusion) in setting it up so I decided to document what I have done. Here goes..

Install and run Cygserver as background service

The Cygwin User's Manual states that Cygserver provides Cygwin applications with services which require security arbitration or which need to persist while no other cygwin application is running.

Once installed as a service, you can start cygserver by running the net start cygserver command. Consequently, the service can be stopped by issuing a net stop cygserver command.

Create the postgres Windows user account

The account shall be used to run postgres as a service. Execute the command mkpasswd -l > /etc/passwd to update the local password file.

Additionally, grant the postgres account the rights to Logon as a service. This can be done by using the local security policy editor found under the Administrative Tools of the Windows Control Panel.

Initialize the database

Initialize the database by executing the command initdb -D {dir}. Popular choices for data directory are /var/postgresql/data, /usr/local/pgsql/data, or variations thereof. Change the ownership of the data directory and its sub-directories to postgres.

Install the postmaster service

Firstly, change the ownership of /usr/sbin/postgres.exe to postgres. Install postmaster as a service by running the command

cygrunsrv --install postmaster --disp "CYGWIN postmaster" --path /usr/sbin/postmaster --args "-D /usr/local/pgsql/data -i" --dep cygserver --termsig INT --shutdown --env CYGWIN=server --user postgres

The dependency (--dep) option automatically launches cygserver, if not yet started, when the postmaster service is started.

My Configuration:

- Windows XP Prof Service Pack 2
- Cygwin DLL release version 1.5.24(0.156/4/2)
- PostgreSQL version 8.0.7

Saturday, November 3, 2007

SNMP monitoring using getif and nagios

I use getif. a free Windows GUI-based network tool written by Philippe Simonet, to make a quick query of SNMP values from SNMP informant. You may download getif here.

Once installed, place the downloaded MIBs of SNMP-Informant under the Mibs sub-directory of GETIF. Here's a screenshot of getif in action:


For continuous monitoring of servers and networks, I use nagios to regularly poll environmental and performance statistics. The results can be graphed for better visualization and reporting.

Here are the pertinent nagios service and command configuration entries..

define service{
hostgroup_name windows
service_description mb-temp
check_command check_mbtemp!40!42
use template-service
}

define command{
command_name check_mbtemp
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -o .1.3.6.1.4.1.9600.1.10.6.1.5.1 -l 'MB temp' -u 'Celsius (Warn=$ARG1$ Crit=$ARG2$)'
}

Monday, January 30, 2006

TenderSystem : Open-Source Procurement

Somebody was interested in a procurement system that exploits the Internet to reach business partners in a cost-effective and timely manner. So off I went to sourceforge and searched for procurement. I have been a regular visitor of SF.net so most of the entries look familiar … except … for … TenderSystem!


According to its author …


TenderSystem is an Internet based electronic tendering system to source, award and manage the total procurement process.


This tried and tested technology leverages the age-old principle of supply and demand, through reverse auction, ensuring that products are purchased at the best possible price, at a lower administration and management cost, than any other method.


You can run the demo here.


Or you can build your own site. I decided to do both.


I installed the application on my Windows XP desktop successfully but with a lot of side-installs and much tweaking. Since this is a web-based application, one has to install other support apps to deploy it. All in all, I installed four different packages, namely: Apache 2.054, PHP 5.1.2, MySQL 5.0.18 (server and client), and TenderSystem Beta 0.8


PHP Installation Download the zip package from PHP.net. Do not use the installer package as this does not include the PHP extensions required by TenderSystem. Modify PHP.INI to activate the following directives:


short_open_tag = On
extension_dir = “/php/ext”
extension=php_curl.dll
extension=php_mysql.dll
extension=php_xsl.dll

Modify your Windows PATH to include the PHP installation directory (c:\php) otherwise the dlls included with the PHP package will not be available to Windows and the extensions will not be loaded.


Apache Installation Download apache2.054 from apache.org and install the package. To activate php support, modify the configuration file (httpd.conf) to contain the following directives:


# Allows Apache to serve these files if a directory was invoked.
DirectoryIndex index.html index.html.var index.php
# Load PHP as a module
LoadModule php5_module “C:/php/php5apache2.dll”
PHPIniDir “C:/php”
# Add-type entries
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

TenderSystem Installation Download the package and extract it under apache’s htdocs directory.


If you don’t set (or can’t, since you don’t control your server) short_open_tag on, you’ll be greeted with a code dump when you open your browser to http://localhost/tendersystem. A little sleuthing uncovered three (so far) php scripts which use the PHP short tags:


modules/generic/generic.php
modules/install/generic.php
application/include/modules/generic/class/xml.class

Take a test drive and give me your comments.