Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

@@ 1730-1777 (lines=48) @@
1727
1728
    if (isset($SETTINGS['enable_attachment_encryption']) && $SETTINGS['enable_attachment_encryption'] === "1" && isset($filename_status) && ($filename_status === "clear" || $filename_status === "0")) {
1729
        // file needs to be encrypted
1730
        if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
1731
            // make a copy of file
1732
            if (!copy(
1733
                $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1734
                $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1735
            )) {
1736
                exit;
1737
            } else {
1738
                // do a bck
1739
                copy(
1740
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1741
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1742
                );
1743
            }
1744
1745
            unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework);
1746
1747
            // Now encrypt the file with saltkey
1748
            $err = '';
1749
            try {
1750
                \Defuse\Crypto\File::encryptFile(
1751
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1752
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1753
                    \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1754
                );
1755
            } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1756
                $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.";
1757
            } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1758
                $err = $ex;
1759
            } catch (Defuse\Crypto\Exception\IOException $ex) {
1760
                $err = $ex;
1761
            }
1762
            if (empty($err) === false) {
1763
                echo $err;
1764
            }
1765
1766
            unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1767
1768
            // update table
1769
            DB::update(
1770
                prefix_table('files'),
1771
                array(
1772
                    'status' => 'encrypted'
1773
                    ),
1774
                "id=%i",
1775
                substr($_POST['uri'], 1)
1776
            );
1777
        }
1778
    } elseif (isset($SETTINGS['enable_attachment_encryption']) && $SETTINGS['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1779
        // file needs to be decrypted
1780
        if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
@@ 1780-1827 (lines=48) @@
1777
        }
1778
    } elseif (isset($SETTINGS['enable_attachment_encryption']) && $SETTINGS['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1779
        // file needs to be decrypted
1780
        if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
1781
            // make a copy of file
1782
            if (!copy(
1783
                $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1784
                $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1785
            )) {
1786
                exit;
1787
            } else {
1788
                // do a bck
1789
                copy(
1790
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1791
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1792
                );
1793
            }
1794
1795
            unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework);
1796
1797
            // Now encrypt the file with saltkey
1798
            $err = '';
1799
            try {
1800
                \Defuse\Crypto\File::decryptFile(
1801
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1802
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1803
                    \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1804
                );
1805
            } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1806
                $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.";
1807
            } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1808
                $err = $ex;
1809
            } catch (Defuse\Crypto\Exception\IOException $ex) {
1810
                $err = $ex;
1811
            }
1812
            if (empty($err) === false) {
1813
                echo $err;
1814
            }
1815
1816
            unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1817
1818
            // update table
1819
            DB::update(
1820
                prefix_table('files'),
1821
                array(
1822
                    'status' => 'clear'
1823
                    ),
1824
                "id=%i",
1825
                substr($_POST['uri'], 1)
1826
            );
1827
        }
1828
    }
1829
}
1830