Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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