Advertisement
Guest User

Untitled

a guest
Apr 5th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <?php
  2.  
  3. header ('Content-Type: text/plain; charset=utf-8');
  4.  
  5. $q = $_GET['q'];
  6.  
  7. $opts = explode('/',$q);
  8.  
  9. function getmsg($t) {
  10.     $t = preg_replace("/[^a-zA-Z0-9]+/", "", $t);
  11.     return @file_get_contents ("msg/$t");
  12. }
  13.  
  14. function getecho($t) {
  15.     $t = preg_replace("/[^a-z0-9!_.-]+/", "", $t);
  16.     return @file_get_contents ("echo/$t");
  17. }
  18.  
  19. //======================================================
  20.  
  21. function b64c($s,$us) {
  22.     if($us) return base64_encode($s);
  23.     else return rtrim(strtr(base64_encode($s), '+/', '-_'), '=');
  24. }
  25. function b64d($s) {
  26.     //return base64_decode($s);
  27.     return base64_decode(str_pad(strtr($s, '-_', '+/'), strlen($s) % 4, '=', STR_PAD_RIGHT));
  28. }
  29.  
  30. function hsh($s) {
  31.     $s1 = b64c(hash("sha256",$s,true), 0);
  32.     $s1=str_replace("-","A",$s1);
  33.     $s1=str_replace("_","z",$s1);
  34.     return substr($s1,0,20);
  35. }
  36.  
  37. //=============================================
  38.  
  39. if ($opts[1] == 'e') {
  40.     echo getecho($opts[2]);
  41. } # e
  42.  
  43. if ($opts[1] == 'm') {
  44.     echo getmsg($opts[2]);
  45. } # m
  46.  
  47. if ($opts[1] == 'u' and $opts[2] == 'm') {
  48.     for ($x=3;$x<count($opts);$x++) {
  49.         $hash = base64_encode(getmsg($opts[$x]));
  50.         echo "$opts[$x]:$hash\n";
  51.     }
  52. } # um
  53.  
  54. if ($opts[1] == 'u' and $opts[2] == 'e') {
  55.     for ($x=3;$x<count($opts);$x++) {
  56.         echo $opts[$x] . "\n";
  57.         echo getecho($opts[$x]);
  58.     }
  59. } # ue
  60.  
  61. function parsePoints() {
  62.     $arr=[
  63.         ["123456","root"],
  64.         ["78910","point1"]
  65.     ];
  66.     return $arr;
  67. }
  68. function pointSend($msg,$authname) {
  69.     $goodmsg=explode("\n",b64d($msg));
  70.  
  71.     $msgid=hsh($msg);
  72.  
  73.     $echo=$goodmsg[0];
  74.     $receiver=$goodmsg[1];
  75.     $subj=$goodmsg[2];
  76.     $rep=$goodmsg[4];
  77.     $repto="";
  78.     $time=time();
  79.  
  80.     $othermsg="";
  81.     $msgwrite="";
  82.  
  83.     for($i=5;$i<count($goodmsg);$i++) {
  84.         if($i==(count($goodmsg)-1)) {
  85.             $othermsg.=$goodmsg[$i];
  86.         } else {
  87.             $othermsg.=$goodmsg[$i]."\n";
  88.         }
  89.     }
  90.     if(substr($rep,0,7)=="@repto:") {
  91.         $repto=substr($rep,7);
  92.         dbg("|$repto|");
  93.     }
  94.    
  95.     if($repto) {
  96.         $msgwrite.="repto/$repto\n";
  97.     } else {
  98.         $msgwrite.="\n";
  99.         $norep=1;
  100.     }
  101.  
  102.     $msgwrite.="$echo
  103. $time
  104. $authname
  105. anonimous
  106. $receiver
  107. $subj\n\n";
  108.  
  109.     if(!$norep) {
  110.         $msgwrite.=$othermsg;
  111.     } else {
  112.         $msgwrite.=$rep.$othermsg;
  113.     }
  114.  
  115.     $echofile=fopen("echo/".$echo,"a");
  116.     fputs($echofile,$msgid."\n"); fclose($echofile);
  117.     $msgfile=fopen("msg/".$msgid,"w");
  118.     fputs($msgfile,$msgwrite); fclose($msgfile);
  119. }
  120.  
  121. $parr=parsePoints();
  122. $auth=0;
  123. $authname=0;
  124.  
  125. if ($opts[1] == 'u' and $opts[2] == 'point') {
  126.     if ($opts[3] && $opts[4]) {
  127.         $au=$opts[3];
  128.         $ms=$opts[4];
  129.     } elseif($_POST['pauth'] && $_POST['tmsg']) {
  130.         $au=$_POST['pauth'];
  131.         $ms=$_POST['tmsg'];
  132.     } else $error=1;
  133.     if(!$error) {
  134.         for($i=0;$i<count($parr);$i++) {
  135.             if($parr[$i][0]==$au) {
  136.                 $auth=$au;
  137.                 $authname=$parr[$i][1];
  138.                 break;
  139.             }
  140.         }
  141.         if($auth and $authname) {
  142.             pointSend($ms,$authname);
  143.         }
  144.         else {
  145.             die("|no auth|");
  146.         }
  147.     }
  148.     else die('|error: unknown|');
  149. }
  150.  
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement