3 function upload_data_file() {
4 // XXX sec. bug over sec. bug
6 global $db,$error,$node;
8 require(INCLUDE_DIR.'filez.inc');
10 if (($node['node_permission']!='owner') &&
11 ($node['node_permission']!='master')) {
12 $error=$error_messages['EVENT_PERMISSION_ERROR'];
16 $node_id=$node['node_id'];
17 filez::upload_data_file($node_id);
19 if ($suffix=='zip' && $_POST['unzip']) {
20 mkdir(TMP."/".$_FILES['data_file']['name']);
22 // directory traversal si dissabled by default from zip v 5.50
23 $cmd="unzip ".$_FILES['data_file']['tmp_name']." -d "
24 .TMP."/".$_FILES['data_file']['name'];
27 $handle=opendir(TMP."/".$_FILES['data_file']['name']);
29 // XXX move this mess into a function
30 while (($file = readdir($handle))!==false) {
31 if ($file!="." && $file!="..") {
33 // Need to check extenstions of all extracted files
34 if ( !filez::filename_secure($_FILES['data_file']['file'])) {
35 $error = 'ale ale, kto nam to tady loupe pernicek.. ';
39 $node_params['node_name']=$file;
40 $node_params['node_creator']=$_SESSION['user_id'];
41 $node_params['template_id']=DEF_DATA_TEMPLATE;
42 $node_params['node_parent']=$node['node_id'];
44 $node_params['node_content']=$file;
45 $datanode_id=nodes::addNode($node_params);
46 $file_suffix = array_pop(explode('.', basename($file)));
47 copy(TMP."/".$_FILES['data_file']['name']."/".$file,
48 FILE_DIR.$_SESSION['user_id'].'/'.$datanode_id.".$file_suffix");
49 symlink(FILE_DIR.$_SESSION['user_id'].'/'.$datanode_id.".$file_suffix",
50 SYSTEM_ROOT.'/files/'.$datanode_id);
52 # Removed for now, need complete rewrite
54 # if ($_POST['gallery']) {
55 # $node_params['template_id']=DEF_GALLERY_TEMPLATE;
56 # $image=TMP."/".$_FILES['data_file']['name']."/".$file;
58 # $width=NODE_IMAGE_WIDTH;
60 # if (stristr($image_name,".jpg") ||
61 # stristr($image_name,".jpeg") ){
63 # /// XXX UTILZ_DIR is not set. remove?
64 # $cmd=UTILZ_DIR."/jpegtopnm $image |".UTILZ_DIR."/pnmscale -width=$width | ".UTILZ_DIR."ppmquant 256 |".UTILZ_DIR."ppmtogif >".SYSTEM_ROOT.SYSTEM_IMAGES.'/nodes/'.substr($datanode_id,0,1)."/".substr($datanode_id,1,1)."/".$datanode_id.".gif";
66 # elseif (stristr($image_name,".gif")) {
67 # $cmd=UTILZ_DIR."/gifsicle --resize ".$width."x_ $image > ".SYSTE_ROOT.SYSTEM_IMAGES.'/nodes/'.substr($datanode_id,0,1)."/".substr($datanode_id,1,1)."/".$datanode_id.".gif";
82 copy($_FILES['data_file']['tmp_name'],
83 FILE_DIR.$_SESSION['user_id'].'/'.$node['node_id'].".$suffix");
84 symlink(FILE_DIR.$_SESSION['user_id'].'/'.$node['node_id'].".$suffix",
85 FILE_DIR.'/'.$node['node_id']);