function makeRows($files)
{
    $rows = "";
    foreach ($files as $file) {
        $extension = fileExtension($file);
        if ($extension != "") {
            $row = makeRow($file, $extension);
            $rows = "{$rows}{$row}\n";
        }
    }
    return $rows;
}
示例#2
0
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/
/*
	pfSense_MODULE:	shaper
*/
##|+PRIV
##|*IDENT=page-diagnostics-patters
##|*NAME=Diagnostics: Patterns page
##|*DESCR=Allow access to the 'Diagnostics: Patterns' page.
##|*MATCH=patterns.php*
##|-PRIV
require "guiconfig.inc";
//Move the upload file to /usr/local/share/protocols (is_uploaded_file must use tmp_name as argument)
if ($_POST['submit'] == gettext("Upload Pattern file") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
    if (fileExtension($_FILES['ulfile']['name'])) {
        if (!is_array($config['l7shaper']['custom_pat'])) {
            $config['l7shaper']['custom_pat'] = array();
        }
        $config['l7shaper']['custom_pat'][$_FILES['ulfile']['name']] = base64_encode(file_get_contents($_FILES['ulfile']['tmp_name']));
        write_config(sprintf(gettext("Added custom l7 pattern %s"), $_FILES['ulfile']['name']));
        move_uploaded_file($_FILES['ulfile']['tmp_name'], "/usr/local/share/protocols/" . $_FILES['ulfile']['name']);
        $ulmsg = gettext("Uploaded file to") . " /usr/local/share/protocols/" . htmlentities($_FILES['ulfile']['name']);
    } else {
        $ulmsg = gettext("Warning: You must upload a file with .pat extension.");
    }
}
//Check if file has correct extension (.pat)
function fileExtension($nameFile)
{
    $format = substr($nameFile, -4);
示例#3
0
file_put_contents('files/[debug].txt', 'Root: ' . $_SERVER['DOCUMENT_ROOT'] . $link_prefix . $upload_dir, FILE_APPEND);
$img_id = countOfFilesInDir($link_prefix . $upload_dir) + 1;
file_put_contents('files/[debug].txt', 'IMG_ID: ' . $img_id . "\n", FILE_APPEND);
file_put_contents('files/[debug].txt', $upload_dir . "\n", FILE_APPEND);
// HERE PERMISSIONS FOR IMAGE
$imgsets = array('maxsize' => 2000, 'maxwidth' => 3000, 'maxheight' => 2500, 'minwidth' => 10, 'minheight' => 10, 'type' => array('bmp', 'gif', 'jpg', 'jpe', 'png', 'jpeg', 'svg'));
$re = '';
if (isset($_FILES['upload']) && strlen($_FILES['upload']['name']) >= 1) {
    $upload_dir = trim($upload_dir, '/') . '/';
    $img_name = basename($_FILES['upload']['name']);
    // get protocol and host name to send the absolute image path to CKEditor
    $protocol = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
    $site = $protocol . $_SERVER['SERVER_NAME'] . '/';
    $uploadpath = $_SERVER['DOCUMENT_ROOT'] . $link_prefix . $upload_dir . $img_id;
    // full file path
    $type = fileExtension($_FILES['upload']['name']);
    // gets extension
    $uploadpath .= '.' . $type;
    list($width, $height) = getimagesize($_FILES['upload']['tmp_name']);
    // gets image width and height
    $err = '';
    // to store the errors
    // Checks if the file has allowed type, size, width and height (for images)
    if (!in_array($type, $imgsets['type'])) {
        $err .= 'The file: ' . $_FILES['upload']['name'] . ' has not the allowed extension type.';
    }
    if ($_FILES['upload']['size'] > $imgsets['maxsize'] * 1024) {
        $err .= '\\n Maximum file size must be: ' . $imgsets['maxsize'] . ' KB.';
    }
    if (isset($width) && isset($height)) {
        if ($width > $imgsets['maxwidth'] || $height > $imgsets['maxheight']) {
示例#4
0
function outputImageList()
{
    //Read all images from directories
    //if (!isset($_SESSION['imagesIndexed']) || $_SESSION['imagesIndexed'] != false || !isset($allImages)) {
    $dir = opendir("../images");
    $counter = 1;
    do {
        $nextDir = readdir($dir);
        if ($nextDir != '.' && $nextDir != '..' && $nextDir !== false) {
            if (filetype($nextDir) != 'dir' && fileExtension($nextDir) != 'html' && fileExtension($nextDir) != 'txt' && fileExtension($nextDir) != 'php') {
                $allImages[] = htmlspecialchars($nextDir);
            }
        }
    } while ($nextDir !== false);
    for ($i = 0; $i < count($allImages); $i++) {
        $newImages[] = strtolower($allImages[$i]);
    }
    //echo 'Done,';
    array_multisort($newImages, SORT_ASC, SORT_STRING, $allImages);
    //} else { /*$allImages = $_SESSION['allImages'];*/ unset($_SESSION['imagesIndexed']); } // Only re-index all files if the list is empty, in this case, $allImages must already be set
    //Print ImageList Table Header
    $ret = '<div>';
    $ret .= '<i>Total Images</i>: ' . count($allImages) . ' <span id="imageListMsg"></span><br><i>Listing</i> ';
    $_SESSION['imageSet'][0] . ($beginEntries = array());
    for ($i = 0; $i < count($allImages); $i += $_SESSION['imageSet'][1]) {
        $beginEntries[] = $i;
    }
    $begins = '<select id="imageSetStart" onchange="changeImageSet(this.value,' . (int) $_SESSION['imageSet'][1] . ')">';
    for ($i = 0; $i < count($beginEntries); $i++) {
        $begins .= '<option value="' . $beginEntries[$i] . '" ' . ($_SESSION['imageSet'][0] == $beginEntries[$i] ? 'selected=""' : '') . '>' . $beginEntries[$i] . '</option>';
    }
    $begins .= '</select>';
    $setSizes = array(50, 100, 500, 1000, 2500, 5000, 10000);
    $ends = '<select id="imageSet" onchange="changeImageSet(' . (int) $_SESSION['imageSet'][0] . ',this.value)">';
    for ($i = 0; $i < count($setSizes); $i++) {
        $ends .= '<option value="' . $setSizes[$i] . '" ' . ($_SESSION['imageSet'][1] == $setSizes[$i] ? 'selected=""' : '') . '>' . $setSizes[$i] . '</option>';
    }
    $ends .= '</select>';
    $topbound = min($_SESSION['imageSet'][0] + $_SESSION['imageSet'][1], count($allImages));
    $ret .= $begins;
    $ret .= ' to ' . $topbound . ', <i>Show</i> ' . $ends . "\r\n";
    $ret .= '<table class="imageTable" width="100%" align="left" cellpadding="0" cellspacing="0" border="0">';
    //Print each row/image for table
    //echo 'Outputting from '.$_SESSION['imageSet'][0].' to '.$topbound.'<br>';
    for ($i = $_SESSION['imageSet'][0]; $i < $topbound; $i++) {
        // Original method outputting all data
        $ret .= '<tr id="ir_' . $allImages[$i] . '"><td class="' . ($i % 2 ? 'I2' : 'I1') . '"><input type="image" src="images/edit.png" onclick="iR(\'' . $allImages[$i] . '\');" /></td><td id="hovRow_' . $allImages[$i] . '"';
        if ($i % 2) {
            $ret .= ' style="background-color: #EEE;" onmouseover="hoverOn2(this);" onmouseout="hoverOff2(this);"';
        } else {
            $ret .= ' onmouseover="hoverOn(this);" onmouseout="hoverOff(this);"';
        }
        $ret .= '><div id="vDiv_' . $allImages[$i] . '" class="I" onclick="iC(\'' . $allImages[$i] . '\');">' . htmlentities($allImages[$i]) . '</div>' . '<div id="eDiv_' . $allImages[$i] . '" style="float: left; display: none;">' . '<input type="text" size="30" id="tBox_' . $allImages[$i] . '" value="' . $allImages[$i] . '" />' . '<input type="image" src="images/check.png" onclick="imageSavename(\'' . $allImages[$i] . '\');" /></div>' . '</td><td' . ($i % 2 ? ' style="background-color: #EEE;"' : '') . '>' . '<input type="image" src="images/delete.png" onclick="imageDelete(\'' . $allImages[$i] . '\');" /></td></tr>';
    }
    //End old format
    /* $ret .= '[^S}'; // New format
    	for ($i=$_SESSION['imageSet'][0]; $i<$topbound; $i++){
    		$ret .= $allImages[$i].'[>}';
    	}
    	$ret .= '[^E}'; // End new format */
    $ret .= '</table>';
    return $ret;
}
示例#5
0
 public static function FetchBy($kwargs)
 {
     extract($kwargs, EXTR_PREFIX_ALL, 't');
     $select_list = '*';
     $eq_conds = array();
     $order_by = '';
     $limit = '';
     $offset = '';
     $where_addition = '';
     $is_assoc = false;
     $is_unique = false;
     $special = array();
     if (isset($t_select_list)) {
         $select_list = $t_select_list;
     }
     if (isset($t_eq_conds)) {
         $eq_conds = $t_eq_conds;
     }
     if (isset($t_order_by)) {
         $order_by = $t_order_by;
     }
     if (isset($t_limit)) {
         $limit = $t_limit;
     }
     if (isset($t_offset)) {
         $offset = $t_offset;
     }
     if (isset($t_where_addition)) {
         $where_addition = $t_where_addition;
     }
     if (isset($t_is_assoc)) {
         $is_assoc = $t_is_assoc;
     }
     if (isset($t_is_unique)) {
         $is_unique = $t_is_unique;
     }
     if (isset($t_special)) {
         $special = $t_special;
     }
     global $db_connection;
     $where_clause = '';
     $i = 0;
     $size = count($eq_conds);
     $need_where_word = $size !== 0 || StringNotEmpty($where_addition);
     foreach ($eq_conds as $key => $value) {
         $value_tmp = $db_connection->real_escape_string($value);
         if (is_string($value)) {
             $value_tmp = '"' . $value_tmp . '"';
         }
         $where_clause .= ' (' . $key . ' = ' . $value_tmp . ') ';
         if ($i < $size - 1) {
             $where_clause .= 'OR';
         }
         ++$i;
     }
     if ($need_where_word) {
         if (StringNotEmpty($where_clause) && StringNotEmpty($where_addition)) {
             $where_clause = '(' . $where_clause . ') AND ';
             $where_addition = '(' . $where_addition . ')';
         }
         $where_clause = "WHERE " . $where_clause . ' ' . $where_addition;
     }
     if (StringNotEmpty($order_by)) {
         $where_clause .= ' ORDER BY ' . $order_by;
     }
     if (StringNotEmpty($limit)) {
         $where_clause .= ' LIMIT ' . $limit;
     }
     if (StringNotEmpty($offset)) {
         $where_clause .= ' OFFSET ' . $offset;
     }
     if (!StringNotEmpty($lang)) {
         $lang = GetLanguage();
     }
     $from_table = self::$table;
     $res = $db_connection->query("SELECT " . $select_list . " FROM " . $from_table . " " . $where_clause);
     if (!$res) {
         return new Error($db_connection->error, Error::db_error);
     }
     $res = self::ArrayFromDBResult($res, $is_assoc);
     $res_count = count($res);
     if ($is_unique) {
         if ($res_count > 1) {
             return Error::ambiguously;
         }
         if ($res_count === 0) {
             return Error::not_found;
         }
     }
     for ($i = 0, $count = count($special); $i < $count; ++$i) {
         switch ($special[$i]) {
             case 'file_type':
                 if ($is_assoc === false) {
                     break;
                 }
                 global $valid_extensions;
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['name'])) {
                         $type = fileExtension($res[$j]['name']);
                         if (!in_array($type, $valid_extensions)) {
                             $type = 'file';
                         }
                         $res[$j]['file_type'] = $type;
                     }
                 }
                 break;
             case 'link_to_download':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['path_to_file']) && isset($res[$j]['name']) && isset($res[$j]['is_directory'])) {
                         $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'is_directory' => $res[$j]['is_directory']]);
                         $res[$j]['link_to_download'] = $tmp->GetLinkToFile();
                     }
                 }
                 break;
             case 'link_to_delete':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) {
                         $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]);
                         $res[$j]['link_to_delete'] = $tmp->GetLinkToDelete();
                     }
                 }
                 break;
             case 'link_to_edit':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) {
                         $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]);
                         $res[$j]['link_to_edit'] = $tmp->GetLinkToEdit();
                     }
                 }
                 break;
             case 'link_to_link_to_download':
                 if ($is_assoc === false) {
                     break;
                 }
                 for ($j = 0; $j < $res_count; ++$j) {
                     if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) {
                         $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'id' => $res[$j]['id']]);
                         $link = $tmp->CreateDownloadLink();
                         $res[$j]['link_to_link_to_download'] = SecretLink::WrapLinkToButton($link->GetPublicLink());
                     }
                 }
                 break;
             default:
                 break;
         }
     }
     if (!$is_unique) {
         return $res;
     } else {
         return $res[0];
     }
 }
                 default:
                     break;
             }
         default:
             break;
     }
 } else {
     if (isset($_REQUEST['upload'])) {
         if (isset($_FILES['file'])) {
             global $link_prefix;
             $dir = '';
             $author_id = GetUserID();
             switch ($_REQUEST['type']) {
                 case Report::$type:
                     global $link_to_report_files;
                     $type = fileExtension($_FILES['file']['name']);
                     switch ($_REQUEST['files_action']) {
                         case 'add':
                         case 'edit':
                             $dir = $_SERVER['DOCUMENT_ROOT'] . $link_prefix . $link_to_report_files . 'tmp_' . $author_id . '/file.' . $type;
                             break;
                         default:
                             break;
                     }
                     break;
                 case MyFile::$type:
                     global $link_to_files_manager_dir;
                     $file = urlencode($_FILES['file']['name']);
                     switch ($_REQUEST['files_action']) {
                         case 'add':
                             $dir = $_SERVER['DOCUMENT_ROOT'] . $link_prefix . $link_to_files_manager_dir . 'tmp_' . $author_id . '/' . $file;