Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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