2 if (!$_SESSION[creds][validated] && !isset($_GET['f']))exit();
4 require_once("squasher.class.php");
6 $squashweb = new squashweb();
8 $squashweb->update_history();
11 $basedir = "../uploads";
12 if (isset($_GET['path']) && $_GET['path']!=NULL && strlen($_GET['path'])!=1){
13 $subf = $_GET['path'];
14 $path = $basedir . $subf;
19 $squashweb->set_root($basedir);
21 if ((isset($_GET['f']) && $_GET['f']!=NULL) || (isset($_GET['d']) && $_GET['d']!=NULL) || $_GET['show_all']==true || $_GET['tools']=='hide' || $_GET['tools']=='unhide' || $_GET['tools']=='delete'){
29 //update folder rights if form is submitted
30 if($submitted['edited_user'] > 0 && $submitted['formtype'] == 'folderrights') $squashweb->update_rights($submitted,$_SESSION[creds][user_level]);
33 if (isset($_GET['f']) && $_GET['f']!=NULL){
34 $squashweb->give_rights(0);
36 $squashweb->give_rights($_SESSION[creds][user_id]);
39 if (isset($_GET['f']) && $_GET['f']!=NULL){
40 $f_q = "SELECT * FROM file_hash WHERE md5_hash = '".$_GET['f']."'";
41 $f_r = mysql_query($f_q);
42 $f_o = mysql_fetch_object($f_r);
45 @mysql_query("INSERT INTO log (hash,file,action,user_id,user_name,ip,date) VALUES ('".$_GET['f']."','{$f_o->file}','download','".$_SESSION[creds][user_id]."','".$_SESSION[creds][user_name]."','".$_SERVER[REMOTE_ADDR]."',NOW())");
47 $_hpath_arr=explode("/",$f_o->file);
48 $file=array_pop($_hpath_arr); //Remove filename
49 $path=implode("/",$_hpath_arr);
50 $squashweb->read_single_file($path,$file);
51 #$squashweb->read_directory($path,false,true,false,false);
53 //parse folders for readable files
54 $squashweb->read_directory($path,true,true,$getdeepfiles,$populate);
57 //check if a file is requested
58 if (isset($_GET['f']) && $_GET['f']!=NULL){
59 //get the config of requested file
60 $request = $squashweb->get_config($_GET['f']);
62 //------------------------------------
63 //-check-file-and-request-type--start-
64 //------------------------------------
65 if (strpos($request['mime'],'ideo') && isset($_GET['d'])){ //embed video
66 $squashweb->embed_video($_GET['f']);
68 elseif (strpos($request['mime'],'ideo') && isset($_GET['x'])){ //show stream playlist
69 $squashweb->create_playlist($_GET['f'],$_GET['x'],$request[2]);
71 else{ //show requested file
72 # header('Cache-control: private');
73 header('Content-Disposition: attachment; filename="'.$request[2].'"');
74 header("Content-Type: ".$request['mime']);
75 if($request[3])header('Content-Length: '.$request[3]);
78 $squashweb->print_files($request['path'],$request[2]);
80 //---------------------------------
81 //-check-file-and-request-type-end-
82 //---------------------------------
84 }elseif ($tools=="hide" && isset($_GET['h'])){
85 if ($_SESSION[creds][user_level] > 99){
86 $request = $squashweb->get_config($_GET['h']);
87 $handle = fopen($request['path'].'/'.$request[2].'.hidden', 'x');
88 fwrite($handle, 'hidden by '.$_SESSION[creds][user_name]);
90 $path=substr($request['path'],strlen($basedir));
91 header( 'Location: '.$_SERVER['PHP_SELF'].'?path='.$path) ;
93 }elseif ($tools=="unhide" && isset($_GET['h'])){
94 if ($_SESSION[creds][user_level] > 99){
95 $request = $squashweb->get_config($_GET['h']);
96 @unlink($request['path'].'/'.$request[2].'.hidden');
97 $path=substr($request['path'],strlen($basedir));
98 header( 'Location: '.$_SERVER['PHP_SELF'].'?path='.$path) ;
100 }elseif ($tools=="delete" && isset($_GET['h'])){
101 if ($_SESSION[creds][user_level] > 99){
102 if ($_GET['h'] == "multiple"){
103 $h_post = $_POST['h'];
104 foreach ($h_post as $h_key => $h){
105 $request = $squashweb->get_config($h);
106 $squashweb->delete_file($h,$_SESSION[creds]);
110 $request = $squashweb->get_config($h);
111 $squashweb->delete_file($h,$_SESSION[creds]);
113 $path=substr($request['path'],strlen($basedir));
114 header( 'Location: '.$_SERVER['PHP_SELF'].'?path='.$path);
116 }elseif ($_GET['tools']=='access' && $_SESSION[creds][user_level] > 100){
118 require_once("smarty/Smarty.class.php");
120 $smarty = new Smarty;
122 $smarty->assign('user_level',$_SESSION[creds][user_level]);
123 $smarty->assign('user_name',$_SESSION[creds][user_name]);
124 $smarty->assign('users',$squashweb->get_users($_SESSION[creds][user_level]));
126 $smarty->assign('edited_user',$_GET['user']);
128 $tree = $squashweb->show_rights_tree($path,0,$_GET['user']);
130 $smarty->assign('style',$tree[style]);
131 $smarty->assign('layout',$tree[layout]);
133 $smarty->assign('debug',$vars[debug]);
134 $smarty->assign('folderrights',$squashweb->folderrights());
135 $smarty->assign('userrights',$squashweb->userrights());
136 $smarty->display('admin.tpl');
138 }elseif ($_GET['tools']=='users' && $_SESSION[creds][user_level] > 100){
140 if ($submitted[type]=="update"){$squashweb->update_users($submitted);}
141 if ($submitted[type]=="disable"){$squashweb->disable_users($submitted);}
142 if ($submitted[type]=="delete"){$squashweb->remove_users($submitted);}
143 if ($submitted[type]=="new"){$squashweb->insert_users($submitted,$_SESSION[creds][user_level]);}
144 require_once("smarty/Smarty.class.php");
146 $smarty = new Smarty;
148 $smarty->assign('user_level',$_SESSION[creds][user_level]);
149 $smarty->assign('user_name',$_SESSION[creds][user_name]);
150 $smarty->assign('users',$squashweb->get_users($_SESSION[creds][user_level]));
152 if ($_SESSION[creds][user_level] > 199){
153 $smarty->assign('user_levels', array(155 => 'admin' , 55 => 'user' ) );
155 $smarty->assign('user_levels', array(55 => 'user' ) );
157 $smarty->assign('debug',$vars[debug]);
159 $smarty->display('udmin.tpl');
161 }elseif ($_GET['tools']=='logs' && $_SESSION[creds][user_level] > 100){
162 $logtype=($_GET['logtype']) ? $_GET['logtype'] : 'all';
163 require_once("smarty/Smarty.class.php");
165 $smarty = new Smarty;
167 $smarty->assign('user_level',$_SESSION[creds][user_level]);
168 $smarty->assign('user_name',$_SESSION[creds][user_name]);
169 $smarty->assign('logtype',$logtype);
170 $smarty->assign('logs',$squashweb->get_logs($logtype));
172 $smarty->display('logs.tpl');
174 }else{ //show overview
176 require_once("smarty/Smarty.class.php");
178 $smarty = new Smarty;
188 * [6] -> CRC32 checksum
191 $configs_num = $squashweb->get_configs();
193 $configs_sorted = named_records_sort($configs_num,'lastchange',true);
195 foreach ($configs_sorted AS $key => $value){
196 $configs[$key]['squashed'] = $value['squashed'];
197 $configs[$key]['version'] = $value[0];
198 //$configs[$key]['date'] = $value[1]; //removed because user local creation date is irrelevant
199 $configs[$key]['name'] = $value[2];
200 $configs[$key]['size'] = $value[3];
201 $configs[$key]['chunk_size'] = $value[4];
202 $configs[$key]['chunks'] = $value[5];
203 $configs[$key]['crc'] = $value[6];
204 $paths[substr($value['path'], strlen($basedir))]=array_pop(explode('/',$value['path']));
205 (strpos($value['mime'],'ideo')) ? $embedable=true : $embedable=false;
206 (@array_sum($value['stats']) == $value[5]) ? $finished=true : $finished=false;
208 $configs[$key]['embedable'] = $embedable;
209 $configs[$key]['finished'] = $finished;
210 $configs[$key]['mime'] = $value['mime'];
211 $configs[$key]['status'] = $value['status'];
212 $configs[$key]['hidden'] = $value['hidden'];
213 $configs[$key]['chunks_finished'] = @array_sum($value['stats']);
215 $configs[$key]['chunks_partial'] = $configs[$key]['chunks_finished'];
218 foreach($value['stats'] AS $sk => $sv){
220 $configs[$key]['chunks_partial']=$configs[$key]['chunks_partial']+$sv;
221 if($sv != '1.00')$continue=false;
225 $configs[$key]['date'] = date('d.m.y - H:i:s - T',$value['added']);
226 $configs[$key]['lastchange'] = date('d.m.y - H:i:s - T',$value['lastchange']);
231 $basepath['/']=' top ';
232 foreach (explode('/',$subf) AS $key => $value){
235 $basepath[$bpath]=$value;
238 $smarty->assign('debug',$vars[debug]);
239 $smarty->assign('user_level',$_SESSION[creds][user_level]);
240 $smarty->assign('user_name',$_SESSION[creds][user_name]);
241 $smarty->assign('folderrights',$squashweb->folderrights());
243 $smarty->assign('squashed',$configs);
244 $smarty->assign('paths',$paths);
245 $smarty->assign('base',$basepath);
246 $smarty->assign('currentfolder',$subf);
247 $subs = $squashweb->subfolders();
249 $smarty->assign('subfolders',$subs);
251 //if($vars[debug])print_r($configs);
252 if(!$vars[newtpl])$smarty->display('index.tpl'); //Display normal template
253 if($vars[newtpl])$smarty->display('wip_massdelete.tpl'); //Display Work In Progress template