Issue Details (XML | Word | Printable)

Key: MDL-11845
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Petr Skoda
Reporter: Dan Poltawski
Votes: 0
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Fix various components that don't respect http proxy settings

Created: 19/Oct/07 11:19 PM   Updated: 01/Jan/08 08:25 AM
Return to search
Component/s: Lib
Affects Version/s: 1.9
Fix Version/s: 1.9, 2.0

File Attachments: 1. Text File filelib.patch (3 kB)

Issue Links:
Dependency
 
Relates
 

Participants: Dan Poltawski, Eloy Lafuente (stronk7), Martin Dougiamas, Petr Skoda and Sam Marshall
Security Level: None
Resolved date: 01/Jan/08
Affected Branches: MOODLE_19_STABLE
Fixed Branches: MOODLE_19_STABLE, MOODLE_20_STABLE

Sub-Tasks  All   Open   
 Sub-Task Progress: 

 Description  « Hide
There are various places where the http proxy variables are not respected making the setting useless.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Eloy Lafuente (stronk7) added a comment - 07/Dec/07 12:51 AM
+5 for this. Sam is familiar with it.

Eloy Lafuente (stronk7) added a comment - 07/Dec/07 12:54 AM
Just guessing, also... if we should make timezones information download to use componentlib instead of own code.

Sam Marshall added a comment - 07/Dec/07 01:09 AM
I have coded fixes for these using Snoopy and $CFG->proxyhost/port, but am currently unable to test as our developer server has just gone down.

Once it comes back (either later this evening, or tomorrow, I should think) I'll test & commit to 1.9 once the code works.


Eloy Lafuente (stronk7) added a comment - 07/Dec/07 01:19 AM
B-)

Dan Poltawski added a comment - 07/Dec/07 02:16 AM
Just in case you haven't seen it as I think its fairly new, there is download_file_content in filelib which I fixed recently to work properly though proxy.

Sam Marshall added a comment - 07/Dec/07 02:16 AM
I have changed this as described, tested (I can install language packs now! Yay!), and committed to 1.9 and HEAD.

Eloy's suggestion about using componentlib might be correct but I am leaving that as an exercise for the viewer For now I just changed the code directly.


Petr Skoda added a comment - 07/Dec/07 07:36 AM - edited
oops, the download_file_content() is the right way, it uses either curl extension or PHP emulation
my -1 for using snoopy, looking at the code there should be an empty() test to prevent potential warnings during upgrades/installs

my SoC student was supposed to get rid of magpie&snoopy and replace it with download_file_content() and simplepie, unfortunately he did not even start


Eloy Lafuente (stronk7) added a comment - 07/Dec/07 08:34 AM
Uhm... I really don't know why Snoopy is so bad... is it?

Anyway, if the UNIFIED solution is to use download_file_content() everywhere, oki, let's go.

This also makes me think what we have the curl extension in the environmental checks is there is one pure-php alternative. Any insight?


Petr Skoda added a comment - 07/Dec/07 04:42 PM - edited
Hi,

the pure PHP alternatives have limitation - both snoopy and that curl emulation stuff - speed, url fopen, socket read, ssl, ect. The emulation is not good enough for mnet, that is why it is why the real curl is tested in environmnet check.

Curl is official PHP extension which is supposed to do this kind of stuff that is why I originally worked on the integration of emulation and a wrapper function.


Sam Marshall added a comment - 07/Dec/07 06:12 PM
I will change to use download_file_content, certainly it is better to do things the same way.

Unfortunately, the very helpful comment pointing out this function, which I didn't know about, crossed over with me checking it in and going home.


Sam Marshall added a comment - 07/Dec/07 06:26 PM
OK, done. I have changed all three places to use download_file_content. (This is much nicer, I was actually thinking there should be a function for it, even if using snoopy...) Only thing I don't like about it is the name, I wish it was 'contents'. Anyway.

