コード例 #1
0
ファイル: fetcher.php プロジェクト: et169tkm/mytv-mirror
function download_chunklist()
{
    global $chunklist_list, $effective_url, $chunklist_url;
    // try download the chunk list
    l("getting chunk list");
    if ($chunklist_url) {
        $c = new_curl($chunklist_url);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        $chunklist = curl_exec($c);
        $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
        if ($status == 200) {
            return $chunklist;
        }
    }
    // if we can't download the chunk list, start over
    l("getting cdn url");
    $cdn_url = get_cdn_url();
    l("cdn url: " . $cdn_url);
    if (!$cdn_url) {
        // if we can't even get this, there's nothing more we can do
        exit(1);
    }
    l("getting list of chunk list urls");
    $chunklist_list_and_effective_url = get_chunklist_list_and_effective_url($cdn_url);
    if ($chunklist_list_and_effective_url) {
        $chunklist_list = $chunklist_list_and_effective_url[0];
        $effective_url = $chunklist_list_and_effective_url[1];
        $parsed_chunklist_list = parse_chunklist_list($chunklist_list);
        $chunklist_filename = $parsed_chunklist_list[count($parsed_chunklist_list) - 1]["filename"];
        $chunklist_url = str_replace("playlist.m3u8", $chunklist_filename, $effective_url);
        l("chunklist url: " . $chunklist_url);
    } else {
        // Can't get chunk list URLs, should not happen
        exit(1);
    }
    l("getting chunk list again");
    $c = new_curl($chunklist_url);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    $chunklist = curl_exec($c);
    $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
    if ($status == 200) {
        return $chunklist;
    } else {
        l("status: " . $status);
        exit(1);
    }
}
コード例 #2
0
/**
 * Save CloudFiles CDN Settings
 */
function save_cdn_settings()
{
    if (is_admin() && current_user_can('manage_options') && !empty($_POST) && !empty($_POST['rs_cdn'])) {
        // Turn off SSL if custom CNAME is being used
        if (isset($_POST['rs_cdn']['custom_cname']) && trim($_POST['rs_cdn']['custom_cname']) != '') {
            unset($_POST['rs_cdn']['use_ssl']);
        } else {
            unset($_POST['rs_cdn']['custom_cname']);
        }
        // Save settings in database
        $cdn_settings = $_POST['rs_cdn'];
        // Turn off SSL if custom CNAME is being used
        if (isset($_POST['rs_cdn']['custom_cname']) && trim($_POST['rs_cdn']['custom_cname']) != '') {
            $_SESSION['cdn']->cdn_url = $_POST['rs_cdn']['custom_cname'];
        } else {
            // Set API settings to the new settings
            update_option(RS_CDN_OPTIONS, (object) $cdn_settings);
            // Create new CDN instance
            try {
                // Try to create new CDN instance
                unset($_SESSION['cdn']);
                $_SESSION['cdn'] = new RS_CDN();
                // Set API settings for CDN instance
                $_SESSION['cdn']->api_settings = (object) $cdn_settings;
                // Assign URL
                if ($_SESSION['cdn']->container_object()) {
                    $_SESSION['cdn']->cdn_url = isset($_POST['rs_cdn']['use_ssl']) ? get_cdn_url('ssl') : get_cdn_url();
                } else {
                    $_SESSION['cdn']->cdn_url = null;
                }
            } catch (Exception $exc) {
                // Exception
            }
        }
    }
}
コード例 #3
0
/**
 *	Verify file exists
 */
function verify_exists($file_path)
{
    // Get CDN URL
    if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
        $cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
    } else {
        $cdn_url = isset($_SESSION['cdn']->api_settings->use_ssl) ? get_cdn_url('ssl') : get_cdn_url();
    }
    // Define variables needed
    $upload_dir = wp_upload_dir();
    // Set CDN URL
    if (stripos($file_path, $cdn_url) === false) {
        $file_url = $cdn_url . '/' . $file_path;
    } else {
        $file_url = str_replace($upload_dir['basedir'], $cdn_url, $file_path);
    }
    // Verify file exists, use curl if "allow_url_fopen" is not allowed
    if (ini_get('allow_url_fopen')) {
        if (strstr(current(get_headers($file_url)), "200")) {
            return true;
        } else {
            return false;
        }
    } else {
        $ch = curl_init($file_url);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_exec($ch);
        curl_close($ch);
        $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($return_code == 200) {
            return true;
        } else {
            return false;
        }
    }
    return true;
}
コード例 #4
0
/**
 *	Verify file exists
 */
function verify_exists($file_path = null)
{
    // Ensure CDN instance exists
    if (check_cdn() === false || is_null($file_path)) {
        return false;
    }
    // Get CDN URL
    if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
        $cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
    } else {
        $cdn_url = isset($_SESSION['cdn']->api_settings->use_ssl) ? get_cdn_url('ssl') : get_cdn_url();
    }
    // Define variables needed
    $upload_dir = wp_upload_dir();
    // Get local file path
    $file_url = str_replace(array($cdn_url . '/', $upload_dir['basedir'] . '/', $upload_dir['baseurl'] . '/'), '', $file_path);
    // Return true/false if file exists on CDN or not
    return find_file_name($file_url, $cdn_objects);
}
コード例 #5
0
/**
 * Multidimensional array search
 */
