Author Topic: [1.7] Allow IP in download URL and remote image path  (Read 13596 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[1.7] Allow IP in download URL and remote image path
« on: March 16, 2005, 04:24:54 AM »
This fix will let u use IP and FTP addresses in download URL and remote image path.

Open /includes/functions.php

Find:
Code: [Select]
  return (preg_match('#^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $file_name)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?(\/)?/i", $file_name)) ? 1 : 0;

Find:
Code: [Select]
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.([a-z]{1,4})$)#is", $file_name)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/.*\.([a-z]{1,4})$/i", $file_name)) ? 1 : 0;

Find:
Code: [Select]
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $remote_media_file)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/.*\.(".$config['allowed_mediatypes_match'].")$/i", $remote_media_file)) ? 1 : 0;

Find:
Code: [Select]
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.(gif|jpg|jpeg|png)$)#is", $remote_thumb_file)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/.*\.(gif|jpg|jpeg|png)$/i", $remote_thumb_file)) ? 1 : 0;

Find:
Code: [Select]
  if (!preg_match("/^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+/i", $url)) {
Replace with:
Code: [Select]
  if (!preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?(\/)?/i", $url)) {

I've tested it with this url types:
http://example.com/image.jpg
http://user@example.com/image.jpg
http://user:pass@example.com/image.jpg
http://123.123.123.123/image.jpg
http://user@123.123.123.123/image.jpg
http://user:pass@123.123.123.123/image.jpg
ftp://, https:// and port numbers also working

Please let me know if u find anything not working after these changes.

P.S. there is a bug in member.php that let u upload not existing images by using remote url.
« Last Edit: July 16, 2005, 08:07:37 PM by V@no »

Offline oswald

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Allow IP in download URL and remote image path
« Reply #1 on: March 16, 2005, 09:03:28 AM »
Hmmm... what version is it for or what other mods do you have installed..... can't find most of the lines to edit in my original functions.php

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Allow IP in download URL and remote image path
« Reply #2 on: March 16, 2005, 02:43:53 PM »
that fix for v1.7
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)