Koozali.org: home of the SME Server

PhreeBooks - currencies not updating

Offline Charles2008

  • *
  • 174
  • +0/-0
PhreeBooks - currencies not updating
« on: October 09, 2013, 08:39:55 PM »
I installed PhreeBooks in an ibay on my SME8 LAN test-server (server only mode) a few months ago. Execution of dynamic content (CGI, PHP, SSI) = enabled. Open basedir restriction - all fine.
http://www.phreebooks.com/pb-demo   ...   (demo, demouser)
Previously I had it running happily on a Debian PC (localhost) and the multi-currency updates worked as expected.

Recently I have begun testing the multi-currency functionality (on the SME8 server install) and have noticed that the exchange rates aren't being updated as they should.

- I have reinstalled 3 times on my server. Same outcome each time.
- I have confirmed that other users using exactly the same PhreeBooks software (same release code) aren't having problems.
- I have 2 different aged releases running on the server - both have the same issue.
- At my request the 'multi-currency' feature on the 'official demo' (above) has been switched on   ...   and works fine.

From tests advised by the PhreeBooks team it has been confirmed that "you are not getting a response back from the currencies servers PhreeBooks uses. Could something be blocking your internet access?"

The two currency sources are:
Oanda   ...   http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=
Yahoo   ...   http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=

I am beginning to wonder if there is anything obvious that I may be missing on the SMEserver side of things.
Could there be a simple explanation for this?
Any advice would be much appreciated.
Charles



« Last Edit: October 09, 2013, 08:45:32 PM by Charles2008 »

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #1 on: October 10, 2013, 04:30:11 AM »
Charles2008

Quote
From tests advised by the PhreeBooks team it has been confirmed that "you are not getting a response back from the currencies servers PhreeBooks uses. Could something be blocking your internet access?"
The two currency sources are:
Oanda   ...   http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=
Yahoo   ...   http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=


In server only mode it suggests you have a seperate firewall router. You may need to forward appropriate ports to your server that the return currency info comes in on. Ask the PhreeBooks support people.

Quote
I have confirmed that other users using exactly the same PhreeBooks software (same release code) aren't having problems.

Are they using sme server or some other server ?
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #2 on: October 10, 2013, 09:12:24 AM »
I will ask about specific port forwarding. However, wouldn't this also have been the case when I was running Debian/Localhost?

I think that they us Ubuntu server.

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #3 on: October 10, 2013, 10:04:21 AM »
Charles2008

Debian, Ubuntu & SME server (CentOS) are all different & it's highly likely the firewalls are configured differently.
Don't assume.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline hawk

  • *
  • 141
  • +0/-0
    • hawkelectronics
Re: PhreeBooks - currencies not updating
« Reply #4 on: October 11, 2013, 11:36:50 AM »
hi charles

i was wondering if you have got this working, if so can you give a step by step as to how you did it,

thanks
john


Offline mmccarn

  • *
  • 2,627
  • +10/-0
Re: PhreeBooks - currencies not updating
« Reply #5 on: October 11, 2013, 01:28:35 PM »
Charles2008 -
If the exchange rate update process involves the creation of temporary files, you may need to customize PHPBaseDir or find the temp folder specification in the Phreebooks config files and point it to a location within the ibay.

Perhaps this is why you asked about PHPBaseDir in another post?

Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #6 on: October 11, 2013, 06:09:48 PM »
@Hawk
If you mean, did I get PhreeBooks working, the answer is yes. However, there are some bugs in the latest release (PhreeBooksv3.6RC2). I am trying to help with the debugging. Installation is simple to an ibay. I will provide a 'How To' if you want it.

If you mean the currencies - no, I haven't gotten to the bottom of this yet.

@mmccarn
Thank you for your suggestion. I will ask about the creation of temporary files.
My PHPBaseDir question wasn't for anything that exciting  :smile:
I just wanted another test install for debug purposes.

Offline hawk

  • *
  • 141
  • +0/-0
    • hawkelectronics
Re: PhreeBooks - currencies not updating
« Reply #7 on: October 11, 2013, 08:59:01 PM »
hi

yes i also managed to get it working,but have the same problem with currencies. i get the error about the database will look again into it next week.

thanks

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #8 on: October 11, 2013, 11:36:10 PM »
Charles2008

Quote
I installed PhreeBooks in an ibay on my SME8 LAN test-server (server only mode)

In addition to my earlier comment about opening & forwarding appropriate ports from your firewall device to your SME test server (in server only mode), could the answer to the currency update issue be as simple as you have not forwarded http port 80 from your firewall to your test server ?
Also did you configure your test server to have Internet access via your gateway/firewall. This is done in the admin console menu "Configure this server".

You do not describe your network layout & whether you have another SME server in server & gateway mode acting as your firewall/gateway, or whether you have a seperate firewall device, please describe it to us.

The reason your PhreeBooks install worked previously was probably because your Linux Debian PC had unrestricted Internet access.
« Last Edit: October 11, 2013, 11:58:38 PM by janet »
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline hawk

  • *
  • 141
  • +0/-0
    • hawkelectronics
