Licenses added & README.md edited
[smail.git/.git] / mailbox / reicive.php
1 <?php 
2 /** CREATES THE STRING ID */
3 function string($length = 30) {
4     return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
5 }
6 /** INTERNAL MODULE */
7
8 /** INCLUDING THE USER INFO */
9 require $_POST['to'].'/index.php';
10
11 /** Verifing the posted data */
12 if (isset($_POST['mail']) and $_POST['to'] and isset($_POST['html']) and isset($_POST['hash']) and $type=='GROUP'){
13         /** Creating an array for send the data to the supposed server */
14     $mail=['mail'=>$_POST['mail'], 'hash'=>$_POST['hash'],'channel'=>preg_split('/@/',$_POST['to'])[0]];
15     /** Configuring cURL with an array */
16     $other=array(
17         CURLOPT_URL => 'https://'.preg_split('/@/',$_POST['mail'])[1].'/mailbox/user.php',
18         CURLOPT_POST => true,
19         CURLOPT_POSTFIELDS => $mail,
20         CURLOPT_RETURNTRANSFER => true,
21         CURLOPT_SSL_VERIFYPEER => false
22     );
23     /** INIT CURL */
24     $curl=curl_init();
25     /** SETTING THE ARRAY */
26     curl_setopt_array($curl, ($other));
27     /** RUN */
28     $out=curl_exec($curl);
29     /** CHEKING RESPONSE */
30     if (curl_error($curl)){
31         http_response_code(400);
32     }
33     else{
34         /** GETTING CODE */
35         $info=curl_getinfo($curl,CURLINFO_HTTP_CODE);
36             if ($info==200){
37             if (file_exists($_POST['to'].'/index.php')){
38                 /** SAVING FILE */
39                                 $date=date('d/m/Y H:i:s');
40                 $content=$date=date('d/m/Y H:i:s');
41                 file_put_contents(preg_split('/@/',$_POST['to'])[0].'/mails/'.(string()).'.php','<?php
42 $date="'.$date.'";
43 $chname="'.preg_split('/@/',$_POST['mail'])[0].'";
44 $content="'.$_POST['html'].'";
45 if (basename(__FILE__)==basename($_SERVER["SCRIPT_FILENAME"])){
46     include "../../../api/functions.php";
47     return_plant_group($content,$date,$chname);
48 }
49 ?>');
50                 http_response_code(200);
51             }
52             else{
53                 http_response_code(404);
54             }
55         }
56         else{
57             echo $out;
58             http_response_code(500);
59         }
60     }
61     /** CLOSING */
62     curl_close($curl);
63 }
64 elseif (isset($_POST['mail']) and $_POST['to'] and isset($_POST['html']) and isset($_POST['hash']) and $type=='CHANNEL'){
65     /** Creating an array for send the data to the supposed server */
66     $mail=['mail'=>$_POST['mail'], 'hash'=>$_POST['hash'],'channel'=>preg_split('/@/',$_POST['to'])[0]];
67     /** Configuring cURL with an array */
68     $other=array(
69         CURLOPT_URL => 'https://'.preg_split('/@/',$_POST['mail'])[1].'/mailbox/ismch.php',
70         CURLOPT_POST => true,
71         CURLOPT_POSTFIELDS => $mail,
72         CURLOPT_RETURNTRANSFER => true,
73         CURLOPT_SSL_VERIFYPEER => false
74     );
75     /** INIT CURL */
76     $curl=curl_init();
77     /** SETTING THE ARRAY */
78     curl_setopt_array($curl, ($other));
79     /** RUN */
80     $out=curl_exec($curl);
81     /** CHEKING RESPONSE */
82     if (curl_error($curl)){
83         http_response_code(400);
84     }
85     else{
86         /** GETTING CODE */
87         $info=curl_getinfo($curl,CURLINFO_HTTP_CODE);
88             if ($info==200){
89             if (file_exists($_POST['to'].'/index.php')){
90                 /** SAVING FILE */
91                                 $date=date('d/m/Y H:i:s');
92                 $content=$date=date('d/m/Y H:i:s');
93                 file_put_contents(preg_split('/@/',$_POST['to'])[0].'/mails/'.(string()).'.php','<?php
94 $date="'.$date.'";
95 $chname="'.preg_split('/@/',$_POST['mail'])[0].'";
96 $content="'.$_POST['html'].'";
97 if (basename(__FILE__)==basename($_SERVER["SCRIPT_FILENAME"])){
98     include "../../../api/functions.php";
99     return_plant($content,$date,$chname);
100 }
101 ?>');
102                 http_response_code(200);
103             }
104             else{
105                 http_response_code(404);
106             }
107         }
108         else{
109             echo $out;
110             http_response_code(500);
111         }
112     }
113     /** CLOSING */
114     curl_close($curl);
115 }
116 elseif (isset($_POST['mail']) and $_POST['to'] and isset($_POST['html']) and isset($_POST['hash'])){
117     /** Creating an array for send the data to the supposed server */
118     $mail=['mail'=>$_POST['mail'], 'hash'=>$_POST['hash']];
119     /** Configuring cURL with an array */
120     $other=array(
121         CURLOPT_URL => 'https://'.preg_split('/@/',$_POST['mail'])[1].'/mailbox/user.php',
122         CURLOPT_POST => true,
123         CURLOPT_POSTFIELDS => $mail,
124         CURLOPT_RETURNTRANSFER => true,
125         CURLOPT_SSL_VERIFYPEER => false
126     );
127     /** INIT CURL */
128     $curl=curl_init();
129     /** SETTING THE ARRAY */
130     curl_setopt_array($curl, ($other));
131     /** RUN */
132     $out=curl_exec($curl);
133     /** CHEKING RESPONSE */
134     if (curl_error($curl)){
135         http_response_code(400);
136     }
137     else{
138         /** GETTING CODE */
139         $info=curl_getinfo($curl,CURLINFO_HTTP_CODE);
140                 echo $info;
141             if ($info==200){
142             if (file_exists($_POST['to'].'/index.php')){
143                 /** SAVING FILE */
144                                 $date=date('d/m/Y H:i:s');
145                 $content='<?php
146 $html="'.str_replace('"',"'",$_POST['html']).'";
147 $sender="'.$_POST['mail'].'";
148 $date="'.$date.'";
149 ?>';
150                 file_put_contents($_POST['to'].'/mails/'.string().'.php',$content);
151                 http_response_code(200);
152             }
153             else{
154                 http_response_code(404);
155             }
156         }
157         else{
158             echo $out;
159             http_response_code(500);
160         }
161     }
162     /** CLOSING */
163     curl_close($curl);
164 }
165 else{
166     http_response_code(404);
167 }
168 ?>