Advertisement
teknisiazza

Youtube Cache HTTPS TCP_HIT

Sep 2nd, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.08 KB | None | 0 0
  1. konfigurasi
  2. =============================================
  3. apt-get update && apt-get upgrade -y
  4.  
  5. apt-get install devscripts \
  6. build-essential \
  7. openssl libssl-dev \
  8. fakeroot \
  9. libcppunit-dev \
  10. libsasl2-dev \
  11. cdbs \
  12. ccze \
  13. libfile-readbackwards-perl \
  14. libcap2 \
  15. libcap-dev \
  16. libcap2-dev \
  17. libtool \
  18. sysv-rc-conf -y &&
  19. wget http://www.squid-cache.org/Versions/v3/3.5/squid-3.5.20.tar.bz2 &&
  20. tar -xjf squid-3.5.20.tar.bz2 &&
  21. cd squid-3.5.20 &&
  22. ./configure \
  23. --prefix=/usr \
  24. --includedir=/usr/include \
  25. --infodir=/usr/share/info \
  26. --sysconfdir=/etc \
  27. --localstatedir=/var \
  28. --libexecdir=/usr/lib/squid \
  29. --srcdir=. \
  30. --datadir=/usr/share/squid \
  31. --sysconfdir=/etc/squid \
  32. --mandir=/usr/share/man \
  33. --enable-inline \
  34. --enable-async-io=24 \
  35. --enable-storeio=ufs,aufs,diskd,rock \
  36. --enable-removal-policies=lru,heap \
  37. --enable-gnuregex \
  38. --enable-delay-pools \
  39. --enable-cache-digests \
  40. --enable-underscores \
  41. --enable-icap-client \
  42. --enable-follow-x-forwarded-for \
  43. --enable-eui \
  44. --enable-esi \
  45. --enable-icmp \
  46. --enable-zph-qos \
  47. --enable-http-violations \
  48. --enable-ssl-crtd \
  49. --enable-linux-netfilter \
  50. --enable-ltdl-install \
  51. --enable-ltdl-convenience \
  52. --enable-x-accelerator-vary \
  53. --disable-maintainer-mode \
  54. --disable-dependency-tracking \
  55. --disable-silent-rules \
  56. --disable-translation \
  57. --disable-ipv6 \
  58. --disable-ident-lookups \
  59. --with-swapdir=/var/spool/squid \
  60. --with-logdir=/var/log/squid \
  61. --with-pidfile=/var/run/squid.pid \
  62. --with-aufs-threads=24 \
  63. --with-filedescriptors=65536 \
  64. --with-large-files \
  65. --with-maxfd=65536 \
  66. --with-openssl \
  67. --with-default-user=proxy \
  68. --with-included-ltdl &&
  69. make && make install
  70.  
  71.  
  72. mkdir /var/lib/squid &&
  73. chown -R nobody /var/lib/squid/ &&
  74. /usr/lib/squid/ssl_crtd -c -s /var/lib/squid/ssl_db &&
  75. chown -R proxy:proxy /var/lib/squid/ssl_db/ &&
  76. chmod -R 777 /var/lib/squid/ssl_db/
  77.  
  78. silahkan buat certifikat sendiri
  79.  
  80.  
  81. squid.conf
  82. =============================================
  83.  
  84. acl localnet src all
  85.  
  86. acl SSL_ports port 443
  87.  
  88. acl Safe_ports port 88 # http
  89. acl Safe_ports port 80 # http
  90. acl Safe_ports port 21 # ftp
  91. acl Safe_ports port 443 # https
  92. acl Safe_ports port 70 # gopher
  93. acl Safe_ports port 210 # wais
  94. acl Safe_ports port 1025-65535 # unregistered ports
  95. acl Safe_ports port 280 # http-mgmt
  96. acl Safe_ports port 488 # gss-http
  97. acl Safe_ports port 591 # filemaker
  98. acl Safe_ports port 777 # multiling http
  99. acl CONNECT method CONNECT
  100.  
  101. # TAG: QUERY
  102. # -----------------------------------------------------------------------------
  103. acl QUERY urlpath_regex -i (hackshield|blank.html|infinity.js|hshield.da|renew_session_token.php|recaptcha.js|dat.asp|notice.swf|patchlist.txt|hackshield|captcha|reset.css|update.ver|notice.html|updates.txt|gamenotice|images.kom|patchinfo.xml|noupdate.ui|\.Xtp|\.htc|\.txt)
  104. acl QUERY urlpath_regex -i (patch.conf|uiimageset.xml.iop|gashaponwnd.xml.iop|loading.swf|download.swf|version.list|version.ini|launch.jnlp|server_patch.cfg.iop|core.swf|Loading.swf|resouececheck.sq|mainloading.swf|config.xml|gemmaze.swf|xml.png|size.xml|resourcesbar.swf|version.xml|version.list|delete.ini)
  105. acl QUERY urlpath_regex -i \.(jsp|asp|aspx|cfg|iop|zip|php|xml|html)(\?|$)
  106. cache deny QUERY
  107.  
  108. #
  109. acl dontstore url_regex ^http:\/\/(([\d\w-]*(\.[^\.\-]*?\..*?))(\/\mosalsal\/[\d]{4}\/.*\/)(.*\.flv))\?start.*
  110. acl dontstore url_regex redbot\.org \.php
  111. acl dontstore url_regex -i ^http:\/\/.*gemscool\.com\/.*
  112. acl dontstore url_regex \.(aspx|php)\?
  113. acl dontstore url_regex goldprice\.org\/NewCharts\/gold\/images\/.*\.png
  114. acl dontstore url_regex google\.co(m|\.[a-z]{2})\/complete\/search\?
  115. acl dontstore url_regex redirector\.([0-9.]{4}|.*\.youtube\.com|.*\.googlevideo\.com|.*\.video\.google\.com)\/(get_video\?|videodownload\?|videoplayback.*id|get_video_info\?|ptracking\?|player_204\?|stream_204\?).*
  116.  
  117. acl store_yt_id url_regex -i youtube.*(ptracking|stream_204|playback|player_204|watchtime|set_awesome|s\?|ads).*(video_id|docid|\&v|content_v)\=([^\&\s]*).*$
  118. acl store_id_list_yt url_regex -i (youtube|googlevideo).*videoplayback.*$
  119. acl store_id_list_yt url_regex ^https?\:\/\/([0-9.]{4}|.*\.youtube\.com|.*\.googlevideo\.com|.*\.video\.google\.com)\/(get_video\?|videodownload\?|videoplayback.*id).*
  120.  
  121. request_header_access Range deny store_id_list_yt
  122. range_offset_limit 10 KB store_id_list_yt
  123.  
  124. acl loop_302 http_status 302
  125. acl getmethod method GET
  126.  
  127. #Permisision
  128.  
  129. http_access deny !Safe_ports
  130. http_access deny CONNECT !SSL_ports
  131. http_access allow localhost manager
  132. http_access deny manager
  133. http_access allow localnet
  134. http_access allow localhost
  135. http_access deny all
  136.  
  137. #SSL
  138.  
  139. always_direct allow all
  140. ssl_bump server-first all
  141. sslproxy_cert_error deny all
  142. sslproxy_flags DONT_VERIFY_PEER
  143.  
  144. sslcrtd_program /usr/lib/squid/ssl_crtd -s /var/lib/squid/ssl_db -M 4MB
  145. sslcrtd_children 8 startup=1 idle=1
  146.  
  147. ###############################################################################
  148. # Squid normally listens to port 3128
  149. ###############################################################################
  150. http_port 3130 ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=/etc/squid/ssl_cert/myCA2.pem
  151. http_port 3129 tproxy
  152. http_port 3128
  153.  
  154. # TAG: Store-id Program
  155. # -----------------------------------------------------------------------------
  156. store_id_program /etc/squid/store-ytb.pl
  157. store_id_children 100 startup=0 idle=1 concurrency=1000
  158.  
  159. # TAG: Store-id Access
  160. # -----------------------------------------------------------------------------
  161. store_id_access deny dontstore
  162. store_id_access deny !getmethod
  163.  
  164. store_id_extras "%{Referer}>h"
  165.  
  166. store_id_access allow store_id_list_yt
  167. store_id_access allow store_yt_id
  168. store_id_access deny all
  169. store_id_bypass on
  170.  
  171. # TAG: Youtube 302
  172. # -----------------------------------------------------------------------------
  173. store_miss deny store_id_list_yt loop_302
  174. send_hit deny store_id_list_yt loop_302
  175.  
  176. acl loop rep_mime_type -i mime-type ^text/html
  177. acl loop rep_mime_type -i mime-type ^text/plain
  178.  
  179. store_miss deny loop_302
  180. send_hit deny loop_302
  181.  
  182. store_miss deny loop
  183. send_hit deny loop
  184. #MEMORY
  185. client_dst_passthru on
  186. cache_mem 8 MB
  187. maximum_object_size_in_memory 0
  188. memory_cache_shared off
  189. memory_cache_mode disk
  190. memory_replacement_policy heap GDSF
  191. #DISK
  192. cache_replacement_policy heap LFUDA
  193. minimum_object_size 1 bytes
  194. maximum_object_size 1 GB
  195.  
  196. cache_dir aufs /cache-1 320000 16 256 # sesuaikan dengan drive penyimpanan cache
  197. cache_dir aufs /cache-2 500000 16 256 # sesuaikan dengan drive penyimpanan cache
  198.  
  199. store_dir_select_algorithm round-robin
  200. cache_swap_low 90
  201. cache_swap_high 95
  202.  
  203.  
  204. #LOG
  205. access_log /tmp/access.log squid
  206. logfile_daemon /usr/lib/squid/log_file_daemon
  207. cache_store_log none
  208. logfile_rotate 1
  209. mime_table /etc/squid/mime.conf
  210. pid_filename /var/run/squid.pid
  211. strip_query_terms off
  212. buffered_logs off
  213.  
  214. cache_log /dev/null
  215. coredump_dir /var/spool/squid
  216.  
  217. ###############################################################################
  218. # Add any of your own refresh_pattern entries above these.
  219. ###############################################################################
  220. refresh_pattern ^ftp: 1440 20% 10080
  221. refresh_pattern ^gopher: 1440 0% 1440
  222. refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
  223.  
  224. # Youtube Video
  225. refresh_pattern -i (get_video\?|videoplayback\?|videodownload\?|\.mp4|\.webm|\.flv|((audio|video)\/(webm|mp4))) 241920 100% 241920 override-expire ignore-reload ignore-private ignore-no-store ignore-must-revalidate reload-into-ims ignore-auth store-stale
  226. refresh_pattern -i ^https?\:\/\/.*\.googlevideo\.com\/videoplayback.* 10080 99% 43200 override-lastmod override-expire ignore-reload reload-into-ims ignore-private reload-into-ims ignore-auth store-stale
  227. refresh_pattern -i ^https?\:\/\/.*\.googlevideo\.com\/videoplayback.*$ 241920 100% 241920 override-expire ignore-reload ignore-private ignore-no-store ignore-must-revalidate reload-into-ims ignore-auth store-stale
  228.  
  229. # Image Youtube
  230. refresh_pattern -i (yimg|twimg)\.com\.* 1440 100% 129600 override-expire ignore-reload reload-into-ims
  231. refresh_pattern -i (ytimg|ggpht)\.com\.* 1440 80% 129600 override-expire override-lastmod ignore-auth ignore-reload reload-into-ims
  232.  
  233.  
  234. ###############################################################################
  235. ## ERROR PAGE OPTIONS
  236. ###############################################################################
  237. error_directory /usr/share/squid/errors/en
  238. error_log_languages off
  239.  
  240. qos_flows tos local-hit=0x30 parent-hit=0x34
  241.  
  242. store-ytb.pl
  243. =========================
  244. #!/usr/bin/perl
  245. ###########################
  246. #
  247. # Store-ID dengan asumsi chanel berapapun
  248. #
  249. ###########################
  250. $|=1;
  251. while (<>) {
  252. my $chan = "";
  253. if (s/^(\d+\s+)//o) {
  254. $chan = $1;
  255. }
  256. $_ =~ s/(\s+.+)//o;
  257.  
  258. if ($_ =~ m/^https?\:\/\/.*youtube.*(ptracking|stream_204|player_204|gen_204).*(video_id|docid|v)\=([^\&\s]*).*/){
  259. $vid = $3 ;
  260. @cpn = m/[&?]cpn\=([^\&\s]*)/;
  261. $fn = "/tmp/@cpn";
  262. unless (-e $fn) {
  263. open FH,">".$fn ;
  264. print FH "$vid\n";
  265. close FH;
  266. }
  267. print $chan, "ERR\n" ;
  268.  
  269. } elsif ($_ =~ m/^https?\:\/\/.*(youtube|google).*videoplayback.*/){
  270. @itag = m/[&?](itag=[0-9]*)/;
  271. @ids = m/[&?]id\=([^\&\s]*)/;
  272. @mime = m/[&?](mime\=[^\&\s]*)/;
  273. @cpn = m/[&?]cpn\=([^\&\s]*)/;
  274. @range = m/[&?](range=[^\&\s]*)/;
  275. if (defined($cpn[0])) {
  276. $fn = "/tmp/@cpn";
  277. if (-e $fn) {
  278. open FH,"<".$fn ;
  279. $id = <FH>;
  280. chomp $id ;
  281. close FH ;
  282. } else {
  283. $id = $ids[0] ;
  284. }
  285. print $chan, "OK store-id=http://googlevideo.squid.internal/id=" . $id . "&@itag@range@mime\n" ;
  286. } else {
  287. print $chan, "ERR\n" ;
  288. }
  289. } else {
  290. print $chan, "ERR\n" ;
  291. }
  292. }
  293.  
  294.  
  295. =================================
  296. chmod +x store-ytb.pl
  297. chmod +x squid
  298. chown proxy:proxy /cache-1
  299. chown proxy:proxy /cache-2 &&
  300. chmod 777 /cache-1 &&
  301. chmod 777 /cache-2
  302. squid -f /etc/squid/squid.conf -z
  303.  
  304. update-rc.d squid defaults
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement