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

Размер файла: 9.84Kb
  1. <?php
  2. error_reporting(7);
  3. require_once('nast.php');
  4. require_once('shapka.php');
  5. require_once('func.php');
  6. require_once('function.php');
  7. require_once('win_to_utf.php');
  8.  
  9. include('db.php');
  10. print $beginpage;
  11. include('rekl.php');
  12. $ip=mysql_escape_string($REMOTE_ADDR);
  13. $Host=preg_replace('/:\d+/s','',getenv('HTTP_HOST'));
  14. $user=mysql_escape_string($HTTP_USER_AGENT);
  15. $file=mysql_escape_string($file);
  16. while($file[0]=='/')
  17. $sd=substr($file,1,strlen($file));
  18. $dirname=dirname($file);
  19. $basename=basename($file);
  20. $filesize=@filesize($file);
  21. $result=mysql_query("SELECT * from `file` WHERE `sd`='$dirname' and `file`='$basename' limit 1");
  22. if($filesize>1024)
  23. $filesize=round($filesize/1024,2).' кб';
  24. else
  25. $filesize=$filesize.' бт';
  26. if(!strstr($dirname,"..") and file_exists($file) and filesize($file)<=$maxfile)
  27. {if(!mysql_num_rows($result))
  28. {
  29. mysql_query("INSERT into `file` VALUES(0,'$dirname','$basename','0','".time()."','".time()."')");
  30. $infof['rat']=0;
  31. $infof['ldate']=time();
  32. }
  33. else
  34. {
  35. $infof=mysql_fetch_array($result);
  36. }
  37. $papka=explode('/',$dirname);
  38. $papka[0]='';
  39. $papkaname=transdir(join('/',$papka));
  40. $filename=translit($basename);
  41. print "Папка: $papkaname<br/>";
  42. print "Файл: $filename<br/>";
  43. $infop=mysql_fetch_row(mysql_query("SELECT MAX(`time`) FROM `send` WHERE `ip`='$ip' or `user`='$user'"));
  44. if($infop[0]>time()-60)
  45. print "Ошибка!Вы не можете отправлять файлы ччаще, чем 1 раз в 1 минуту.Пожалуйста повторите попытку позднее<br/>";
  46. else
  47. {
  48. class Mail
  49. {
  50. var $sendto = array();
  51. var $acc = array();
  52. var $abcc = array();
  53. var $aattach = array();
  54. var $xheaders = array();
  55. var $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
  56. var $charset = "utf-8";
  57. var $ctencoding = "7bit";
  58. var $receipt = 0;
  59.  
  60. function Mail()
  61. {
  62. $this->autoCheck( true );
  63. $this->boundary= "--" . md5( uniqid("myboundary") );
  64. }
  65.  
  66.  
  67. function autoCheck( $bool )
  68. {
  69. if( $bool )
  70. $this->checkAddress = true;
  71. else
  72. $this->checkAddress = false;
  73. }
  74.  
  75. function Subject( $subject )
  76. {
  77. $this->xheaders['Subject'] = strtr( $subject, "\r\n" , " " );
  78. }
  79.  
  80.  
  81. function From( $from )
  82. {
  83.  
  84. if( ! is_string($from) ) {
  85. echo "Class Mail: error, From is not a string";
  86. exit;
  87. }
  88. $this->xheaders['From'] = $from;
  89. }
  90.  
  91. function ReplyTo( $address )
  92. {
  93.  
  94. if( ! is_string($address) )
  95. return false;
  96. $this->xheaders["Reply-To"] = $address;
  97. }
  98.  
  99. function Receipt()
  100. {
  101. $this->receipt = 1;
  102. }
  103.  
  104. function To( $to )
  105. {
  106.  
  107. // TODO : test validit? sur to
  108. if( is_array( $to ) )
  109. $this->sendto= $to;
  110. else
  111. $this->sendto[] = $to;
  112.  
  113. if( $this->checkAddress == true )
  114. $this->CheckAdresses( $this->sendto );
  115.  
  116. }
  117.  
  118.  
  119. function Cc( $cc )
  120. {
  121. if( is_array($cc) )
  122. $this->acc= $cc;
  123. else
  124. $this->acc[]= $cc;
  125. if( $this->checkAddress == true )
  126. $this->CheckAdresses( $this->acc );
  127. }
  128.  
  129. function Bcc( $bcc )
  130. {
  131. if( is_array($bcc) ) {
  132. $this->abcc = $bcc;
  133. } else {
  134. $this->abcc[]= $bcc;
  135. }
  136.  
  137. if( $this->checkAddress == true )
  138. $this->CheckAdresses( $this->abcc );
  139. }
  140.  
  141.  
  142. function Body( $body, $charset="" )
  143. {
  144. $this->body = $body;
  145. if( $charset != "" ) {
  146. $this->charset = strtolower($charset);
  147. if( $this->charset != "us-ascii" )
  148. $this->ctencoding = "8bit";
  149. }
  150. }
  151.  
  152.  
  153. function Organization( $org )
  154. {
  155. if( trim( $org != "" ) )
  156. $this->xheaders['Organization'] = $org;
  157. }
  158.  
  159.  
  160. function Priority( $priority )
  161. {
  162. if( ! intval( $priority ) )
  163. return false;
  164. if( ! isset( $this->priorities[$priority-1]) )
  165. return false;
  166.  
  167. $this->xheaders["X-Priority"] = $this->priorities[$priority-1];
  168. return true;
  169. }
  170.  
  171. function Attach( $filename, $filetype = "", $disposition = "inline" )
  172. {
  173. if( $filetype == "" )
  174. $filetype = "application/x-unknown-content-type";
  175. $this->aattach[] = $filename;
  176. $this->actype[] = $filetype;
  177. $this->adispo[] = $disposition;
  178. }
  179.  
  180. function BuildMail()
  181. {
  182.  
  183.  
  184. $this->headers = "";
  185.  
  186. if( count($this->acc) > 0 )
  187. $this->xheaders['CC'] = implode( ", ", $this->acc );
  188. if( count($this->abcc) > 0 )
  189. $this->xheaders['BCC'] = implode( ", ", $this->abcc );
  190.  
  191. if( $this->receipt ) {
  192. if( isset($this->xheaders["Reply-To"] ) )
  193. $this->xheaders["Disposition-Notification-To"] = $this->xheaders["Reply-To"];
  194. else
  195. $this->xheaders["Disposition-Notification-To"] = $this->xheaders['From'];
  196. }
  197. if( $this->charset != "" ) {
  198. $this->xheaders["Mime-Version"] = "1.0";
  199. $this->xheaders["Content-Type"] = "text/plain; charset=$this->charset";
  200. $this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
  201. }
  202.  
  203. $this->xheaders["X-Mailer"] = "Php/libMailv1.3";
  204. if( count( $this->aattach ) > 0 ) {
  205. $this->_build_attachement();
  206. } else {
  207. $this->fullBody = $this->body;
  208. }
  209.  
  210. reset($this->xheaders);
  211. while( list( $hdr,$value ) = each( $this->xheaders ) ) {
  212. if( $hdr != "Subject" )
  213. $this->headers .= "$hdr: $value\n";
  214. }
  215.  
  216. }
  217.  
  218. function Send()
  219. {
  220. $this->BuildMail();
  221. $this->strTo = implode( ", ", $this->sendto );
  222. $res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers );
  223.  
  224. }
  225.  
  226. function Get()
  227. {
  228. $this->BuildMail();
  229. $mail = "To: " . $this->strTo . "\n";
  230. $mail .= $this->headers . "\n";
  231. $mail .= $this->fullBody;
  232. return $mail;
  233. }
  234. function ValidEmail($address)
  235. {
  236. if( ereg( ".*<(.+)>", $address, $regs ) ) {
  237. $address = $regs[1];
  238. }
  239. if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int|ru|ua|eu)\$",$address) )
  240. return true;
  241. else
  242. return false;
  243. }
  244.  
  245.  
  246. function CheckAdresses( $aad )
  247. {
  248. for($i=0;$i< count( $aad); $i++ ) {
  249. if( ! $this->ValidEmail( $aad[$i]) ) {
  250. echo "Class Mail, method Mail : invalid address $aad[$i]";
  251. exit;
  252. }
  253. }
  254. }
  255.  
  256. function _build_attachement()
  257. {
  258.  
  259. $this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";
  260.  
  261. $this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
  262. $this->fullBody .= "Content-Type: text/plain; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n" . $this->body ."\n";
  263. $sep= chr(13) . chr(10);
  264. $ata= array();
  265. $k=0;
  266. for( $i=0; $i < count( $this->aattach); $i++ ) {
  267. $filename = $this->aattach[$i];
  268. $basename = basename($filename);
  269. $ctype = $this->actype[$i]; // content-type
  270. $disposition = $this->adispo[$i];
  271. if( ! file_exists( $filename) ) {
  272. echo "Class Mail, method attach : file $filename can't be found"; exit;
  273. }
  274. $subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n filename=\"$basename\"\n";
  275. $ata[$k++] = $subhdr;
  276.  
  277. $linesz= filesize( $filename)+1;
  278. $fp= fopen( $filename, 'r' );
  279. $ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
  280. fclose($fp);
  281. }
  282. $this->fullBody .= implode($sep, $ata);
  283. }
  284.  
  285.  
  286. } //class mail
  287. if(!$act)
  288. {
  289. if($str=='wml')
  290. {
  291. $r=rand(1,1000);
  292. echo "email:<br/></small>
  293. <input name=\"mail$r\" type=\"text\" title=\"\" value=\"\" maxlength=\"15\"/><br/>
  294. <small>Комментарии:<br/></small>
  295. <input name=\"komm$r\" type=\"text\" title=\"\" value=\"\" maxlength=\"150\"/><br/>
  296. <anchor title=\"go\">Отправить<go href=\"mail.php?act=nar&amp;str=$str&amp;file=$file\" method=\"post\">
  297. <postfield name=\"mail\" value=\"$(mail$r)\"/>
  298. <postfield name=\"komm\" value=\"$(komm$r)\"/>
  299. <postfield name=\"all\" value=\"$(all)\"/>";
  300. echo "</go></anchor><br/><small>";
  301. }
  302. else
  303. {
  304. print"
  305. <form action=\"mail.php?act=nar&amp;str=$str&amp;file=$file\" method=\"post\">
  306. email:<br/>
  307. <input name=\"mail\" maxlength=\"450\" value=\"\"/><br/>
  308. Комментарии:<br/>
  309. <input name=\"komm\" maxlength=\"450\" value=\"\"/><br/>
  310. <input type=\"submit\" name=\"a\" value=\"отправить\"/>
  311. </form>";
  312. }
  313. }
  314. else
  315. {
  316. $mail=mysql_escape_string($mail);
  317. $komm=mysql_escape_string($komm);
  318. $err='';
  319. if(0==preg_match("/^[0-9a-z\-._]+@[0-9a-z_\-.]+\.[a-z]{2,3}$/si", $mail))
  320. $err.='Ошибка!Введите адрес сайта ввиде login@server.com<br/>';
  321. if($err)
  322. print $err;
  323. else
  324. {
  325. if(r($file)=="txt" || strpos($name,".dat"))$o="text/plain";
  326. if(r($file)=="gif")$o="image/gif";
  327. if(r($file)=="jpg" || r($file)=="jpeg")$o="image/jpeg";
  328. if(r($file)=="png")$o="image/png";
  329. if(r($file)=="zip")$o="archive/zip";
  330. if(r($file)=="rar")$o="archive/rar";
  331. if(r($file)=="mid")$o="media/midi";
  332. if(r($file)=="mmf")$o="media/mmf";
  333. if(r($file)=="jar")$o="application/java-archive";
  334. if(r($file)=="jad")$o="archive/jar";
  335. if(r($file)=="thm")$o="archive/vnd.eri";
  336. if(r($file)=="nth")$o="archive/vnh.nth";
  337. if(r($file)=="3gp")$o="video/3gpp";
  338. if(r($file)=="avi")$o="video/avi";
  339. if(r($file)=="mp3")$o="media/mp3";
  340. if(r($file)=="sdt")$o="application/vnd.siemens-mp.theme";
  341. if(r($file)=="scs")$o="application/vnd.siemens-mp.skin";
  342. if(r($file)=="sis")$o="application/vnd.symbian.install";
  343. $subj="Vam fajl ot $Host";
  344. $mess='Данный файл был отослан вам посетителем сайта '.$Host.$komm;
  345. //$mess=utf_to_win($mess);
  346. //$mess=convert_cyr_string($mess, "w","k");
  347. $m=new Mail;
  348. $m->From("files@$Host");
  349. $m->To("$mail");
  350. $m->Subject("$subj");
  351. $m->Body($mess);
  352. $m->Priority(4);
  353. $m->Attach(@realpath($file),$o);
  354. $m->Send();
  355. print 'Ваше сообщение успешно отправлено<br/>';
  356. mysql_query("INSERT into `send` VALUES('0','$mail','".time()."','$ip','$user')");
  357. }
  358. }
  359. }
  360. }
  361. else
  362. {
  363. print 'Ошибка!Неверно указан файл<br/>';
  364. }
  365. $t=explode('/',dirname($file));
  366. $t[0]='';
  367. //unset($t[0]);
  368. print $razd."<a href=\"sd.php?sd=".substr(join('/',$t),1,150)."&amp;str=$str\">Вернуться в папку /".transdir($t[count($t)-1])."</a><br/>";
  369. print '&gt;<a href="index.php?str='.$str.'">Выбрать раздел</a><br/>';
  370. print $endpage;
  371. ?>