Esempio n. 1
0
 public function test_file()
 {
     $file1 = self::getDir() . '/dir1/foo.txt';
     $file2 = self::getDir() . '/dir2/bar.txt';
     $file3 = self::getDir() . '/dir2/baz.txt';
     $file3_name = 'baz.txt';
     $file4 = self::getDir() . '/dir4/yolo.txt';
     $this->assertFalse(file_exists($file1));
     file_create($file1);
     file_write($file1, '');
     $this->assertTrue(file_exists($file1));
     $this->assertEquals('', file_read($file1));
     file_write($file1, 'foo');
     $this->assertEquals('foo', file_read($file1));
     file_append($file1, '_bar');
     $this->assertEquals('foo_bar', file_read($file1));
     file_prepend($file1, '#');
     $this->assertEquals('#foo_bar', file_read($file1));
     file_append($file1, '_bar');
     file_prepend($file1, '#');
     $this->assertEquals('##foo_bar_bar', file_read($file1));
     file_append($file1 . '_append', '_bar');
     $this->assertEquals(file_read($file1 . '_append'), '_bar');
     file_prepend($file1 . '_prepend', '#');
     $this->assertEquals(file_read($file1 . '_prepend'), '#');
     $this->assertFalse(file_exists($file2));
     file_copy($file1, $file2);
     $this->assertTrue(file_exists($file2));
     $this->assertEquals(file_read($file1), file_read($file2));
     $this->assertFalse(file_exists($file3));
     file_rename($file2, $file3_name);
     $this->assertFalse(file_exists($file2));
     $this->assertTrue(file_exists($file3));
     $this->assertEquals(file_read($file1), file_read($file3));
     $this->assertFalse(file_exists($file4));
     file_move($file3, $file4);
     $this->assertFalse(file_exists($file3));
     $this->assertTrue(file_exists($file4));
     $this->assertEquals(file_read($file1), file_read($file4));
     file_delete($file4);
     file_delete($file4);
     $this->assertFalse(file_exists($file4));
     $this->assertEquals(self::getDir() . '/dir1', file_get_directory($file1));
     $this->assertEquals('txt', file_get_extension($file1));
     $this->assertEquals('foo.txt', file_get_name($file1));
 }
Esempio n. 2
0
function save_logo()
{
    global $input;
    if (file_exists("../commons/config.inc")) {
        include_once '../commons/config.inc';
    } else {
        include_once '../commons/config-sample.inc';
    }
    $target_dir = "./htdocs/img/organization-logo.png";
    $errors = array();
    if (!isset($_FILES['organization_logo']) || $_FILES['organization_logo']['name'] == "") {
        return true;
    }
    if ($_FILES['organization_logo']['error'] > 0) {
        $errors['file_error'] = "Error while uploading logo file";
        require template_getpath('install.php');
        die;
    }
    if ($_FILES['organization_logo']['size'] > 1048576) {
        $errors['file_error'] = "Logo file bigger than 1Mo";
    }
    $filename_info = file_get_extension(basename($_FILES['organization_logo']['name']));
    if (strtolower($filename_info['ext']) != 'png') {
        $errors['file_error'] = "Bad extension for logo file (expected 'png' found '" . $filename_info['ext'] . "')";
    }
    if (count($errors) > 0) {
        require template_getpath('install.php');
        die;
    }
    $res = move_uploaded_file($_FILES['organization_logo']['tmp_name'], $target_dir);
    if (!$res) {
        $errors['file_error'] = "Error while saving logo file";
        require template_getpath('install.php');
        die;
    }
    copy($target_dir, "../ezmanager/htdocs/images/Header/organization-logo.png");
    copy($target_dir, "../ezplayer/htdocs/images/Header/organization-logo.png");
    copy($target_dir, $apache_documentroot . "/ezmanager/images/Header/organization-logo.png");
    copy($target_dir, $apache_documentroot . "/ezplayer/images/Header/organization-logo.png");
    copy($target_dir, $apache_documentroot . "/ezadmin/img/organization-logo.png");
    return true;
}
Esempio n. 3
0
function file_type_check($p_file_name)
{
    $t_allowed_files = config_get('allowed_files');
    $t_disallowed_files = config_get('disallowed_files');
    # grab extension
    $t_extension = file_get_extension($p_file_name);
    # check against disallowed files
    if (!is_blank($t_disallowed_files)) {
        $t_disallowed_arr = explode(',', $t_disallowed_files);
        foreach ($t_disallowed_arr as $t_val) {
            if (0 == strcasecmp($t_val, $t_extension)) {
                return false;
            }
        }
    }
    # if the allowed list is note populated then the file must be allowed
    if (is_blank($t_allowed_files)) {
        return true;
    }
    # check against allowed files
    $t_allowed_arr = explode(',', $t_allowed_files);
    foreach ($t_allowed_arr as $t_val) {
        if (0 == strcasecmp($t_val, $t_extension)) {
            return true;
        }
    }
    return false;
}
Esempio n. 4
0
 /**
  * @param $path
  *
  * @return bool
  */
 public function supports($path)
 {
     return file_get_extension($path) == 'ini';
 }
