Browse Source

Minor UI edits and working through PHP 7.4 stuff

pjc 5 years ago
parent
commit
731aaeaf53
4 changed files with 594 additions and 378 deletions
  1. 36
    33
      classes/crypto.class.php
  2. 1
    1
      classes/torrent_form.class.php
  3. 518
    344
      sections/torrents/browse.php
  4. 39
    0
      static/functions/validate_upload.js

+ 36
- 33
classes/crypto.class.php View File

@@ -1,37 +1,40 @@
1
-<?
2
-class Crypto {
3
-  /**
4
-   * Encrypts input text for use in database
5
-   *
6
-   * @param string $plaintext
7
-   * @return encrypted string or false if DB key not accessible
8
-   */
9
-  public static function encrypt($plaintext) {
10
-    if (apcu_exists('DBKEY')) {
11
-      $iv_size = openssl_cipher_iv_length('AES-128-CBC');
12
-      $iv = openssl_random_pseudo_bytes($iv_size);
13
-      $ret = base64_encode($iv.openssl_encrypt($plaintext, 'AES-128-CBC', apcu_fetch('DBKEY'), OPENSSL_RAW_DATA, $iv));
14
-      return $ret;
15
-    } else {
16
-      return false;
1
+<?php
2
+
3
+class Crypto
4
+{
5
+    /**
6
+     * Encrypts input text for use in database
7
+     *
8
+     * @param string $plaintext
9
+     * @return encrypted string or false if DB key not accessible
10
+     */
11
+    public static function encrypt($plaintext)
12
+    {
13
+        if (apcu_exists('DBKEY')) {
14
+            $iv_size = openssl_cipher_iv_length('AES-128-CBC');
15
+            $iv = openssl_random_pseudo_bytes($iv_size);
16
+            $ret = base64_encode($iv.openssl_encrypt($plaintext, 'AES-128-CBC', apcu_fetch('DBKEY'), OPENSSL_RAW_DATA, $iv));
17
+            return $ret;
18
+        } else {
19
+            return false;
20
+        }
17 21
     }
18
-  }
19 22
 
20
-  /**
21
-   * Decrypts input text from database
22
-   *
23
-   * @param string $ciphertext
24
-   * @return decrypted string string or false if DB key not accessible
25
-   */
26
-  public static function decrypt($ciphertext) {
27
-    if (apcu_exists('DBKEY')) {
28
-      $iv_size = openssl_cipher_iv_length('AES-128-CBC');
29
-      $iv = substr(base64_decode($ciphertext), 0, $iv_size);
30
-      $ciphertext = substr(base64_decode($ciphertext), $iv_size);
31
-      return openssl_decrypt($ciphertext, 'AES-128-CBC', apcu_fetch('DBKEY'), OPENSSL_RAW_DATA, $iv);
32
-    } else {
33
-      return false;
23
+    /**
24
+     * Decrypts input text from database
25
+     *
26
+     * @param string $ciphertext
27
+     * @return decrypted string string or false if DB key not accessible
28
+     */
29
+    public static function decrypt($ciphertext)
30
+    {
31
+        if (apcu_exists('DBKEY')) {
32
+            $iv_size = openssl_cipher_iv_length('AES-128-CBC');
33
+            $iv = substr(base64_decode($ciphertext), 0, $iv_size);
34
+            $ciphertext = substr(base64_decode($ciphertext), $iv_size);
35
+            return openssl_decrypt($ciphertext, 'AES-128-CBC', apcu_fetch('DBKEY'), OPENSSL_RAW_DATA, $iv);
36
+        } else {
37
+            return false;
38
+        }
34 39
     }
35
-  }
36 40
 }
37
-?>

+ 1
- 1
classes/torrent_form.class.php View File

@@ -177,7 +177,7 @@ class TorrentForm
177 177
             <?php
178 178
             foreach (Misc::display_array($this->Categories) as $Index => $Cat) {
179 179
                 echo "\t\t\t\t\t\t<option value=\"$Index\"";
180
-                if ($Cat == $this->Torrent['CategoryName']) {
180
+                if ($Cat === $this->Torrent['CategoryName']) {
181 181
                     echo ' selected="selected"';
182 182
                 }
183 183
                 echo ">$Cat</option>\n";

+ 518
- 344
sections/torrents/browse.php
File diff suppressed because it is too large
View File


+ 39
- 0
static/functions/validate_upload.js View File

@@ -0,0 +1,39 @@
1
+/*
2
+$(() => {
3
+  $("#post").click(e => {
4
+    let hard_error = m => {
5
+      if (e.isDefaultPrevented()) return
6
+      alert(m)
7
+      e.preventDefault()
8
+    }
9
+    let soft_error = m => {
10
+      if (e.isDefaultPrevented()) return
11
+      if (!confirm(`${m}\n\nPress OK to upload anyway`)) {
12
+        e.preventDefault()
13
+      }
14
+    }
15
+
16
+    if (!$('#file').raw().value) {
17
+      hard_error('No torrent file is selected')
18
+    }
19
+    if ($('#album_desc').raw().value.length < 10) {
20
+      hard_error('The group description is too short')
21
+    }
22
+
23
+    if ($('#file').raw().value.slice(-8).toLowerCase() != '.torrent') {
24
+      soft_error('The file selected does not appear to be a .torrent file')
25
+    }
26
+    let mi = $('#mediainfo').raw().value
27
+    if (mi && (!mi.includes('General') || (!mi.includes('Video') && !mi.includes('Audio')))) {
28
+      soft_error('Your MediaInfo does not appear to be from a valid MediaInfo utility')
29
+    }
30
+    if (!$('#image').raw().value) {
31
+      soft_error('You did not include a cover image, which is mandatory if one exists')
32
+    }
33
+    if ($('#media_tr select').raw().value == 'DVD' && (['720p','1080i','1080p','4K'].includes($('#ressel').raw().value) || +$('#resolution').raw().value.split('x')[1] > 576)) {
34
+      soft_error('Your selected resolution is too high to be a DVD. Are you sure the media type should be DVD and not WEB?')
35
+    }
36
+  })
37
+  $('#tags').on('blur', e => $('#tags').raw().value = $('#tags').raw().value.split(',').map(t=>t.trim()).filter(t=>t).join(', '))
38
+})
39
+*/

Loading…
Cancel
Save