Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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