Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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