function find_file_name($file_name)
{
    // Ensure CDN instance exists
    if (check_cdn() === false) {
        return false;
    }
    // Get CDN URL
    if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
        $cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
    } else {
        $cdn_url = isset($_SESSION['cdn']->api_settings->use_ssl) ? get_cdn_url('ssl') : get_cdn_url();
    }
    // Get CDN objects
    $cdn_objects = $_SESSION['cdn']->get_cdn_objects();
    // Loop through and see if we can find the file name
    foreach ($cdn_objects as $cur_cdn_object) {
        if ($cur_cdn_object['file_name'] === $file_name) {
            return true;
        }
    }
    // Return false by default
    return false;
}
コード例 #6
0
/**
 *	Verify file exists
 */
function verify_exists($file_path)
{
    // Get CDN URL
    if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
        $cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
    } else {
        $cdn_url = isset($_SESSION['cdn']->api_settings->use_ssl) ? get_cdn_url('ssl') : get_cdn_url();
    }
    // Define variables needed
    $upload_dir = wp_upload_dir();
    // Set CDN URL
    $file_url = str_replace($upload_dir['basedir'], $cdn_url, $file_path);
    // Setup CURL request
    if (strstr(current(get_headers($file_url)), "200")) {
        return true;
    } else {
        return false;
    }
}
コード例 #7
0
/**
 *	Verify file exists
 */
function verify_exists($file_path)
{
    // Ensure CDN instance exists
    if (check_cdn() === false) {
        return false;
    }
    // Get CDN URL
    if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
        $cdn_url = stripos($_SESSION['cdn']->api_settings->custom_cname, 'http') === false ? 'http://' . $_SESSION['cdn']->api_settings->custom_cname : $_SESSION['cdn']->api_settings->custom_cname;
    } else {
        $cdn_url = isset($_SESSION['cdn']->api_settings->use_ssl) ? get_cdn_url('ssl') : get_cdn_url();
    }
    // Define variables needed
    $upload_dir = wp_upload_dir();
    // Set CDN URL
    if (stripos($file_path, $cdn_url) === false) {
        $file_url = $cdn_url . '/' . $file_path;
    } else {
        $file_url = str_replace($upload_dir['basedir'], $cdn_url, $file_path);
    }
    // Make sure URL starts with http, if not, prepend it
    $file_url = strripos($file_url, 'http') === false ? 'http://' . $file_url : $file_url;
    // Verify file exists, try to use curl first
    if (function_exists('curl_version')) {
        // Get headers via curl
        $curl = curl_init($file_url);
        curl_setopt($curl, CURLOPT_NOBODY, true);
        $result = curl_exec($curl);
        if ($result !== false) {
            try {
                $status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
                if ($status_code == 200) {
                    curl_close($curl);
                    return true;
                } else {
                    curl_close($curl);
                    return false;
                }
            } catch (Exception $exc) {
                // Get headers via PHP's get_headers function
                if (ini_get('allow_url_fopen')) {
                    if (strstr(current(get_headers($file_url)), "200")) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
        }
        curl_close($curl);
    } else {
        // Get headers via PHP's get_headers function
        if (strstr(current(get_headers($file_url)), "200")) {
            return true;
        } else {
            return false;
        }
    }
    return false;
}
コード例 #8
0
/**
 *	Verify file was uploaded
 */
function verify_successful_upload($file_path)
{
    // Get CDN object and settings
    $_SESSION['cdn'] = isset($_SESSION['cdn']) ? $_SESSION['cdn'] : new RS_CDN();
    if (isset($_SESSION['cdn']->api_settings->custom_cname) && trim($_SESSION['cdn']->api_settings->custom_cname) != '') {
        $_SESSION['cdn']->cdn_url = $_SESSION['cdn']->api_settings->custom_cname;
    } else {
        $_SESSION['cdn']->cdn_url = isset($_SESSION['cdn']->api_settings->use_ssl) ? get_cdn_url('ssl') : get_cdn_url();
    }
    // Define variables needed
    $upload_dir = wp_upload_dir();
    // Set CDN URL
    $file_url = str_replace($upload_dir['basedir'], $_SESSION['cdn']->cdn_url, $file_path);
    // Setup CURL request
    $curl = curl_init($file_url);
    // Issue a HEAD request and follow any redirects.
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_HEADER, TRUE);
    curl_setopt($curl, CURLOPT_NOBODY, TRUE);
    // Submit request and grab Content-Length header
    $data = curl_exec($curl);
    $remote_file_size = curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
    $local_file_size = filesize($file_path);
    // Close CURL request and return successful upload or not
    @curl_close($curl);
    return $remote_file_size == $local_file_size ? true : false;
}