I retested (made it download timezone file, imported a language pack.) It seems to work.


Petr Skoda added a comment - 07/Dec/07 07:09 PM
Thanks Sam and Dan!
...and Eloy too :-P

Martin Dougiamas added a comment - 20/Dec/07 10:36 AM
Currently in 1.9, timezone download is working OK for me but language packs are not. Is this a regression?

Notice: Undefined offset: 3 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 4 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 5 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 6 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 7 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 8 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 9 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 10 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 11 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 12 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 13 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 14 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 15 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 16 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 17 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 18 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535
Notice: Undefined offset: 19 in /moodle/19/lib/libcurlemu/libcurlexternal.inc.php on line 535

Downloaded file check failed.


Martin Dougiamas added a comment - 20/Dec/07 10:43 AM
Ah, this failure is on PHP4 only ... my PHP5 servers work fine. Perhaps a PHP5-ism has crept in to MOODLE_19_STABLE?

Petr Skoda added a comment - 20/Dec/07 06:14 PM
maybe there is a curl PHP extension in your PHP5

Eloy Lafuente (stronk7) added a comment - 20/Dec/07 08:29 PM
I really think that the key here is the nature of files being downloaded:
  • timezone files are text files.
  • lang files and environmental files are zip files

and it seems that the libcurl-emu (when executing external OS curl executable), returns information "inline" with some extra info attached (sizes, times... are concatenated to the binary result).

I guess that curl-emu code then tries to strip that attached info and it causes the binary contents to become garbled.

So perhaps, when using external executable, we should separate both that statistical info and the binary file itself to prevent that garbled files.

Once done, those .zip binary files should arrive perfectly to Moodle.

In fact, that would be perfect because I've another bug ( MDL-12024 ) about timezones info open and I really want to change it to use the central component download methods. That implies downloading .zip files and that's the problem right now.

Ciao


Dan Poltawski added a comment - 29/Dec/07 12:40 AM
Hmm. I think that its screwing with the data and altering the hash even when not using the OS executable

Dan Poltawski added a comment - 29/Dec/07 12:53 AM
Ahh.. and the native implemententation of libcurl-emu doesn't support proxies!

Dan Poltawski added a comment - 29/Dec/07 01:57 AM
How about something like this patch to use snoopy when curl isn't available for the time being (since the curl emulated proxy support isn't good)

Eloy Lafuente (stronk7) added a comment - 29/Dec/07 02:22 AM
Well, if I'm not wrong, the target was to avoid using Snoopy completely and move any file-download to download_file_content.() that will use curl exclusively, in any of its 3 variants:

1- CURL PHP Extension.
2- CURL OS executable.
3- CURL PHP pure code.

I think Petr was going to take a look to this (in order to have 2 & 3 working better than now) because it severely breaks lang & environment updates under 1.9 (and timezones soon too).

So let's wait if he finds the way inside 100% curl of we need to add something else to the 1), 2), 3) above.

Ciao


Petr Skoda added a comment - 30/Dec/07 01:40 AM
Hi,
if anybody has need for proxy he/she should install curl in the first place, as a bonus curl extension works with several types of proxies.
Another problem is exploits of url fopen for remote file inclusions, we should not recommend it enabled - url fopen and register globals on is a fatal combination

I should be back tomorrow working full time on this problem...


Dan Poltawski added a comment - 30/Dec/07 02:08 AM
I agree. Is it too much to require curl extension? For 2.0?

Petr Skoda added a comment - 30/Dec/07 02:25 AM
The component downloading is not essential IMO, you can always workaround it by uploading of files manually.
It should work for majority of ppl out of the box, but proxy is not used in majority of installs.

I think we can make it rock solid if curl installed and usable if not in 1.9.


Eloy Lafuente (stronk7) added a comment - 30/Dec/07 02:57 AM
Yep, with curl-extension installed, everything will be rock-solid.

