function dunlink($filename, $havethumb = 0, $remote = 0) { global $authkey, $ftp, $attachdir; if ($remote) { 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; } } dftp_delete($ftp['connid'], $filename); $havethumb && dftp_delete($ftp['connid'], $filename . '.thumb.jpg'); } else { @unlink($attachdir . '/' . $filename); $havethumb && @unlink($attachdir . '/' . $filename . '.thumb.jpg'); } }
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; }
@unlink($attach_dir . '/' . $testfile); } $attachsave && @rmdir($attach_dir); } if (!$alertmsg) { require_once './include/ftp.func.php'; if (!empty($settingsnew['ftp']['password'])) { $settings['ftp'] = unserialize($db->result_first("SELECT value FROM {$tablepre}settings WHERE variable='ftp'")); $settings['ftp']['password'] = authcode($settings['ftp']['password'], 'DECODE', md5($authkey)); $pwlen = strlen($settingsnew['ftp']['password']); if ($settingsnew['ftp']['password'][0] == $settings['ftp']['password'][0] && $settingsnew['ftp']['password'][$pwlen - 1] == $settings['ftp']['password'][strlen($settings['ftp']['password']) - 1] && substr($settingsnew['ftp']['password'], 1, $pwlen - 2) == '********') { $settingsnew['ftp']['password'] = $settings['ftp']['password']; } } $ftp['pasv'] = intval($settingsnew['ftp']['pasv']); $ftp_conn_id = dftp_connect($settingsnew['ftp']['host'], $settingsnew['ftp']['username'], $settingsnew['ftp']['password'], $settingsnew['ftp']['attachdir'], $settingsnew['ftp']['port'], $settingsnew['ftp']['ssl'], 1); switch ($ftp_conn_id) { case '-1': $alertmsg = $lang['settings_attach_remote_conerr']; break; case '-2': $alertmsg = $lang['settings_attach_remote_logerr']; break; case '-3': $alertmsg = $lang['settings_attach_remote_pwderr']; break; case '-4': $alertmsg = $lang['settings_attach_remote_ftpoff']; break; default: $alertmsg = '';
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; }
} } elseif ($operation == 'down') { $_G['setting']['upgradeurl'] = str_replace('upgrade.php', '', $_G['setting']['upgradeurl']); $id = intval($id); $file = array(); $lines = file($_G['setting']['upgradeurl'] . $release . '/info.txt'); foreach ($lines as $line) { list($file['script'], $file['type'], $file['chmod'], $file['run']) = explode("\t", trim($line)); $files[] = $file; } $mod = strval($files[$id]['chmod']); $type = $files[$id]['type'] == 1 ? 1 : 0; $run = $files[$id]['run'] == 1 ? 1 : 0; $script = $files[$id]['script']; @(list($ftphost, $ftpport, $ftpuser, $ftppass, $ftppath, $ftpssl) = explode("\t", authcode($cdb_ftp_auth, 'DECODE'))); if (!($ftpid = dftp_connect($ftphost, $ftpuser, $ftppass, $ftppath, $ftpport, $ftpssl))) { exit(false); } else { if (!file_exists($packagepath)) { mkdir($packagepath, 0777); } if (!file_exists($backuppath)) { mkdir($backuppath, 0777); } $packagepath .= '/' . $release; $backuppath .= '/' . $release; if (!file_exists($packagepath)) { mkdir($packagepath, 0777); } if (!file_exists($backuppath)) { mkdir($backuppath, 0777);
function getremotefile($file) { global $authkey, $ftp, $attachdir; @set_time_limit(0); if(!@readfile($ftp['attachurl'].'/'.$file)) { require_once DISCUZ_ROOT.'./include/ftp.func.php'; if(!($ftp['connid'] = dftp_connect($ftp['host'], $ftp['username'], authcode($ftp['password'], 'DECODE', md5($authkey)), $ftp['attachdir'], $ftp['port'], $ftp['ssl']))) { return FALSE; } $tmpfile = @tempnam($attachdir, ''); if(dftp_get($ftp['connid'], $tmpfile, $file, FTP_BINARY)) { @readfile($tmpfile); @unlink($tmpfile); } else { @unlink($tmpfile); return FALSE; } } return TRUE; }
function getremotefile($file) { global $_G; @set_time_limit(0); if (!@readfile($_G['setting']['ftp']['attachurl'] . '/forum/' . $file)) { require_once libfile('function/ftp'); if (!($_G['setting']['ftp']['connid'] = dftp_connect($_G['setting']['ftp']['host'], $_G['setting']['ftp']['username'], authcode($_G['setting']['ftp']['password'], 'DECODE', md5($_G['config']['security']['authkey'])), $_G['setting']['ftp']['attachdir'], $_G['setting']['ftp']['port'], $_G['setting']['ftp']['ssl']))) { return FALSE; } $tmpfile = @tempnam($_G['setting']['attachdir'], ''); if (dftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) { @readfile($tmpfile); @unlink($tmpfile); } else { @unlink($tmpfile); return FALSE; } } return TRUE; }