Просмотр файла mail.php

Размер файла: 12.26Kb
  1. <?php
  2. require_once ("../includes/start.php");
  3. require_once ("../includes/functions.php");
  4. require_once ("../includes/header.php");
  5. include_once ("../themes/".$config['themes']."/index.php");
  6.  
  7. include_once("inc/func.inc");
  8. include_once("inc/conf.inc");
  9.  
  10. extract($HTTP_GET_VARS);
  11. extract($HTTP_POST_VARS);
  12.  
  13. $text = file("../local/profil/$log.prof");
  14. if ($text!=""){
  15. $udata = explode(":||:",$text[0]);
  16. $provlog=trim($udata[0]);
  17. $provpar=trim($udata[1]);
  18. $privat=trim($udata[10]);
  19. $uz_mail=trim($udata[4]);}
  20.  
  21. /////////////////////////////удаление временных файлов/////////////////////////////////
  22. $odir = opendir("temp");
  23. while ($files = readdir($odir)){
  24. if (($files!==".")&&($files!=="..")){
  25. $ftime = filectime("temp/$files");
  26. $ttime = time();
  27. if ($ttime >= $ftime+$f_temp*60){
  28. unlink("temp/$files");
  29. }}}
  30. closedir($odir);
  31. ///////////////////////////////////////////////////////////////////////////////////////////
  32. if($f_mail=='on'){
  33. /////////////////////////////
  34. $did=str_replace("../","",$did);
  35. $did=str_replace("./","",$did);
  36. $did=str_replace("..","",$did);
  37. $did=str_replace(".","",$did);
  38. if (is_dir("files$did")==false or is_file("files$did/$fid")==false){
  39. echo "<center><font color=\"red\">FACK!!! =))))</font></center><br /><br />";
  40. echo "</div><div>[<a href='index.php?'>К разделам</a>]<br>";
  41. echo "</div><div>[<a href='../index.php'>На главную</a>]";
  42. include_once"../themes/$config_themes/foot.php";
  43. exit;}
  44. /////////////////////////////
  45.  
  46. echo '</div><div class="b">Отправка файла на E-mail</div><div>';
  47.  
  48. if ($_SESSION['log']!="" && md5($_SESSION['par'])!="" && md5($_SESSION['par'])==$provpar && $_SESSION['log']==$provlog ) {
  49. if($udata[10]>0){
  50. echo'<img src="../images/img/mail.gif" alt=""> <b><a href="../pages/privat.php?'.SID.'"><font color="red">Приватное сообщение! ('.$privat.')</font></a></b><br>';}
  51.  
  52. $Host=preg_replace('/:\d+/s','',getenv('HTTP_HOST'));
  53. $user = $brow;
  54. $file="files$did/$fid";
  55.  
  56. $maxfile=$m_file*1024;
  57.  
  58. while($file[0]=='/')
  59. $sd=substr($file,1,strlen($file));
  60. $dirname=dirname($file);
  61. $basename=basename($file);
  62. $filesize=@filesize($file);
  63.  
  64. if($filesize>1024)
  65. $filesize=round($filesize/1024,2).' Кб';
  66. else
  67. $filesize=$filesize.' бт';
  68. if(!strstr($dirname,"..") and file_exists($file) and filesize($file)<=$maxfile)
  69. {
  70. print "<br/>Папка: $did<br/>";
  71. print "Файл: $fid<br/>";
  72. print "Размер: $filesize<br/>";
  73. class Mail
  74. {
  75. var $sendto = array();
  76. var $acc = array();
  77. var $abcc = array();
  78. var $aattach = array();
  79. var $xheaders = array();
  80. var $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
  81. var $charset = "utf-8";
  82. var $ctencoding = "7bit";
  83. var $receipt = 0;
  84.  
  85. function Mail()
  86. {
  87. $this->autoCheck( true );
  88. $this->boundary= "--" . md5( uniqid("myboundary") );
  89. }
  90.  
  91. function autoCheck( $bool )
  92. {
  93. if( $bool )
  94. $this->checkAddress = true;
  95. else
  96. $this->checkAddress = false;
  97. }
  98.  
  99. function Subject( $subject )
  100. {
  101. $this->xheaders['Subject'] = strtr( $subject, "\r\n" , " " );
  102. }
  103.  
  104. function From( $from )
  105. {
  106. if( ! is_string($from) ) {
  107. echo "Class Mail: error, From is not a string";
  108. exit;
  109. }
  110. $this->xheaders['From'] = $from;
  111. }
  112.  
  113. function ReplyTo( $address )
  114. {
  115. if( ! is_string($address) )
  116. return false;
  117. $this->xheaders["Reply-To"] = $address;
  118. }
  119.  
  120. function Receipt()
  121. {
  122. $this->receipt = 1;
  123. }
  124.  
  125. function To( $to )
  126. {
  127. if( is_array( $to ) )
  128. $this->sendto= $to;
  129. else
  130. $this->sendto[] = $to;
  131.  
  132. if( $this->checkAddress == true )
  133. $this->CheckAdresses( $this->sendto );
  134.  
  135. }
  136.  
  137. function Cc( $cc )
  138. {
  139. if( is_array($cc) )
  140. $this->acc= $cc;
  141. else
  142. $this->acc[]= $cc;
  143. if( $this->checkAddress == true )
  144. $this->CheckAdresses( $this->acc );
  145. }
  146.  
  147. function Bcc( $bcc )
  148. {
  149. if( is_array($bcc) ) {
  150. $this->abcc = $bcc;
  151. } else {
  152. $this->abcc[]= $bcc;
  153. }
  154. if( $this->checkAddress == true )
  155. $this->CheckAdresses( $this->abcc );
  156. }
  157.  
  158. function Body( $body, $charset="" )
  159. {
  160. $this->body = $body;
  161. if( $charset != "" ) {
  162. $this->charset = strtolower($charset);
  163. if( $this->charset != "us-ascii" )
  164. $this->ctencoding = "8bit";
  165. }
  166. }
  167.  
  168. function Organization( $org )
  169. {
  170. if( trim( $org != "" ) )
  171. $this->xheaders['Organization'] = $org;
  172. }
  173.  
  174. function Priority( $priority )
  175. {
  176. if( ! intval( $priority ) )
  177. return false;
  178. if( ! isset( $this->priorities[$priority-1]) )
  179. return false;
  180.  
  181. $this->xheaders["X-Priority"] = $this->priorities[$priority-1];
  182. return true;
  183. }
  184.  
  185. function Attach( $filename, $filetype = "", $disposition = "inline" )
  186. {
  187. if( $filetype == "" )
  188. $filetype = "application/x-unknown-content-type";
  189. $this->aattach[] = $filename;
  190. $this->actype[] = $filetype;
  191. $this->adispo[] = $disposition;
  192. }
  193.  
  194. function BuildMail()
  195. {
  196. $this->headers = "";
  197.  
  198. if( count($this->acc) > 0 )
  199. $this->xheaders['CC'] = implode( ", ", $this->acc );
  200. if( count($this->abcc) > 0 )
  201. $this->xheaders['BCC'] = implode( ", ", $this->abcc );
  202. if( $this->receipt ) {
  203. if( isset($this->xheaders["Reply-To"] ) )
  204. $this->xheaders["Disposition-Notification-To"] = $this->xheaders["Reply-To"];
  205. else
  206. $this->xheaders["Disposition-Notification-To"] = $this->xheaders['From'];
  207. }
  208. if( $this->charset != "" ) {
  209. $this->xheaders["Mime-Version"] = "1.0";
  210. $this->xheaders["Content-Type"] = "text/plain; charset=$this->charset";
  211. $this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
  212. }
  213.  
  214. $this->xheaders["X-Mailer"] = "Php/libMailv1.3";
  215. if( count( $this->aattach ) > 0 ) {
  216. $this->_build_attachement();
  217. } else {
  218. $this->fullBody = $this->body;
  219. }
  220.  
  221. reset($this->xheaders);
  222. while( list( $hdr,$value ) = each( $this->xheaders ) ) {
  223. if( $hdr != "Subject" )
  224. $this->headers .= "$hdr: $value\n";
  225. }
  226. }
  227.  
  228. function Send()
  229. {
  230. $this->BuildMail();
  231. $this->strTo = implode( ", ", $this->sendto );
  232. $res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers );
  233. }
  234.  
  235. function Get()
  236. {
  237. $this->BuildMail();
  238. $mail = "To: " . $this->strTo . "\n";
  239. $mail .= $this->headers . "\n";
  240. $mail .= $this->fullBody;
  241. return $mail;
  242. }
  243.  
  244. function ValidEmail($address)
  245. {
  246. if( ereg( ".*<(.+)>", $address, $regs ) ) {
  247. $address = $regs[1];
  248. }
  249. if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int|ru|ua|eu)\$",$address) )
  250. return true;
  251. else
  252. return false;
  253. }
  254.  
  255. function CheckAdresses( $aad )
  256. {
  257. for($i=0;$i< count( $aad); $i++ ) {
  258. if( ! $this->ValidEmail( $aad[$i]) ) {
  259. echo "Class Mail, method Mail : invalid address $aad[$i]";
  260. exit;
  261. }
  262. }
  263. }
  264.  
  265. function _build_attachement()
  266. {
  267. $this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";
  268.  
  269. $this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
  270. $this->fullBody .= "Content-Type: text/plain; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n" . $this->body ."\n";
  271. $sep= chr(13) . chr(10);
  272. $ata= array();
  273. $k=0;
  274. for( $i=0; $i < count( $this->aattach); $i++ ) {
  275. $filename = $this->aattach[$i];
  276. $basename = basename($filename);
  277. $ctype = $this->actype[$i]; // content-type
  278. $disposition = $this->adispo[$i];
  279. if( ! file_exists( $filename) ) {
  280. echo "Class Mail, method attach : file $filename can't be found"; exit;
  281. }
  282. $subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$basename\"\n";
  283. $ata[$k++] = $subhdr;
  284.  
  285. $linesz= filesize( $filename)+1;
  286. $fp= fopen( $filename, 'r' );
  287. $ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
  288. fclose($fp);
  289. }
  290. $this->fullBody .= implode($sep, $ata);
  291. }
  292. } //class mail
  293.  
  294. if(!$act)
  295. {
  296. print "
  297. <br/><form action=\"mail.php?act=nar&amp;did=$did&fid=$fid&id=$id\" method=\"post\">
  298. E-mail: ";
  299. if ($mail_uz=="off"){
  300. echo $uz_mail.'<br>';
  301. $mail = $uz_mail;
  302. }else{
  303. print "<br/><input name=\"mail\" maxlength=\"25\" value=\"\" size=40 /><br/>";}
  304. print "Комментарий:<br/>
  305. <textarea name=\"komm\" maxlength=\"450\" rows=5 cols=20></textarea><br/>
  306. <input type=\"submit\" name=\"a\" value=\"Отправить\"/>
  307. </form>";
  308.  
  309. }
  310. else
  311. {
  312. $odir = opendir("temp");
  313. while ($filess = readdir($odir)){
  314. if ($filess==$provlog.'.txt'){
  315. echo "<br><font color='red'>Ошибка!!! Вы не можете отправлять файл чаше чем раз в ".$f_temp." минут.</font><br>";
  316.  
  317. echo "<br>[<a href='index.php?did=$did&fid=$fid&act=desc'>К файлу</a>]<br>";
  318. echo "<div>[<a href='index.php?did=$did'>К категории</a>]<br>";
  319. echo "</div><div>[<a href='index.php?'>К разделам</a>]<br>";
  320. echo "</div><div>[<a href='../index.php'>На главную</a>]";
  321.  
  322. include_once"../themes/$config_themes/foot.php";
  323. exit;}
  324. }
  325. if ($mail_uz=="off"){$mail = $uz_mail;}
  326. $err='';
  327. if(0==preg_match("/^[0-9a-z\-._]+@[0-9a-z_\-.]+\.[a-z]{2,3}$/si", $mail))
  328. $err.='<br/><font color="red">Ошибка!Введите адрес e-mail в виде login@server.com</font><br/>';
  329. if($err)
  330. print $err;
  331. else
  332. {
  333. $format=format($fid);
  334. if($format==".txt")$o="text/plain";
  335. if($format=="gif")$o="image/gif";
  336. if($format=="jpg" || $format=="jpeg")$o="image/jpeg";
  337. if($format=="png")$o="image/png";
  338. if($format=="zip")$o="archive/zip";
  339. if($format=="rar")$o="archive/rar";
  340. if($format=="mid")$o="media/midi";
  341. if($format=="mmf")$o="media/mmf";
  342. if($format=="jar")$o="application/java-archive";
  343. if($format=="jad")$o="archive/jar";
  344. if($format=="thm")$o="archive/vnd.eri";
  345. if($format=="nth")$o="archive/vnh.nth";
  346. if($format=="3gp")$o="video/3gpp";
  347. if($format=="avi")$o="video/avi";
  348. if($format=="mp3")$o="media/mp3";
  349. if($format=="sdt")$o="application/vnd.siemens-mp.theme";
  350. if($format=="scs")$o="application/vnd.siemens-mp.skin";
  351. if($format=="sis")$o="application/vnd.symbian.install";
  352. $subj="Вам файл от $provlog с сайта $Host";
  353. $mess='Вы получили это письмо потому что кто-то, возможно Вы, указал этот E-mail в качестве получателя файла отосланого с сайта http://'.$Host.' . Если это было сделано по ошибке, то пожалуйста удалите это сообщение. С уважением Администрация сайта: "'.$Host.'"
  354.  
  355. Комментарий к файлу: '.$komm;
  356.  
  357. $m=new Mail;
  358. $m->From("files@$Host");
  359. $m->To("$mail");
  360. $m->Subject("$subj");
  361. $m->Body($mess);
  362. $m->Priority(3);
  363. $m->Attach(@realpath("$file"),"$o");
  364. $m->Send();
  365. print '<br/><font color="red">Ваше сообщение успешно отправлено</font><br/>';
  366.  
  367. $fp = fopen('temp/'.$provlog.'.txt','w');
  368. fputs($fp,$mail);
  369. fclose($fp);
  370. ///////////////////////запись счетчика отправок/////////////////////////
  371. if (is_file("files$did/$fid")){
  372. $dik=str_replace("/", "", $did);
  373. if (is_file("baze/$dik.baz")){
  374. $fn=file("baze/$dik.baz");
  375. $fp=fopen("baze/$dik.baz","a+");
  376. flock ($fp,LOCK_EX);
  377. ftruncate ($fp,0);
  378. foreach ($fn as $n=>$f){
  379. $data = explode("|",$fn[$n]);
  380. if ($data[0]==$id and $data[11]=="$did/$fid"){$kol=$data[2]+1;
  381. $zap="$data[0]|$data[1]|$kol|$data[3]|$data[4]|$data[5]|$data[6]|$data[7]|$data[8]|$data[9]|$data[10]|$data[11]|\r\n";
  382. fputs($fp,"$zap");}
  383. else{fputs($fp,$fn[$n]);}
  384. fflush ($fp);
  385. }
  386. flock ($fp,LOCK_UN);
  387. fclose($fp);
  388. @chmod("$fp", 0666);
  389. }}
  390. /////////////////////////////////////////////////////////////////////
  391. }
  392. }
  393. }
  394. else
  395. {
  396. print '<br/><font color="red"><b><blink>Ошибка!</blink></b> Неверно указан файл, или его размер превышает лимит!</font><br/>';
  397. }
  398. $t=explode('/',dirname($file));
  399. $t[0]='';
  400. //unset($t[0]);
  401. }else echo "<br/><font color='red'>Этот сервис доступен только зарегестрированным пользователям сайта!!!</font>";
  402. }
  403. echo "<br>[<a href='index.php?did=$did&fid=$fid&act=desc'>К файлу</a>]<br>";
  404. echo "<div>[<a href='index.php?did=$did'>К категории</a>]<br>";
  405. echo "</div><div>[<a href='index.php?'>К разделам</a>]<br>";
  406. echo "</div><div>[<a href='../index.php'>На главную</a>]";
  407.  
  408. include_once"../../themes/$config_themes/foot.php";
  409.  
  410. ?>