Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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