Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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