DownloadRawTest

contents

  1. <?php /* --- ۞---> text { encoding:utf-8;bom:no;linebreaks:unix;tabs:4sp; } */
  2. $auto_hotlink['version'] = '0.5';
  3. /*
  4. Auto-Hotlink [requires php >= v4.2 + GD]
  5. This script is designed to function as a hot-link image generator.
  6. The image can be generated from scratch, or imported. Either way, you can
  7. also lay text onto the image, even get clever and lay dynamic text on it, if
  8. that's your bag. A counter would be easily doable. The idea is, you can
  9. overlay some promotional message onto the image.
  10. Finally, Auto-HotLink logs the offending hit to a file.
  11. Auto-Hotlink can generate a png or jpeg image. If you import a transparent
  12. png, it will be output that way, too. The image part is all very basic, no
  13. point getting too fancy, just to tell someone to bugger off, politely.
  14. To use:
  15. In .htaccess, use mod_rewrite to rewrite image requests to *this* script..
  16. # hot-linking..
  17. RewriteCond %{HTTP_REFERER} !^$
  18. RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain\. [nc]
  19. RewriteRule ^(.*)\.(gif|jpe?g|png)$ http://%{HTTP_HOST}/path/to/hotlink.php?url=$1.$2 [R,NC,L]
  20. .. which will then catch the hot-linking requests and spit out your
  21. hotlink image. The "?url=$1.$2" part is optional, and enables us to log
  22. exactly what resource they were trying to snatch.
  23. NOTE: On some servers, you will need to specify the host, so use
  24. "mydomain.com" instead of the %{HTTP_HOST}, above.
  25. For more info on .htaccess + mod_rewrite, see here:
  26. https://corz.org/server/tricks/htaccess2.php
  27. Don't forget to set your preferences below.
  28. Have fun!
  29. ;o)
  30. (c) 2005->tomorrow! ~ corz.org
  31. Please view the license for this free software, here:
  32. https://corz.org/free-scripts-licence.nfo
  33. */
  34. /*
  35. prefs.. */
  36. // site prefs in here..
  37. /*
  38. Output Image Type
  39. [default: $auto_hotlink['img_type'] = 'png';]
  40. Choose from "png" and "jpg"
  41. */
  42. $auto_hotlink['img_type'] = 'png';
  43. //
  44. // If you mess up the preference, or don't specify, the type defaults to jpg.
  45. /*
  46. Import Image..
  47. [default: $auto_hotlink['import_img'] = 'hotlink.png';]
  48. Leave this blank to generate an image, or else insert the FULL path to the image you would like
  49. to use. If the image is in the same folder as this script, you can use the file name by itself.
  50. */
  51. $auto_hotlink['import_img'] = '';
  52. /*
  53. NOTE: You can import a png, and output a jpeg, and vica-versa.
  54. */
  55. /*
  56. Use Original Image
  57. [default: $auto_hotlink['use_original'] = false;]
  58. By request, you can also display the original image they requested, but with your hotlinking
  59. text overlayed on top.
  60. */
  61. $auto_hotlink['use_original'] = false;
  62. /*
  63. Output Image Dimensions.
  64. [default: $auto_hotlink['img_width'] = 280;]
  65. [default: $auto_hotlink['img_height'] = 32;]
  66. If not using an imported (or original) image, specify the size of the image to generate from scratch..
  67. */
  68. $auto_hotlink['img_width'] = 280;
  69. $auto_hotlink['img_height'] = 32;
  70. /*
  71. Background color..
  72. [default: $auto_hotlink['bg_color'] = '#FF0000';]
  73. Only for generated images. Use standard RGB value, with or without the "#".
  74. */
  75. $auto_hotlink['bg_color'] = '#FF0000';
  76. //tmp
  77. $trans_color = false;
  78. /*
  79. Text Overlay
  80. [default: $auto_hotlink['hotlink_text'] = 'we love '.$_SERVER['HTTP_HOST'].'!';]
  81. Insert your own text here. I like to use the domain name, as an advert to go on the pages of
  82. those who would hot-link to the org.
  83. If you don't want to overlay any text, leave this blank (or comment out)
  84. examples..
  85. $auto_hotlink['hotlink_text'] = $_SERVER['HTTP_HOST']; // or maybe..
  86. $auto_hotlink['hotlink_text'] = "hot-linked from ".$_SERVER['HTTP_HOST'];
  87. $auto_hotlink['hotlink_text'] = $_SERVER['HTTP_HOST']. " lover!";
  88. */
  89. $auto_hotlink['hotlink_text'] = 'we love '.$_SERVER['HTTP_HOST'].'!';
  90. /*
  91. This text could be tailored to the site (referrer), user's IP, such as corz.org hot-linker from
  92. 220.2..., or whatever. It could be a simple counter, which is be easy to do in php, or anything
  93. you like. You can also leave it blank, and send only the image.
  94. For small to medium sized abusers, a nice advert for your site seems like good value for the
  95. bandwidth taken. I have one advert currently seen my 1000+ visitors a day! Some band's myspace
  96. page .:roll:. For serious abusers, see below.
  97. */
  98. /*
  99. Text Color
  100. [default: $auto_hotlink['text_color'] = '#ffffff';]
  101. RGB, as bg_color, above.
  102. */
  103. $auto_hotlink['text_color'] = '#ffffff';
  104. /*
  105. Text Size
  106. [default: $auto_hotlink['text_size'] = 5;]
  107. From 1 - 5
  108. */
  109. $auto_hotlink['text_size'] = 5;
  110. //
  111. // I might add truetypes, later.
  112. /*
  113. Text Align
  114. [default: $auto_hotlink['align'] = 'center';]
  115. Horizontal align - choose from 'center', 'right', and 'left'..
  116. */
  117. $auto_hotlink['align'] = 'center';
  118. /*
  119. Text Border
  120. [default: $auto_hotlink['txt_border'] = 5;]
  121. Set the text border (edge space, in pixels)..
  122. Text won't go any closer than *this* to the edge..
  123. (unless you have way too much text for the size of the image!)
  124. */
  125. $auto_hotlink['txt_border'] = 5;
  126. /*
  127. Text Vertical Placement
  128. [default: $auto_hotlink['text_y'] = 5;]
  129. Set the vertical placement of the text (in pixels)..
  130. */
  131. $auto_hotlink['text_y'] = 5;
  132. /*
  133. Image Quality
  134. [default: $auto_hotlink['compression_level'] = 9;]
  135. png: Compression level: from 0 (no compression) to 9 (max compression).
  136. (9 is best)
  137. jpg: Quality level: from 10 (dire) to 100 (near lossless).
  138. 80 is good, but 50 uses less bandwidth.
  139. Large text is still readable at 15.
  140. */
  141. $auto_hotlink['compression_level'] = 9;
  142. /*
  143. Log File..
  144. [default: $auto_hotlink['log_file'] = $_SERVER['DOCUMENT_ROOT'].'/inc/log/.ht_hotlinks';]
  145. Unless you are logging to the same folder, use the FULL path, including
  146. document root..
  147. */
  148. $auto_hotlink['log_file'] = $_SERVER['DOCUMENT_ROOT'].'/inc/log/.ht_hotlinks';
  149. /*
  150. Evil Domains
  151. Instead of the usual cute image, we'll send these f*ck3rz something else..
  152. Separate evil domains with a comma.
  153. Then it's basically the same prefs again, but for an alternative image..
  154. */
  155. $auto_hotlink['evil_domains'] = 'repost-agent.blogspot,remote.namusae.com,nutest.org';
  156. $auto_hotlink['evil_type'] = 'jpg';
  157. $auto_hotlink['evil_image'] = 'evil.jpg';
  158. $auto_hotlink['evil_width'] = 314;
  159. $auto_hotlink['evil_height'] = 236;
  160. $auto_hotlink['evil_bg_color'] = 'ffffff';
  161. $auto_hotlink['evil_text'] = 'some ***** stole this article from corz.org!';
  162. $auto_hotlink['evil_text_color'] = '#ffffff';
  163. $auto_hotlink['evil_text_size'] = 2;
  164. $auto_hotlink['evil_align'] = 'center';
  165. $auto_hotlink['evil_txt_border'] = 1;
  166. $auto_hotlink['evil_y'] = 222;
  167. $auto_hotlink['evil_compression_level'] = 50;
  168. /*
  169. Of course, what you use here, is up to you. But note, most dirty web masters, are male, and
  170. usually at least slightly homophobic. I find an image of homosexual fellatio, perhaps with the
  171. text, "some cocksucker stole this from mydomain.com!", works well. Their guests will usually
  172. complain pretty quickly, jobe done. ;o)
  173. The usual rules about trying to produce the smallest possible image, don't apply here; we're
  174. trying to send a message. BIGGER may be better!
  175. */
  176. /*
  177. end prefs. */
  178. if (!empty($GLOBALS['do_debug'])) { debug("\n".'$auto_hotlink:: '."\t".print_r($auto_hotlink, true)."\n\n"); }//:debug:
  179. /*
  180. okay, let's go..
  181. */
  182. $auto_hotlink['url'] = '';
  183. $auto_hotlink['referrer'] = '';
  184. $auto_hotlink['ref_domain'] = '';
  185. // Capture any GET Variables..
  186. if (!empty($_GET['url'])) { $auto_hotlink['url'] = $_GET['url']; }
  187. // We are using the original requested image..
  188. if ($auto_hotlink['use_original'] == true) {
  189. $auto_hotlink['import_img'] = $_SERVER['REQUEST_URI'];
  190. }
  191. /*
  192. Capture "Referer" [sic] information..
  193. mod_rewrite should have already established that it is a hot-link.
  194. This is a double-check. We need to capture the referrer, anyway.
  195. Also, it means keeping a demo on-site won't trigger the logging (later).
  196. */
  197. if (!empty($_SERVER['HTTP_REFERER'])) {
  198. $auto_hotlink['referrer'] = $_SERVER['HTTP_REFERER'];
  199. $auto_hotlink['ref_domain'] = trim(substr($auto_hotlink['referrer'], strpos($auto_hotlink['referrer'], "/")+2, strpos($auto_hotlink['referrer'], "/", 8)-7), '/');
  200. }
  201. /*
  202. Splitting the referrer into a domain part, saves us searching for multiple
  203. variations. So long as your host name appears somewhere in the domain part,
  204. then it's not a hot-link.
  205. */
  206. // Is this an Evil Domain??
  207. $auto_hotlink['evil_domains'] = explode(',', $auto_hotlink['evil_domains']);
  208. foreach($auto_hotlink['evil_domains'] as $evil) {
  209. if (stristr($auto_hotlink['referrer'], trim($evil))) {
  210. $auto_hotlink['img_type'] = $auto_hotlink['evil_type'];
  211. $auto_hotlink['import_img'] = $auto_hotlink['evil_image'];
  212. $auto_hotlink['img_width'] = $auto_hotlink['evil_width'];
  213. $auto_hotlink['img_height'] = $auto_hotlink['evil_height'];
  214. $auto_hotlink['bg_color'] = $auto_hotlink['evil_bg_color'];
  215. $auto_hotlink['hotlink_text'] = $auto_hotlink['evil_text'];
  216. $auto_hotlink['text_color'] = $auto_hotlink['evil_text_color'];
  217. $auto_hotlink['text_size'] = $auto_hotlink['evil_text_size'];
  218. $auto_hotlink['align'] = $auto_hotlink['evil_align'];
  219. $auto_hotlink['txt_border'] = $auto_hotlink['evil_txt_border'];
  220. $auto_hotlink['text_y'] = $auto_hotlink['evil_y'];
  221. $auto_hotlink['compression_level'] = $auto_hotlink['evil_compression_level'];
  222. }
  223. }
  224. // in case we get a "site" path..
  225. if (!empty($auto_hotlink['import_img']) and file_exists($_SERVER['DOCUMENT_ROOT'].$auto_hotlink['import_img'])) {
  226. $auto_hotlink['import_img'] = $_SERVER['DOCUMENT_ROOT'].$auto_hotlink['import_img'];
  227. }
  228. // Import an image, if required..
  229. //
  230. if (!empty($auto_hotlink['import_img']) and file_exists($auto_hotlink['import_img'])) {
  231. // if (end(explode('.', $auto_hotlink['import_img'])) == 'png') {
  232. if (substr(strrchr($auto_hotlink['import_img'], "."), 1) == 'png') {
  233. $auto_hotlink['img'] = imagecreatefrompng($auto_hotlink['import_img']);
  234. imagealphablending($auto_hotlink['img'], true);
  235. imagesavealpha($auto_hotlink['img'], true);
  236. } else {
  237. $auto_hotlink['img'] = imagecreatefromjpeg($auto_hotlink['import_img']);
  238. }
  239. $auto_hotlink['img_width'] = imagesx($auto_hotlink['img']);
  240. $auto_hotlink['img_height'] = imagesy($auto_hotlink['img']);
  241. } else {
  242. $auto_hotlink['img'] = imagecreate($auto_hotlink['img_width'], $auto_hotlink['img_height']) or die();
  243. }
  244. // prepare the user colors..
  245. //
  246. $auto_hotlink['bg_color'] = hex2dec($auto_hotlink['bg_color']);
  247. $hot_bg_red = $auto_hotlink['bg_color'][0];
  248. $hot_bg_green = $auto_hotlink['bg_color'][1];
  249. $hot_bg_blue = $auto_hotlink['bg_color'][2];
  250. $auto_hotlink['text_color'] = hex2dec($auto_hotlink['text_color']);
  251. $hot_red = $auto_hotlink['text_color'][0];
  252. $hot_green = $auto_hotlink['text_color'][1];
  253. $hot_blue = $auto_hotlink['text_color'][2];
  254. $auto_hotlink['bg_color'] = imagecolorallocate($auto_hotlink['img'], $hot_bg_red, $hot_bg_green, $hot_bg_blue);
  255. $auto_hotlink['text_color'] = imagecolorallocate($auto_hotlink['img'], $hot_red, $hot_green, $hot_blue);
  256. if ($trans_color) {
  257. imagecolortransparent($auto_hotlink['img'], $auto_hotlink['bg_color']);
  258. }
  259. // Align the text and overlay onto the image..
  260. //
  261. if (!empty($auto_hotlink['hotlink_text'])) {
  262. $halfway = ($auto_hotlink['img_width'] / 2);
  263. $chr_width = imagefontwidth($auto_hotlink['text_size']);
  264. $string_width = strlen($auto_hotlink['hotlink_text']) * $chr_width;
  265. switch ($auto_hotlink['align']) {
  266. case 'center':
  267. $text_x = $halfway - ($string_width / 2);
  268. break;
  269. case 'right':
  270. $text_x = $auto_hotlink['img_width'] - $string_width - $auto_hotlink['txt_border'];
  271. break;
  272. case 'left':
  273. $text_x = $auto_hotlink['txt_border'];
  274. break;
  275. }
  276. imagestring($auto_hotlink['img'], $auto_hotlink['text_size'], $text_x, $auto_hotlink['text_y'], $auto_hotlink['hotlink_text'], $auto_hotlink['text_color']); // size 4 built-in font
  277. }
  278. // send the image to the browser..
  279. if ($auto_hotlink['img_type'] == 'png') {
  280. if ($auto_hotlink['compression_level'] > 9) { $auto_hotlink['compression_level'] = 9; }
  281. header('Content-type: image/png');
  282. imagepng($auto_hotlink['img'], NULL, $auto_hotlink['compression_level']) or die("there was an error. sorree");
  283. } else {
  284. if ($auto_hotlink['compression_level'] < 10) { $auto_hotlink['compression_level'] *= 10; }
  285. header('Content-type: image/jpg');
  286. imagejpeg($auto_hotlink['img'], NULL, $auto_hotlink['compression_level']) or die("there was an error. sorree");
  287. }
  288. imagedestroy($auto_hotlink['img']);
  289. // Log the Hot-link..
  290. //
  291. if (!stristr($auto_hotlink['ref_domain'], $_SERVER['HTTP_HOST'])) {
  292. $auto_hotlink['hit_data'] = "\n"
  293. .$auto_hotlink['referrer']."\n"
  294. ."\t\t".'['.$_SERVER['REMOTE_ADDR'].']'."\t".date('Y.m.d h:i:s A')."\n"
  295. ."\t\t".'http://'.$_SERVER['HTTP_HOST'].'/'.$auto_hotlink['url']."\n";
  296. log_hotlink($auto_hotlink['log_file'], $auto_hotlink['hit_data']);
  297. }
  298. /*
  299. fin
  300. */
  301. /*
  302. Hex >> Dec
  303. Converts an HTML #hex colour to decimal colour levels..
  304. */
  305. function hex2dec($rgb) {
  306. if (substr($rgb, 0, 1) == "#") {
  307. $rgb = substr($rgb, 1);
  308. }
  309. $r = hexdec(substr($rgb, 0, 2));
  310. $g = hexdec(substr($rgb, 2, 2));
  311. $b = hexdec(substr($rgb, 4, 2));
  312. return array($r, $g, $b);
  313. }
  314. /*
  315. Log the Hot-Link
  316. */
  317. function log_hotlink($file, $data) {
  318. if (!file_exists($file)) { $fp = @fopen($file, 'wb'); }
  319. if (is_writable($file)) {
  320. $fp = @fopen($file, 'ab');
  321. if (is_writable($file)) {
  322. $lock = flock($fp, LOCK_EX);
  323. if ($lock) {
  324. fwrite($fp, $data);
  325. flock ($fp, LOCK_UN);
  326. }
  327. fclose($fp);
  328. clearstatcache();
  329. }
  330. }
  331. }
  332. /*
  333. itstory
  334. 0.5
  335. * There is now the capability to use the original image (the one they
  336. requested) with your hot-link text overlayed.
  337. Essentially, this turns auto-hotlink into an automatic watermarking
  338. script.
  339. 0.4.4
  340. * Fixed the bug I introduced (0.4.3) in the referer logging.
  341. 0.4.3
  342. + Improved Referer (sic) checking.
  343. Didn't note changes prior to this.
  344. */
  345. ?>

Welcome to corz.org!

I'm always messing around with the back-end.. See a bug? Wait a minute and try again. Still see a bug? Mail Me!