Re: PhreeBooks - currencies not updating
« Reply #9 on: October 14, 2013, 11:20:03 AM »
Charles

a 'How To' if you want it.

yes please i am still battling and have got into a bit of a spin on this, i would just like to compare notes to see where i might have gone wrong

thanks
john


Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #10 on: October 15, 2013, 12:26:15 AM »
@Hawk
At what point is it needing attention?

Although now I find it straightforward (famous last words) to create another test instance in an ibay, when I first installed it I got myself in a real muddle. In the end it transpired that I had somehow corrupted the files between my original download and copying into ibay. Here is the original thread where I received a lot of help   ...   trying to straighten up my corrupted install  :-)  When I downloaded a fresh copy it all went pretty smoothly.
http://forums.contribs.org/index.php?topic=49363.0


Saying all that, there are areas that I am still not sure about - for example file permissions - tightening it all down to keep the bad guys out in an WAN facing install. Security in general.

Anyway, I will help you in any way that I can. It might take me a few evenings to get the How-To together - but that's not a problem.
Charles

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #11 on: October 15, 2013, 01:54:57 AM »
Charles2008

Please answer the issues & queries raised in my earlier post here
http://forums.contribs.org/index.php/topic,50263.msg252520.html#msg252520
and the post(s) earlier than that too.

It's no use continuing on saying you have a problem & then not providing the feedback requested to help solve your problem.

Re permissions etc:
Usually if you transfer the tgz or zip file for an application to your server & unpack it into the required ibay, all the permissions & ownership will be correct. On some occasions I have found it necessary to repack the unpacked files & folders into a new tgz file (or similar), with the correct folder layout, & then unpack that again into the ibay so the installed folder structure matches the authors design intention, thus catering for the differences between the sme way of doing things eg to ..../ibayappname/html/appfolders... rather than to other Linux servers generic .../www/appname/appfolders.... location. This avoids manually copying files & folders & inadvertantly changing permissions & ownership in the process. You have to be careful when using the copy (cp) command. Perhaps I do not know how to use untar correctly (?), but this approach has worked for me quite satisfactorily.

The ibay settings & other sme server firewall settings etc, are what are protecting you.
Playing with file permissions is dangerous, & usually not necessary, as you are more likely to create a security risk.

« Last Edit: October 15, 2013, 01:56:38 AM by janet »
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #12 on: October 15, 2013, 03:50:44 PM »
@Janet
Sorry for the delay, I hadn't had an opportunity to test your suggestions.

I have tried forwarding port 80 in the firewall - no change. Infact, I went through every single one of the pre-set firewall port forwarding rules (about 30). No change with any of them. Port 80 and 443 are currently set as fowarding to my SME8 LAN server-only box.

I have received this from the PhreeBooks forum:

Quote
"These are the PHP functions I use to pull the data from remote websites:

file() - http://us1.php.net/manual/en/function.file.php

and

file_get_contents() - http://us1.php.net/manual/en/function.file-get-contents.php

There may be some configuration information in there that might help. This is not an issue with PhreeBooks but a configuration problem. At best, a note or check should be added to the install script to check for php configuration and notify. "

