Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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