示例#1
0
 function import_url_list($url_list, $report_id)
 {
     $report_id = intval($report_id);
     if (!$this->state || $report_id <= 0) {
         return false;
     }
     $query = '';
     foreach ($url_list as $ftp_list_item) {
         list($url, $ftp_client) = $ftp_list_item;
         $domain = trim(extract_domain($url));
         if (strlen($domain)) {
             $query .= ",('" . mysql_real_escape_string($domain) . "')";
         }
     }
     if (strlen($query)) {
         $result = mysql_query('INSERT IGNORE INTO pony_domainlist (url_domain) VALUES ' . substr($query, 1), $this->db_link);
         if (!$result) {
             return false;
         }
     }
     $query_values = '';
     foreach ($url_list as $ftp_list_item) {
         list($url, $ftp_client) = $ftp_list_item;
         $url = trim($url);
         $ftp_client = trim($ftp_client);
         if (!strlen($url) || !strlen($ftp_client)) {
             continue;
         }
         $hash = mixed_sha1($url);
         if (str_begins($url, 'rdp://')) {
             $url_type = 'rdp';
         } elseif (str_begins($url, 'http://') || str_begins($url, 'https://')) {
             $url_type = 'http';
         } elseif (str_begins($url, 'sftp://')) {
             $url_type = 'ssh';
             $url = 'ftp://' . substr($url, strlen('sftp://'));
         } else {
             $url_type = 'ftp';
         }
         if (!strlen($query_values)) {
             $query_values .= 'VALUES';
         }
         $query_values .= sprintf("('%s','%s','%s','%s','%s','%s',IFNULL((SELECT domain_id FROM `pony_domainlist` WHERE url_domain='%s'), '0')),", mysql_real_escape_string($report_id), mysql_real_escape_string($url), mysql_real_escape_string($url_type), mysql_real_escape_string($hash), mysql_real_escape_string($ftp_client), mysql_real_escape_string(mysql_now_date()), mysql_real_escape_string(extract_domain($url)));
     }
     $query_values = substr($query_values, 0, -1);
     if (strlen($query_values)) {
         $query = "INSERT DELAYED IGNORE INTO pony_ftp (report_id, url, url_type, url_hash, ftp_client, import_time, domain_id) " . $query_values;
         $result = mysql_query($query, $this->db_link);
         if (!$result) {
             return false;
         }
     }
     return true;
 }
示例#2
0
文件: misc.php 项目: captincook/Pony
function ftp_force_ssh($ftp, $is_ssh = true)
{
    if (!$is_ssh) {
        return $ftp;
    }
    $ftp = trim($ftp);
    if (!strlen($ftp)) {
        return '';
    }
    if ($is_ssh) {
        $p = strpos($ftp, '://');
        if ($p === false) {
            return "sftp://" . $ftp;
        } else {
            if (str_begins($ftp, 'ftp://')) {
                $ftp = 'sftp://' . substr($ftp, strlen('ftp://'));
            }
            return $ftp;
        }
    }
    return $ftp;
}
 protected function process_conf($value)
 {
     if (!strlen($value)) {
         return;
     }
     $line_start = 'user_pref(';
     $line_end = ');';
     $values = parse_lines($value);
     $conf_values = array();
     foreach ($values as $line) {
         $line = Utf8ToWin(trim($line));
         if (str_begins($line, $line_start) && str_ends($line, $line_end)) {
             $line = stripslashes(substr($line, strlen($line_start), -strlen($line_end)));
             if (strlen($line) < 2) {
                 continue;
             }
             $name_end = strpos($line, '",');
             if ($name_end !== false && $line[0] == '"') {
                 $name = substr($line, 1, $name_end - 1);
                 $value = trim(substr($line, $name_end + 2));
                 if (str_begins($value, '"') && str_ends($value, '"')) {
                     $value = trim(substr($value, 1, -1));
                 }
                 $name = strtolower($name);
                 $conf_values[$name] = $value;
             }
         }
     }
     $accounts = assign($conf_values['mail.accountmanager.accounts']);
     $accounts = explode(',', $accounts);
     if (is_array($accounts) && count($accounts)) {
         foreach ($accounts as $account) {
             $server = assign($conf_values['mail.account.' . $account . '.server']);
             $host = assign($conf_values['mail.server.' . $server . '.hostname']);
             $port = assign($conf_values['mail.server.' . $server . '.port']);
             $user = assign($conf_values['mail.server.' . $server . '.username']);
             $protocol = assign($conf_values['mail.server.' . $server . '.type']);
             $pass = '';
             if ($protocol == 'imap') {
                 if (isset($this->mailboxes['imap://' . $host])) {
                     $pass = $this->mailboxes['imap://' . $host][1];
                 }
             } elseif ($protocol == 'pop3') {
                 if (isset($this->mailboxes['pop3://' . $host])) {
                     $pass = $this->mailboxes['pop3://' . $host][1];
                 }
             }
             if (!strlen($pass)) {
                 if (isset($this->mailboxes['mailbox://' . $host])) {
                     $pass = $this->mailboxes['mailbox://' . $host][1];
                 } else {
                     $pass = '';
                 }
             }
             $identities = assign($conf_values['mail.account.' . $account . '.identities']);
             $identities = explode(',', $identities);
             if (is_array($identities) && count($identities)) {
                 foreach ($identities as $identity) {
                     $email = assign($conf_values['mail.identity.' . $identity . '.useremail']);
                     $smtp_name = assign($conf_values['mail.identity.' . $identity . '.smtpserver']);
                     // find default server
                     if (!strlen($smtp_name)) {
                         $smtp_name = assign($conf_values['mail.smtp.defaultserver']);
                     }
                     if (!strlen($smtp_name)) {
                         $smtp_names = assign($conf_values['mail.smtpservers']);
                         $smtp_names = explode(',', $smtp_names);
                         if (is_array($smtp_names) && count($smtp_names)) {
                             $smtp_name = $smtp_names[0];
                         }
                     }
                     $smtp_host = assign($conf_values['mail.smtpserver.' . $smtp_name . '.hostname']);
                     $smtp_user = assign($conf_values['mail.smtpserver.' . $smtp_name . '.username']);
                     $smtp_port = assign($conf_values['mail.smtpserver.' . $smtp_name . '.port']);
                     if (isset($this->mailboxes['smtp://' . $smtp_host])) {
                         $smtp_pass = $this->mailboxes['smtp://' . $smtp_host][1];
                     } else {
                         $smtp_pass = '';
                     }
                     if (is_array($smtp_pass)) {
                         $smtp_pass = $smtp_pass[1];
                     }
                     // pop3/imap
                     if ($protocol == 'pop3' || $protocol == 'imap') {
                         $this->add_email($email, $protocol, $host, $port, $user, $pass);
                     }
                     $this->add_email($email, 'smtp', $smtp_host, $smtp_port, $smtp_user, $smtp_pass);
                 }
             }
         }
     }
 }