In the file currency.php, these are the lines that deal with the info request (I think):
Code: [Select]
  function quote_oanda($code, $base = DEFAULT_CURRENCY) {
        $page = file('http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch='.$code.'&format=CSV&dest=Get+Table&sel_$
        $match = array();
        preg_match('/(.+),(\w{3}),([0-9.]+),([0-9.]+)/i', implode('', $page), $match);
        return (sizeof($match) > 0) ? $match[3] : false;
  }

  function quote_yahoo($to, $from = DEFAULT_CURRENCY) {
        $page = file_get_contents('http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='.$from.$to.'=X');
        if ($page) $parts = explode(',', trim($page));
        return ($parts[1] > 0) ? $parts[1] : false;
  }

I noted this comment in the comments section of the file_get_contents() help page listed above:
Quote
"On Centos 5, and maybe other Red Hat based systems, any attempt to use file_get_contents to access a URL on an http  port other than 80 (e.g. "http://www.example.com:8040/page") may fail with a permissions violation (error 13) unless the box you are running php on has its seLinux set to 'permissive' not 'enforcing' . Otherwise the request doesn't even get out of the box, i.e. the permissions violation is generated locally by seLinux."

However, there is no suggestion of any particular port being used in the PHP request noted above.

PHP is currently beyond my current abilities (but on my roadmap).
Charles


@mmccarn
On the temporary files - I asked the question, but haven't received a direct and clear reply.
« Last Edit: October 15, 2013, 04:51:40 PM by Charles2008 »

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #13 on: October 16, 2013, 03:24:00 AM »
Charles2008

I can only make general comments about this as I do not use PhreeBooks.

Quote
I have tried forwarding port 80 in the firewall - no change. Infact, I went through every single one of the pre-set firewall port forwarding rules (about 30). No change with any of them. Port 80 and 443 are currently set as fowarding to my SME8 LAN server-only box.

What about outgoing, does your firewall/router allow outgoing data on port 80 ?
How is it configured ?

Quote
I noted this comment in the comments section of the file_get_contents() help page listed above...
"On Centos 5, .... any attempt to use file_get_contents to access a URL on an http  port other than 80 .....may fail with a permissions violation (error 13) unless the box you are running php on has its seLinux set to 'permissive' not 'enforcing' . Otherwise the request doesn't even get out of the box, i.e. the permissions violation is generated locally by seLinux."

As stated, that issue on CentOS 5.x only applies to ports other than  80, so debatable whether it is an issue or not for you.

Would you be able to conduct a test & reconfigure your SME server to server & gateway mode & change your modem/router to bridged mode, & see if PhreeBooks works any better ? That might indicate whether your local network was the problem or whether the SME server config was the problem.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #14 on: October 16, 2013, 10:45:43 AM »
@Hawk

Ok, I have done the PhreeBooks How-To, as you requested.
I have put much more detail into it than I would have done if it was just for you. I have aimed it, audience wise, at me (six months ago) i.e. a very green novice.

I am glad that you have prompted me to do this as it meant that I had to finally put some effort into the file permissions - I had been avoiding this.

I shall make a separate post for this, so as not to detract from the currency update mystery.
Please let me know how you get on.
Charles

Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #15 on: October 16, 2013, 03:51:11 PM »
@Janet
I will investigate further the Port 80 issue.

I had been thinking, like you, that if this server was 'Server & Gateway' this may well not be happening.
I will try the 'bridge mode' angle.
Charles

Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #16 on: October 16, 2013, 10:45:12 PM »
I am beginning to think that this is related to the allow_url_fopen issue.

However, I have checked my logs and can't see anything:
/var/log/httpd/error_log
/var/log/messages

http://forums.contribs.org/index.php?topic=31809.0
http://forums.contribs.org/index.php?topic=33951.0;wap2

This sort of remote interrogation and downloading of data seems to be disabled by design.
I have come across the following to allow this globally, but I would prefer to do it for just the ibay in question if sensible:

http://wiki.contribs.org/DB_Variables_Configuration#Php
Code: [Select]
db configuration setprop php AllowUrlFopen On
Code: [Select]
expand-template /etc/php.ini
Code: [Select]
/etc/init.d/httpd-e-smith restart
I need to investigate further.
Charles


Edit:  I am pretty sure that this is what I need:
'Allow PHP URL File Open per ibay'
http://wiki.contribs.org/Useful_Commands

Now before I do anything drastic, can someone who is a little more experienced than me just confirm that this is the right solution. Thanks.
« Last Edit: October 16, 2013, 11:00:52 PM by Charles2008 »

Offline Charles2008

  • *
  • 174
  • +0/-0
[Solved ]Re: PhreeBooks - currencies not updating
« Reply #17 on: October 17, 2013, 12:11:30 AM »
I am delighted to say that I have solved it.
It was in fact this PHP URL File Open issue, and the details in my 'Edit' above have the solution.
I had to make a 'custom-template fragment':

Here is exactly what I did:

ssh into LAN server and at the command line:

Code: [Select]
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.confActually, it looks like I had one of these already, but no harm done.

Create the template name (file) 99allow_url_fopen :
Code: [Select]
cd /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
Code: [Select]
touch 99allow_url_fopen
Edit the new custom-template file:
Code: [Select]
nano 99allow_url_fopen
and copy in the code given here - http://wiki.contribs.org/Useful_Commands (Allow PHP URL File Open per ibay):
Code: [Select]
<Directory /home/e-smith/files/ibays/IBAYNAME/html>
php_admin_flag allow_url_fopen on
</Directory>

Put in the correct ibay name, save and exit nano.

As per the instructions, expand:
Code: [Select]
expand-template /etc/httpd/conf/httpd.confand finally, restart httpd.
Code: [Select]
/etc/init.d/httpd-e-smith restart
Code: [Select]
exit
And now currencies are updating beautifully  :lol:
« Last Edit: October 17, 2013, 12:37:59 AM by Charles2008 »

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: [Solved ]Re: PhreeBooks - currencies not updating
« Reply #18 on: October 17, 2013, 01:43:18 AM »
Charles2008

Well done. You have learnt something & I am sure you are happy now !
Just goes to show that reading the available documentation does lead to answers.
That approach is probably applicable to many other web app contribs.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Charles2008

  • *
  • 174
  • +0/-0
Re: PhreeBooks - currencies not updating
« Reply #19 on: October 17, 2013, 11:06:24 AM »
@Janet
Why, thank you! :D
You are right, it makes me very happy that I have sorted it out - it was really bugging me.

BTW, I have printed off your 'Well Done' message, cut it out and stuck it to the wall above my desk alongside my Gymkhana Rosettes, my '3rd place in the 100m Dash' Certificate and my 'Cycling Proficiency' badge!

Thanks for your help/encouragement.
Charles