Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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