Monday, October 6, 2014

Standalone Tomcat7 re-deployment for Oxalis

Its already a third time when I have to re-deploy Tomcat due to application, environment or even Tomcat issues.

Current system/situation:
- Centos 6.5
- Running Tomcat6, Tomcat7 (7.0.37). Integrated
- Difi Oxalis cant run in the same 'house' with Difi XML validator
- Difi Oxalis AS2 has mime issues running Tomcat 7.0.37-7.0.40
- Java available: 1.6, 1.7 (both JDK's and JRE's). Ref "update-alternatives --config java"

Quick cheat-sheet on how to re-deply Tomcat7 (7.0.55) with Oxalis config:

# cd /opt/
# wget http://apache.mirror.vu.lt/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz
# tar -xvf apache-tomcat-7.0.55.tar.gz
# mv apache-tomcat-7.0.55 tomcat7
# cd tomcat7
# export TOMCAT_HOME=/opt/tomcat7
# export CATALINA_HOME=/opt/tomcat7
# ant -Dtomcat.home=$TOMCAT_HOME -f /root/metro/metro-on-tomcat.xml install
# nano /opt/tomcat7/tomcat-users.xml

   <user username="manager" password="******" roles="manager"/>

# nano /opt/tomcat7/web.xml
    -- comment out all the welcome lines. cocoon needs this
    <welcome-file-list>
     <!--
        <welcome-file>index.html</welcome-file>.
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
     -->
    </welcome-file-list>     

# cp /var/lib/tomcat7/webapps/*.war /opt/tomcat7/webapps/
# nano /opt/tomcat7/server.xml

  <connector port="8443" protocol="HTTP/1.1" sslenabled="true">
   maxThreads="150" scheme="https" secure="true"              
   clientAuth="false" sslProtocol="TLS" sslEnabledProtocols="TLSv1,SSLv3,SSLv2Hello" keystoreFile=".keystore" keyAlias="tomcat"  keystorePass="******" />

# cp /usr/share/tomcat7/ssl_tomcat /opt/tomcat7/ -R
# cp /usr/share/tomcat7/.keystore /opt/tomcat7/
# sh bin/startup.sh

--- edit or create tomcat startup script

# nano /etc/init.d/tomcat7

  #!/bin/bash
  # description: Tomcat Start Stop Restart
  # processname: tomcat
  # chkconfig: 234 20 80
  PATH=$JAVA_HOME/bin:$PATH
  export PATH
  CATALINA_HOME=/opt/tomcat7

  # Define the tomcat username
  TOMCAT_USER="${TOMCAT_USER:-tomcat}"

  case $1 in
  start)
    sh $CATALINA_HOME/bin/startup.sh
  ;;
  stop)
    sh $CATALINA_HOME/bin/shutdown.sh
  ;;
  restart)
    sh $CATALINA_HOME/bin/shutdown.sh
    sh $CATALINA_HOME/bin/startup.sh
  ;;
     status)
         if [ -f "/var/run/${NAME}.pid" ]; then
 #           status ${NAME}
 #           RETVAL="$?"   
             read kpid < /var/run/${NAME}.pid
             if [ -d "/proc/${kpid}" ]; then
                 echo "${NAME} (pid ${kpid}) is running..."
                 RETVAL="0"   
             fi
         else
             pid="$(/usr/bin/pgrep -d , -u ${TOMCAT_USER} -G ${TOMCAT_USER}  java)"
             if [ -z "$pid" ]; then
 #               status ${NAME}     
 #               RETVAL="$?"
                 echo "${NAME} is stopped"
                 RETVAL="3"          
             else
             echo "${NAME} (pid $pid) is running..."
                 RETVAL="0"          
             fi
         fi
         ;;
     version)
         sh $CATALINA_HOME/bin/version.sh      
         ;;                
     *)                    
         echo "Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status|version}"
         RETVAL="2"
  esac
  exit 0   

# chmod 755 /etc/init.d/tomcat7
# chkconfig --add tomcat7
# chkconfig --level 234 tomcat7 on
# chkconfig --list tomcat7
# /etc/init.d/tomcat7 restart

Some explanations of the cheat-sheet:
- Tomcat7 was deployed as current stable Centos compatible version (7.0.37)
- wget url - download using preferred server
- Metro requirement - ref to Oxalis installation description, its just one .jar file stored in endorsed dir, it might as well be just copied from your old Tomcat installation
- passwords in '*******' - dont forget to replace with your passwords
- cocoon installation is optional
- please note that Tomcat 7.0.55 cant locate your .keystore and you have to define its path manually using tags "keystoreFile" and "keyAlias" which where not needed before
- sslEnabledProtocols is another fix related to SSLv2 beeing disabled in Java7 and OpenSSL 1.0.0+
- ssl_tomcat folder is optional

Monday, March 24, 2014

Tomcat7 startup. This account is currently not available.

There are a couple of possible causes and solutions online. Main problem is pretty obvious: tomcat user account.
One of the solutions tells:

Using a standard Tomcat installation and a tomcat user with no login shell, attempts to start Tomcat failed with a "This account is currently not available." message. However, the tomcat user shouldn't have a shell available as it's not a login account. Updating the tomcat6 command in/etc/init.d/tomcat6 to specify the shell when invoking Tomcat fixes this.

Some other solutions tell that account should be reset, password changed and shell set from nologin to bash. In all these cases you are making a security hole, tomcat account should be disabled in all cases. My suggestion would be to check if you had tomcat user defined before, for example when deploying tomcat6..  Then check if TOMCAT_HOME matches tomcat users home. If TOMCAT_HOME value is set to /usr/share/tomcat6 and you are starting tomcat7 - you will get the same error as with a locked account.

