Browse code

Changed majority of files.

DoubleBastionAdmin authored on 30/11/2024 06:56:40
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,227 @@
1
+<?php
2
+/**
3
+ *  Copyright (C) 2022, 2024  Double Bastion LLC
4
+ *
5
+ *  This file is part of Roundpin, which is licensed under the
6
+ *  GNU Affero General Public License Version 3.0. The license terms
7
+ *  are detailed in the "LICENSE.txt" file located in the root directory.
8
+ */
9
+
10
+session_start();
11
+
12
+if (isset($_POST['sipusername']) && $_POST['sipusername'] != '' && isset($_POST['encextenpass']) && $_POST['encextenpass'] != '' && isset($_POST['conferenceext']) && 
13
+    $_POST['conferenceext'] != '' && isset($_POST['vcextensionpm']) && $_POST['vcextensionpm'] != '') {
14
+
15
+    define('ACCESSCONST', TRUE);
16
+
17
+    require('db-connect.php');
18
+
19
+    $vconfExtension = $_POST['sipusername'];
20
+    $extenPassEnc = $_POST['encextenpass'];
21
+    $videoConfExt = $_POST['conferenceext'];
22
+
23
+    $vcExtensionpm = $_POST['vcextensionpm'];
24
+    $resmessage = '';
25
+
26
+    // Check if the received external user extension, the corresponding encrypted password and the extension of the conference, match the data in the 'external_users' table
27
+    $query = $mysqli->prepare("SELECT id, exten_for_external, exten_for_ext_pass, conf_extension FROM external_users WHERE exten_for_external = ? AND exten_for_ext_pass = ? AND conf_extension = ?");
28
+    $query->bind_param("sss", $vconfExtension, $extenPassEnc, $videoConfExt);
29
+    $query->execute();
30
+    $extqueryres = $query->get_result()->fetch_array();
31
+
32
+    if (!$extqueryres) {
33
+
34
+        http_response_code(400);
35
+        exit();
36
+
37
+    } else {
38
+
39
+	  try {
40
+
41
+	    // Check for undefined error, multiple files, $_FILES corruption
42
+	    if (!isset($_FILES['uploadedFileVCPM']['error']) || is_array($_FILES['uploadedFileVCPM']['error'])) {
43
+		throw new RuntimeException('Invalid parameters.');
44
+	    }
45
+
46
+	    // Check $_FILES['upfile']['error'] value
47
+	    switch ($_FILES['uploadedFileVCPM']['error']) {
48
+		case UPLOAD_ERR_OK:
49
+		     break;
50
+		case UPLOAD_ERR_NO_FILE:
51
+		     throw new RuntimeException('No file sent.');
52
+		case UPLOAD_ERR_INI_SIZE:
53
+		     throw new RuntimeException('The file size limit was exceeded! Please choose a file with a smaller size!');
54
+		case UPLOAD_ERR_FORM_SIZE:
55
+		     throw new RuntimeException('The file size limit was exceeded! Please choose a file with a smaller size!');
56
+		default:
57
+		     throw new RuntimeException('Unknown error.');
58
+	    }
59
+
60
+	    // Check file size (in bytes)
61
+	    if ($_FILES['uploadedFileVCPM']['size'] > 786432000) {
62
+		throw new RuntimeException('Uploaded file size exceeds the limit of 750 MB.');
63
+	    }
64
+
65
+	    // Check MIME Type
66
+	    $finfo = new finfo(FILEINFO_MIME_TYPE);
67
+	    if (false === $ext = array_search($finfo->file($_FILES['uploadedFileVCPM']['tmp_name']),
68
+		array(
69
+		'aac' => 'audio/aac',
70
+		'abw' => 'application/x-abiword',
71
+		'arc' => 'application/x-freearc',
72
+		'avi' => 'video/x-msvideo',
73
+		'azw' => 'application/vnd.amazon.ebook',
74
+		'bin' => 'application/octet-stream',
75
+                'bmp' => 'image/x-ms-bmp',
76
+		'bz' => 'application/x-bzip',
77
+		'bz2' => 'application/x-bzip2',
78
+		'cda' => 'application/x-cdf',
79
+		'csh' => 'application/x-csh',
80
+		'css' => 'text/css',
81
+		'csv' => 'text/csv',
82
+		'doc' => 'application/msword',
83
+		'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
84
+		'eot' => 'application/vnd.ms-fontobject',
85
+		'epub' => 'application/epub+zip',
86
+		'gz' => 'application/gzip',
87
+		'gif' => 'image/gif',
88
+		'htm' => 'text/html',
89
+		'html' => 'text/html',
90
+		'ico' => 'image/vnd.microsoft.icon',
91
+		'ics' => 'text/calendar',
92
+		'jar' => 'application/java-archive',
93
+		'jpeg' => 'image/jpeg',
94
+		'jpg' => 'image/jpeg',
95
+		'json' => 'application/json',
96
+		'jsonld' => 'application/ld+json',
97
+		'mid' => 'audio/midi',
98
+		'midi' => 'audio/midi',
99
+		'mp3' => 'audio/mpeg',
100
+		'mp4' => 'video/mp4',
101
+		'mpeg' => 'video/mpeg',
102
+		'mpkg' => 'application/vnd.apple.installer+xml',
103
+		'odp' => 'application/vnd.oasis.opendocument.presentation',
104
+		'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
105
+		'odt' => 'application/vnd.oasis.opendocument.text',
106
+		'oga' => 'audio/ogg',
107
+		'ogv' => 'video/ogg',
108
+		'ogx' => 'application/ogg',
109
+		'opus' => 'audio/opus',
110
+		'otf' => 'font/otf',
111
+		'png' => 'image/png',
112
+		'pdf' => 'application/pdf',
113
+		'ppt' => 'application/vnd.ms-powerpoint',
114
+		'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
115
+		'rar' => 'application/vnd.rar',
116
+		'rtf' => 'application/rtf',
117
+		'sh' => 'application/x-sh',
118
+		'swf' => 'application/x-shockwave-flash',
119
+		'tar' => 'application/x-tar',
120
+		'tif' => 'image/tiff',
121
+		'tiff' => 'image/tiff',
122
+		'ts' => 'video/mp2t',
123
+		'ttf' => 'font/ttf',
124
+		'txt' => 'text/plain',
125
+		'vsd' => 'application/vnd.visio',
126
+		'wav' => 'audio/wav',
127
+		'weba' => 'audio/webm',
128
+		'webm' => 'video/webm',
129
+		'webp' => 'image/webp',
130
+		'woff' => 'font/woff',
131
+		'woff2' => 'font/woff2',
132
+		'xhtml' => 'application/xhtml+xml',
133
+		'xls' => 'application/vnd.ms-excel',
134
+		'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
135
+		'xml' => 'text/xml',
136
+		'xul' => 'application/vnd.mozilla.xul+xml',
137
+		'zip' => 'application/zip',
138
+		'3gp' => 'video/3gpp',
139
+		'3g2' => 'video/3gpp2',
140
+		'7z' => 'application/x-7z-compressed',
141
+		),
142
+		true
143
+	    )) {
144
+		throw new RuntimeException('Invalid file format.');
145
+	    }
146
+
147
+	    // Check if the uploaded file contains PHP or JavaScript code tags
148
+	    $upFileContent = file_get_contents($_FILES['uploadedFileVCPM']['tmp_name']);
149
+	    if ((strpos($upFileContent, "<?php") !== false) || (strpos($upFileContent, "<script") !== false)) { throw new RuntimeException('Invalid file type.'); }
150
+
151
+	    // Create the directories if they don't exist
152
+	    if (!is_dir('../textchat/' . $vcExtensionpm)) {
153
+		mkdir('../textchat/' . $vcExtensionpm, 0700);
154
+	    }
155
+
156
+	    if (!is_dir('../textchat/' . $vcExtensionpm . '/uploads')) {
157
+		mkdir('../textchat/' . $vcExtensionpm . '/uploads', 0700);
158
+	    }
159
+
160
+	    // Check if the name of the uploaded file is valid
161
+	    $nameWithoutExt = pathinfo($_FILES["uploadedFileVCPM"]["name"], PATHINFO_FILENAME);
162
+
163
+	    if (preg_match('/^[a-zA-Z0-9\-\_\.]+$/', $nameWithoutExt)) {
164
+
165
+		// Check if the name of the uploaded file is larger than 50 bytes
166
+		if (strlen(basename($_FILES["uploadedFileVCPM"]["name"])) <= 50) {
167
+
168
+		    // Check if a file with the same name already exists in the 'uploads' directory of that respective user
169
+		    if (!file_exists('../textchat/' . $vcExtensionpm . '/uploads/' . basename($_FILES["uploadedFileVCPM"]["name"]))) {
170
+
171
+		        $upload_dir = '../textchat/' . $vcExtensionpm . '/uploads/';
172
+		        $targetfile = $upload_dir . basename($_FILES["uploadedFileVCPM"]["name"]);
173
+
174
+		        // Scan the uploaded file with ClamAV if ClamAV is installed
175
+		        if (file_exists('/usr/bin/clamdscan')) {
176
+
177
+		            $clamdisrunning = exec("systemctl show -p ActiveState --value clamav-daemon");
178
+
179
+		            if ($clamdisrunning == 'active') {
180
+
181
+				$safePath = escapeshellarg($_FILES["uploadedFileVCPM"]['tmp_name']);
182
+		                $runclamdscan = 'clamdscan --fdpass --quiet ' . $safePath . '';
183
+				$resout = '';
184
+				$rescheck = 1;
185
+				exec($runclamdscan, $resout, $rescheck);
186
+
187
+				if ($rescheck == 0) {
188
+
189
+		                    if (move_uploaded_file($_FILES["uploadedFileVCPM"]["tmp_name"], $targetfile)) {
190
+		                        chmod($targetfile, 0600);
191
+		                    } else {
192
+		                        throw new RuntimeException('There was an error while uploading the file.');
193
+		                    }
194
+
195
+		                } else { unlink($safePath); throw new RuntimeException('The file contains a virus or other type of malware.'); }
196
+
197
+		            } else { throw new RuntimeException("The ClavAV antivirus is installed but clamav-daemon is not active and the uploaded file couldn't be scanned! Please check the status of clamav-daemon!"); }
198
+
199
+		        } else {
200
+
201
+		                if (move_uploaded_file($_FILES["uploadedFileVCPM"]["tmp_name"], $targetfile)) {
202
+		                    chmod($targetfile, 0600);
203
+		                } else { throw new RuntimeException('There was an error while uploading the file.'); }
204
+		        }
205
+
206
+		    } else { throw new RuntimeException('A file with the same name, ' . basename($_FILES["uploadedFileVCPM"]["name"]) . ', has been already sent. Please send a different file or rename your file before sending it.'); }
207
+
208
+		} else { throw new RuntimeException('The name of the uploaded file is too long. File name length should not exceed 50 (Latin) characters. You can give a shorter name to your file and try again.'); }
209
+
210
+	    } else { throw new RuntimeException('The name of the uploaded file is not valid. File names should contain only alphanumeric characters, hyphens, underscores and dots.'); }
211
+
212
+	  } catch (RuntimeException $e) {
213
+
214
+		  $resmessage = $e->getMessage();
215
+	  }
216
+
217
+  }
218
+
219
+  $respdata = ['error' => $resmessage];
220
+
221
+  echo json_encode($respdata);
222
+
223
+} else {
224
+       header("Location: ../login.php");
225
+}
226
+
227
+?>