Esempio n. 5
0
            access_denied();
        }
        access_ensure_project_level(config_get('view_proj_doc_threshold'), $v_project_id);
        break;
}
# flush output buffer to protect download
if (ob_get_length()) {
    @ob_end_clean();
}
# Make sure that IE can download the attachments under https.
header('Pragma: public');
header('Content-Type: ' . $v_file_type);
header('Content-Length: ' . $v_filesize);
$t_filename = file_get_display_name($v_filename);
$t_inline_files = explode(',', config_get('inline_file_exts', 'gif'));
if (in_array(strtolower(file_get_extension($t_filename)), $t_inline_files)) {
    $t_disposition = '';
    //'inline;';
} else {
    $t_disposition = ' attachment;';
}
header('Content-Disposition:' . $t_disposition . ' filename="' . urlencode($t_filename) . '"');
header('Content-Description: Download Data');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', db_unixtimestamp($v_date_added)));
# To fix an IE bug which causes problems when downloading
# attached files via HTTPS, we disable the "Pragma: no-cache"
# command when IE is used over HTTPS.
global $g_allow_file_cache;
if (isset($_SERVER["HTTPS"]) && "on" == strtolower($_SERVER["HTTPS"]) && preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
    # Suppress "Pragma: no-cache" header.
} else {
Esempio n. 6
0
/**
 * insert original cam or slide in repository and if user submit, checks submitted file's extension
 * @param string $camslide
 * @param assoc_array $recording_metadata
 * @param string $recording_dir
 * @return bool
 */
function originals_mam_insert_media($album_name, $asset_name, $camslide, &$recording_metadata, $recording_dir)
{
    $media_name = 'original_' . $camslide;
    //initialize media metadata and media metadata
    $media_meta['author'] = $recording_metadata['author'];
    $media_meta['title'] = $recording_metadata['title'];
    $media_meta['description'] = $recording_metadata['description'];
    $media_meta['record_date'] = $recording_metadata['record_date'];
    $media_meta['width'] = "N/A";
    $media_meta['height'] = "N/A";
    $media_meta['duration'] = "N/A";
    $media_meta['video_codec'] = "N/A";
    $media_meta['audio_codec'] = "N/A";
    $media_meta['disposition'] = 'file';
    //check the name of submited file to keep the extension (pcastaction is quite sensitive to extension type)
    if (isset($recording_metadata['submitted_' . $camslide])) {
        $res = file_get_extension($recording_metadata['submitted_' . $camslide]);
        $ext = $res['ext'];
        if ($ext == '') {
            //if there wasn't an extension, then check mimetype
            $mimetype = $recording_metadata['submitted_mimetype'];
            list($type, $subtype) = explode('/', $mimetype);
            $mimetypes2ext = array('mpeg' => 'mpg', 'quicktime' => 'mov', 'x-msvideo' => 'avi');
            if (isset($mimetypes2ext[$subtype])) {
                $ext = $mimetypes2ext[$subtype];
            } else {
                $ext = 'mov';
            }
            //default extension
        }
        if (ctype_alnum($ext)) {
            //an extension should not have bad chars
            $mov_filepath = $recording_dir . '/' . $camslide . '.mov';
            $goodext_filepath = $recording_dir . '/' . $camslide . '.' . $ext;
            //rename cam.mov into cam.mpg if submit was an .mpg file
            rename($mov_filepath, $goodext_filepath);
            $media_file_path = $goodext_filepath;
            $media_meta['filename'] = "{$camslide}.{$ext}";
        } else {
            print "submitted filename has bad extension: {$ext}";
            myerror("submitted filename has bad extension: {$ext}");
        }
    } else {
        $media_file_path = system("ls {$recording_dir}/{$camslide}.*");
        $media_meta['filename'] = basename($media_file_path);
    }
    $filesize = round(filesize($media_file_path) / 1048576);
    $media_meta['file_size'] = $filesize;
    $res1 = ezmam_media_new($album_name, $asset_name, $media_name, $media_meta, $media_file_path);
    if (!$res1) {
        myerror("error adding original_{$camslide}:" . ezmam_last_error() . "\n");
    } else {
        print "{$camslide} media inserted in repository in {$album_name} {$asset_name} {$media_name}\n";
    }
    return $res1;
}
Esempio n. 7
0
function print_file_icon($p_filename)
{
    $t_file_type_icons = config_get('file_type_icons');
    $ext = strtolower(file_get_extension($p_filename));
    if (is_blank($ext) || !isset($t_file_type_icons[$ext])) {
        $ext = '?';
    }
    $t_name = $t_file_type_icons[$ext];
    print '<img src="' . config_get('path') . 'images/fileicons/' . $t_name . '" alt="' . $ext . ' file icon" width="16" height="16" border="0" />';
}
Esempio n. 8
0
function file_list_attachments($p_bug_id)
{
    $t_attachment_rows = bug_get_attachments($p_bug_id);
    $num_files = sizeof($t_attachment_rows);
    if ($num_files === 0) {
        return;
    }
    $t_can_download = file_can_download_bug_attachments($p_bug_id);
    $t_can_delete = file_can_delete_bug_attachments($p_bug_id);
    $image_previewed = false;
    for ($i = 0; $i < $num_files; $i++) {
        $row = $t_attachment_rows[$i];
        extract($row, EXTR_PREFIX_ALL, 'v');
        $t_file_display_name = file_get_display_name($v_filename);
        $t_filesize = number_format($v_filesize);
        $t_date_added = date(config_get('normal_date_format'), db_unixtimestamp($v_date_added));
        if ($image_previewed) {
            $image_previewed = false;
            print '<br />';
        }
        if ($t_can_download) {
            $t_href_start = "<a href=\"file_download.php?file_id={$v_id}&amp;type=bug\">";
            $t_href_end = '</a>';
            $t_href_clicket = " [<a href=\"file_download.php?file_id={$v_id}&amp;type=bug\" target=\"_blank\">^</a>]";
        } else {
            $t_href_start = '';
            $t_href_end = '';
            $t_href_clicket = '';
        }
        print $t_href_start;
        print_file_icon($t_file_display_name);
        print $t_href_end . '</a>&nbsp;' . $t_href_start . $t_file_display_name . $t_href_end . "{$t_href_clicket} ({$t_filesize} bytes) <span class=\"italic\">{$t_date_added}</span>";
        if ($t_can_delete) {
            print " [<a class=\"small\" href=\"bug_file_delete.php?file_id={$v_id}\">" . lang_get('delete_link') . '</a>]';
        }
        if (FTP == config_get('file_upload_method') && file_exists($v_diskfile)) {
            print ' (' . lang_get('cached') . ')';
        }
        if ($t_can_download && $v_filesize <= config_get('preview_attachments_inline_max_size') && $v_filesize != 0 && in_array(strtolower(file_get_extension($t_file_display_name)), array('png', 'jpg', 'jpeg', 'gif', 'bmp'), true)) {
            print "<br /><img src=\"file_download.php?file_id={$v_id}&amp;type=bug\" />";
            $image_previewed = true;
        }
        if ($i != $num_files - 1) {
            print '<br />';
        }
    }
}
Esempio n. 9
0
function file_list_attachments($p_bug_id)
{
    $t_attachment_rows = bug_get_attachments($p_bug_id);
    $num_files = sizeof($t_attachment_rows);
    if ($num_files === 0) {
        return;
    }
    $t_can_download = file_can_download_bug_attachments($p_bug_id);
    $t_can_delete = file_can_delete_bug_attachments($p_bug_id);
    $t_preview_text_ext = config_get('preview_text_extensions');
    $t_preview_image_ext = config_get('preview_image_extensions');
    $image_previewed = false;
    for ($i = 0; $i < $num_files; $i++) {
        $row = $t_attachment_rows[$i];
        extract($row, EXTR_PREFIX_ALL, 'v');
        $t_file_display_name = string_display_line(file_get_display_name($v_filename));
        $t_filesize = number_format($v_filesize);
        $t_date_added = date(config_get('normal_date_format'), db_unixtimestamp($v_date_added));
        if ($image_previewed) {
            $image_previewed = false;
            print '<br />';
        }
        if ($t_can_download) {
            $t_href_start = "<a href=\"file_download.php?file_id={$v_id}&amp;type=bug\">";
            $t_href_end = '</a>';
            $t_href_clicket = " [<a href=\"file_download.php?file_id={$v_id}&amp;type=bug\" target=\"_blank\">^</a>]";
        } else {
            $t_href_start = '';
            $t_href_end = '';
            $t_href_clicket = '';
        }
        $t_exists = config_get('file_upload_method') != DISK || file_exists($v_diskfile);
        if (!$t_exists) {
            print_file_icon($t_file_display_name);
            print '&nbsp;<span class="strike">' . $t_file_display_name . '</span> (attachment missing)';
        } else {
            print $t_href_start;
            print_file_icon($t_file_display_name);
            print $t_href_end . '&nbsp;' . $t_href_start . $t_file_display_name . $t_href_end . "{$t_href_clicket} ({$t_filesize} bytes) <span class=\"italic\">{$t_date_added}</span>";
            if ($t_can_delete) {
                print " [<a class=\"small\" href=\"bug_file_delete.php?file_id={$v_id}\">" . lang_get('delete_link') . '</a>]';
            }
            if (FTP == config_get('file_upload_method') && file_exists($v_diskfile)) {
                print ' (' . lang_get('cached') . ')';
            }
            if ($t_can_download && $v_filesize <= config_get('preview_attachments_inline_max_size') && $v_filesize != 0 && in_array(strtolower(file_get_extension($t_file_display_name)), $t_preview_text_ext, true)) {
                $c_id = db_prepare_int($v_id);
                $t_bug_file_table = config_get('mantis_bug_file_table');
                echo "<script type=\"text/javascript\" language=\"JavaScript\">\r\n<!--\r\nfunction swap_content( span ) {\r\ndisplayType = ( document.getElementById( span ).style.display == 'none' ) ? '' : 'none';\r\ndocument.getElementById( span ).style.display = displayType;\r\n}\r\n\r\n -->\r\n </script>";
                print " <span id=\"hideSection_{$c_id}\">[<a class=\"small\" href='#' id='attmlink_" . $c_id . "' onclick='swap_content(\"hideSection_" . $c_id . "\");swap_content(\"showSection_" . $c_id . "\");return false;'>" . lang_get('show_content') . "</a>]</span>";
                print " <span style='display:none' id=\"showSection_{$c_id}\">[<a class=\"small\" href='#' id='attmlink_" . $c_id . "' onclick='swap_content(\"hideSection_" . $c_id . "\");swap_content(\"showSection_" . $c_id . "\");return false;'>" . lang_get('hide_content') . "</a>]";
                print "<pre>";
                switch (config_get('file_upload_method')) {
                    case DISK:
                        if (file_exists($v_diskfile)) {
                            $v_content = file_get_contents($v_diskfile);
                        }
                        break;
                    case FTP:
                        if (file_exists($v_diskfile)) {
                            file_get_contents($v_diskfile);
                        } else {
                            $ftp = file_ftp_connect();
                            file_ftp_get($ftp, $v_diskfile, $v_diskfile);
                            file_ftp_disconnect($ftp);
                            $v_content = file_get_contents($v_diskfile);
                        }
                        break;
                    default:
                        $query = "SELECT *\r\n\t                  \t\t\t\t\t\tFROM {$t_bug_file_table}\r\n\t\t\t\t            \t\t\tWHERE id='{$c_id}'";
                        $result = db_query($query);
                        $row = db_fetch_array($result);
                        $v_content = $row['content'];
                }
                echo htmlspecialchars($v_content);
                print "</pre></span>\n";
            }
            if ($t_can_download && $v_filesize <= config_get('preview_attachments_inline_max_size') && $v_filesize != 0 && in_array(strtolower(file_get_extension($t_file_display_name)), $t_preview_image_ext, true)) {
                $t_preview_style = 'border: 0;';
                $t_max_width = config_get('preview_max_width');
                if ($t_max_width > 0) {
                    $t_preview_style .= ' max-width:' . $t_max_width . 'px;';
                }
                $t_max_height = config_get('preview_max_height');
                if ($t_max_height > 0) {
                    $t_preview_style .= ' max-height:' . $t_max_height . 'px;';
                }
                $t_preview_style = 'style="' . $t_preview_style . '"';
                $t_title = file_get_field($v_id, 'title');
                print "\n<br />{$t_href_start}<img alt=\"{$t_title}\" {$t_preview_style} src=\"file_download.php?file_id={$v_id}&amp;type=bug\" />{$t_href_end}";
                $image_previewed = true;
            }
        }
        if ($i != $num_files - 1) {
            print "<br />\n";
        }
    }
}
Esempio n. 10
0
            access_denied();
        }
        access_ensure_project_level(config_get('view_proj_doc_threshold'), $v_project_id);
        break;
}
# flush output buffer to protect download
if (ob_get_length()) {
    @ob_end_clean();
}
# Make sure that IE can download the attachments under https.
header('Pragma: public');
header('Content-Type: ' . $v_file_type);
header('Content-Length: ' . $v_filesize);
$t_filename = file_get_display_name($v_filename);
$t_inline_files = explode(',', config_get('inline_file_exts', 'gif'));
if (in_array(file_get_extension($t_filename), $t_inline_files)) {
    $t_disposition = '';
    //'inline;';
} else {
    $t_disposition = ' attachment;';
}
header('Content-Disposition:' . $t_disposition . ' filename="' . urlencode($t_filename) . '"');
header('Content-Description: Download Data');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', db_unixtimestamp($v_date_added)));
# To fix an IE bug which causes problems when downloading
# attached files via HTTPS, we disable the "Pragma: no-cache"
# command when IE is used over HTTPS.
global $g_allow_file_cache;
if (isset($_SERVER["HTTPS"]) && "on" == strtolower($_SERVER["HTTPS"]) && preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
    # Suppress "Pragma: no-cache" header.
} else {