forked from poppyred/1.6.x
/
exec.squidstream.php
executable file
·1421 lines (1186 loc) · 52.7 KB
/
exec.squidstream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if(is_file("/etc/artica-postfix/FROM_ISO")){if(is_file("/etc/init.d/artica-cd")){print "Starting......: ".date("H:i:s")." artica-". basename(__FILE__)." Waiting Artica-CD to finish\n";die();}}
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
$GLOBALS["FORCE"]=false;
$GLOBALS["RECONFIGURE"]=false;
$GLOBALS["SWAPSTATE"]=false;
$GLOBALS["CHECK"]=false;
$GLOBALS["SERVICE_NAME"]="Squid-Cache Stream Backend";
$GLOBALS["SERVICE_NAME2"]="Videocache Scheduler";
if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["VERBOSE"]=true;$GLOBALS["OUTPUT"]=true;$GLOBALS["debug"]=true;ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);ini_set('error_append_string',null);}
if(preg_match("#--output#",implode(" ",$argv))){$GLOBALS["OUTPUT"]=true;}
if(preg_match("#schedule-id=([0-9]+)#",implode(" ",$argv),$re)){$GLOBALS["SCHEDULE_ID"]=$re[1];}
if(preg_match("#--force#",implode(" ",$argv),$re)){$GLOBALS["FORCE"]=true;}
if(preg_match("#--reconfigure#",implode(" ",$argv),$re)){$GLOBALS["RECONFIGURE"]=true;}
if(preg_match("#--check#",implode(" ",$argv),$re)){$GLOBALS["CHECK"]=true;}
$GLOBALS["AS_ROOT"]=true;
include_once(dirname(__FILE__).'/framework/class.unix.inc');
include_once(dirname(__FILE__).'/framework/frame.class.inc');
include_once(dirname(__FILE__).'/framework/class.settings.inc');
include_once(dirname(__FILE__).'/ressources/class.squid.inc');
$GLOBALS["ARGVS"]=implode(" ",$argv);
if($argv[1]=="--stop"){$GLOBALS["OUTPUT"]=true;stop();die();}
if($argv[1]=="--start"){$GLOBALS["OUTPUT"]=true;start();die();}
if($argv[1]=="--restart"){$GLOBALS["OUTPUT"]=true;restart();die();}
if($argv[1]=="--reload"){$GLOBALS["OUTPUT"]=true;reload();die();}
if($argv[1]=="--build"){$GLOBALS["OUTPUT"]=true;build();reload(true);die();}
if($argv[1]=="--install"){$GLOBALS["OUTPUT"]=true;install_video_cache(true);die();}
if($argv[1]=="--reinstall"){$GLOBALS["OUTPUT"]=true;reinstall_video_cache(true);die();}
if($argv[1]=="--parse"){$GLOBALS["OUTPUT"]=true;ParseScheduler();die();}
if($argv[1]=="--backend-ip"){$GLOBALS["VERBOSE"]=true;BackendIP();die();}
if($argv[1]=="--vc-scheduler-start"){$GLOBALS["OUTPUT"]=true;start_vc_scheduler();die();}
if($argv[1]=="--vc-scheduler-stop"){$GLOBALS["OUTPUT"]=true;stop_vc_scheduler();die();}
if($argv[1]=="--vc-scheduler-restart"){$GLOBALS["OUTPUT"]=true;restart_vc_scheduler();die();}
if($argv[1]=="--vc-scheduler-reload"){$GLOBALS["OUTPUT"]=true;restart_vc_scheduler();die();}
if($argv[1]=="--status"){get_status();exit;}
function restart($nopid=false){
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if(!$nopid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Restarting....: ".date("H:i:s")." [INIT]: Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
@file_put_contents($pidfile, getmypid());
stop(true);
if($GLOBALS["CHECK"]){check_dirs();}
build();
if(!install_video_cache()){
if($GLOBALS["OUTPUT"]){echo "Restarting....: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Unable to install\n";}
return;
}
start(true);
$php=$unix->LOCATE_PHP5_BIN();
$nohup=$unix->find_program("nohup");
if($GLOBALS["OUTPUT"]){echo "Restarting....: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Reloading Apache\n";}
shell_exec("$php /usr/share/artica-postfix/exec.freeweb.php --reload");
if($GLOBALS["OUTPUT"]){echo "Restarting....: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Reloading Main Proxy\n";}
shell_exec("/etc/init.d/squid reload --script=".basename(__FILE__));
}
function reload($nopid=false){
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if(!$nopid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
@file_put_contents($pidfile, getmypid());
$sock=new sockets();
$EnableStreamCache=intval($sock->GET_INFO("EnableStreamCache"));
if($EnableStreamCache==0){
if($GLOBALS["OUTPUT"]){echo "Reload........: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see EnableStreamCache )...\n";}
return;
}
$masterbin=$unix->find_program("streamsquidcache");
if(!is_file($masterbin)){
if($GLOBALS["OUTPUT"]){echo "Reload........: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n";}
return;
}
$pid=streamsquidcache_pid();
if($unix->process_exists($pid)){
$time=$unix->PROCCESS_TIME_MIN($pid);
$php=$unix->LOCATE_PHP5_BIN();
if($GLOBALS["OUTPUT"]){echo "Reload........: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Service running since {$time}Mn...\n";}
shell_exec("$masterbin -f /etc/streamsquidcache/squid.conf -k reconfigure");
reload_vc_scheduler();
if($GLOBALS["OUTPUT"]){echo "Reload........: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Reloading Apache\n";}
shell_exec("$php /usr/share/artica-postfix/exec.freeweb.php --reload");
if($GLOBALS["OUTPUT"]){echo "Reload........: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Reloading Main Proxy\n";}
shell_exec("/etc/init.d/squid reload --script=".basename(__FILE__));
return;
}
start(true);
}
function NETWORK_ALL_INTERFACES(){
if(isset($GLOBALS["NETWORK_ALL_INTERFACES"])){return $GLOBALS["NETWORK_ALL_INTERFACES"];}
$unix=new unix();
$GLOBALS["NETWORK_ALL_INTERFACES"]=$unix->NETWORK_ALL_INTERFACES(true);
unset($GLOBALS["NETWORK_ALL_INTERFACES"]["127.0.0.1"]);
}
function BackendIP(){
$squid=new squidbee();
echo "\n\nResult: ".$squid->VerifStreamProxyBindIP()."\n\n";
}
function build(){
$sock=new sockets();
$emailprefix=null;
$unix=new unix();
$ini=new Bs_IniHandler();
$IPADDRSSL=array();
$IPADDRSSL2=array();
$users=new usersMenus();
$uuid=$unix->GetUniqueID();
if($uuid==null){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} no UUID !!, return\n";}
return;
}
$ArticaSquidParameters=$sock->GET_INFO('ArticaSquidParameters');
$visible_hostname=$ini->_params["NETWORK"]["visible_hostname"];
if($visible_hostname==null){$visible_hostname=$unix->hostname_g();}
$SquidBinIpaddr=$sock->GET_INFO("SquidBinIpaddr");
$AllowAllNetworksInSquid=$sock->GET_INFO("AllowAllNetworksInSquid");
if(!is_numeric($AllowAllNetworksInSquid)){$AllowAllNetworksInSquid=1;}
$ini->loadString($ArticaSquidParameters);
NETWORK_ALL_INTERFACES();
$LISTEN_PORT=intval($ini->_params["NETWORK"]["LISTEN_PORT"]);
$ICP_PORT=intval(trim($ini->_params["NETWORK"]["ICP_PORT"]));
$certificate_center=$ini->_params["NETWORK"]["certificate_center"];
$SSL_BUMP=intval($ini->_params["NETWORK"]["SSL_BUMP"]);
$ssl=false;
if($ICP_PORT==0){$ICP_PORT=3130;}
if($LISTEN_PORT==0){$LISTEN_PORT=3128;}
$squid=new squidbee();
$q=new mysql_squid_builder();
$LogsWarninStop=intval($sock->GET_INFO("LogsWarninStop"));
$chown=$unix->find_program("chown");
$python=$unix->find_program("python");
$StreamCachePort=intval($sock->GET_INFO("StreamCachePort"));
$StreamCacheSize=intval($sock->GET_INFO("StreamCacheSize"));
$StreamCacheSSLPort=intval($sock->GET_INFO("StreamCacheSSLPort"));
$StreamCacheICPPort=intval($sock->GET_INFO("StreamCacheICPPort"));
$StreamCacheLocalPort=intval($sock->GET_INFO("StreamCacheLocalPort"));
$StreamCacheUrlRewiteNumber=intval($sock->GET_INFO("StreamCacheUrlRewiteNumber"));
if($StreamCacheSize==0){$StreamCacheSize=1500;}
if($StreamCachePort==0){$StreamCachePort=5559;}
if($StreamCacheLocalPort==0){$StreamCacheLocalPort=5563;}
if($StreamCacheSSLPort==0){$StreamCacheSSLPort=5560;}
if($StreamCacheICPPort==0){$StreamCacheICPPort=5562;}
if($StreamCacheUrlRewiteNumber==0){$StreamCacheUrlRewiteNumber=15;}
$StreamCacheBindProxy=$squid->VerifStreamProxyBindIP();
$StreamCacheOutProxy=$sock->GET_INFO("StreamCacheOutProxy");
if(!isset($GLOBALS["NETWORK_ALL_INTERFACES"][$StreamCacheOutProxy])){$StreamCacheOutProxy=null;}
$f[]="";
$f[]="# ************** REDIRECTOR ********************";
$f[]="url_rewrite_program $python /usr/share/videocache/videocache.py";
$f[]="url_rewrite_children $StreamCacheUrlRewiteNumber";
$f[]="url_rewrite_concurrency $StreamCacheUrlRewiteNumber";
$f[]="";
$f[]="# ***********************************************";
$f[]="";
$f[]="acl vc_deny_myport myport $StreamCacheLocalPort";
$f[]="";
$f[]="acl vc_deny_url url_regex -i \.blip\.tv\/(.*)filename \.hardsextube\.com\/videothumbs \.xtube\.com\/(.*)(Thumb|videowall) www\.youtube\.com\/";
$f[]="acl vc_deny_url url_regex -i \.(youtube|googlevideo)\.com\/.*\/manifest";
$f[]="acl vc_deny_url url_regex -i \.(youtube|googlevideo)\.com\/videoplayback?.*playerretry=[0-9]";
$f[]="acl vc_deny_dom dstdomain .manifest.youtube.com .manifest.googlevideo.com";
$f[]="acl vc_deny_dom dstdomain .redirector.googlevideo.com .redirector.youtube.com";
$f[]="";
$f[]="acl vc_url url_regex -i \/youku\/[0-9A-Z]+\/[0-9A-Z\-]+\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg)";
$f[]="acl vc_url url_regex -i \/(.*)key=[a-z0-9]+(.*)\.flv";
$f[]="acl vc_url url_regex -i \-xh\.clients\.cdn[0-9a-zA-Z]?[0-9a-zA-Z]?[0-9a-zA-Z]?\.com\/data\/(.*)\.flv";
$f[]="acl vc_url url_regex -i \.(youtube|youtube-nocookie|googlevideo)\.com\/feeds\/api\/videos\/[0-9a-zA-Z_-]{11}\/";
$f[]="acl vc_url url_regex -i \.(youtube|youtube-nocookie|googlevideo)\.com\/(videoplayback|get_video|watch_popup|user_watch|stream_204|get_ad_tags|get_video_info|player_204|ptracking|set_awesome)\?";
$f[]="acl vc_url url_regex -i \.(youtube|youtube-nocookie|googlevideo)\.com\/(v|e|embed)\/[0-9a-zA-Z_-]{11}";
$f[]="acl vc_url url_regex -i \.youtube\.com\/s\? \.youtube\.com\/api\/stats\/(atr|delayplay|playback|watchtime)\?";
$f[]="acl vc_url url_regex -i \.(youtube|youtube-nocookie|googlevideo)\.com\/videoplayback\/id\/[0-9a-zA-Z_-]+\/";
$f[]="acl vc_url url_regex -i \.android\.clients\.google\.com\/market\/GetBinary\/";
$f[]="acl vc_url url_regex -i cs(.*)\.vk\.me\/(.*)/([a-zA-Z0-9.]+)\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg)";
$f[]="acl vc_url url_regex -i video(.*)\.rutube\.ru\/(.*)/([a-zA-Z0-9.]+)\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg)Seg[0-9]+-Frag[0-9]+";
$f[]="";
$f[]="acl vc_dom_r dstdom_regex -i msn\..*\.(com|net)";
$f[]="acl vc_dom_r dstdom_regex -i msnbc\..*\.(com|net)";
$f[]="acl vc_dom_r dstdom_regex -i video\..*\.fbcdn\.net";
$f[]="acl vc_dom_r dstdom_regex -i myspacecdn\..*\.footprint\.net";
$f[]="";
$f[]="acl vc_dom dstdomain .stream.aol.com .5min.com .msn.com .blip.tv .dmcdn.net .break.com .vimeo.com .vimeocdn.com video.thestaticvube.com";
$f[]="acl vc_dom dstdomain .dailymotion.com .c.wrzuta.pl .v.imwx.com .mccont.com .myspacecdn.com video-http.media-imdb.com fcache.veoh.com";
$f[]="acl vc_dom dstdomain .hardsextube.com .public.extremetube.phncdn.com .redtubefiles.com .video.pornhub.phncdn.com .videos.videobash.com";
$f[]="acl vc_dom dstdomain .public.keezmovies.com .public.keezmovies.phncdn.com .slutload-media.com .public.spankwire.com .xtube.com";
$f[]="acl vc_dom dstdomain .public.youporn.phncdn.com .xvideos.com .tube8.com .public.spankwire.phncdn.com .pornhub.com";
$f[]="";
$f[]="";
$f[]="acl vc_deny_url url_regex -i crossdomain.xml";
$f[]="acl vc_method method GET";
$f[]="acl vc_header req_header X-Requested-With -i videocache";
$f[]="url_rewrite_access deny vc_deny_myport";
$f[]="url_rewrite_access deny !vc_method";
$f[]="url_rewrite_access deny vc_header";
$f[]="url_rewrite_access deny vc_deny_dom";
$f[]="url_rewrite_access deny vc_deny_url";
$f[]="url_rewrite_access allow vc_dom";
$f[]="url_rewrite_access allow vc_url";
$f[]="url_rewrite_access allow vc_dom_r";
CheckFilesAndSecurity();
$f=array();
$f[]="[main]";
$StreamCacheBindHTTP=VerifHTTPIP();
$FreeWebListenPort=$sock->GET_INFO("FreeWebListenPort");
$FreeWebListenSSLPort=$sock->GET_INFO("FreeWebListenSSLPort");
if(!is_numeric($FreeWebListenSSLPort)){$FreeWebListenSSLPort=443;}
if(!is_numeric($FreeWebListenPort)){$FreeWebListenPort=80;}
if($FreeWebListenPort<>80){ $StreamCacheBindHTTP="$StreamCacheBindHTTP:$FreeWebListenPort"; }
$SquidMgrListenPort=intval($sock->GET_INFO("SquidMgrListenPort"));
$SquidDebugPortInterface=intval($sock->GET_INFO("SquidDebugPortInterface"));
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache IP...............: $StreamCacheBindHTTP:$FreeWebListenPort\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Proxy Port..............: $SquidMgrListenPort\n";}
if(!$users->CORP_LICENSE){$emailprefix="trial_"; }
$f[]="client_email = {$emailprefix}$uuid@articatech.com";
$f[]="scheduler_pidfile = /var/run/squid/videocache.pid";
$f[]="cache_host = $StreamCacheBindHTTP";
$f[]="source_ip = 127.0.0.1";
$f[]="videocache_user = squid";
$f[]="";
$f[]="# # # Proxy specifications # # #";
$f[]="squid_access_log=/var/log/squid/access.log";
$f[]="enable_access_log_monitoring = 1";
$f[]="squid_access_log_format_combined = 0";
$f[]="";
$f[]="base_dir = /home/squid/videocache/";
$f[]="logdir = /var/log/squid/";
$f[]="pidfile = pidfile.txt";
$f[]="this_proxy=127.0.0.1:$SquidMgrListenPort";
$f[]="cache_swap_low = 90";
$f[]="cache_swap_high = 93";
$f[]="disk_cleanup_strategy = 1";
$f[]="enable_videocache = 1";
$f[]="offline_mode = 0";
$f[]="base_dir_selection = 2";
$f[]="# # # MySQL setup # # #";
$f[]="db_hostname = /var/run/mysqld/squid-db.sock";
$f[]="db_username = root";
$f[]="db_password =";
$f[]="db_database = videocache";
$f[]="max_cache_processes = 4";
$f[]="max_cache_speed = 0";
$f[]="";
$f[]="# # # Remote Proxy # # #";
$f[]="proxy =127.0.0.1:$SquidMgrListenPort";
$f[]="max_video_size = 0";
$f[]="min_video_size = 0";
$f[]="force_video_size = 1";
$f[]="logformat = %tl %p %s %i %w %c %v %m %d";
$f[]="scheduler_logformat = %tl %p %s %i %w %c %v %m %d";
$f[]="cleaner_logformat = %tl %p %s %w %c %v %m %d";
$f[]="db_query_logformat = %tl %m";
$f[]="timeformat = %d/%b/%Y:%H:%M:%S";
$f[]="enable_videocache_log = 1";
$f[]="enable_scheduler_log = 1";
$f[]="enable_cleaner_log = 1";
$f[]="enable_trace_log = 1";
$f[]="enable_db_query_log = 0";
$f[]="logfile = videocache.log";
$f[]="scheduler_logfile = videocache-scheduler.log";
$f[]="cleaner_logfile = videocache-cleaner.log";
$f[]="tracefile = videocache-trace.log";
$f[]="db_query_logfile = videocache-database.log";
$f[]="max_logfile_size = 90";
$f[]="max_scheduler_logfile_size = 90";
$f[]="max_cleaner_logfile_size = 5";
$f[]="max_tracefile_size = 5";
$f[]="max_db_query_logfile_size = 5";
$f[]="#------------------------------------------------------------------------------";
$f[]="# Website Specific Options |";
$f[]="#------------------------------------------------------------------------------";
$f[]="";
$f[]="# This option enables the caching of Android apps across various devices.";
$f[]="# This option's value can be either 0 or 1.";
$f[]="enable_android_cache = 1";
$f[]="";
$f[]="# These options set minimum and maximum size (in KB) for android apps. An app with";
$f[]="# size smaller than min_android_app_size or larger than max_android_app_size will";
$f[]="# not be cached. Set to zero (0) to disable.";
$f[]="# Default:";
$f[]="# min_android_app_size = 1024";
$f[]="# max_android_app_size = 0";
$f[]="min_android_app_size = 1024";
$f[]="max_android_app_size = 0";
$f[]="";
$f[]="# This option enables the caching of youtube videos.";
$f[]="# This option's value can be either 0 or 1.";
$f[]="#----------------------------------------------------------------------------";
$f[]="# | IMPORTANT : Each supported website have an option to enable or disable |";
$f[]="# | caching of its videos in the form enable_website_cache. You can opt to |";
$f[]="# | cache the websites you want by disabling the caching for other websites |";
$f[]="#----------------------------------------------------------------------------";
$f[]="# Default : 1";
$f[]="enable_youtube_cache = 1";
$f[]="";
$f[]="# This options determines if Videocache will cache different YouTube video";
$f[]="# formats separately. Please select an appropriate algorithm from the listed below.";
$f[]="# Available strategies:";
$f[]="# 1 : (disabled) Don't check for YouTube video formats. Cache one of the formats";
$f[]="# and serve it for requests for all kinds of formats.";
$f[]="# 2 : (strict) Strictly check for YouTube formats and cache all formats separately.";
$f[]="# Consumes maximum bandwidth.";
$f[]="# 3 : (approximate) Check YouTube formats but with approximation. For example,";
$f[]="# if a client asked for a video in 480p format and we already have 360p";
$f[]="# format of the same video in cache, then serve 360p format and vice-versa.";
$f[]="# Default : 3";
$f[]="enable_youtube_format_support = 3";
$f[]="";
$f[]="# This option enables the caching of HTML5 videos from YouTube.";
$f[]="# This option's value can be 0 or 1.";
$f[]="# Default : 1";
$f[]="enable_youtube_html5_videos = 1";
$f[]="";
$f[]="# This option enables the caching of 3D videos from YouTube.";
$f[]="# This option's value can either be 0 or 1.";
$f[]="# Default : 1";
$f[]="enable_youtube_3d_videos = 1";
$f[]="";
$f[]="# This option enables the caching of several video segments used by YouTube";
$f[]="# to serve a single video. This option works only when enable_store_log_monitoring";
$f[]="# option is enabled. This option's value can either be 0 or 1.";
$f[]="# Default : 1";
$f[]="enable_youtube_partial_caching = 1";
$f[]="";
$f[]="# This option enforces the maximum video quality from Youtube. If a user browses";
$f[]="# a video in higher quality format, Videocache will still cache and serve the video";
$f[]="# in the format specified below or a lower quality format depending on the availability.";
$f[]="# Valid values : 480p, 720p, 1080p, 2304p (Please don't append p)";
$f[]="# Default : 720";
$f[]="max_youtube_video_quality = 720";
$f[]="";
$f[]="# This option will help in enhancing the performance of Videocache.";
$f[]="# If min_youtube_views is set to 1000, then Videocache will cache a video only";
$f[]="# if it has received at least 1000 views on Youtube. Otherwise, video will not";
$f[]="# be cached. Set this to 0 to disable this option.";
$f[]="# Default : 100";
$f[]="min_youtube_views = 100";
$f[]="";
$f[]="# www.aol.com";
$f[]="enable_aol_cache = 1";
$f[]="";
$f[]="# www.bing.com";
$f[]="enable_bing_cache = 1";
$f[]="";
$f[]="# www.blip.tv";
$f[]="enable_bliptv_cache = 1";
$f[]="";
$f[]="# www.break.com";
$f[]="enable_breakcom_cache = 1";
$f[]="";
$f[]="# www.dailymotion.com";
$f[]="enable_dailymotion_cache = 1";
$f[]="";
$f[]="# www.facebook.com";
$f[]="enable_facebook_cache = 1";
$f[]="";
$f[]="# www.imdb.com";
$f[]="enable_imdb_cache = 1";
$f[]="";
$f[]="# www.metacafe.com";
$f[]="enable_metacafe_cache = 1";
$f[]="";
$f[]="# www.myspace.com";
$f[]="enable_myspace_cache = 1";
$f[]="";
$f[]="# www.veoh.com";
$f[]="enable_veoh_cache = 1";
$f[]="";
$f[]="# www.videobash.com";
$f[]="enable_videobash_cache = 1";
$f[]="";
$f[]="# www.vimeo.com";
$f[]="enable_vimeo_cache = 1";
$f[]="";
$f[]="# www.vube.com";
$f[]="enable_vube_cache = 1";
$f[]="";
$f[]="# www.weather.com";
$f[]="enable_weather_cache = 1";
$f[]="";
$f[]="# www.wrzuta.pl";
$f[]="enable_wrzuta_cache = 1";
$f[]="";
$f[]="# www.youku.com";
$f[]="enable_youku_cache = 1";
$f[]="";
$f[]="# Pr0n sites";
$f[]="# www.extremetube.com";
$f[]="enable_extremetube_cache = 1";
$f[]="";
$f[]="# www.hardsextube.com";
$f[]="enable_hardsextube_cache = 1";
$f[]="";
$f[]="# www.keezmovies.com";
$f[]="enable_keezmovies_cache = 1";
$f[]="";
$f[]="# www.pornhub.com";
$f[]="enable_pornhub_cache = 1";
$f[]="";
$f[]="# www.redute.com";
$f[]="enable_redtube_cache = 1";
$f[]="";
$f[]="# www.slutload.com";
$f[]="enable_slutload_cache = 1";
$f[]="";
$f[]="# www.spankwire.com";
$f[]="enable_spankwire_cache = 1";
$f[]="";
$f[]="# www.tube8.com";
$f[]="enable_tube8_cache = 1";
$f[]="";
$f[]="# www.xhamster.com";
$f[]="enable_xhamster_cache = 1";
$f[]="";
$f[]="# www.xtube.com";
$f[]="enable_xtube_cache = 1";
$f[]="";
$f[]="# www.xvideos.com";
$f[]="enable_xvideos_cache = 1";
$f[]="";
$f[]="# www.youporn.com";
$f[]="enable_youporn_cache = 1";
$f[]="";
$f[]="";
$f[]="#------------------------------------------------------------------------------";
$f[]="# Apache Configuration Options |";
$f[]="#------------------------------------------------------------------------------";
$f[]="";
$f[]="# Use this option if you don't want Videocache to generate Apache specific";
$f[]="# configuration on your system. This can be used when you are using other";
$f[]="# web server than Apache. Like lighttpd etc.";
$f[]="# Default : 0";
$f[]="skip_apache_conf = 0";
$f[]="";
$f[]="# This option specifies the absolute path to your Apache's conf.d or extra";
$f[]="# directory. Videocache will generate and save Videocache spcecific ";
$f[]="# configuration for Apache in this directory.";
$f[]="# Example : /etc/httpd/conf.d/ or /etc/apache2/conf.d/ or /etc/httpd/extra/";
$f[]="# Default : NOT SET";
$httpdconf=$unix->LOCATE_APACHE_CONF_PATH();
$python=$unix->find_program("python");
$DAEMON_PATH=$unix->getmodpathfromconf($httpdconf);
$sock->SET_INFO("EnableFreeWeb",1);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache..................: $DAEMON_PATH\n";}
$f[]="apache_conf_dir = $DAEMON_PATH";
$f[]="";
$f[]="# This option can be used to hide cache directories from your clients. Your";
$f[]="# clients will not be able to browse the contents cache directories via HTTP";
$f[]="# if this option is enabled. Browsing videos will not be affected.";
$f[]="# Default : 1";
$f[]="hide_cache_dirs = 1";
$f[]="";
@file_put_contents("/etc/videocache.conf", @implode("\n", $f));
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/videocache.conf done\n";}
shell_exec("$python /usr/share/videocache/vc-update >/dev/null 2>&1");
$f[]=array();
$StreamCacheCache=$sock->GET_INFO("StreamCacheCache");
$StreamCacheMainCache=$sock->GET_INFO("StreamCacheMainCache");
if($StreamCacheCache==null){$StreamCacheCache="/home/squid/videocache";}
if($StreamCacheMainCache==null){$StreamCacheMainCache="/home/squid/streamcache";}
$f[]="##############################################################################";
$f[]="# #";
$f[]="# file : $DAEMON_PATH/videocache.conf #";
$f[]="# #";
$f[]="# Videocache is a squid url rewriter to cache videos from various websites. #";
$f[]="# Check http://cachevideos.com/ for more details. #";
$f[]="# #";
$f[]="# ----------------------------- Note This ---------------------------------- #";
$f[]="# Don't change this file under any circumstances. #";
$f[]="# Use /etc/videocache.conf to configure Videocache. #";
$f[]="# #";
$f[]="##############################################################################";
$f[]="";
$f[]="";
$f[]="Alias /crossdomain.xml /home/squid/videocache/youtube_crossdomain.xml";
$f[]="Alias /videocache $StreamCacheCache/";
$f[]="<Directory $StreamCacheCache/>";
$f[]=" Options -Indexes";
$f[]=" Order Allow,Deny";
$f[]=" Allow from all";
$f[]=" <IfModule mod_headers.c>";
$f[]=" Header add Videocache \"2.0.0\"";
$f[]=" Header add X-Cache \"HIT from 192.168.1.210\"";
$f[]=" </IfModule>";
$f[]=" <IfModule mod_mime.c>";
$f[]=" AddType video/webm .webm";
$f[]=" AddType application/vnd.android.package-archive .android";
$f[]=" </IfModule>";
$f[]="</Directory>";
$f[]="";
if(!is_file("$DAEMON_PATH/videocache.conf")){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} $DAEMON_PATH/videocache.conf done\n";}
@file_put_contents("$DAEMON_PATH/videocache.conf", @implode("\n", $f));
}
$f=array();
$LOCATE_APACHE_CONF_PATH=$unix->LOCATE_APACHE_CONF_PATH();
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache config: $LOCATE_APACHE_CONF_PATH\n";}
$APACHECONF=FALSE;
$exp=explode("\n",@file_get_contents($LOCATE_APACHE_CONF_PATH));
while (list ($index, $line) = each ($exp)){
if(!preg_match("#Include.*?videocache\.conf#", $line)){continue;}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache $line Done\n";}
$APACHECONF=true;
}
$php=$unix->LOCATE_PHP5_BIN();
if(!$APACHECONF){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Reconfigure Apache\n";}
shell_exec("$php /usr/share/artica-postfix/exec.freeweb.php --httpd");
}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Configuration done..\n";}
}
function pythonInstallDir(){
return "/usr/local/lib/python2.7/dist-packages";
}
function VerifHTTPIP(){
$unix=new unix();
$sock=new sockets();
$StreamCacheBindHTTP=$sock->GET_INFO("StreamCacheBindHTTP");
$IpClass=new IP();
if(!$IpClass->isIPAddress($StreamCacheBindHTTP)){$StreamCacheBindHTTP=null;}
$NETWORK_ALL_INTERFACES=$unix->NETWORK_ALL_INTERFACES(true);
unset($NETWORK_ALL_INTERFACES["127.0.0.1"]);
if(!isset($NETWORK_ALL_INTERFACES[$StreamCacheBindHTTP])){$StreamCacheBindHTTP=null;}
if($StreamCacheBindHTTP<>null){return $StreamCacheBindHTTP;}
return $unix->NETWORK_DEFAULT_IP_ADDR();
}
function install_module($modulename){
$unix=new unix();
$packagePath="/usr/share/artica-postfix/bin/install/squid/$modulename.tar.gz";
$TMPDIR=$unix->TEMP_DIR()."/".time();
build_progress("Installing module $modulename",25);
$tar=$unix->find_program("tar");
$cd=$unix->find_program("cd");
$python=$unix->find_program("python");
$rm=$unix->find_program("rm");
if(!is_file($packagePath)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} ". basename($packagePath)." no such file\n";}
return false;}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} extracting ". basename($packagePath)."\n";}
@mkdir($TMPDIR,0755,true);
shell_exec("$tar xf $packagePath -C $TMPDIR/");
$dirs=$unix->dirdir($TMPDIR);
$workingdir=null;
while (list ($Directory, $val) = each ($dirs)){
if(is_file("$Directory/setup.py")){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} found $Directory\n";}
$workingdir=$Directory;
break;
}
}
if($workingdir==null){
recursive_remove_directory("$TMPDIR");
return false;
}
chdir($workingdir);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} installing - $python - \n";}
system("$python setup.py install");
$pythonInstallDir=pythonInstallDir();
recursive_remove_directory("$TMPDIR");
if(python_verify_modules($modulename)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} $modulename installed\n";}
return true;
}
}
function python_verify_modules($modulename){
$unix=new unix();
$python=$unix->find_program("python");
exec("$python -c \"import $modulename\" 2>&1",$results);
while (list ($index, $line) = each ($results)){
if(preg_match("#ImportError:#i", $line)){return false;}
}
return true;
}
function install_video_cache_python(){
$unix=new unix();
$packagePath="/usr/share/artica-postfix/bin/install/squid/videocache.tar.gz";
$TMPDIR=$unix->TEMP_DIR()."/".time();
$tar=$unix->find_program("tar");
$cd=$unix->find_program("cd");
$python=$unix->find_program("python");
$rm=$unix->find_program("rm");
if(!is_file($packagePath)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} ". basename($packagePath)." no such file\n";}
return false;}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} extracting ". basename($packagePath)."\n";}
@mkdir($TMPDIR,0755,true);
build_progress("Uncompressing videocache package",30);
shell_exec("$tar xf $packagePath -C $TMPDIR/");
$dirs=$unix->dirdir($TMPDIR);
$workingdir=null;
while (list ($Directory, $val) = each ($dirs)){
if(is_file("$Directory/setup.py")){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} found $Directory\n";}
$workingdir=$Directory;
break;
}
}
if($workingdir==null){
recursive_remove_directory("$TMPDIR");
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Failed workdir = NULL\n";}
return false;
}
chdir($workingdir);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} using $workingdir\n";}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} installing - $python - \n";}
build_progress("Installing videocache package",35);
system("$python setup.py -e a@b.me -u squid --cache-host 10.1.1.1 --this-proxy 127.0.0.1:3128 --squid-access-log /var/log/squid3/access.log --apache-conf-dir /etc/httpd/conf.d --db-hostname /var/run/mysqld/squid-db.sock --db-username root --db-database videocache install");
system("$python setup.py -e a@b.me -u squid --cache-host 10.1.1.1 --this-proxy 127.0.0.1:3128 --squid-access-log /var/log/squid3/access.log --apache-conf-dir /etc/httpd/conf.d --db-hostname /var/run/mysqld/squid-db.sock --db-username root --db-database videocache install");
recursive_remove_directory("$TMPDIR");
chdir("/root");
if(!is_file("/usr/share/videocache/videocache.py")){return false;}
return true;
}
function reinstall_video_cache($aspid=false){
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if($aspid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
build_progress("Already Artica task running",110);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
@file_put_contents($pidfile, getmypid());
$chattr=$unix->find_program("chattr");
build_progress("Remove old install",5);
shell_exec("$chattr -i -R /usr/share/videocache");
@unlink("/usr/share/videocache/videocache.py");
if(!install_video_cache()){
build_progress("{failed}",110);
return;
}
build_progress("Stopping services",50);
stop(true);
build_progress("Building configuration",55);
build();
build_progress("Starting services",60);
start(true);
build_progress("{done}",100);
}
function build_progress($text,$pourc){
$PROGRESS_FILE="/usr/share/artica-postfix/ressources/logs/videocache.install.progress";
$array["POURC"]=$pourc;
$array["TEXT"]=$text;
@file_put_contents($PROGRESS_FILE, serialize($array));
@chmod($GLOBALS["PROGRESS_FILE"],0755);
}
function install_video_cache($aspid=false){
$unix=new unix();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if($aspid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
@file_put_contents($pidfile, getmypid());
$modules["setuptools"]=true;
$modules["iniparse"]=true;
$modules["netifaces"]=true;
$modules["cloghandler"]=true;
$unix=new unix();
$python=$unix->find_program("python");
CHECK_DATABASE();
build_progress("Checking modules",15);
while (list ($modulename, $line) = each ($modules)){
build_progress("Checking modules $modulename",20);
if(!python_verify_modules($modulename)){
if(!install_module($modulename)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} [!!] $modulename failed\n";}
build_progress("Installing module $modulename failed",110);
return false;
}else{
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} [OK] $modulename INSTALLED\n";}
}
}else{
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} [OK] $modulename\n";}
}
}
$files=videocache_files();
$INSTALLED=true;
while (list ($modulename, $filepath) = each ($files)){
if(!is_file($filepath)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} [!!] ".basename($filepath)." no such file\n";}
$INSTALLED=false;
break;
}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} [OK] ".basename($filepath)." \n";}
}
if(!$INSTALLED){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Installing VideoCache\n";}
if(!install_video_cache_python()){
build_progress("Installing videocache package failed",110);
return false;}
$files=videocache_files();
while (list ($modulename, $filepath) = each ($files)){
if(!is_file($filepath)){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} [!!] ".basename($filepath)." no such file\n";}
return false;
}
}
}
$chattr=$unix->find_program("chattr");
shell_exec("$chattr +i -R /usr/share/videocache");
$tables["video_files"]=true;
$tables["video_queue"]=true;
$tables["youtube_cpns"]=true;
$tablesz=true;
build_progress("Installing Tables",40);
while (list ($tablename, $line) = each ($tables)){
if(!TABLE_EXISTS($tablename,"videocache")){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} missing table $tablename\n";}
$tablesz=false;}
}
if(!$tablesz){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} upgrading videocache\n";}
shell_exec("$python /usr/share/videocache/vc-update >/dev/null 2>&1");
reset($tables);
$GLOBALS["VIDEOCACHE_TABLES"]=array();
$tablesz=true;
while (list ($tablename, $line) = each ($tables)){
if(!TABLE_EXISTS($tablename,"videocache")){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} missing table $tablename\n";}
$tablesz=false;
break;
}
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} `$tablename` OK\n";}
}
}
if(!$tablesz){
build_progress("Installing Tables failed",110);
return false;}
build_progress("Installing Tables success",45);
return true;
// /artica-postfix/bin/install/squid/videocache.tar.gz
}
function videocache_files(){
$f[]="/usr/share/videocache/vcconfig.py";
$f[]="/usr/share/videocache/vcsysinfo.py";
$f[]="/usr/share/videocache/store.pyc";
$f[]="/usr/share/videocache/__init__.py";
$f[]="/usr/share/videocache/vcconfig.pyc";
$f[]="/usr/share/videocache/database.pyc";
$f[]="/usr/share/videocache/common.pyc";
$f[]="/usr/share/videocache/vcoptions.pyc";
$f[]="/usr/share/videocache/videocache.py";
$f[]="/usr/share/videocache/database.py";
$f[]="/usr/share/videocache/vcoptions.py";
$f[]="/usr/share/videocache/common.py";
$f[]="/usr/share/videocache/vcsysinfo.pyc";
$f[]="/usr/share/videocache/vcdaemon.py";
$f[]="/usr/share/videocache/websites/hardsextube.py";
$f[]="/usr/share/videocache/websites/redtube.py";
$f[]="/usr/share/videocache/websites/dailymotion.py";
$f[]="/usr/share/videocache/websites/youporn.py";
$f[]="/usr/share/videocache/websites/wrzuta.py";
$f[]="/usr/share/videocache/websites/extremetube.py";
$f[]="/usr/share/videocache/websites/rutube.pyc";
$f[]="/usr/share/videocache/websites/pornhub.py";
$f[]="/usr/share/videocache/websites/bing.py";
$f[]="/usr/share/videocache/websites/slutload.py";
$f[]="/usr/share/videocache/websites/__init__.py";
$f[]="/usr/share/videocache/websites/vube.py";
$f[]="/usr/share/videocache/websites/imdb.py";
$f[]="/usr/share/videocache/websites/bliptv.py";
$f[]="/usr/share/videocache/websites/vimeo.py";
$f[]="/usr/share/videocache/websites/tube8.py";
$f[]="/usr/share/videocache/websites/keezmovies.py";
$f[]="/usr/share/videocache/websites/youtube.py";
$f[]="/usr/share/videocache/websites/android.py";
$f[]="/usr/share/videocache/websites/veoh.py";
$f[]="/usr/share/videocache/websites/rutube.py";
$f[]="/usr/share/videocache/websites/xhamster.py";
$f[]="/usr/share/videocache/websites/videobash.py";
$f[]="/usr/share/videocache/websites/myspace.py";
$f[]="/usr/share/videocache/websites/vkcom.py";
$f[]="/usr/share/videocache/websites/weather.py";
$f[]="/usr/share/videocache/websites/aol.py";
$f[]="/usr/share/videocache/websites/xvideos.py";
$f[]="/usr/share/videocache/websites/facebook.py";
$f[]="/usr/share/videocache/websites/xtube.py";
$f[]="/usr/share/videocache/websites/vkcom.pyc";
$f[]="/usr/share/videocache/websites/youku.py";
$f[]="/usr/share/videocache/websites/breakcom.py";
$f[]="/usr/share/videocache/websites/__init__.pyc";
$f[]="/usr/share/videocache/websites/spankwire.py";
$f[]="/usr/share/videocache/websites/metacafe.py";
$f[]="/usr/share/videocache/vc-update";
$f[]="/usr/share/videocache/vc-scheduler";
$f[]="/usr/share/videocache/Commercial License.txt";
$f[]="/usr/share/videocache/store.py";
$f[]="/usr/share/videocache/fsop.pyc";
$f[]="/usr/share/videocache/fsop.py";
return $f;
}
function CHECK_DATABASE(){
build_progress("Chking database",10);
$bd=@mysql_connect(":/var/run/mysqld/squid-db.sock","root",null);
if(!$bd){
$des=@mysql_error(); $errnum=@mysql_errno();
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Error $errnum $des\n";}
return false;
}
$ok=@mysql_select_db("mysql",$bd);
if(!$ok){
$des=@mysql_error(); $errnum=@mysql_errno();
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Error $errnum $des\n";}
return false;
}
@mysql_unbuffered_query("CREATE DATABASE videocache",$bd);
}
function TABLE_EXISTS($table){
$resutz=false;
if(isset($GLOBALS["VIDEOCACHE_TABLES"][$table])){return true;}
$bd=@mysql_connect(":/var/run/mysqld/squid-db.sock","root",null);
if(!$bd){
$des=@mysql_error(); $errnum=@mysql_errno();
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Error $errnum $des\n";}
return false;
}
$ok=@mysql_select_db("videocache",$bd);
if(!$ok){
$des=@mysql_error(); $errnum=@mysql_errno();
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Error $errnum $des\n";}
return false;
}
$results=@mysql_unbuffered_query("SHOW TABLES",$bd);
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$GLOBALS["VIDEOCACHE_TABLES"][$ligne["Tables_in_videocache"]]=true;
if(strtolower($table)==strtolower($ligne["Tables_in_videocache"])){$resutz= true;}
}
return $resutz;
}
function start($nopid=false){
$unix=new unix();
$sock=new sockets();
$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
if(!$nopid){
$pid=$unix->get_pid_from_file($pidfile);
if($unix->process_exists($pid,basename(__FILE__))){
$time=$unix->PROCCESS_TIME_MIN($pid);
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID $pid since {$time}mn\n";}
return;
}
}
$enableStreamCache=intval($sock->GET_INFO("EnableStreamCache"));
if($enableStreamCache==0){
if($GLOBALS["OUTPUT"]){echo "Starting......: ".date("H:i:s")." [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see enableStreamCache )...\n";}