function CHECK_STREAMCACHE()
{
    $unix = new unix();
    $sock = new sockets();
    $squid = new squidbee();
    $masterbin = $unix->find_program("streamsquidcache");
    if (!is_file($masterbin)) {
        return;
    }
    $enabled = intval($sock->GET_INFO("EnableStreamCache"));
    if ($enabled == 0) {
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    if (!is_file("/usr/share/videocache/videocache.py")) {
        squid_admin_mysql(0, "VideoCache backend ( missing videocache.py) not installed, re-install it...", null, __FILE__, __LINE__);
        shell_exec("{$php} /usr/share/artica-postfix/exec.squidstream.php --reinstall");
        return;
    }
    if (!is_file("/usr/share/videocache/vc-scheduler")) {
        squid_admin_mysql(0, "VideoCache backend ( missing vc-scheduler) not installed, re-install it...", null, __FILE__, __LINE__);
        shell_exec("{$php} /usr/share/artica-postfix/exec.squidstream.php --reinstall");
        return;
    }
    $VerifStreamProxyBindIP = $squid->VerifStreamProxyBindIP();
    $pid = streamsquidcache_pid();
    if ($GLOBALS["VERBOSE"]) {
        echo "streamsquidcache: PID: {$pid}\n";
    }
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "streamsquidcache: Running -> YES\n";
        }
    } else {
        if ($GLOBALS["VERBOSE"]) {
            echo "streamsquidcache: Running -> NO\n";
        }
        squid_admin_mysql(0, "VideoCache backend not running, start it...", null, __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid-stream start");
        return;
    }
    $StreamCachePort = intval($sock->GET_INFO("StreamCachePort"));
    if ($StreamCachePort == 0) {
        $StreamCachePort = 5559;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "streamsquidcache: {$VerifStreamProxyBindIP}:{$StreamCachePort}\n";
    }
    if (!@fsockopen($VerifStreamProxyBindIP, $StreamCachePort, $errno, $errstr, 1)) {
        squid_admin_mysql(0, "VideoCache backend unable to open port {$VerifStreamProxyBindIP}:{$StreamCachePort} (action = restart)", "Err.{$errno} {$errstr}\n", __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid-stream restart");
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "streamsquidcache: {$VerifStreamProxyBindIP}:{$StreamCachePort} OK\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 ="******"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";
    }
}