Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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