function clean_dir($dir, $checktime = 0) { $handle = @opendir($dir); if (!is_resource($handle)) { return 0; } echo '*** ' . $dir . "\n"; $count = 0; while (($file = readdir($handle)) !== false) { if ($file[0] == '.') { continue; } // hidden files if ((($p = strpos($file, '.')) !== false or $file == 'RCS' or $file == 'CVS') and is_dir($dir . '/' . $file)) { continue; } if (is_dir($dir . '/' . $file)) { $count += clean_dir($dir . '/' . $file, $checktime); continue; } $mtime = filemtime($dir . '/' . $file); #print $dir . '/' . $file . ' ' . $mtime . "\n"; if ($mtime < $checktime) { $count++; #print $file . ' ' . "\n"; unlink($dir . '/' . $file); } } closedir($handle); return $count; // return the number of deleted files }
function clean_dir($path) { if (!is_dir($path)) { if (is_file($path)) { unlink($path); } return; } $p = opendir($path); while ($f = readdir($p)) { if ($f == "." || $f == "..") { continue; } clean_dir($path . $f); } @rmdir($path); return; }
} //提取insert preg_match_all("/INSERT INTO .*\\(.*\\)\\;/iUs", $get_sql_data, $iarr); $iarr = $iarr[0]; //插入数据 foreach ($iarr as $c) { @mysql_query($c); } //插入管理员信息 $admin_pwd = md5('wk' . $admin_pwd . 'cms'); $admin_sql = "INSERT INTO `dami_admin` (`id`, `username`, `password`, `lastlogintime`, `lastloginip`, `status`, `is_client`) VALUES (1, '{$admin_name}', '{$admin_pwd}', 1435742234, '127.0.0.1', 1, 0);"; @mysql_query($admin_sql); @mysql_close($conn); //清理缓存文件 clean_dir('../Admin/Runtime/'); clean_dir('../Web/Runtime/'); $fp = fopen($lock_file, "w") or die("<script>alert('写入失败,请检查目录" . dirname(dirname(__FILE__)) . "是否可写入!');history.go(-1);</script>"); fwrite($fp, '已安装'); fclose($fp); include './templates/step-4.html'; exit; } else { if ($step == 10) { header("Pragma:no-cache\r\n"); header("Cache-Control:no-cache\r\n"); header("Expires:0\r\n"); if ($dbhost == '' || $dbuser == '') { exit; } $conn = @mysql_connect($dbhost, $dbuser, $dbpwd); if ($conn) {
function clean_dir($path, $exc = array()) { $path = rtrim($path, '/') . '/'; $handle = opendir($path); for ($i = 0; false !== ($file = readdir($handle)); $i++) { if ($file != "." and $file != "..") { $fullpath = $path . $file; if (is_dir($fullpath)) { clean_dir($fullpath); rmdir($fullpath); } elseif (!in_array($file, $exc)) { unlink($fullpath); } } } closedir($handle); }
public function sendemail() { $this->config->load('oinvoices', TRUE); $this->load->library('email'); if (!empty($_POST['message'])) { $message = $this->input->post('message'); } else { $message = $this->lang->line('email_message_text'); } $emailTo = $this->input->post('email'); $this->email->clear(true); $this->email->from($this->config->item('system_email', 'oinvoices'), $this->config->item('site_title', 'oinvoices')); $this->email->to($emailTo); $this->email->cc($this->input->post('cc')); $filepath = $this->getpdf($this->input->post('invoiceId'), FALSE); $this->email->attach($filepath); $this->email->subject($this->input->post('subject')); $this->email->message($message); if ($this->email->send()) { $data['message'] = "Email Send Successfully"; $this->session->set_flashdata('message', $data); clean_dir($filepath); redirect('invoice'); return TRUE; } else { $this->set_error('Email Sending unsuccessful'); return FALSE; } }
function ftp_get_files_in_dir($opts, $pipe, $cmd = __FUNCTION__) { # set prefix $prefix = 'ftp'; # merge opts $opts = merge_opts($opts, $pipe, 'dir'); # get execute opt $execute = get_opt_config_value($prefix, $opts, 'execute', true); if (!check_opt_set_type($cmd, $execute, 'execute', 'boolean')) { return false; } # check if we should execute or not if (!$execute) { return true; } # get dir opt $dir = get_opt($prefix, $opts, 'dir'); if (!check_opt_set_type($cmd, $dir, 'dir', 'string')) { return false; } # get local dir opt $local_dir = get_opt($prefix, $opts, 'local_dir', $dir); if (!check_opt_set_type($cmd, $local_dir, 'local_dir', 'string')) { return false; } # setup connection $conn = ftp_get_conn($opts, $cmd); if (!$conn) { return false; } # clean and make dir if (!clean_dir($local_dir, $opts, $cmd)) { return false; } if (!make_dir($local_dir, $opts, $cmd)) { return false; } $opts['make_dir'] = false; # get list of files from remote server $files = ftp_scandir($opts, false, $cmd); if (!$files) { return false; } # build list of files $file_list = array(); foreach ($files as $file_name) { $remote_file = "{$dir}/{$file_name}"; $local_file = "{$local_dir}/{$file_name}"; $file_list[] = array($remote_file, $local_file); } $opts['files'] = $file_list; # get all the files return ftp_get_files($opts, null, $cmd); }
function dump_pcap($fname, $force = false) { $hdr = null; $path_parts = pathinfo($fname); $dir = preg_replace('#.pcap$#i', '', $path_parts['basename']); if (!is_dir('./' . $dir)) { mkdir('./' . $dir); } $ret = ''; $fs = filesize($fname); if (file_exists($dir . '/' . $fs . ".htm") && !$force) { $ret = "Previously parsed<br/>" . file_get_contents($dir . '/' . $fs . ".htm"); return $ret; } clean_dir($dir); $ret = $fname . "<br/>" . get_now() . "<br/><br/>"; if (valid_pcap($fname)) { $cnt = 0; $hdr = new pcap_hdr_s(); $hdr->records = array(); $hdr->size = $fs; $b = file_get_contents($fname, NULL, NULL, 0, 24); $lng = byte_array_to_long($b, 0); $hdr->magic_number = $lng; $hdr->version_major = byte_array_to_int($b, 4); $hdr->version_minor = byte_array_to_int($b, 6); $hdr->thiszone = byte_array_to_long($b, 8); $hdr->sigfigs = byte_array_to_long($b, 12); $hdr->snaplen = byte_array_to_long($b, 16); $hdr->network = byte_array_to_long($b, 20); $offset = 24; if ($hdr->network == 1) { // link type was expected. continue while ($offset + 54 < $hdr->size) { $off = $offset; $cnt++; $pr = new pcap_record(); $b = file_get_contents($fname, NULL, NULL, $offset, 16); $pr->ts_sec = byte_array_to_long($b, 0); $pr->ts_usec = byte_array_to_long($b, 4); $pr->incl_len = byte_array_to_long($b, 8); $pr->orig_len = byte_array_to_long($b, 12); $off += 16; if ($pr->incl_len < 0 || $pr->orig_len < 0) { $ret .= "Error parsing"; break; } else { // ethernet header $pr->eth = parse_ethernet_header($fname, $off); $off += 14; // add size of ethernet packet header // ip header $pr->ip = parse_ip($fname, $off); $off += $pr->ip->hdr_len * 4; // add size of ip packet header if ($pr->ip->proto == 6) { // tcp $pr->tcp = parse_tcp($fname, $off, $pr->ip->src, $pr->ip->dest, $pr->incl_len - (14 + $pr->ip->hdr_len * 4)); $off += $pr->tcp->data_offset * 4; // add size of tcp packet header // data $dend = $pr->incl_len - (14 + $pr->ip->hdr_len * 4 + $pr->tcp->data_offset * 4); if ($dend > 0) { $pr->tcp->data = file_get_contents($fname, NULL, NULL, $off, $dend); if ($pr->tcp->data != "") { $fn = $pr->ip->src_ip . "-" . $pr->tcp->src_port; $fn .= "--" . $pr->ip->dest_ip . "-" . $pr->tcp->dest_port; $fn .= "--" . $pr->tcp->ack; $seq = 0; if (file_exists($dir . '/' . $fn . ".seq")) { $seq = file_get_contents($dir . '/' . $fn . ".seq"); } //$se = chr(($pr->tcp->seq >> 24) & 0xff) . chr(($pr->tcp->seq >> 16) & 0xff) . chr(($pr->tcp->seq >> 8) & 0xff) . chr($pr->tcp->seq & 0xff); if ($pr->tcp->seq > $seq) { // is packet unique? file_put_contents($dir . '/' . $fn . ".seq", $pr->tcp->seq); file_put_contents($dir . '/' . $fn . ".raw", $pr->tcp->data, FILE_APPEND); } } } } elseif ($pr->ip->proto == 17) { // udp } elseif ($pr->ip->proto == 1) { // icmp } } $pr->index = $cnt; $offset += $pr->incl_len + 16; } } else { $ret .= "Unknown network link type<br/>"; } } else { $ret .= "Invalid pcap file<br/>"; } $ret .= parse_streams($fname); file_put_contents($dir . '/' . $fs . ".htm", $ret); return $ret; }