Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

@@ 1735-1782 (lines=48) @@
1732
1733
        if (isset($SETTINGS['enable_attachment_encryption']) && $SETTINGS['enable_attachment_encryption'] === "1" && isset($filename_status) && ($filename_status === "clear" || $filename_status === "0")) {
1734
            // File needs to be encrypted
1735
            if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
1736
                // Make a copy of file
1737
                if (!copy(
1738
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1739
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1740
                )) {
1741
                    exit;
1742
                } else {
1743
                    // Do a bck
1744
                    copy(
1745
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1746
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1747
                    );
1748
                }
1749
1750
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework);
1751
1752
                // Now encrypt the file with saltkey
1753
                $err = '';
1754
                try {
1755
                    \Defuse\Crypto\File::encryptFile(
1756
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1757
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1758
                        \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1759
                    );
1760
                } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1761
                    $err = "An attack! Either the wrong key was loaded, or the ciphertext has changed since it was created either corrupted in the database or intentionally modified by someone trying to carry out an attack.";
1762
                } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1763
                    $err = $ex;
1764
                } catch (Defuse\Crypto\Exception\IOException $ex) {
1765
                    $err = $ex;
1766
                }
1767
                if (empty($err) === false) {
1768
                    echo $err;
1769
                }
1770
1771
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1772
1773
                // update table
1774
                DB::update(
1775
                    prefix_table('files'),
1776
                    array(
1777
                        'status' => 'encrypted'
1778
                        ),
1779
                    "id = %i",
1780
                    $fileInfo['id']
1781
                );
1782
            }
1783
        } elseif (isset($SETTINGS['enable_attachment_encryption']) && $SETTINGS['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1784
            // file needs to be decrypted
1785
            if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
@@ 1785-1832 (lines=48) @@
1782
            }
1783
        } elseif (isset($SETTINGS['enable_attachment_encryption']) && $SETTINGS['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1784
            // file needs to be decrypted
1785
            if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
1786
                // make a copy of file
1787
                if (!copy(
1788
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1789
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1790
                )) {
1791
                    exit;
1792
                } else {
1793
                    // do a bck
1794
                    copy(
1795
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1796
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1797
                    );
1798
                }
1799
1800
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework);
1801
1802
                // Now encrypt the file with saltkey
1803
                $err = '';
1804
                try {
1805
                    \Defuse\Crypto\File::decryptFile(
1806
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1807
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1808
                        \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1809
                    );
1810
                } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1811
                    $err = "An attack! Either the wrong key was loaded, or the ciphertext has changed since it was created either corrupted in the database or intentionally modified by someone trying to carry out an attack.";
1812
                } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1813
                    $err = $ex;
1814
                } catch (Defuse\Crypto\Exception\IOException $ex) {
1815
                    $err = $ex;
1816
                }
1817
                if (empty($err) === false) {
1818
                    echo $err;
1819
                }
1820
1821
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1822
1823
                // update table
1824
                DB::update(
1825
                    prefix_table('files'),
1826
                    array(
1827
                        'status' => 'clear'
1828
                        ),
1829
                    "id = %i",
1830
                    $fileInfo['id']
1831
                );
1832
            }
1833
        }
1834
    }
1835