Skip to content

Commit 59f2911

Browse files
committedNov 12, 2018
2018.11.12. / official release
- initial release
0 parents  commit 59f2911

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+7603
-0
lines changed
 

‎README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## PHPoC Shield
2+
PHPoC source codes to use [PHPoC (WiFi) Shield for Arduino](http://www.phpoc.com/phpoc_shield_for_arduino.php).
3+
4+
## Available Web Applications
5+
* Setup
6+
* Web Serial Monitor
7+
* Web Serial Plotter
8+
* Web Remote Push
9+
* Web Remote Slide
10+
* Web Remote Pad
11+
12+
## References
13+
* [PHPoC Shield for Arduino](https://www.phpoc.com/support/manual/p4s-348-r2_user_manual/)
14+
* [PHPoC WiFi Shield for Arduino](https://www.phpoc.com/support/manual/p4s-347-r2_user_manual/)

‎cmd_smtp.php

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
3+
define("MAX_DATA_LEN", 1024);
4+
5+
$smtp_to_email = "";
6+
$smtp_to_name = "";
7+
$smtp_subject = "";
8+
$smtp_data = "";
9+
10+
function cmd_smtp_server($cmd)
11+
{
12+
if(count($cmd) < 4)
13+
{
14+
esmtp_msa("", 0);
15+
return 0;
16+
}
17+
18+
echo "cmd_smtp_server: ", $cmd[2], " ", $cmd[3], "\r\n";
19+
20+
esmtp_msa($cmd[2], (int)$cmd[3]);
21+
22+
return 0;
23+
}
24+
25+
function cmd_smtp_login($cmd)
26+
{
27+
if(count($cmd) < 4)
28+
return 0;
29+
30+
echo "cmd_smtp_login: ", $cmd[2], " ", $cmd[3], "\r\n";
31+
32+
esmtp_auth($cmd[2], $cmd[3]);
33+
34+
return 0;
35+
}
36+
37+
function cmd_smtp_from($cmd)
38+
{
39+
global $pid_pipe_data;
40+
41+
if(count($cmd) < 3)
42+
return 0;
43+
44+
$email = $cmd[2];
45+
$name = "";
46+
47+
pid_read($pid_pipe_data, $name);
48+
49+
echo "cmd_smtp_from: \"$name\" <$email>\r\n";
50+
51+
esmtp_account($email, $name);
52+
53+
return 0;
54+
}
55+
56+
function cmd_smtp_to($cmd)
57+
{
58+
global $smtp_to_email, $smtp_to_name;
59+
global $pid_pipe_data;
60+
61+
if(count($cmd) < 3)
62+
return 0;
63+
64+
$email = $cmd[2];
65+
$name = "";
66+
67+
pid_read($pid_pipe_data, $name);
68+
69+
echo "cmd_smtp_to: \"$name\" <$email>\r\n";
70+
71+
$smtp_to_email = $email;
72+
$smtp_to_name = $name;
73+
74+
return 0;
75+
}
76+
77+
function cmd_smtp_subject($cmd)
78+
{
79+
global $smtp_subject;
80+
global $pid_pipe_data;
81+
82+
pid_read($pid_pipe_data, $smtp_subject);
83+
84+
echo "cmd_smtp_subject: $smtp_subject\r\n";
85+
86+
return 0;
87+
}
88+
89+
function cmd_smtp_data($cmd)
90+
{
91+
global $smtp_data;
92+
global $pid_pipe_data;
93+
94+
if(count($cmd) > 2)
95+
{
96+
if($cmd[2] == "begin")
97+
{
98+
echo "cmd_smtp_data: begin\r\n";
99+
$smtp_data = "";
100+
return 0;
101+
}
102+
else
103+
return -EINVAL;
104+
}
105+
106+
$rbuf = "";
107+
$rlen = pid_read($pid_pipe_data, $rbuf);
108+
109+
echo "$rbuf";
110+
111+
if((strlen($smtp_data) + $rlen) <= MAX_DATA_LEN)
112+
$smtp_data .= $rbuf;
113+
114+
return 0;
115+
}
116+
117+
function cmd_smtp_send($cmd)
118+
{
119+
global $smtp_to_email, $smtp_to_name;
120+
global $smtp_subject, $smtp_data;
121+
122+
if(count($cmd) > 2)
123+
{
124+
if($cmd[2] == "ip6")
125+
$ip6 = true;
126+
else
127+
return -EINVAL;
128+
}
129+
else
130+
$ip6 = false;
131+
132+
esmtp_setup(UDP_ID_DNS, TCP_ID_SMTP, "", $ip6);
133+
esmtp_start($smtp_to_email, $smtp_to_name, $smtp_subject, $smtp_data);
134+
135+
return 0;
136+
}
137+
138+
function cmd_smtp_status($cmd)
139+
{
140+
global $pid_pipe_data;
141+
142+
$msg = esmtp_loop();
143+
144+
if($msg === false)
145+
return 0;
146+
else
147+
{
148+
if(!$msg)
149+
return 999;
150+
else
151+
return (int)$msg;
152+
}
153+
}
154+
155+
function cmd_smtp($cmd)
156+
{
157+
if(count($cmd) < 2)
158+
return -EINVAL;
159+
160+
switch($cmd[1])
161+
{
162+
case "server":
163+
return cmd_smtp_server($cmd);
164+
case "login":
165+
return cmd_smtp_login($cmd);
166+
case "from":
167+
return cmd_smtp_from($cmd);
168+
case "to":
169+
return cmd_smtp_to($cmd);
170+
case "subject":
171+
return cmd_smtp_subject($cmd);
172+
case "data":
173+
return cmd_smtp_data($cmd);
174+
case "send":
175+
return cmd_smtp_send($cmd);
176+
case "status":
177+
return cmd_smtp_status($cmd);
178+
default:
179+
return -EINVAL;
180+
}
181+
}
182+
183+
?>

0 commit comments

Comments
 (0)
Please sign in to comment.