But we must guarantee that download_file_content() works (in a limited way, agree) for normal servers. Right now it's broken for binary files in normal servers.

I think we all share this objective, just to confirm it, ok?

About making the extension mandatory, I wouldn't do that. Just highly recommended. Nothing else. Perhaps in the admin->proxy settings we can re-recommend the extension. Just that. And only if the OS command curl emulation doesn't provide it (I think it does).


Petr Skoda added a comment - 30/Dec/07 03:54 AM
my +1 Eloy, in fact I already started tweaking the admin settings (adding CURL warning, password, username, proxy type)

1/ binary safe emulation
2/ rock solid/full featured with PHP CURL
3/ add settings into admin tree
4/ tweak RSS feeds to use the new code too


Petr Skoda added a comment - 31/Dec/07 04:52 AM
After hours of trying to fix issues in curl emulation library I have to agree with Dan: using snoopy when cURL extension not present is much, much easier and works in majority of cases.
I have removed the cURL emulation library from CVS, used snoopy if cURL not present, added all admin settings with some explanation, added new debug messages and did some other improvements.
Everything tested with anonymous proxy http and SOCKS5 servers + local squid installation.

Going to review all uses of fopne, snoopy and new download_file_content() now...


Eloy Lafuente (stronk7) added a comment - 31/Dec/07 05:13 AM
Oki, so then, the fallback for download_file_content() is, simply:

1) PHP Curl extension
2) Snoopy

correct?


Dan Poltawski added a comment - 31/Dec/07 06:28 AM
I think we have a proxy lying around in the office with NTLM auth setup on it so I'll give it a bit of testing next week.

Petr Skoda added a comment - 31/Dec/07 06:39 AM
Yes Eloy,
thanks Dan.

Dan Poltawski added a comment - 31/Dec/07 06:49 AM
Any reason for the proxy password not to be an unmask field?

Petr Skoda added a comment - 31/Dec/07 07:07 AM
yep, the reason is I forgot to add that :-D

Dan Poltawski added a comment - 31/Dec/07 07:27 AM
I'd like to suggest we also use the http 1.0 response codes for error messages rather than the 1.1 messages (RFC1945 / 2616)

We have a transparent proxy which returns 302 to be interpreted as 'Moved Temporarily' and that error is much more of an error than 'Found'!

But furthermore we can't assume things support 1.1 and also most apps I use tend to default to 1.0 errors because of this [Read: wget moans to me about Moved Temporarily and I know to explicitly set the proxy, found seems a bit.. eh if its found give it me]


Petr Skoda added a comment - 31/Dec/07 07:38 AM
Feel free to submit patches for better error messages, I am going to work on other parts now

Dan Poltawski added a comment - 31/Dec/07 08:17 AM
Its only 302 which conflicts with anything else in 1.0, so i've fixed that in CVS

Eloy Lafuente (stronk7) added a comment - 31/Dec/07 10:23 AM
So, then.... this can be considered resolved yep?

If so, great work! Else, too! :-D

Ciao


Petr Skoda added a comment - 31/Dec/07 03:57 PM
reclosing, thanks everybody
please reopen again in case of any problems

Petr Skoda added a comment - 31/Dec/07 10:13 PM
reopenening again, going to add snoopy emulation using curl extension and patch magpie to use it, that should solve RSS+proxy

Petr Skoda added a comment - 01/Jan/08 12:46 AM
reclosing again, please test - I hope there will not be any regressions

changes:

  • magpie uses download_file_content() - cURL should be much better than snoopy there
  • redirection now supported
  • custom headers supported
  • post data supported
  • detailed response option - it was needed for etag support in magpie
  • better debug messages

Petr Skoda added a comment - 01/Jan/08 05:45 AM
eh, reopening - have to fix curl related security issues

Petr Skoda added a comment - 01/Jan/08 08:25 AM
reclosing again, the download_file_content() should be much more secure now