Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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