Sunday, November 17, 2013

Currency exchange for non-supported Paypal currencies in Drupal Ubercart Payments module

Problem

Paypal payments for Drupal Ubercart do not support just any currency. The list of supported currencies is pretty static: AUD, BRL, CAD, CHF, CZK, DKK, EUR, GBP, HKD, HUF, ILS, JPY, MXN, MYR, NOK, NZD, PHP, PLN, SEK, SGD, THB, TWD, USD.
Webshop is using LTL as its default currency and as you can see its not supported by Paypal. When cart is submitted - it submits full amount, just in EUR (Paypals default currency in websites settings). If default website setting is not set - it will be USD. Keep this in mind, so you could adjust your case accordingly.

Installation details

- Drupal 7
- Ubercart 7.x-3.5
- Paypal Website Payments Standard (WPS)
- Currency LTL

Research

There are a couple of suggestions online for INR, ZAR and RUB, but none of them suited my case. Research on suggested behavior gave no results, most of the answers led to 6.x solutions, one time patches on different D7 versions or bold suggestions to try Currency modules in Drupal. Thing is - all currency modules i've tested are outdated or have no connection to WPS, Cart or at least Language.

m0rg0t suggests to adjust main Store module and add a language filter. This would work if you wish to change all the prices when user changes current site language. This option is very user friendly, but in my case I needed all users to see same default store currency: LTL.

Another suggestion by Rahul suggests intercepting the WPS and putting currency converter in between. This solution makes some sense, but I was not able to find out how the from/to variables are populated. Also this suggestion is limited to order total amount and WPS. After some testing it resulted in convert(order_total)+tax+handling. As you can see it omits the handling fees and taxes. Suggestion is not complete, but it definitely gives you an idea.

After some investigation on uc_paypal module I found references to Paypal payment options. File ubercart/payment/uc_paypal/uc_paypal.module:
- DirectPayment ( 'METHOD' => 'DoDirectPayment')
- ExpressCheckout ('METHOD' => 'DoExpressCheckoutPayment')
- Website payment standard (function uc_paypal_wps_form($form, &$form_state, $order) {)

Implementation option 1

Change all amounts based on current site language. Edit file ubercart/uc_store/uc_store.module, locate the procedure uc_currency_format and adjust the following:

  // If the value is significantly less than the minimum precision, zero it.
  if ($prec > 0 && round(abs($value), $prec + 1) < pow(10, -$prec)) {
    $value = 0;
  }

  define('LTL',0.4528);
  $curr =  variable_get('uc_paypal_wps_currency', 'USD');
  if ($curr=='EUR') 
    {//$sign = 'lt'; 
     //$thou = ','; 
     //$dec = '.';    
     $value = $value / LTL; // conversion happens here
     //$sign_after = TRUE;
    };

  // Force the price to a positive value and add a negative sign if necessary.
  if ($value < 0) {
    $value = abs($value);
    $output .= '-';
  }

Change is done just before the modulus calculation. You may also uncomment the few commented lines, I only had use of just 1 of them.

Implementation option 2 (my choice)

Change only the amount passed to WPS, in this case site displays same currency independent of language selected. In order to adjust the amount for all payment methods just search for uc_currency_format and replace all the occurrences. In this case just edit the file ubercart/payment/uc_paypal/uc_paypal.module. Locate the function uc_paypal_wps_form and adjust the following:

define('LTL',3.4528);   // add this line somewhere at the top of the function
'handling_cart' => uc_currency_format($shipping / LTL, FALSE, FALSE, '.'),
'tax_cart' => uc_currency_format($tax / LTL, FALSE, FALSE, '.'),
$data['amount_' . $i] = uc_currency_format($item->price / LTL, FALSE, FALSE, '.');
$data['amount_1'] = uc_currency_format($order->order_total - $shipping - $tax / LTL, FALSE, FALSE, '.');

References

Geekport, "Converting INR to USD in during paypal checkout". http://www.geekport.in/samples/Drupal7-currency-convertor.php
Drupalize.me, "uc_currency_format". http://api.drupalize.me/api/drupal/function/uc_currency_format/7
m0rg0t suggestion on stackoverflow: http://stackoverflow.com/questions/7688662/mulitcurrency-for-ubercart-3-drupal-7
Rahul Nahar, "Drupal 7 Ubercart currency convert (ZAR to USD)". http://rahulnahar001.blogspot.com/2012/09/drupal-7-ubercart-currency-convert-zar.html

Monday, January 21, 2013

Seedr 500MB up

Seedr allows instant Torrent download from online Torrent trackers, link to Seedr.cc. Blog posting about this service gives you extra 500 megs of storage.

Wednesday, January 26, 2011

Pluto

Astronomers on the New Horizons team, who sent a spacecraft to Pluto in 2006, are very unhappy. The thing their craft is going to is no longer a planet. It’s sort of fun to tease them about that.

Wednesday, March 24, 2010

Tabular forms

This quote tells more than needed:

Finally, someone concedes that all of their problems are the result of tabular forms! ;) If everyone else in this community would come to that realization we'd have 1/100 the questions on the forum, wars would end, world hunger would be resolved, dogs and cats would be friends...

Thanks Tyler

Tuesday, October 13, 2009

Computers

Computers - they where ok in 1984.
Things have changed since then. (Dailymotion)