Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elphel-web-393
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
elphel-web-393
Commits
0a31e92d
Commit
0a31e92d
authored
Aug 25, 2017
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
default option set to download single zip
parent
49717aca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
42 deletions
+89
-42
elphel_functions_include.php
src/php_top/elphel_functions_include.php
+49
-11
index.php
src/snapshot/index.php
+38
-31
snapshot.js
src/snapshot/snapshot.js
+2
-0
No files found.
src/php_top/elphel_functions_include.php
View file @
0a31e92d
...
...
@@ -111,7 +111,7 @@ function respond_xml($result,$error=null,$color_mode = 3){ // default white bold
header
(
"Pragma: no-cache
\n
"
);
printf
(
$rslt
);
}
if
(
isset
(
$GLOBALS
[
'logFile'
])){
if
(
$result
!==
""
){
//"" will not be loged/output
log_msg
(
''
.
$result
,
$color_mode
);
...
...
@@ -128,7 +128,7 @@ function respond_xml($result,$error=null,$color_mode = 3){ // default white bold
// PARALLEL HTTP REQUESTS
// Using parallel requests, PHP has to be configured '--with-curl=' (and libcurl should be installed)
function
curl_multi_start
(
$urls
)
{
function
curl_multi_start
(
$urls
,
$with_headers
=
0
)
{
// numprime is needed to actually send the request and remote starts executing it
// Not really clear - what it should be
$numprime
=
4
;
// magic number, see http://lampe2e.blogspot.com/2015/03/making-stuff-faster-with-curlmultiexec.html
...
...
@@ -138,7 +138,7 @@ function curl_multi_start($urls) {
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
0
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
$with_headers
);
$aCurlHandles
[]
=
$ch
;
curl_multi_add_handle
(
$curl_mh
,
$ch
);
}
...
...
@@ -151,8 +151,8 @@ function curl_multi_start($urls) {
}
return
array
(
"mh"
=>
$curl_mh
,
"handles"
=>
$aCurlHandles
);
}
function
curl_multi_finish
(
$data
,
$use_xml
=
true
,
$ntry
=
0
,
$echo
=
false
)
{
function
curl_multi_finish
(
$data
,
$use_xml
=
true
,
$ntry
=
0
,
$echo
=
false
,
$with_headers
=
0
)
{
$curl_active
=
1
;
$curl_mrc
=
CURLM_OK
;
$nrep
=
0
;
...
...
@@ -170,6 +170,7 @@ function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false) {
}
}
$results
=
array
();
$names
=
array
();
if
(
$use_xml
)
{
foreach
(
$data
[
'handles'
]
as
$i
=>
$ch
)
{
$xml
=
simplexml_load_string
(
curl_multi_getcontent
(
$ch
));
...
...
@@ -187,13 +188,50 @@ function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false) {
foreach
(
$data
[
'handles'
]
as
$i
=>
$ch
)
{
$r
=
curl_multi_getcontent
(
$ch
);
curl_multi_remove_handle
(
$curl_mh
,
$ch
);
if
(
$with_headers
==
1
){
$hsize
=
curl_getinfo
(
$ch
,
CURLINFO_HEADER_SIZE
);
$h
=
substr
(
$r
,
0
,
$hsize
);
$r
=
substr
(
$r
,
$hsize
);
$names
[]
=
curl_get_filename_from_header
(
$h
);
}
$results
[]
=
$r
;
}
if
(
$with_headers
==
1
){
$results
=
Array
(
'names'
=>
$names
,
'contents'
=>
$results
);
}
}
curl_multi_close
(
$curl_mh
);
return
$results
;
}
function
curl_get_filename_from_header
(
$h
){
$h
=
explode
(
"
\n
"
,
$h
);
$res
=
""
;
if
(
$h
){
foreach
(
$h
as
$e
){
if
(
strlen
(
$e
)
!=
0
){
$tmp
=
explode
(
":"
,
$e
);
if
(
$tmp
[
0
]
==
"Content-Disposition"
){
$tmp
=
explode
(
";"
,
$tmp
[
1
]);
foreach
(
$tmp
as
$t
){
$t
=
trim
(
$t
);
$t
=
explode
(
"="
,
$t
);
if
(
$t
[
0
]
==
"filename"
){
$res
=
trim
(
$t
[
1
],
"
\t\n\r\0\x0B\"
"
);
break
;
}
}
break
;
}
}
}
}
return
$res
;
}
// DEVICES
/** Get a list of suitable partitions. The list will contain SATA devices only and
...
...
@@ -218,7 +256,7 @@ function get_partitions()
/** Get a list of disk devices which have file system and can be mounted. This function
* uses 'blkid' command from busybox.
*/
*/
function
get_mnt_dev
()
{
$partitions
=
get_partitions
();
...
...
@@ -237,7 +275,7 @@ function get_mnt_dev()
$i
++
;
}
}
return
array
(
"devices"
=>
$devices
,
"types"
=>
$fs_types
);
}
...
...
@@ -246,12 +284,12 @@ function get_raw_dev()
{
$j
=
0
;
$ret
=
get_mnt_dev
();
$devices
=
$ret
[
"devices"
];
$devices
=
$ret
[
"devices"
];
$types
=
$ret
[
"types"
];
$names
=
get_partitions
();
// filter out partitions with file system
// filter out partitions with file system
$i
=
0
;
$raw_devices
=
array
();
...
...
@@ -267,7 +305,7 @@ function get_raw_dev()
$i
++
;
}
}
//special case
if
(
count
(
$raw_devices
)
>
1
)
{
foreach
(
$raw_devices
as
$k
=>
$v
){
...
...
src/snapshot/index.php
View file @
0a31e92d
...
...
@@ -22,6 +22,8 @@
?>
<?php
include
"../include/elphel_functions_include.php"
;
$port0
=
2323
;
$path
=
"/sys/devices/soc0/elphel393-detect_sensors@0"
;
$available_ports
=
Array
();
...
...
@@ -99,49 +101,54 @@
if
(
isset
(
$_GET
[
'zip'
])){
$
tmpdir
=
"/tmp/snapshot"
;
// create tmp dir
if
(
!
is_dir
(
$tmpdir
)
){
mkdir
(
$tmpdir
);
$
contents
=
Array
()
;
$filenames
=
Array
();
$rqs
=
Array
();
foreach
(
$available_ports
as
$port
){
array_push
(
$rqs
,
"http://
{
$_SERVER
[
'SERVER_ADDR'
]
}
:
$port
/timestamp_name/bimg"
);
}
$cdata
=
curl_multi_start
(
$rqs
,
1
);
$results
=
curl_multi_finish
(
$cdata
,
false
,
0
,
false
,
1
);
$filenames
=
$results
[
'names'
];
$contents
=
$results
[
'contents'
];
/*
foreach($available_ports as $port){
exec
(
"wget --content-disposition -P
$tmpdir
http://
{
$_SERVER
[
'SERVER_ADDR'
]
}
:
$port
/timestamp_name/bimg"
);
//exec("wget --content-disposition -P $tmpdir http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg");
//fopen("http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg",'r');
$content = file_get_contents("http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg");
$filename = get_filename_from_headers($http_response_header);
if ($filename==""){
$filename = "bimg.jp4";
}
array_push($filenames,$filename);
array_push($contents,$content);
}
*/
$fstring
=
""
;
$zipfile
=
"bimg.zip"
;
$zipfilename
=
preg_replace
(
"/_\d+\.jp4$/"
,
".zip"
,
$filenames
[
0
]);
$files
=
scandir
(
$tmpdir
);
//remove . & ..
array_splice
(
$files
,
0
,
2
)
;
//tmpfile
$tmpfile
=
tmpfile
();
$tmpfilename
=
stream_get_meta_data
(
$tmpfile
)[
'uri'
]
;
$prefixed_files
=
preg_filter
(
'/^/'
,
"
$tmpdir
/"
,
$files
);
$fstring
=
implode
(
" "
,
$prefixed_files
);
$zip
=
new
ZipArchive
;
// pick name for the zip archive
foreach
(
$files
as
$file
){
$tmp
=
explode
(
"."
,
$file
);
if
(
$tmp
[
1
]
==
"jp4"
||
$tmp
[
1
]
==
"jpeg"
){
$tmp
=
explode
(
"_"
,
$tmp
[
0
]);
if
(
$tmp
[
2
]
==
"0"
){
$zipfile
=
$tmp
[
0
]
.
"_"
.
$tmp
[
1
]
.
".zip"
;
break
;
}
}
if
(
$zip
->
open
(
$tmpfilename
,
ZipArchive
::
OVERWRITE
)
!==
TRUE
)
{
die
(
"cannot access temporary file <
$tmpfilename
>
\n
"
);
}
$zipped_data
=
`zip -qj - $fstring `
;
header
(
'Content-type: application/zip'
);
header
(
'Content-Disposition: attachment; filename="'
.
$zipfile
.
'"'
);
echo
$zipped_data
;
// clean up
foreach
(
$prefixed_files
as
$file
){
unlink
(
$file
);
foreach
(
$filenames
as
$k
=>
$v
){
$zip
->
addFromString
(
$v
,
$contents
[
$k
]);
}
$zip
->
close
();
header
(
'Content-type: application/zip'
);
header
(
'Content-Disposition: attachment; filename="'
.
$zipfilename
.
'"'
);
echo
file_get_contents
(
$tmpfilename
);
die
();
}
...
...
src/snapshot/snapshot.js
View file @
0a31e92d
...
...
@@ -59,6 +59,8 @@ function download_all(rtp){
pass_to_file_reader
(
filename
,
http
.
response
);
if
(
$
(
"#synced"
).
prop
(
"checked"
))
{
read_tp
();
}
else
{
$
(
"#snapshot"
).
attr
(
"disabled"
,
false
);
}
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment