-
Notifications
You must be signed in to change notification settings - Fork 3
/
sisDownload.php
123 lines (89 loc) · 2.83 KB
/
sisDownload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
proc_nice(8);
ob_start();
require_once("config.php");
$download_dest = 'tmp';
$progress_file = $download_dest.DIRECTORY_SEPARATOR."progress.txt";
$zip_file = $download_dest.DIRECTORY_SEPARATOR."sisyphos.zip";
$lock_file = $download_dest.DIRECTORY_SEPARATOR."lock";
$source_url = 'https://codeload.github.com/nekpap/sisyphos/zip/master';
define('DOWNLOAD_DEST', $download_dest);
define('PROGRESS_FILE', $progress_file);
define('ZIP_FILE', $zip_file);
define('GIT_URL',$source_url);
$done = false;
$max_download_size = 0;
$max_downloaded_size = 0;
if (isset($_GET['key']) && trim($_GET['key'])!=''){
$key = $_GET['key'];
$conn = mysqli_connect($nuConfigDBHost,$nuConfigDBUser,$nuConfigDBPassword, $nuConfigDBName);
if (mysqli_connect_errno()) {
die("Connect to DataBase Failed: ".mysqli_connect_error());
}
$sql = "SELECT COUNT(*) FROM zzzsys_debug WHERE deb_message='$key'";
$result = mysqli_query($conn, $sql);
if (mysqli_connect_errno()) {
die ("Query to DataBase Failed: ".mysqli_connect_error());
}
$row = $result->fetch_array();
$sql = "DELETE FROM zzzsys_debug WHERE deb_message='$key'";
$result = mysqli_query($conn, $sql);
if($row[0]>0){
$fp = fopen($lock_file, "w");
if (flock($fp, LOCK_EX)) {
file_put_contents(PROGRESS_FILE,"[0,0]",LOCK_EX);
ob_flush();
flush();
$targetFile = fopen($zip_file, 'w' );
$ch = curl_init($source_url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_NOPROGRESS, false );
curl_setopt( $ch, CURLOPT_PROGRESSFUNCTION, 'progressCallback' );
curl_setopt( $ch, CURLOPT_FILE, $targetFile );
if(curl_exec( $ch )!==FALSE){
if(curl_error($ch)) {
file_put_contents(PROGRESS_FILE,"[-1,0]",LOCK_EX);
ob_flush();
flush();
} else{
$done = true;
$total_size = filesize($zip_file);
file_put_contents(PROGRESS_FILE,"[$total_size,$total_size]",LOCK_EX);
ob_flush();
flush();
}
} else {
file_put_contents(PROGRESS_FILE,"[-1,0]",LOCK_EX);
ob_flush();
flush();
}
curl_close($ch);
fclose($targetFile);
flock($fp, LOCK_UN);
} else {
die ("Failed to lock!");
}
fclose($fp);
unlink($lock_file);
} else {
die ("Key not matching!");
}
$conn->close();
} else {
die ("Key not provided!");
}
ob_flush();
flush();
function progressCallback($resource,$download_size, $downloaded_size, $upload_size, $uploaded_size ){
global $done;
global $max_download_size;
global $max_downloaded_size;
if(!$done){
if(!is_null($download_size) && $download_size>$max_download_size){$max_download_size=$download_size;}
if(!is_null($downloaded_size) && $downloaded_size>$max_downloaded_size){$max_downloaded_size=$downloaded_size;}
file_put_contents(PROGRESS_FILE,"[$max_downloaded_size,$max_download_size]",LOCK_EX);
ob_flush();
flush();
}
}
?>