2 require_once("include/connect.inc.php");
4 function zfill($n,$a) {
5 return str_repeat("0",max(0,$a-strlen($n))).$n;
8 function named_records_sort($named_recs, $order_by, $reverse=false, $flags=0)
10 $named_hash = array();
11 foreach($named_recs as $key => $fields)$named_hash[$key] = $fields[$order_by];
13 if($reverse) arsort($named_hash,$flags=0) ;
14 else asort($named_hash, $flags=0);
16 $sorted_records = array();
17 foreach($named_hash as $key => $val)$sorted_records[$key] = $named_recs[$key];
19 return $sorted_records;
22 function validate_user($vars,$salt){
23 $creds[validated] = false;
24 $query="SELECT * FROM users";
25 $q_result = mysql_query($query);
26 while ($fetched_object = mysql_fetch_object($q_result)){
27 if ($fetched_object->user_name == $vars[user]){
28 if (md5($fetched_object->user_pass.$salt) == $vars[pass]){
30 $creds[user_id] = $fetched_object->user_id;
31 $creds[user_name] = $fetched_object->user_name;
32 $creds[user_level] = $fetched_object->user_level;
33 $creds[validated] = true;
35 $log_hash=(isset($vars['f'])) ? $vars['f'] : $vars['h'] ;
36 if ($log_hash==NULL)$log_hash=str_repeat("0",32);
37 $q="insert into log (hash,action,user_id,user_name,ip,date) values ('{$log_hash}','login','".$creds['user_id']."','".$creds['user_name']."','".$_SERVER[REMOTE_ADDR]."',NOW())";
42 $_SESSION[creds] = $creds;
43 return $creds[validated];
57 function set_root($root){
58 $this->basepath = $root;
61 function get_configs(){
62 return $this->configs;
65 function subfolders(){
66 return $this->subfolders;
69 function get_config($h){
71 return $this->configs[$h];
74 function folderrights(){
75 return $this->folderrights;
78 function userrights(){
79 return $this->userrights;
82 function update_history(){
83 $q="SELECT md5_hash,file,completed,checked FROM file_hash";
85 while($o=mysql_fetch_object($r)){
86 $this->history[$o->md5_hash]['file']=$o->file;
87 $this->history[$o->md5_hash]['completed']=$o->completed;
88 $this->history[$o->md5_hash]['checked']=$o->checked;
92 function got_rights_checkbox($needle){
93 $result = $this->got_rights_array($needle,'',0,'userrights');
106 function get_users($user_level){
107 $q = "SELECT * FROM users WHERE user_level < '".$user_level."' order by user_name asc";
108 $r = mysql_query($q);
110 while ($o = mysql_fetch_object($r)){
111 $return[$o->user_id]['id'] = $o->user_id;
112 $return[$o->user_id]['name'] = $o->user_name;
113 $return[$o->user_id]['level'] = $o->user_level;
114 $return[$o->user_id]['enabled'] = ($o->user_pass == '') ? false : true ;;
120 function get_logs($type='all'){
121 $q="SELECT log.* FROM log WHERE log.user_id != '1' and ip != '87.233.211.2' ";
122 if($_SESSION[creds][user_id] == 1)$q="SELECT log.* FROM log WHERE log.user_id != 'x' ";
125 $q.= " and log.action = 'delete'";
128 $q.= " and log.action = 'download'";
131 $q.= " and log.action = 'login'";
134 $q.= " and log.action = 'debug'";
141 $today =" and date > date(date_add(now(), interval -0 day)) ";
142 $yesterday =" and date < date(date_add(now(), interval -0 day)) and date > date(date_add(now(), interval -1 day)) ";
143 $lastweek =" and date < date(date_add(now(), interval -1 day)) and date > date(date_add(now(), interval -6 day)) ";
144 $older =" and date < date(date_add(now(), interval -7 day)) and date > date(date_add(now(), interval -30 day)) ";
146 $order=" order by log.log_id desc ";
147 $r = mysql_query($q.$today.$order);
148 while($a = mysql_fetch_array($r)){
149 $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{$a[ip]}' group by users.user_name";
150 $ru = mysql_query($qu);
151 $a[users_from_ip]=" | ";
152 while($au = mysql_fetch_array($ru))$a[users_from_ip].=$au[user_name]." | ";
153 $return['today'][$a['log_id']]=$a;
155 $r = mysql_query($q.$yesterday.$order);
156 while($a = mysql_fetch_array($r)){
157 $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{$a[ip]}' group by users.user_name";
158 $ru = mysql_query($qu);
159 $a[users_from_ip]=" | ";
160 while($au = mysql_fetch_array($ru))$a[users_from_ip].=$au[user_name]." | ";
161 $return['yesterday'][$a['log_id']]=$a;
163 $r = mysql_query($q.$lastweek.$order);
164 while($a = mysql_fetch_array($r)){
165 $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{$a[ip]}' group by users.user_name";
166 $ru = mysql_query($qu);
167 $a[users_from_ip]=" | ";
168 while($au = mysql_fetch_array($ru))$a[users_from_ip].=$au[user_name]." | ";
169 $return['lastweek'][$a['log_id']]=$a;
171 $r = mysql_query($q.$older.$order);
172 while($a = mysql_fetch_array($r)){
173 $qu="select users.user_name from users left join log on users.user_id = log.user_id where log.ip='{$a[ip]}' group by users.user_name";
174 $ru = mysql_query($qu);
175 $a[users_from_ip]=" | ";
176 while($au = mysql_fetch_array($ru))$a[users_from_ip].=$au[user_name]." | ";
177 $return['older'][$a['log_id']]=$a;
183 function insert_users($submitted,$admin_level){
184 $q = "INSERT INTO users (user_name,user_pass,user_level) values ('".$submitted[u][user_name]."','".md5($submitted[u][user_pass])."','".$submitted[u][user_level]."')";
185 $r = mysql_query($q);
188 function update_users($submitted){
189 $q = "UPDATE users SET user_name = '".$submitted[u][user_name]."', user_pass = '".md5($submitted[u][user_pass])."', user_level = '".$submitted[u][user_level]."' WHERE user_id = '".$submitted[u][user_id]."'";
190 $r = mysql_query($q);
193 function disable_users($submitted){
194 $q = "UPDATE users SET user_name = '".$submitted[u][user_name]."', user_pass = '', user_level = '".$submitted[u][user_level]."' WHERE user_id = '".$submitted[u][user_id]."'";
195 $r = mysql_query($q);
198 function remove_users($submitted){
199 $q = "DELETE FROM users WHERE user_id = '".$submitted[u][user_id]."'";
200 $r = mysql_query($q);
203 function give_rights($user_id,$type='folderrights'){
205 $q = "SELECT folder_path, access FROM user_rights WHERE user_id = '".$user_id."'";
206 $r = mysql_query($q);
207 while ($o = mysql_fetch_object($r)){
210 $arr_string = '$this->'.$type;
212 //get foldernames from path
213 if($o->folder_path != '/'){
214 $path = $o->folder_path;
215 if($path{0}=='/')$path=substr($path,1);
216 $folder_arr = explode('/',$path);
218 //create folder structure array
219 foreach ($folder_arr AS $key => $value){
220 $arr_string .= "['".$value."']";
223 $arr_string .= "['__access__']";
226 // access = # --deny-all
227 // access = * --allow-dir-only
228 // access = @ --allow-inc-subs
229 /* switch($o->access){
240 //echo $arr_string." = '".$icon."'\n";
241 //echo $arr_string." = '".$o->access."';";
242 eval($arr_string." = '".$o->access."';");
245 return $this->folderrights;
248 function update_rights($submitted,$admin_level){
249 $q = "SELECT count(*) result FROM users WHERE user_id = '".$submitted['edited_user']."' AND user_level < '".$admin_level."'";
250 $r = mysql_query($q);
251 $o = mysql_fetch_object($r);
254 foreach ($submitted[m] AS $path => $access){
255 $p_q = "SELECT count(*) result FROM user_rights WHERE user_id = '".$submitted['edited_user']."' AND folder_path = '".$path."'";
256 $p_r = mysql_query($p_q);
257 $p_o = mysql_fetch_object($p_r);
258 if ($p_o->result == 1) mysql_query("UPDATE user_rights SET access = ".$access." WHERE folder_path = '".$path."' AND user_id = '".$submitted['edited_user']."'");
259 if ($p_o->result == 0) mysql_query("INSERT INTO user_rights (user_id,folder_path,access) values ('".$submitted['edited_user']."','".$path."','".$access."') ");
265 function show_rights_tree($path,$depth=0,$userid=0){
267 if ($userid==0)return false;
268 if ($depth==0)$this->give_rights($userid,'userrights');
270 // access = # | 0 --deny-all
271 // access = * | 1 --allow-dir-only
272 // access = @ | 2 --allow-inc-subs
274 for ($i=0;$depth > $i; $i++)$layout .= " ";
275 if ($dir = opendir($path)){
276 $layout .= "<div style='clear:both;' >\n";
278 while (false !== ($file = readdir($dir))) { $files_array[]=$file; }
280 foreach ($files_array as $f_index => $file)
282 // while (false !== ($file = readdir($dir)))
284 if (($file{0} !== ".") && ($file !== ".."))
286 $filename = $path."/".$file;
287 if (!is_file($filename)){if ($this->got_rights_array($filename) > 0)
290 if(substr($filename,0,strlen($this->basepath))==$this->basepath) $name=substr($filename,strlen($this->basepath));
291 //$check = $this->got_rights_checkbox($filename);
292 $check = $this->got_rights_array_admin($filename,'',0,'userrights');
298 $check_all = 'checked';
301 $check_allow = 'checked';
305 $check_deny = 'checked';
309 if($f==1)$style[$depth] = ".depth".$depth."{float:right;width:".(600-($depth*10))."px;border-left:2px solid #FFFFFF;border-top:1px solid #FFFFFF;background:#".dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).dechex(14-$depth).";}";
310 if($f==1)$layout .= "<div class='depth".$depth."'>";
311 $layout .= "<div class='white_border' >".$file."</div>\n";
312 $layout .= "<div class='check_deny'><input name='m[".$name."]' value=0 type=radio ".$check_deny."></div>\n";
313 $layout .= "<div class='check_allow'><input name='m[".$name."]' value=1 type=radio ".$check_allow."></div>\n";
314 $layout .= "<div class='check_all'><input name='m[".$name."]' value=2 type=radio ".$check_all."></div>\n";
315 $sub_return = $this->show_rights_tree($filename,$depth+1,$userid);
316 if(is_array($style) && is_array($sub_return['style']))$style = $style + $sub_return['style'];
317 $layout .= $sub_return['layout'];
321 if($f!=0)$layout .= "</div>";
322 $layout .= "</div>\n";
325 $return['style'] = $style;
326 $return['layout'] = $layout;
331 function got_rights_path($needle,$haystack){
333 if(!is_array($haystack)) $haystack = $this->folderrights;
334 foreach($haystack as $v){
336 if($needle == $v) return true;
339 if(is_in_array($needle, $v, $case_sensitive) === true) return true;
345 function got_rights_array($needle,$haystack='',$c=0,$type='folderrights'){
347 if(!is_array($haystack)) eval('$haystack = $this->'.$type.';');
348 if(substr($needle,0,strlen($this->basepath))==$this->basepath) $needle=substr($needle,strlen($this->basepath));
350 //if($needle{0}=='.')$needle=substr($needle,strlen($this->basepath));
353 if($needle{0}=='/' && $haystack['__access__'] == 2 ) return 2;
355 //check folder tights
356 if($needle{0}=='/')$needle=substr($needle,1);
358 $needle_arr = explode('/',$needle);
359 $n = count($needle_arr);
362 foreach($haystack as $k => $v){
363 if($needle_arr[$c] == $k){
364 if(!is_array($v['__access__'])){
365 if (($v['__access__'] == '@' || $v['__access__'] == 2) ) return 2;
366 if (($v['__access__'] == '*' || $v['__access__'] == 1) && $d == $n ) return 1;
367 if (($v['__access__'] == '#' || $v['__access__'] == 0) && $d == $n ) return 0;
369 $return = $this->got_rights_array($needle, $v, $d);
376 function got_rights_array_admin($needle,$haystack='',$c=0,$type='folderrights'){
378 if(!is_array($haystack)) eval('$haystack = $this->'.$type.';');
379 if(substr($needle,0,strlen($this->basepath))==$this->basepath) $needle=substr($needle,strlen($this->basepath));
381 //if($needle{0}=='.')$needle=substr($needle,strlen($this->basepath));
384 if($needle{0}=='/' && $haystack['__access__'] == 2 ) return 2;
386 //check folder rights
387 if($needle{0}=='/')$needle=substr($needle,1);
389 $needle_arr = explode('/',$needle);
390 $n = count($needle_arr);
395 if($haystack['__access__'] == 2)return $haystack['__access__'];
396 if(is_array($haystack[$needle_arr[$c]]))$return = $this->got_rights_array_admin($needle, $haystack[$needle_arr[$c]], $d);
398 if($haystack['__access__'] > 0)$return = $haystack['__access__'];
404 function got_rights_array_recursive($needle,$haystack='',$c=0,$type='folderrights'){
406 if(!is_array($haystack)) eval('$haystack = $this->'.$type.';');
407 if(substr($needle,0,strlen($this->basepath))==$this->basepath) $needle=substr($needle,strlen($this->basepath));
409 //if($needle{0}=='.')$needle=substr($needle,strlen($this->basepath));
412 if($needle{0}=='/' && $haystack['__access__'] == 2 ) return 2;
414 //check folder rights
415 if($needle{0}=='/')$needle=substr($needle,1);
417 $needle_arr = explode('/',$needle);
418 $n = count($needle_arr);
422 foreach($haystack as $k => $v){
423 if($needle_arr[$c] == $k){
425 if($v['__access__'] == 2) $return = $return + $v['__access__'];
426 $return = $return + $this->got_rights_array_recursive($needle, $v, $d);
428 $return = $return + $this->in_array_recursive($v);
431 $return = $return + $v['__access__'];
432 if($k != '__access__')$return = $return + $this->in_array_recursive($v);
439 function in_array_recursive($haystack){
441 if (is_array($haystack))foreach ($haystack as $key1 => $value1){
442 if (is_array($value1)){
443 $return = $return + $this->in_array_recursive($value1);
452 function read_single_file($path,$file){
453 $filename = $path."/".$file;
455 if ($this->got_rights_array($path) > 0){
456 if (is_file($filename.'.Completed'))$file.='.Completed';
457 if (is_file($filename.'.InProgress'))$file.='.InProgress';
458 if (is_file($filename.'.Starting'))$file.='.Starting';
459 if (is_file($filename.'.Processed'))$file.='.Processed';
460 $filename = $path."/".$file;
461 $handle = @fopen($filename, "rb");
462 if (strpos($file,'.Completed') )$ext='.Completed';
463 if (strpos($file,'.InProgress'))$ext='.InProgress';
464 if (strpos($file,'.Starting') )$ext='.Starting';
465 if (strpos($file,'.Processed') )$ext='.Processed';
466 $sub_pos=strpos($file,$ext);
467 $base_name=substr($file,0,$sub_pos);
468 $filecontent = @fread($handle, @filesize($filename));
469 $config[$i]=explode("\r\n",$filecontent);
478 * [6] -> CRC32 checksum
480 if (@filesize($filename) > 0){
481 $h=md5($path."/".$config[$i][2]);
482 $this->configs[$h]=$config[$i];
483 $this->configs[$h]['squashed']=true;
484 $this->configs[$h]['path']=$path;
485 $this->configs[$h]['status']=substr($ext, 1);
486 $this->configs[$h]['mime']=$this->set_mime($this->configs[$h][2]);
487 $this->configs[$h]['hidden']= (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
488 //to prevent dates of 1-1-1970 we set te dates of the config file
489 $this->configs[$h]['added'] = filectime($filename);
490 $this->configs[$h]['lastchange'] = filemtime($filename);
492 $this->populate_stats($path,$h);
494 #$this->update_hash($h,$path."/".$config[$i][2]);
496 $this->check_stats($h);
502 function read_directory($path,$getsubs=false,$getfirstfiles=true,$getdeepfiles=true,$populate=true){
504 if ($dir = @opendir($path)){
507 while (false !== ($file = readdir($dir))){
508 if (($file{0} !== ".") && substr($file,0,1) !== "SQ"){
509 $filename = $path."/".$file;
510 if (!is_file($filename) && !strpos($filename,'./uploads/recieving')){
512 if ($this->got_rights_array_recursive($filename) > 0){
513 $key = substr($path,strlen($this->basepath)) . '/' . $file;
514 $this->subfolders[$key]=$file;
517 if($getdeepfiles)$this->read_directory($filename,false,$getdeepfiles,$getdeepfiles,$populate);
518 }elseif(strpos($filename,'./uploads/ftp')){ //ftp files
519 if ($this->got_rights_array($path) > 0 && !strpos($filename,'.hidden') ){
521 $name_only=substr($filename,strlen($path)+1);
522 $file_structure=explode('.',$name_only);
523 $ext=array_pop($file_structure);
524 $base_name=array_pop($file_structure);
525 $this->configs[$h]['path']=$path;
526 $this->configs[$h][0]='manual ftp';
527 $this->configs[$h][2]=$name_only;
528 $this->configs[$h][3]=filesize($filename);
529 $this->configs[$h]['added']=filectime($filename);
530 $this->configs[$h]['lastchange']=filemtime($filename);
531 $this->configs[$h]['status']='unknown';
532 $this->configs[$h]['squashed']=false;
533 $this->configs[$h]['mime']=$this->set_mime($name_only);
534 $this->configs[$h]['hidden']= (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
536 }elseif($getfirstfiles){ //squashed files
537 if ($this->got_rights_array($path) > 0){
538 if (strpos($filename,'.Completed') || strpos($filename,'.InProgress') || strpos($filename,'.Starting') || strpos($filename,'.Processed')){
540 $handle = @fopen($filename, "rb");
541 if (strpos($file,'.Completed') )$ext='.Completed';
542 if (strpos($file,'.InProgress'))$ext='.InProgress';
543 if (strpos($file,'.Starting') )$ext='.Starting';
544 if (strpos($file,'.Processed') )$ext='.Processed';
545 $sub_pos=strpos($file,$ext);
546 $base_name=substr($file,0,$sub_pos);
547 $filecontent = @fread($handle, @filesize($filename));
548 $config[$i]=explode("\r\n",$filecontent);
558 * [6] -> CRC32 checksum
561 if (@filesize($filename) > 0){
562 $h=md5($path."/".$config[$i][2]);
563 $this->configs[$h]=$config[$i];
564 $this->configs[$h]['squashed']=true;
565 $this->configs[$h]['path']=$path;
566 $this->configs[$h]['status']=substr($ext, 1);
567 $this->configs[$h]['mime']=$this->set_mime($this->configs[$h][2]);
568 $this->configs[$h]['hidden']= (is_file($path.'/'.$base_name.'.hidden')) ? true : false ;
569 //to prevent dates of 1-1-1970 we set te dates of the config file
570 $this->configs[$h]['added'] = filectime($filename);
571 $this->configs[$h]['lastchange'] = filemtime($filename);
573 $this->populate_stats($path,$h);
575 $this->update_hash($h,$path."/".$config[$i][2]);
577 $this->check_stats($h);
587 function check_stats($h){
588 $config = $this->get_config($h);
589 $count = @array_sum($config['stats']);
590 if ($config['status']=='Completed' && $count != $config[5]){
591 $filepath=$config['path'].'/'.$config[2];
592 if($this->history[$h]['completed']=="1"){
593 //don't display broken file, remove it instead
594 unlink($config['path'].'/'.$config[2].'.Completed');
595 unset($this->configs[$h]);
597 if (!$count)$count = 0;
598 $m_subject="Squasher Debug: File Removed";
599 $m_body="Upload removed: \n File: ".$config['path']."/".$config[2]." \n Status: ".$config['status']." \n Chunks: ".$count." out of ".$config[5];
600 mail('jasper@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
601 $qlog="insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','debug','-1','squasher-web','cleanup',NOW())";
606 rename($config['path'].'/'.$config[2].'.Completed',$config['path'].'/'.$config[2].'.InProgress');
607 $this->configs[$h]['status']='InProgress';
610 if (!$count)$count = 0;
611 $m_subject="Squasher Debug: Upload Error";
612 $m_body="Upload error: \n File: ".$config['path']."/".$config[2]." \n Status: ".$config['status']." \n Chunks: ".$count." out of ".$config[5];
613 mail('support@netformatie.nl',$m_subject,$m_body,"From: squasher@netformatie.nl");
614 mail('jan@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
615 mail('joop@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
616 mail('jasper@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
619 //wget -o/dev/null "http://www.mollie.nl/xml/sms/?username=netformatie&password=SMSdolsi&originator=Netformatie&recipients=${ENGINEER}&message=${CALLERID}";
622 $ship=explode('/',$config['path']);
623 if($ship[2] == 'myas' || $ship[2] == 'myez' || $ship[2] == 'myrw')mail('ro1@'.$ship[2].'.greenpeace.org','Squasher: '.$config[2].' resume request','The squasher server has detected an upload error. Please resume the squasher transmission for '.$config[2].' to correct this problem.',"From: support@netformatie.nl\nX-Priority: 1");
625 $qlog="insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','debug','-1','squasher-web','retry',NOW())";
629 }elseif($config['status']=='Completed' && $count == $config[5]){
630 if($this->history[$h]['completed']==0)mysql_query("UPDATE file_hash SET completed = 1 WHERE md5_hash = '".$h."'");
634 function update_hash($hash,$path){
635 $check_hash_query="select * from file_hash where md5_hash = '".$hash."'";
636 $check_hash_result=mysql_query($check_hash_query);
637 if(mysql_num_rows($check_hash_result) == 0){
638 $insert_hash_query="INSERT INTO file_hash (md5_hash,file) values ('".$hash."','".$path."')";
639 mysql_query($insert_hash_query);
643 function path_to_arraystring($path,$arrayname){
644 $path_values = explode('/',$path);
645 $return = $arrayname;
646 foreach ($path_values AS $key => $value){
647 if ($value != '.' && $value != '')$return.= "['".$value."']";
652 function populate_stats($path,$h){
661 * [6] -> CRC32 checksum
663 $config = $this->configs[$h];
665 $q = "SELECT * FROM file_hash WHERE md5_hash = '{$h}'";
666 $r = mysql_query($q);
667 $o = mysql_fetch_object($r);
668 $validated_chunks = $o->validated_chunks;
670 if($this->history[$h]['completed']=="1"){
671 $file_part = $path."/SQ".zfill(1,6)."-".$config[2];
672 if (!is_file($file_part))$file_part = $path."/SQ".zfill(1,3)."-".$config[2];
673 if (is_file($file_part)){
674 $this->configs[$h]['added'] = filectime($file_part);
675 $file_part = $path."/SQ".zfill($config[5],6)."-".$config[2];
676 if (!is_file($file_part))$file_part = $path."/SQ".zfill($config[5],3)."-".$config[2];
677 if (is_file($file_part)) $this->configs[$h]['lastchange'] = filemtime($file_part);
678 for ($i=1;$i<=$config[5];$i++)
680 $this->configs[$h]['stats'][$i]="1.00";
683 //failsafe voor verwijderde bestanden
684 mysql_query("UPDATE file_hash SET completed = 0 WHERE md5_hash = '".$h."'");
687 $keep_validating = true;
688 for ($i=1;$i<=$config[5];$i++){
689 if ($validated_chunks > $i){
690 $this->configs[$h]['stats'][$i]="1.00";
692 $file_part = $path."/SQ".zfill($i,6)."-".$config[2];
693 if (!is_file($file_part))$file_part = $path."/SQ".zfill($i,3)."-".$config[2];
694 if (is_file($file_part)){
695 $handle = fopen($file_part, "rb");
696 $size_this = filesize($file_part);
697 $added = filectime($file_part);
698 $last_changed = filemtime($file_part);
699 if ($this->configs[$h]['added'] > $added || !is_numeric($this->configs[$h]['added'])) $this->configs[$h]['added'] = $added;
700 if ($this->configs[$h]['lastchange'] < $last_changed) $this->configs[$h]['lastchange'] = $last_changed;
701 if ($i != $config[5]){
702 $this->configs[$h]['stats'][$i]=number_format((1/$config[4])*$size_this, 2, '.', '');
703 //number_format((100/$config[4])*$size_this, 2, '.', '')."%";
705 $this->configs[$h]['stats'][$i]=number_format((1/($config[3]-($config[4]*($config[5]-1))))*$size_this, 2, '.', '');
706 //number_format((100/($config[3]-($config[4]*($config[5]-1))))*$size_this, 2, '.', '')."%";
709 if ($config[4] == $size_this && $keep_validating){
710 $validated_chunks = $i;
712 $keep_validating = false;
715 $this->configs[$h]['stats'][$i]="0.00";
716 //$this->configs[$h]['stats'][$i]="0.00%";
721 mysql_query("UPDATE file_hash SET validated_chunks = '{$validated_chunks}' WHERE md5_hash = '".$h."'");
725 function read_config($path,$filename){
726 if (is_file($path."/".$filename.".InProgress")){
727 $config_handle = fopen($path."/".$filename.".InProgress","r");
728 $conf_path=$path."/".$filename.".InProgress";
729 }elseif (is_file($path."/".$filename.".Completed" )){
730 $config_handle = fopen($path."/".$filename.".Completed" ,"r");
731 $conf_path=$path."/".$filename.".Completed";
732 }elseif (is_file($path."/".$filename.".Starting" )){
733 $config_handle = fopen($path."/".$filename.".Starting" ,"r");
734 $conf_path=$path."/".$filename.".Starting";
735 }elseif (is_file($path."/".$filename.".Processed" )){
736 $config_handle = fopen($path."/".$filename.".Processed" ,"r");
737 $conf_path=$path."/".$filename.".Processed";
741 $config_content = fread($config_handle, filesize($conf_path));
742 fclose($config_handle);
743 $config = explode("\n",$config_content);
747 /* $file_count = $config[5];
749 for ($i=1;$i<=$file_count;$i++)
751 $file_part = $path."/SQ".zfill($i,6)."-".$filename;
752 if (is_file($file_part))
755 $handle = fopen($file_part, "rb");
756 $size_this = filesize($file_part);
757 //$stats[$i]=round((100/$config[4])*$size_this)."%";
758 if ((($size_this==$config[4] && ($last+1)==$i) )|| $i == $config[5]){
759 $merged_file.=fread($handle, filesize($file_part));
769 function print_files($path,$filename,$tovar = false){
770 if(strpos($path,'./uploads/ftp')){
771 $filestring=$path.'/'.$filename;
772 if (is_file($filestring)){
773 $handle = fopen($filestring, "rb");
774 while (!feof($handle))
776 print(fread($handle, 1024));
782 if (is_file($path."/".$filename.".InProgress")){
783 $config_handle = fopen($path."/".$filename.".InProgress","r");
784 $conf_path=$path."/".$filename.".InProgress";
785 }elseif (is_file($path."/".$filename.".Completed" )){
786 $config_handle = fopen($path."/".$filename.".Completed" ,"r");
787 $conf_path=$path."/".$filename.".Completed";
788 }elseif (is_file($path."/".$filename.".Starting" )){
789 $config_handle = fopen($path."/".$filename.".Starting" ,"r");
790 $conf_path=$path."/".$filename.".Starting";
791 }elseif (is_file($path."/".$filename.".Processed" )){
792 $config_handle = fopen($path."/".$filename.".Processed" ,"r");
793 $conf_path=$path."/".$filename.".Processed";
797 $config_content = fread($config_handle, filesize($conf_path));
798 fclose($config_handle);
799 $config = explode("\n",$config_content);
801 $file_count = $config[5];
803 $last_part_size=( $config[3] - ( ( $config[5] -1 ) * $config[4] ) );
804 for ($i=0;$i<=$file_count;$i++)
806 $file_part = $path."/SQ".zfill($i,6)."-".$filename;
807 if (!is_file($file_part))$file_part = $path."/SQ".zfill($i,3)."-".$filename;
808 if (is_file($file_part))
810 $handle = fopen($file_part, "rb");
811 $size_this = filesize($file_part);
812 if ( ( ( $size_this==$config[4] ) && ( ($last+1)==$i ) ) || ( ( $i == $config[5] ) && ( $size_this==$last_part_size ) && ( ($last+1)==$i ) ) ){
814 $merged_file.=fread($handle, $size_this);
817 while (!feof($handle))
819 print(fread($handle, 4096));
829 if($tovar)return $merged_file;
833 function check_md5($h){
835 $config=$this->configs[$h];
836 $var=$this->print_files($config['path'],$config[2],true);
838 if($hash==$config[6])$return=true;
843 function file_crc($file_string){
844 //$file_string = file_get_contents($file);
846 $crc = crc32($file_string);
847 return sprintf("%u\n", $crc);
850 function file_crc_debug($file){
851 $file_string = file_get_contents($file);
853 $crc = crc32($file_string);
854 return sprintf("%u\n", $crc);
857 function delete_file($h,$s){
858 $request = $this->get_config($h);
859 if(strpos($request['path'],'./uploads/ftp')){
860 $filepath=$request['path'].'/'.$request[2];
862 if(is_file($filepath)) @unlink($filepath);
863 if(is_file($filepath.'.hidden')) @unlink($filepath.'.hidden');
866 for($i=0;$i<=$request[5];$i++){
867 $part_six = $request['path']."/SQ".zfill($i,6)."-".$request[2];
868 $part_three = $request['path']."/SQ".zfill($i,3)."-".$request[2];
869 if(is_file($part_six)) @unlink($part_six);
870 if(is_file($part_three)) @unlink($part_six);
873 if(is_file($request['path'].'/'.$request[2].'.hidden')) @unlink($request['path'].'/'.$request[2].'.hidden');
874 if(is_file($request['path'].'/'.$request[2].'.Completed')) @unlink($request['path'].'/'.$request[2].'.Completed');
875 if(is_file($request['path'].'/'.$request[2].'.InProgress')) @unlink($request['path'].'/'.$request[2].'.InProgress');
876 if(is_file($request['path'].'/'.$request[2].'.Processed')) @unlink($request['path'].'/'.$request[2].'.Processed');
877 if(is_file($request['path'].'/'.$request[2].'.Starting')) @unlink($request['path'].'/'.$request[2].'.Starting');
881 $q="delete from file_hash where file_hash = '{$h}'";
883 $q="insert into log (hash,file,action,user_id,user_name,ip,date) values ('{$h}','{$filepath}','delete','".$s['user_id']."','".$s['user_name']."','".$_SERVER[REMOTE_ADDR]."',NOW())";
887 $m_name=$s['user_name'];
888 $m_subject="Squasher Debug: File Deleted by {$m_name}";
889 $m_body="File Deleted: \n Requested by: {$m_name} \n File: {$filepath}";
890 mail('jasper@netformatie.nl',$m_subject,$m_body,"From: support@netformatie.nl");
893 function show_files() {
895 $path = "./uploads/";
897 if ($dir = opendir($path)){
901 $files_merged=array();
902 while (false !== ($file = readdir($dir)))
904 if (($file !== ".") && ($file !== ".."))
906 $filename = $path.$file;
907 $handle = fopen($filename, "rb");
908 $size_this = filesize($filename);
909 if ($i==1) $size_first = $size_this;
910 $filecontent = fread($handle, filesize($filename));
911 $files[$i++]=$filename;
912 $files_merged[$file_base][]=$filename;
919 print_r($files_merged);
923 function set_mime($filename){
924 $ext_arr = explode('.',$filename);
925 $ext = strtolower(array_pop($ext_arr));
932 $mime = 'video/mpeg'; //MPEG Video
938 $mime = 'application/octet-stream';
941 $mime = 'image/gif'; //GIF Image
945 $mime = 'image/jpeg'; //JPEG Image
948 $mime = 'image/png'; //PNG Image
952 $mime = 'audio/wav'; //WAV Audio
955 $mime = 'audio/mpeg'; //MP3 Audio
958 $mime = 'video/mov'; //Quicktime Video
961 $mime = 'video/x-ms-wmv'; //Windows WMV video
964 $mime = 'audio/x-ms-wma'; //Windows WMA audio
967 $mime = 'audio/x-realaudio'; //RealPlayer Audio/Video (.rm)
970 $mime = 'audio/x-pn-realaudio'; //RealPlayer Audio/Video (.ram)
973 $mime = 'application/pdf'; //PDF Document
976 $mime = 'application/msword'; //MS Word .doc file
979 $mime = 'application/zip'; //Zip File
982 $mime = 'application/octet-stream';
985 //$return['mime']=$mime;
986 //$return['ext']=$ext;
991 function embed_video($h){
992 /*JASPER FIX, use config->systemurl */
994 <!-- begin embedded WindowsMedia file... -->
995 <table border='0' cellpadding='0' align="center">
997 <OBJECT id='mediaPlayer'
998 classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'
999 codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
1000 standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
1001 <param name='fileName' value="http://master.squasher.netformatie.nl/?x=asx&f=<?=$h;?>">
1002 <param name='animationatStart' value='true'>
1003 <param name='transparentatStart' value='true'>
1004 <param name='autoStart' value="true">
1005 <param name='showControls' value="true">
1006 <param name='loop' value="true">
1007 <param name="BufferingTime" value="3">
1008 <EMBED type='application/x-mplayer2'
1009 pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
1010 id='mediaPlayer' name='mediaPlayer' autosize='1'
1011 bgcolor='darkblue' showcontrols="true" showtracker='-1'
1012 showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='480' height='320'
1013 src="http://master.squasher.netformatie.nl/?x=asx&f=<?=$h;?>" autostart="true" designtimesp='5311' loop="true">
1017 <!-- ...end embedded WindowsMedia file -->
1018 <!-- begin link to launch external media player... -->
1019 <tr><td align='center'>
1020 <a href="http://master.squasher.netformatie.nl/?x=asx&f=<?=$h;?>" style='font-size: 85%;' target='_blank'>Launch in external player</a>
1021 <!-- ...end link to launch external media player... -->
1027 function create_playlist($h,$t='asx',$title='Title'){
1032 header('Content-Disposition: attachment; filename="stream.asx"');
1033 echo '<ASX version="3.0">
1034 <title>Squasher Streaming Video</title>
1036 <title>Video Stream</title>
1037 <ref HREF="http://master.squasher.netformatie.nl/?a=x&f='.$h.'"/>
1045 header('Content-Disposition: attachment; filename="stream.'.$t.'"');
1047 #EXTINF:-1,Squasher Streaming Video - '.$title.'
1048 http://master.squasher.netformatie.nl/?a=x&f='.$h.'';
1055 header('Content-Disposition: attachment; filename="stream.m3u"');
1057 #EXTINF:-1,Squasher Streaming Video - '.$title.'
1058 http://master.squasher.netformatie.nl/?a=x&f='.$h.'';