-
Notifications
You must be signed in to change notification settings - Fork 13
/
import.php
128 lines (118 loc) · 4.44 KB
/
import.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
124
125
126
127
128
<?php
/**
* File: import.php
* Author: Ryan.Prather
* Purpose: Standardized import functionality
* Created: Sep 27, 2013
*
* Change Log:
* - Sep 27, 2013 - File created
* - Aug 30, 2016 - Fixed progress bar
* - Mar 20, 2017 - Replaced with JS Dropzone library
* - Apr 7, 2017 - Added .xlsx extension to accepted files
* - May 13, 2017 - Made this more self-sustaining
* - May 19, 2017 - Change button to match others
* - Apr 29, 2018 - Changed default message and formatting
*/
$files = glob(TMP . "/*.*");
?>
<div id="import" class="box">
<script type="text/javascript" src="/script/dropzone/dropzone.min.js"></script>
<link type="text/css" href="/script/dropzone/dropzone.min.css" rel="stylesheet" />
<link type="text/css" href="/script/dropzone/basic.min.css" rel="stylesheet" />
<script type="text/javascript">
var mydz;
Dropzone.options.dropzone = {
maxFilesize: 150,
success: function (file, res) {
res = JSON.parse(res);
if (res.imageUrl) {
this.emit('thumbnail', file, res.imageUrl);
}
},
acceptedFiles: "text/csv,text/plain,application/vnd.ms-excel,.nessus,.xml,.nmap,.ckl,.xlsx",
addRemoveLinks: true,
dictCancelUpload: "Cancel Upload",
dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
dictRemoveFile: "Delete File?"
};
Dropzone.prototype.submitRequest = function (xhr, formData, files) {
var dt = new Date(files[0].lastModifiedDate);
xhr.setRequestHeader('X-FILENAME', files[0].name);
xhr.setRequestHeader('X-FILEMTIME', dt.toISOString());
return xhr.send(formData);
};
Dropzone.autoDiscover = false;
$(function () {
mydz = new Dropzone('#dropzone');
mydz.on('removedfile', function (file) {
$.ajax('/ajax.php', {
data: {
action: 'delete-file',
filename: file.name
},
success: function (data) {
if (data.error) {
}
else if (data.success) {
alert(data.success);
}
},
error: function (xhr, status, error) {
console.error(error);
},
dataType: 'json',
timeout: 3000,
method: 'post'
});
});
});
/**
* Function to import all the scans
*
* @returns {undefined}
*/
function add_scans() {
$.ajax('/ajax.php', {
data: {
action: 'add_scans',
ste: '<?php print (isset($ste) && is_numeric($ste) ? $ste : ''); ?>',
ignore: ($('#ignore_hidden').is(':checked') ? '1' : '0'),
location: $('#location').val()
},
beforeSend: function () {
close_box();
},
success: function (data) {
if ($('#toggle_refresh').html() == 'Stop Refresh' && !to) {
to = setTimeout(update_script_status, <?php print UPDATE_FREQ * 1000; ?>);
}
},
error: function (xhr, status, error) {
console.error(error);
},
//timeout: 10000,
dataType: 'json',
method: 'post'
});
}
</script>
<form class="dropzone" action="/upload.php" id="dropzone">
<div class="dz-message" data-dz-message><span>Click or Drop files here to upload</span></div>
<div class="fallback">
<input type="file" name="file" multiple />
</div>
</form>
<div style='margin-left: 20px;'>
<?php
if(is_array($files) && count($files)) {
natsort($files);
print "<span style='background-color:red;color:white;font-size:16px;' title='" . implode("\n", $files) . "'>NOTE: There are still files in the " . realpath(TMP) . " directory (mouse over to see)</span><br />";
}
?>
<input type='text' id='location' placeholder='Physical Location...' /><br />
<input type='button' class='button' id='add-scan' value='Add Scan Result' onclick='add_scans();' /><br />
<label for='ignore_hidden' id='ignore_label'>Ignore Hidden Tabs in Excel eChecklists</label>
<input type='checkbox' name='ignore_hidden' id='ignore_hidden' value='1' checked />
</div>
</div>