Esempio n. 1
0
function ftpupload($source, $attach)
{
    global $authkey, $ftp;
    $ftp['pwd'] = isset($ftp['pwd']) ? $ftp['pwd'] : FALSE;
    $dest = $attach['attachment'];
    if ($ftp['on'] && (!$ftp['allowedexts'] && !$ftp['disallowedexts'] || $ftp['allowedexts'] && in_array($attach['ext'], explode("\n", strtolower($ftp['allowedexts']))) || $ftp['disallowedexts'] && !in_array($attach['ext'], explode("\n", strtolower($ftp['disallowedexts'])))) && (!$ftp['minsize'] || $attach['size'] >= $ftp['minsize'] * 1024)) {
        require_once DISCUZ_ROOT . './include/ftp.func.php';
        if (!$ftp['connid']) {
            if (!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) {
                if ($ftp['mirror'] == 1) {
                    ftpupload_error($source, $attach);
                } else {
                    return 0;
                }
            }
            $ftp['pwd'] = FALSE;
        }
        $tmp = explode('/', $dest);
        if (count($tmp) > 1) {
            if (!$ftp['pwd'] && !dftp_chdir($ftp['connid'], $tmp[0])) {
                if (!dftp_mkdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Mkdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    if ($ftp['mirror'] == 1) {
                        ftpupload_error($source, $attach);
                    } else {
                        return 0;
                    }
                }
                if (!function_exists('ftp_chmod') || !dftp_chmod($ftp['connid'], 0777, $tmp[0])) {
                    dftp_site($ftp['connid'], "'CHMOD 0777 {$tmp['0']}'");
                }
                if (!dftp_chdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Chdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    if ($ftp['mirror'] == 1) {
                        ftpupload_error($source, $attach);
                    } else {
                        return 0;
                    }
                }
                dftp_put($ftp['connid'], 'index.htm', $GLOBALS['attachdir'] . '/index.htm', FTP_BINARY);
            }
            $dest = $tmp[1];
            $ftp['pwd'] = TRUE;
        }
        if (dftp_put($ftp['connid'], $dest, $source, FTP_BINARY)) {
            if ($attach['thumb']) {
                if (dftp_put($ftp['connid'], $dest . '.thumb.jpg', $source . '.thumb.jpg', FTP_BINARY)) {
                    if ($ftp['mirror'] != 2) {
                        @unlink($source);
                        @unlink($source . '.thumb.jpg');
                    }
                    return 1;
                } else {
                    dftp_delete($ftp['connid'], $dest);
                }
            } else {
                if ($ftp['mirror'] != 2) {
                    @unlink($source);
                }
                return 1;
            }
        }
        errorlog('FTP', "Upload '{$source}' error.", 0);
        $ftp['mirror'] == 1 && ftpupload_error($source, $attach);
    }
    return 0;
}
Esempio n. 2
0
function ftpupload($source, $dest, $havethumb = 0)
{
    global $authkey, $ftp;
    if ($ftp['on']) {
        require_once DISCUZ_ROOT . './include/ftp.func.php';
        if (!$ftp['connid']) {
            if (!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) {
                return 0;
            }
            $ftp['pwd'] = FALSE;
        }
        $tmp = explode('/', $dest);
        if (count($tmp) > 1) {
            if (!$ftp['pwd'] && !dftp_chdir($ftp['connid'], $tmp[0])) {
                if (!dftp_mkdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Mkdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    return 0;
                }
                if (!function_exists('ftp_chmod') || !dftp_chmod($ftp['connid'], 0777, $tmp[0])) {
                    dftp_site($ftp['connid'], "'CHMOD 0777 {$tmp['0']}'");
                }
                if (!dftp_chdir($ftp['connid'], $tmp[0])) {
                    errorlog('FTP', "Chdir '{$ftp['attachdir']}/{$tmp['0']}' error.", 0);
                    return 0;
                }
                dftp_put($ftp['connid'], 'index.htm', $GLOBALS['attachdir'] . '/index.htm', FTP_BINARY);
            }
            $dest = $tmp[1];
            $ftp['pwd'] = TRUE;
        }
        if (dftp_put($ftp['connid'], $dest, $source, FTP_BINARY)) {
            if ($havethumb) {
                if (dftp_put($ftp['connid'], $dest . '.thumb.jpg', $source . '.thumb.jpg', FTP_BINARY)) {
                    @unlink($source);
                    @unlink($source . '.thumb.jpg');
                    return 1;
                } else {
                    dftp_delete($ftp['connid'], $dest);
                }
            } else {
                @unlink($source);
                return 1;
            }
        }
        errorlog('FTP', "Upload '{$source}' error.", 0);
    }
    return 0;
}
         case '-4':
             $alertmsg = $lang['settings_attach_remote_ftpoff'];
             break;
         default:
             $alertmsg = '';
     }
 }
 if (!$alertmsg) {
     if (!dftp_mkdir($ftp_conn_id, $testdir)) {
         $alertmsg = $lang['settings_attach_remote_mderr'];
     } else {
         if (!(function_exists('ftp_chmod') && dftp_chmod($ftp_conn_id, 0777, $testdir)) && !dftp_site($ftp_conn_id, "'CHMOD 0777 {$testdir}'") && !@ftp_exec($ftp_conn_id, "SITE CHMOD 0777 {$testdir}")) {
             $alertmsg = $lang['settings_attach_remote_chmoderr'] . '\\n';
         }
         $testfile = $testdir . '/' . $testfile;
         if (!dftp_put($ftp_conn_id, $testfile, DISCUZ_ROOT . './robots.txt', FTP_BINARY)) {
             $alertmsg .= $lang['settings_attach_remote_uperr'];
             dftp_delete($ftp_conn_id, $testfile);
             dftp_delete($ftp_conn_id, $testfile . '.uploading');
             dftp_delete($ftp_conn_id, $testfile . '.abort');
             dftp_rmdir($ftp_conn_id, $testdir);
         } else {
             if (!@readfile($settingsnew['ftp']['attachurl'] . '/' . $testfile)) {
                 $alertmsg .= $lang['settings_attach_remote_geterr'];
                 dftp_delete($ftp_conn_id, $testfile);
                 dftp_rmdir($ftp_conn_id, $testdir);
             } else {
                 if (!dftp_delete($ftp_conn_id, $testfile)) {
                     $alertmsg .= $lang['settings_attach_remote_delerr'];
                 } else {
                     dftp_rmdir($ftp_conn_id, $testdir);
Esempio n. 4
0
 } else {
     if (!($fp = fopen($_G['setting']['upgradeurl'] . $release . '/package/' . $script . '.txt', 'rb'))) {
         exit(false);
     }
     $data = '';
     while (($c = fgetc($fp)) !== false) {
         $data .= $c;
     }
     fclose($fp);
     if (file_exists(DISCUZ_ROOT . './' . $script) && !file_exists($backuppath . '/' . $script . '.txt')) {
         copy(DISCUZ_ROOT . './' . $script, $backuppath . '/' . $script . '.txt');
     }
     $fp = fopen($packagepath . '/' . $script . '.txt', 'wb');
     fwrite($fp, $data);
     fclose($fp);
     dftp_put($ftpid, './' . $script, $packagepath . '/' . $script . '.txt', FTP_BINARY);
     if (!empty($mod)) {
         dftp_chmod($ftpid, $mod, '/' . $script);
     }
     $md5 = md5_file(DISCUZ_ROOT . './' . $script);
     $discuzfiles = file(DISCUZ_ROOT . './data/discuzfiles.md5');
     $md5datanew = array();
     foreach ($discuzfiles as $line) {
         $md5file = trim(substr($line, 34));
         $md5str = trim(substr($line, 0, 32));
         $md5datanew[$md5file] = $md5str;
     }
     $md5datanew['./' . $script] = $md5;
     $fp = fopen(DISCUZ_ROOT . './data/discuzfiles.md5', 'wb');
     foreach ($md5datanew as $key => $val) {
         fwrite($fp, $val . ' *' . $key . "\r\n");