Implemented very simple PHP for embedding stuff in control pages.
This commit is contained in:
parent
a10599f32c
commit
7bc5761b3e
15 changed files with 802 additions and 292 deletions
|
@ -37,6 +37,7 @@ Licence: GPL
|
|||
// Language-specific includes
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
// Platform-specific includes
|
||||
|
||||
|
|
130
SD-image/control.php
Normal file
130
SD-image/control.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
<style type="text/css">td { text-align: center; } </style>
|
||||
</head>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<?php if(gotPassword()) echo ' <a href="http://reprappro.com" target="_blank"><img src="logo.png" alt="RepRapPro logo"></a>'; ?>
|
||||
</h2><br><br>
|
||||
<?php if(printLinkTable()) echo '<table><tr>
|
||||
<td> <a href="control.php">Control</a> </td>
|
||||
|
||||
<td> <a href="print.php">Print</a> </td>
|
||||
|
||||
<td> <a href="http://reprap.org/wiki/RepRapPro_RepRap_Firmware" target="_blank">Help</a> </td>
|
||||
|
||||
|
||||
<td> <a href="settings.php">Settings</a> </td>
|
||||
|
||||
<td> <a href="logout.php">Logout</a> </td>
|
||||
|
||||
</tr></table>
|
||||
<br><br>'; ?>
|
||||
|
||||
<table border="1"><div align="center">
|
||||
|
||||
|
||||
<tr>
|
||||
<th colspan="9">Move X Y Z</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td rowspan="2"><button type="button" onclick="return homea()">Home<br>All</button></td>
|
||||
<td colspan="4">- mm</td>
|
||||
<td colspan="4">+ mm</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>-100</td>
|
||||
<td>-10</td>
|
||||
<td>-1</td>
|
||||
<td>-0.1</td>
|
||||
<td>0.1</td>
|
||||
<td>1</td>
|
||||
<td>10</td>
|
||||
<td>100</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><button type="button" onclick="return homex()">Home X</button></td>
|
||||
<td><button type="button" onclick="return xm100mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xm10mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xm1mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xm01mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xp01mm()">X -></button></td>
|
||||
<td><button type="button" onclick="return xp1mm()">X -></button></td>
|
||||
<td><button type="button" onclick="return xp10mm()">X -></button></td>
|
||||
<td><button type="button" onclick="return xp100mm()">X -></button></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><button type="button" onclick="return homey()">Home Y</button></td>
|
||||
<td><button type="button" onclick="return ym100mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return ym10mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return ym1mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return ym01mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return yp01mm()">Y -></button></td>
|
||||
<td><button type="button" onclick="return yp1mm()">Y -></button></td>
|
||||
<td><button type="button" onclick="return yp10mm()">Y -></button></td>
|
||||
<td><button type="button" onclick="return yp100mm()">Y -></button></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><button type="button" onclick="return homez()">Home Z</button></td>
|
||||
<td><button type="button" onclick="return zm100mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zm10mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zm1mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zm01mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zp01mm()">Z -></button></td>
|
||||
<td><button type="button" onclick="return zp1mm()">Z -></button></td>
|
||||
<td><button type="button" onclick="return zp10mm()">Z -></button></td>
|
||||
<td><button type="button" onclick="return zp100mm()">Z -></button></td>
|
||||
</tr>
|
||||
|
||||
</div></table>
|
||||
|
||||
<br><br><form name="input" action="gather.asp" method="get">Send a G Code: <input type="text" name="gcode"><input type="submit" value="Send"></form>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
|
||||
|
||||
function homea(){ window.location.href = "control.php?gcode=G28";}
|
||||
function homex(){ window.location.href = "control.php?gcode=G28%20X0";}
|
||||
function homey(){ window.location.href = "control.php?gcode=G28%20Y0";}
|
||||
function homez(){ window.location.href = "control.php?gcode=G28%20Z0";}
|
||||
|
||||
function xp01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X0.1%0AG90";}
|
||||
function xp1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X1%0AG90";}
|
||||
function xp10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X10%0AG90";}
|
||||
function xp100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X100%0AG90";}
|
||||
|
||||
function xm01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X-0.1%0AG90";}
|
||||
function xm1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X-1%0AG90";}
|
||||
function xm10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X10%0AG90";}
|
||||
function xm100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X100%0AG90";}
|
||||
|
||||
function yp01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y0.1%0AG90";}
|
||||
function yp1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y1%0AG90";}
|
||||
function yp10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y10%0AG90";}
|
||||
function yp100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y100%0AG90";}
|
||||
|
||||
function ym01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y-0.1%0AG90";}
|
||||
function ym1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y-1%0AG90";}
|
||||
function ym10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y10%0AG90";}
|
||||
function ym100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y100%0AG90";}
|
||||
|
||||
function zp01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z0.1%0AG90";}
|
||||
function zp1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z1%0AG90";}
|
||||
function zp10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z10%0AG90";}
|
||||
function zp100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z100%0AG90";}
|
||||
|
||||
function zm01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z-0.1%0AG90";}
|
||||
function zm1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z-1%0AG90";}
|
||||
function zm10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z10%0AG90";}
|
||||
function zm100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z100%0AG90";}
|
||||
|
||||
</script>
|
||||
<br><br></html>
|
130
SD-image/control.php~
Normal file
130
SD-image/control.php~
Normal file
|
@ -0,0 +1,130 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
<style type="text/css">td { text-align: center; } </style>
|
||||
</head>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<?php if(gotPassword()) echo ' <a href="http://reprappro.com" target="_blank"><img src="logo.png" alt="RepRapPro logo"></a>'; ?>
|
||||
</h2><br><br>
|
||||
<?php if(printLinkTable()) echo '<table><tr>
|
||||
<td> <a href="control.php">Control</a> </td>
|
||||
|
||||
<td> <a href="print.php">Print</a> </td>
|
||||
|
||||
<td> <a href="http://reprap.org/wiki/RepRapPro_RepRap_Firmware" target="_blank">Help</a> </td>
|
||||
|
||||
|
||||
<td> <a href="settings.php">Settings</a> </td>
|
||||
|
||||
<td> <a href="logout.php">Logout</a> </td>
|
||||
|
||||
</tr></table>
|
||||
<br><br>'; ?>
|
||||
|
||||
<table border="1"><div align="center">
|
||||
|
||||
|
||||
<tr>
|
||||
<th colspan="9">Move X Y Z</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td rowspan="2"><button type="button" onclick="return homea()">Home<br>All</button></td>
|
||||
<td colspan="4">- mm</td>
|
||||
<td colspan="4">+ mm</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>-100</td>
|
||||
<td>-10</td>
|
||||
<td>-1</td>
|
||||
<td>-0.1</td>
|
||||
<td>0.1</td>
|
||||
<td>1</td>
|
||||
<td>10</td>
|
||||
<td>100</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><button type="button" onclick="return homex()">Home X</button></td>
|
||||
<td><button type="button" onclick="return xm100mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xm10mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xm1mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xm01mm()"><- X</button></td>
|
||||
<td><button type="button" onclick="return xp01mm()">X -></button></td>
|
||||
<td><button type="button" onclick="return xp1mm()">X -></button></td>
|
||||
<td><button type="button" onclick="return xp10mm()">X -></button></td>
|
||||
<td><button type="button" onclick="return xp100mm()">X -></button></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><button type="button" onclick="return homey()">Home Y</button></td>
|
||||
<td><button type="button" onclick="return ym100mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return ym10mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return ym1mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return ym01mm()"><- Y</button></td>
|
||||
<td><button type="button" onclick="return yp01mm()">Y -></button></td>
|
||||
<td><button type="button" onclick="return yp1mm()">Y -></button></td>
|
||||
<td><button type="button" onclick="return yp10mm()">Y -></button></td>
|
||||
<td><button type="button" onclick="return yp100mm()">Y -></button></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><button type="button" onclick="return homez()">Home Z</button></td>
|
||||
<td><button type="button" onclick="return zm100mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zm10mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zm1mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zm01mm()"><- Z</button></td>
|
||||
<td><button type="button" onclick="return zp01mm()">Z -></button></td>
|
||||
<td><button type="button" onclick="return zp1mm()">Z -></button></td>
|
||||
<td><button type="button" onclick="return zp10mm()">Z -></button></td>
|
||||
<td><button type="button" onclick="return zp100mm()">Z -></button></td>
|
||||
</tr>
|
||||
|
||||
</div></table>
|
||||
|
||||
<br><br><form name="input" action="gather.asp" method="get">Send a G Code: <input type="text" name="gcode"><input type="submit" value="Send"></form>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
|
||||
|
||||
function homea(){ window.location.href = "control.php?gcode=G28";}
|
||||
function homex(){ window.location.href = "control.php?gcode=G28%20X0";}
|
||||
function homey(){ window.location.href = "control.php?gcode=G28%20Y0";}
|
||||
function homez(){ window.location.href = "control.php?gcode=G28%20Z0";}
|
||||
|
||||
function xp01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X0.1%0AG90";}
|
||||
function xp1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X1%0AG90";}
|
||||
function xp10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X10%0AG90";}
|
||||
function xp100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X100%0AG90";}
|
||||
|
||||
function xm01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X-0.1%0AG90";}
|
||||
function xm1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X-1%0AG90";}
|
||||
function xm10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X10%0AG90";}
|
||||
function xm100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20X100%0AG90";}
|
||||
|
||||
function yp01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y0.1%0AG90";}
|
||||
function yp1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y1%0AG90";}
|
||||
function yp10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y10%0AG90";}
|
||||
function yp100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y100%0AG90";}
|
||||
|
||||
function ym01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y-0.1%0AG90";}
|
||||
function ym1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y-1%0AG90";}
|
||||
function ym10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y10%0AG90";}
|
||||
function ym100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Y100%0AG90";}
|
||||
|
||||
function zp01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z0.1%0AG90";}
|
||||
function zp1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z1%0AG90";}
|
||||
function zp10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z10%0AG90";}
|
||||
function zp100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z100%0AG90";}
|
||||
|
||||
function zm01mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z-0.1%0AG90";}
|
||||
function zm1mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z-1%0AG90";}
|
||||
function zm10mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z10%0AG90";}
|
||||
function zm100mm(){ window.location.href = "control.php?gcode=G91%0AG1%20Z100%0AG90";}
|
||||
|
||||
</script>
|
||||
<br><br></html>
|
11
SD-image/html404.htm
Normal file
11
SD-image/html404.htm
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<center>
|
||||
|
||||
<h3><br><br>RepRap Firmware<br><br>404 Error: page not found.</h3>
|
||||
|
||||
|
||||
<center>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,18 +1,11 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>404 Error</title>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
|
||||
<h3><br><br>404 Error: page not found.</h3>
|
||||
|
||||
|
||||
<center>
|
||||
<h3>
|
||||
RepRap Web Interface
|
||||
<br><br><br>
|
||||
|
||||
RepRapPro Firmware - 404 Error: page not found.
|
||||
</h3>
|
||||
</html>
|
||||
|
||||
</center>
|
||||
|
||||
</body></html>
|
||||
|
|
6
SD-image/logout.php
Normal file
6
SD-image/logout.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
<?php print(logout()); ?>
|
||||
</head>
|
||||
<html>
|
||||
</html>
|
8
SD-image/logout.php~
Normal file
8
SD-image/logout.php~
Normal file
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
|
||||
<?php print(logout()); ?>
|
||||
|
||||
</head>
|
||||
<html>
|
||||
</html>
|
13
SD-image/passwd.php
Normal file
13
SD-image/passwd.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE HTML>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<br>
|
||||
|
||||
<form name="input" action="control.php" method="get">Password: <input type="password" name="pwd"><input type="submit" value="Submit">
|
||||
|
||||
<br><br>
|
||||
|
||||
</html>
|
13
SD-image/passwd.php~
Normal file
13
SD-image/passwd.php~
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE HTML>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<br>
|
||||
|
||||
<form name="input" action="gather.asp" method="get">Password: <input type="password" name="pwd"><input type="submit" value="Submit">
|
||||
|
||||
<br><br>
|
||||
|
||||
</html>
|
30
SD-image/print.php
Normal file
30
SD-image/print.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<?php if(gotPassword()) echo ' <a href="http://reprappro.com" target="_blank"><img src="logo.png" alt="RepRapPro logo"></a>'; ?>
|
||||
</h2><br><br>
|
||||
<?php if(printLinkTable()) echo '<table><tr>
|
||||
<td> <a href="control.php">Control</a> </td>
|
||||
|
||||
<td> <a href="print.php">Print</a> </td>
|
||||
|
||||
<td> <a href="http://reprap.org/wiki/RepRapPro_RepRap_Firmware" target="_blank">Help</a> </td>
|
||||
|
||||
|
||||
<td> <a href="settings.php">Settings</a> </td>
|
||||
|
||||
<td> <a href="logout.php">Logout</a> </td>
|
||||
|
||||
</tr></table>
|
||||
<br><br>'; ?>
|
||||
|
||||
<br><br>Print: allow user to click a file to print it, upload files, delete files.
|
||||
|
||||
</html>
|
||||
|
30
SD-image/print.php~
Normal file
30
SD-image/print.php~
Normal file
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<?php if(gotPassword()) echo ' <a href="http://reprappro.com" target="_blank"><img src="logo.png" alt="RepRapPro logo"></a>'; ?>
|
||||
</h2><br><br>
|
||||
<?php if(printLinkTable()) echo '<table><tr>
|
||||
<td> <a href="control.php">Control</a> </td>
|
||||
|
||||
<td> <a href="print.php">Print</a> </td>
|
||||
|
||||
<td> <a href="http://reprap.org/wiki/RepRapPro_RepRap_Firmware" target="_blank">Help</a> </td>
|
||||
|
||||
|
||||
<td> <a href="settings.php">Settings</a> </td>
|
||||
|
||||
<td> <a href="logout.htm">Logout</a> </td>
|
||||
|
||||
</tr></table>
|
||||
<br><br>'; ?>
|
||||
|
||||
<br><br>Print: allow user to click a file to print it, upload files, delete files.
|
||||
|
||||
</html>
|
||||
|
30
SD-image/settings.php
Normal file
30
SD-image/settings.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<?php if(gotPassword()) echo ' <a href="http://reprappro.com" target="_blank"><img src="logo.png" alt="RepRapPro logo"></a>'; ?>
|
||||
</h2><br><br>
|
||||
<?php if(printLinkTable()) echo '<table><tr>
|
||||
<td> <a href="control.php">Control</a> </td>
|
||||
|
||||
<td> <a href="print.php">Print</a> </td>
|
||||
|
||||
<td> <a href="http://reprap.org/wiki/RepRapPro_RepRap_Firmware" target="_blank">Help</a> </td>
|
||||
|
||||
|
||||
<td> <a href="settings.php">Settings</a> </td>
|
||||
|
||||
<td> <a href="logout.php">Logout</a> </td>
|
||||
|
||||
</tr></table>
|
||||
<br><br>'; ?>
|
||||
|
||||
<br><br>Settings: allow user to rename machine, set password, set steps/mm etc etc and record the lot.
|
||||
|
||||
</html>
|
||||
|
30
SD-image/settings.php~
Normal file
30
SD-image/settings.php~
Normal file
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
|
||||
<html>
|
||||
|
||||
<h2>RepRap:
|
||||
<?php print(getMyName()); ?>
|
||||
<?php if(gotPassword()) echo ' <a href="http://reprappro.com" target="_blank"><img src="logo.png" alt="RepRapPro logo"></a>'; ?>
|
||||
</h2><br><br>
|
||||
<?php if(printLinkTable()) echo '<table><tr>
|
||||
<td> <a href="control.php">Control</a> </td>
|
||||
|
||||
<td> <a href="print.php">Print</a> </td>
|
||||
|
||||
<td> <a href="http://reprap.org/wiki/RepRapPro_RepRap_Firmware" target="_blank">Help</a> </td>
|
||||
|
||||
|
||||
<td> <a href="settings.php">Settings</a> </td>
|
||||
|
||||
<td> <a href="logout.htm">Logout</a> </td>
|
||||
|
||||
</tr></table>
|
||||
<br><br>'; ?>
|
||||
|
||||
<br><br>Settings: allow user to rename machine, set password, set steps/mm etc etc and record the lot.
|
||||
|
||||
</html>
|
||||
|
49
Webserver.h
49
Webserver.h
|
@ -7,6 +7,15 @@ RepRap machine. It interprests returned values from those pages and uses them t
|
|||
which it sends to the RepRap. It also collects values from the RepRap like temperature and uses
|
||||
those to construct the web pages.
|
||||
|
||||
It implements very very restricted PHP. It can do:
|
||||
|
||||
<?php print(myStringFunction()); ?>
|
||||
<?php if(myBooleanFunction()) print(myOtherStringFunction()); ?>
|
||||
<?php if(myOtherBooleanFunction()) echo 'Some arbitrarily long string of HTML including newlines up to this quote:'; ?>
|
||||
|
||||
Note that by printing a function that returns "" you can just call
|
||||
that function in this C++ code with no effect on the loaded web page.
|
||||
|
||||
-----------------------------------------------------------------------------------------------------
|
||||
|
||||
Version 0.1
|
||||
|
@ -26,8 +35,13 @@ Licence: GPL
|
|||
|
||||
#define CLIENT_CLOSE_DELAY 1000 // Microseconds to wait after serving a page
|
||||
|
||||
#define PASSWORD_PAGE "passwd.htm"
|
||||
#define PASSWORD_PAGE "passwd.php"
|
||||
#define STRING_LENGTH 1000
|
||||
#define PHP_TAG_LENGTH 200
|
||||
#define PHP_IF 1
|
||||
#define PHP_ECHO 2
|
||||
#define PHP_PRINT 3
|
||||
#define NO_PHP 99
|
||||
|
||||
class Webserver
|
||||
{
|
||||
|
@ -49,22 +63,21 @@ class Webserver
|
|||
void ParseQualifier();
|
||||
void CheckPassword();
|
||||
boolean LoadGcodeBuffer(char* gc, boolean convertWeb);
|
||||
boolean InternalFile(char* nameOfFileToSend);
|
||||
void InternalHead(boolean sendTab, int noLink, char* headString);
|
||||
void InternalTail();
|
||||
void CloseClient();
|
||||
void SendControlPage();
|
||||
void SendPrintPage();
|
||||
void SendHelpPage();
|
||||
void SendSettingsPage();
|
||||
void SendLogoutPage();
|
||||
void SendPasswordPage();
|
||||
void Send404Page();
|
||||
void initialisePHP();
|
||||
char PHPParse(char* phpString);
|
||||
boolean printHeadString();
|
||||
boolean printLinkTable();
|
||||
boolean callPHPBoolean(char* phpRecord);
|
||||
char* callPHPString(char* phpRecord);
|
||||
void ProcessPHPByte(char b);
|
||||
void WritePHPByte();
|
||||
|
||||
Platform* platform;
|
||||
unsigned long lastTime;
|
||||
int fileBeingSent;
|
||||
boolean writing;
|
||||
boolean inPHPFile;
|
||||
boolean clientLineIsBlank;
|
||||
unsigned long clientCloseTime;
|
||||
boolean needToCloseClient;
|
||||
|
@ -78,6 +91,20 @@ class Webserver
|
|||
boolean gotPassword;
|
||||
char* password;
|
||||
char* myName;
|
||||
char phpTag[PHP_TAG_LENGTH];
|
||||
char phpRecord[PHP_TAG_LENGTH];
|
||||
int inPHPString;
|
||||
int phpPointer;
|
||||
boolean phpEchoing;
|
||||
boolean phpIfing;
|
||||
boolean phpPrinting;
|
||||
boolean eatInput;
|
||||
boolean recordInput;
|
||||
boolean ifWasTrue;
|
||||
boolean sendTable;
|
||||
char eatInputChar;
|
||||
int phpRecordPointer;
|
||||
boolean ifwasTrue;
|
||||
};
|
||||
|
||||
|
||||
|
|
594
Webserver.ino
594
Webserver.ino
|
@ -7,6 +7,16 @@ RepRap machine. It interprests returned values from those pages and uses them t
|
|||
which it sends to the RepRap. It also collects values from the RepRap like temperature and uses
|
||||
those to construct the web pages.
|
||||
|
||||
It implements very very restricted PHP. It can do:
|
||||
|
||||
<?php print(myStringFunction()); ?>
|
||||
<?php if(myBooleanFunction()) print(myOtherStringFunction()); ?>
|
||||
<?php if(myOtherBooleanFunction()) echo 'Some arbitrarily long string of HTML including newlines up to this quote:'; ?>
|
||||
|
||||
Note that by printing a function that returns "" you can just call
|
||||
that function in this C++ code with no effect on the loaded web page.
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------------
|
||||
|
||||
Version 0.1
|
||||
|
@ -29,6 +39,8 @@ Webserver::Webserver(Platform* p)
|
|||
platform = p;
|
||||
lastTime = platform->time();
|
||||
writing = false;
|
||||
inPHPFile = false;
|
||||
initialisePHP();
|
||||
clientLineIsBlank = true;
|
||||
needToCloseClient = false;
|
||||
clientLinePointer = 0;
|
||||
|
@ -39,6 +51,8 @@ Webserver::Webserver(Platform* p)
|
|||
gotPassword = false;
|
||||
gcodeAvailable = false;
|
||||
gcodePointer = 0;
|
||||
sendTable = true;
|
||||
phpRecordPointer = 0;
|
||||
}
|
||||
|
||||
boolean Webserver::Available()
|
||||
|
@ -81,22 +95,19 @@ boolean Webserver::LoadGcodeBuffer(char* gc, boolean convertWeb)
|
|||
{
|
||||
if(c == '+' && convertWeb)
|
||||
c = ' ';
|
||||
if(c == '%'&& convertWeb) // FIXME - just convert the next two hex bytes to a char
|
||||
if(c == '%'&& convertWeb)
|
||||
{
|
||||
if(StringStartsWith(&gc[gcp], "2B"))
|
||||
c = '+';
|
||||
else if(StringStartsWith(&gc[gcp], "20"))
|
||||
c = ' ';
|
||||
else if(StringStartsWith(&gc[gcp], "0A"))
|
||||
c = '\n';
|
||||
c = 0;
|
||||
if(isalpha(gc[gcp]))
|
||||
c += 16*(gc[gcp] - 'A' + 10);
|
||||
else
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "Webserver: Dud web-form byte: ");
|
||||
platform->Message(HOST_MESSAGE, gc);
|
||||
platform->Message(HOST_MESSAGE, "\n");
|
||||
}
|
||||
gcp += 2;
|
||||
|
||||
c += 16*(gc[gcp] - '0');
|
||||
gcp++;
|
||||
if(isalpha(gc[gcp]))
|
||||
c += gc[gcp] - 'A' + 10;
|
||||
else
|
||||
c += gc[gcp] - '0';
|
||||
gcp++;
|
||||
}
|
||||
gcodeBuffer[gcodePointer++] = c;
|
||||
}
|
||||
|
@ -104,7 +115,6 @@ boolean Webserver::LoadGcodeBuffer(char* gc, boolean convertWeb)
|
|||
gcodeBuffer[gcodePointer] = 0;
|
||||
gcodePointer = 0;
|
||||
gcodeAvailable = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -132,262 +142,24 @@ boolean Webserver::StringStartsWith(char* string, char* starting)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Webserver::InternalHead(boolean sendTab, int noLink, char* headString)
|
||||
{
|
||||
platform->SendToClient("<!DOCTYPE HTML><head>");
|
||||
if(headString)
|
||||
platform->SendToClient(headString);
|
||||
platform->SendToClient("</head><html><h2>RepRap: ");
|
||||
platform->SendToClient(myName);
|
||||
if(gotPassword)
|
||||
platform->SendToClient(" <a href=\"http://reprappro.com\" target=\"_blank\"><img src=\"logo.png\" alt=\"RepRapPro logo\"></a>");
|
||||
platform->SendToClient("</h2><br><br>");
|
||||
if(sendTab)
|
||||
{
|
||||
platform->SendToClient("<table><tr>"); // border=\"1\"
|
||||
|
||||
if(noLink == 0)
|
||||
platform->SendToClient("<td> Control </td>");
|
||||
else
|
||||
platform->SendToClient("<td> <a href=\"control.htm\">Control</a> </td>");
|
||||
|
||||
if(noLink == 1)
|
||||
platform->SendToClient("<td> Print </td>");
|
||||
else
|
||||
platform->SendToClient("<td> <a href=\"print.htm\">Print</a> </td>");
|
||||
|
||||
platform->SendToClient("<td> <a href=\"http://reprap.org/wiki/RepRapPro_RepRap_Firmware\" target=\"_blank\">Help</a> </td>");
|
||||
|
||||
if(noLink == 3)
|
||||
platform->SendToClient("<td> Settings </td>");
|
||||
else
|
||||
platform->SendToClient("<td> <a href=\"settings.htm\">Settings</a> </td>");
|
||||
|
||||
platform->SendToClient("<td> <a href=\"logout.htm\">Logout</a> </td>");
|
||||
|
||||
platform->SendToClient("</tr></table>");
|
||||
}
|
||||
platform->SendToClient("<br><br>");
|
||||
}
|
||||
|
||||
void Webserver::CloseClient()
|
||||
{
|
||||
writing = false;
|
||||
inPHPFile = false;
|
||||
initialisePHP();
|
||||
clientCloseTime = platform->time();
|
||||
needToCloseClient = true;
|
||||
}
|
||||
|
||||
void Webserver::InternalTail()
|
||||
{
|
||||
platform->SendToClient("<br><br></html>\n");
|
||||
CloseClient();
|
||||
}
|
||||
|
||||
void Webserver::SendControlPage()
|
||||
{
|
||||
InternalHead(true, 0, "<style type=\"text/css\">td { text-align: center; } </style>");
|
||||
|
||||
platform->SendToClient("<table border=\"1\"><div align=\"center\">");
|
||||
|
||||
|
||||
platform->SendToClient("<tr>");
|
||||
platform->SendToClient("<th colspan=\"9\">Move X Y Z</th>");
|
||||
platform->SendToClient("</tr>");
|
||||
|
||||
platform->SendToClient("<tr>");
|
||||
platform->SendToClient("<td rowspan=\"2\"><button type=\"button\" onclick=\"return homea()\">Home<br>All</button></td>");
|
||||
platform->SendToClient("<td colspan=\"4\">- mm</td>");
|
||||
platform->SendToClient("<td colspan=\"4\">+ mm</td>");
|
||||
platform->SendToClient("</tr>");
|
||||
|
||||
platform->SendToClient("<tr>");
|
||||
platform->SendToClient("<td>-100</td>");
|
||||
platform->SendToClient("<td>-10</td>");
|
||||
platform->SendToClient("<td>-1</td>");
|
||||
platform->SendToClient("<td>-0.1</td>");
|
||||
platform->SendToClient("<td>0.1</td>");
|
||||
platform->SendToClient("<td>1</td>");
|
||||
platform->SendToClient("<td>10</td>");
|
||||
platform->SendToClient("<td>100</td>");
|
||||
platform->SendToClient("</tr>");
|
||||
|
||||
platform->SendToClient("<tr>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return homex()\">Home X</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xm100mm()\"><- X</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xm10mm()\"><- X</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xm1mm()\"><- X</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xm01mm()\"><- X</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xp01mm()\">X -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xp1mm()\">X -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xp10mm()\">X -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return xp100mm()\">X -></button></td>");
|
||||
platform->SendToClient("</tr>");
|
||||
|
||||
platform->SendToClient("<tr>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return homey()\">Home Y</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return ym100mm()\"><- Y</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return ym10mm()\"><- Y</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return ym1mm()\"><- Y</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return ym01mm()\"><- Y</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return yp01mm()\">Y -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return yp1mm()\">Y -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return yp10mm()\">Y -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return yp100mm()\">Y -></button></td>");
|
||||
platform->SendToClient("</tr>");
|
||||
|
||||
platform->SendToClient("<tr>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return homez()\">Home Z</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zm100mm()\"><- Z</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zm10mm()\"><- Z</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zm1mm()\"><- Z</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zm01mm()\"><- Z</button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zp01mm()\">Z -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zp1mm()\">Z -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zp10mm()\">Z -></button></td>");
|
||||
platform->SendToClient("<td><button type=\"button\" onclick=\"return zp100mm()\">Z -></button></td>");
|
||||
platform->SendToClient("</tr>");
|
||||
|
||||
platform->SendToClient("</div></table>");
|
||||
|
||||
platform->SendToClient("<br><br><form name=\"input\" action=\"gather.asp\" method=\"get\">Send a G Code: <input type=\"text\" name=\"gcode\"><input type=\"submit\" value=\"Send\"></form>\n");
|
||||
|
||||
platform->SendToClient("<script language=\"javascript\" type=\"text/javascript\">");
|
||||
|
||||
// FIXME - this lot can be be easily generated by a single function
|
||||
|
||||
platform->SendToClient("function homea(){ window.location.href = \"control.htm?gcode=G28\";}");
|
||||
platform->SendToClient("function homex(){ window.location.href = \"control.htm?gcode=G28 X0\";}");
|
||||
platform->SendToClient("function homey(){ window.location.href = \"control.htm?gcode=G28 Y0\";}");
|
||||
platform->SendToClient("function homez(){ window.location.href = \"control.htm?gcode=G28 Z0\";}");
|
||||
|
||||
platform->SendToClient("function xp01mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X0.1%0AG90\";}");
|
||||
platform->SendToClient("function xp1mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X1%0AG90\";}");
|
||||
platform->SendToClient("function xp10mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X10%0AG90\";}");
|
||||
platform->SendToClient("function xp100mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X100%0AG90\";}");
|
||||
|
||||
platform->SendToClient("function xm01mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X-0.1%0AG90\";}");
|
||||
platform->SendToClient("function xm1mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X-1%0AG90\";}");
|
||||
platform->SendToClient("function xm10mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X10%0AG90\";}");
|
||||
platform->SendToClient("function xm100mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 X100%0AG90\";}");
|
||||
|
||||
platform->SendToClient("function yp01mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y0.1%0AG90\";}");
|
||||
platform->SendToClient("function yp1mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y1%0AG90\";}");
|
||||
platform->SendToClient("function yp10mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y10%0AG90\";}");
|
||||
platform->SendToClient("function yp100mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y100%0AG90\";}");
|
||||
|
||||
platform->SendToClient("function ym01mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y-0.1%0AG90\";}");
|
||||
platform->SendToClient("function ym1mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y-1%0AG90\";}");
|
||||
platform->SendToClient("function ym10mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y10%0AG90\";}");
|
||||
platform->SendToClient("function ym100mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Y100%0AG90\";}");
|
||||
|
||||
platform->SendToClient("function zp01mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z0.1%0AG90\";}");
|
||||
platform->SendToClient("function zp1mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z1%0AG90\";}");
|
||||
platform->SendToClient("function zp10mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z10%0AG90\";}");
|
||||
platform->SendToClient("function zp100mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z100%0AG90\";}");
|
||||
|
||||
platform->SendToClient("function zm01mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z-0.1%0AG90\";}");
|
||||
platform->SendToClient("function zm1mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z-1%0AG90\";}");
|
||||
platform->SendToClient("function zm10mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z10%0AG90\";}");
|
||||
platform->SendToClient("function zm100mm(){ window.location.href = \"control.htm?gcode=G91%0AG1 Z100%0AG90\";}");
|
||||
|
||||
platform->SendToClient("</script>");
|
||||
InternalTail();
|
||||
}
|
||||
|
||||
void Webserver::SendPrintPage()
|
||||
{
|
||||
InternalHead(true, 1, 0);
|
||||
platform->SendToClient("Print Page - List files in a table: click one to print it; upload a file; delete a file\n");
|
||||
InternalTail();
|
||||
}
|
||||
|
||||
void Webserver::SendHelpPage()
|
||||
{
|
||||
InternalHead(true, 2, 0);
|
||||
platform->SendToClient("Help Page");
|
||||
InternalTail();
|
||||
}
|
||||
|
||||
void Webserver::SendSettingsPage()
|
||||
{
|
||||
InternalHead(true, 3, 0);
|
||||
platform->SendToClient("Settings Page - Change things and save the result: machine name, password, e steps/mm etc etc");
|
||||
InternalTail();
|
||||
}
|
||||
|
||||
void Webserver::SendLogoutPage()
|
||||
{
|
||||
gotPassword = false;
|
||||
SendPasswordPage();
|
||||
}
|
||||
|
||||
void Webserver::SendPasswordPage()
|
||||
{
|
||||
InternalHead(false, -1, 0);
|
||||
platform->SendToClient("<form name=\"input\" action=\"gather.asp\" method=\"get\">Password: <input type=\"password\" name=\"pwd\"><input type=\"submit\" value=\"Submit\">");
|
||||
InternalTail();
|
||||
}
|
||||
|
||||
void Webserver::Send404Page()
|
||||
{
|
||||
InternalHead(false, -1, 0);
|
||||
platform->SendToClient("<h3><br><br>404 Error: page not found.</h3>");
|
||||
InternalTail();
|
||||
}
|
||||
|
||||
boolean Webserver::InternalFile(char* nameOfFileToSend)
|
||||
{
|
||||
if(StringStartsWith(nameOfFileToSend, "index.htm") ||
|
||||
StringStartsWith(nameOfFileToSend, "control.htm"))
|
||||
{
|
||||
SendControlPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(StringStartsWith(nameOfFileToSend, "print.htm"))
|
||||
{
|
||||
SendPrintPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(StringStartsWith(nameOfFileToSend, "help.htm"))
|
||||
{
|
||||
SendHelpPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(StringStartsWith(nameOfFileToSend, "settings.htm"))
|
||||
{
|
||||
SendSettingsPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(StringStartsWith(nameOfFileToSend, "logout.htm"))
|
||||
{
|
||||
SendLogoutPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(StringStartsWith(nameOfFileToSend, "passwd.htm"))
|
||||
{
|
||||
SendPasswordPage();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(StringStartsWith(nameOfFileToSend, "html404.htm"))
|
||||
{
|
||||
Send404Page();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Webserver::SendFile(char* nameOfFileToSend)
|
||||
{
|
||||
if(!gotPassword)
|
||||
{
|
||||
sendTable = false;
|
||||
nameOfFileToSend = PASSWORD_PAGE;
|
||||
} else
|
||||
sendTable = true;
|
||||
|
||||
platform->SendToClient("HTTP/1.1 200 OK\n");
|
||||
|
||||
|
@ -406,8 +178,8 @@ void Webserver::SendFile(char* nameOfFileToSend)
|
|||
|
||||
platform->SendToClient('\n');
|
||||
|
||||
if(InternalFile(nameOfFileToSend))
|
||||
return;
|
||||
// if(InternalFile(nameOfFileToSend))
|
||||
// return;
|
||||
|
||||
//Serial.print("File requested: ");
|
||||
//Serial.println(nameOfFileToSend);
|
||||
|
@ -415,10 +187,14 @@ void Webserver::SendFile(char* nameOfFileToSend)
|
|||
fileBeingSent = platform->OpenFile(nameOfFileToSend, false);
|
||||
if(fileBeingSent < 0)
|
||||
{
|
||||
InternalFile("html404.htm");
|
||||
return;
|
||||
sendTable = false;
|
||||
nameOfFileToSend = "html404.htm";
|
||||
fileBeingSent = platform->OpenFile(nameOfFileToSend, false);
|
||||
}
|
||||
|
||||
inPHPFile = StringEndsWith(nameOfFileToSend, ".php");
|
||||
if(inPHPFile)
|
||||
initialisePHP();
|
||||
writing = true;
|
||||
}
|
||||
|
||||
|
@ -435,6 +211,277 @@ void Webserver::WriteByte()
|
|||
}
|
||||
|
||||
|
||||
void Webserver::initialisePHP()
|
||||
{
|
||||
phpTag[0] = 0;
|
||||
inPHPString = 0;
|
||||
phpPointer = 0;
|
||||
phpEchoing = false;
|
||||
phpIfing = false;
|
||||
phpPrinting = false;
|
||||
eatInput = false;
|
||||
recordInput = false;
|
||||
phpRecordPointer = 0;
|
||||
phpRecord[phpRecordPointer] = 0;
|
||||
ifWasTrue = true;
|
||||
}
|
||||
|
||||
char Webserver::PHPParse(char* phpString)
|
||||
{
|
||||
if(!strcmp(phpString, "if("))
|
||||
return PHP_IF;
|
||||
|
||||
if(!strcmp(phpString, "echo"))
|
||||
return PHP_ECHO;
|
||||
|
||||
if(!strcmp(phpString, "print("))
|
||||
return PHP_PRINT;
|
||||
|
||||
return NO_PHP;
|
||||
}
|
||||
|
||||
|
||||
boolean Webserver::printLinkTable() { boolean r = sendTable; sendTable = true; return r; }
|
||||
|
||||
boolean Webserver::callPHPBoolean(char* phpRecord)
|
||||
{
|
||||
if(!strcmp(phpRecord, "gotPassword("))
|
||||
return gotPassword;
|
||||
|
||||
if(!strcmp(phpRecord, "printLinkTable("))
|
||||
return printLinkTable();
|
||||
|
||||
platform->Message(HOST_MESSAGE, "callPHPBoolean(): non-existent function - ");
|
||||
platform->Message(HOST_MESSAGE, phpRecord);
|
||||
platform->Message(HOST_MESSAGE, "\n");
|
||||
|
||||
return true; // Best default
|
||||
}
|
||||
|
||||
char* Webserver::callPHPString(char* phpRecord)
|
||||
{
|
||||
if(!strcmp(phpRecord, "getMyName("))
|
||||
return myName;
|
||||
|
||||
if(!strcmp(phpRecord, "logout("))
|
||||
{
|
||||
gotPassword = false;
|
||||
return "<meta http-equiv=\"REFRESH\" content=\"0;url=passwd.php\"></HEAD>";
|
||||
}
|
||||
|
||||
platform->Message(HOST_MESSAGE, "callPHPString(): non-existent function - ");
|
||||
platform->Message(HOST_MESSAGE, phpRecord);
|
||||
platform->Message(HOST_MESSAGE, "\n");
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void Webserver::ProcessPHPByte(char b)
|
||||
{
|
||||
if(eatInput)
|
||||
{
|
||||
if(b == eatInputChar)
|
||||
eatInput = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(recordInput)
|
||||
{
|
||||
if(b == eatInputChar)
|
||||
{
|
||||
recordInput = false;
|
||||
phpRecordPointer = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
phpRecord[phpRecordPointer++] = b;
|
||||
if(phpRecordPointer >= PHP_TAG_LENGTH)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "ProcessPHPByte: PHP record buffer overflow.\n");
|
||||
initialisePHP();
|
||||
}
|
||||
phpRecord[phpRecordPointer] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(phpEchoing)
|
||||
{
|
||||
if(b != '\'')
|
||||
{
|
||||
if(ifwasTrue)
|
||||
platform->SendToClient(b);
|
||||
} else
|
||||
{
|
||||
initialisePHP();
|
||||
eatInput = true;
|
||||
eatInputChar = '>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(phpIfing)
|
||||
{
|
||||
boolean ifWas = callPHPBoolean(phpRecord);
|
||||
initialisePHP();
|
||||
ifWasTrue = ifWas;
|
||||
inPHPString = 5;
|
||||
if(b != ')')
|
||||
{
|
||||
eatInput = true;
|
||||
eatInputChar = ')';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(phpPrinting)
|
||||
{
|
||||
char* thingToSend = callPHPString(phpRecord);
|
||||
platform->SendToClient(thingToSend);
|
||||
initialisePHP();
|
||||
eatInput = true;
|
||||
eatInputChar = '>';
|
||||
return;
|
||||
}
|
||||
|
||||
if(inPHPString >= 5)
|
||||
{
|
||||
// We are in a PHP expression
|
||||
|
||||
if(isspace(b))
|
||||
return;
|
||||
phpTag[phpPointer++] = b;
|
||||
phpTag[phpPointer] = 0;
|
||||
if(phpPointer >= PHP_TAG_LENGTH)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "ProcessPHPByte: PHP buffer overflow: ");
|
||||
platform->Message(HOST_MESSAGE, phpTag);
|
||||
platform->Message(HOST_MESSAGE, "\n");
|
||||
initialisePHP();
|
||||
return;
|
||||
}
|
||||
|
||||
switch(PHPParse(phpTag))
|
||||
{
|
||||
case PHP_ECHO:
|
||||
phpEchoing = true;
|
||||
eatInput = true;
|
||||
eatInputChar = '\'';
|
||||
break;
|
||||
|
||||
case PHP_IF:
|
||||
phpIfing = true;
|
||||
recordInput = true;
|
||||
phpRecordPointer = 0;
|
||||
phpRecord[phpRecordPointer] = 0;
|
||||
eatInputChar = ')';
|
||||
break;
|
||||
|
||||
case PHP_PRINT:
|
||||
phpPrinting = true;
|
||||
recordInput = true;
|
||||
phpRecordPointer = 0;
|
||||
phpRecord[phpRecordPointer] = 0;
|
||||
eatInputChar = ')';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// We are not in a PHP expression
|
||||
|
||||
phpTag[inPHPString] = b;
|
||||
|
||||
switch(inPHPString)
|
||||
{
|
||||
case 0:
|
||||
if(b == '<')
|
||||
{
|
||||
inPHPString = 1;
|
||||
} else
|
||||
{
|
||||
phpTag[1] = 0;
|
||||
inPHPString = 0;
|
||||
platform->SendToClient(phpTag);
|
||||
}
|
||||
return;
|
||||
|
||||
case 1:
|
||||
if(b == '?')
|
||||
{
|
||||
inPHPString = 2;
|
||||
} else
|
||||
{
|
||||
phpTag[2] = 0;
|
||||
inPHPString = 0;
|
||||
platform->SendToClient(phpTag);
|
||||
}
|
||||
return;
|
||||
|
||||
case 2:
|
||||
if(b == 'p')
|
||||
{
|
||||
inPHPString = 3;
|
||||
} else
|
||||
{
|
||||
phpTag[3] = 0;
|
||||
inPHPString = 0;
|
||||
platform->SendToClient(phpTag);
|
||||
}
|
||||
return;
|
||||
|
||||
case 3:
|
||||
if(b == 'h')
|
||||
{
|
||||
inPHPString = 4;
|
||||
} else
|
||||
{
|
||||
phpTag[4] = 0;
|
||||
inPHPString = 0;
|
||||
platform->SendToClient(phpTag);
|
||||
}
|
||||
return;
|
||||
|
||||
case 4:
|
||||
if(b == 'p')
|
||||
{
|
||||
inPHPString = 5;
|
||||
phpTag[0] = 0;
|
||||
phpPointer = 0;
|
||||
} else
|
||||
{
|
||||
phpTag[5] = 0;
|
||||
inPHPString = 0;
|
||||
platform->SendToClient(phpTag);
|
||||
}
|
||||
return;
|
||||
|
||||
// Should never get here...
|
||||
|
||||
default:
|
||||
platform->Message(HOST_MESSAGE, "ProcessPHPByte: PHP tag runout.");
|
||||
platform->SendToClient(b);
|
||||
initialisePHP();
|
||||
}
|
||||
}
|
||||
|
||||
void Webserver::WritePHPByte()
|
||||
{
|
||||
unsigned char b;
|
||||
if(platform->Read(fileBeingSent, b))
|
||||
ProcessPHPByte(b);
|
||||
else
|
||||
{
|
||||
platform->Close(fileBeingSent);
|
||||
initialisePHP();
|
||||
CloseClient();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Parse a string in clientLine[] from the user's web browser
|
||||
|
@ -456,6 +503,9 @@ void Webserver::ParseClientLine()
|
|||
if(!StringStartsWith(clientLine, "GET"))
|
||||
return;
|
||||
|
||||
Serial.print("HTTP request: ");
|
||||
Serial.println(clientLine);
|
||||
|
||||
int i = 5;
|
||||
int j = 0;
|
||||
clientRequest[j] = 0;
|
||||
|
@ -480,8 +530,9 @@ void Webserver::ParseClientLine()
|
|||
clientQualifier[j] = 0;
|
||||
}
|
||||
|
||||
|
||||
if(!clientRequest[0])
|
||||
strcpy(clientRequest, "index.htm");
|
||||
strcpy(clientRequest, "control.php");
|
||||
}
|
||||
|
||||
void Webserver::CheckPassword()
|
||||
|
@ -490,7 +541,7 @@ void Webserver::CheckPassword()
|
|||
return;
|
||||
|
||||
gotPassword = true;
|
||||
strcpy(clientRequest, "index.htm");
|
||||
strcpy(clientRequest, "control.php");
|
||||
}
|
||||
|
||||
|
||||
|
@ -498,13 +549,17 @@ void Webserver::ParseQualifier()
|
|||
{
|
||||
if(!clientQualifier[0])
|
||||
return;
|
||||
|
||||
if(StringStartsWith(clientQualifier, "pwd="))
|
||||
CheckPassword();
|
||||
if(!gotPassword) //Doan work fur nuffink
|
||||
return;
|
||||
|
||||
if(StringStartsWith(clientQualifier, "gcode="))
|
||||
{
|
||||
if(!LoadGcodeBuffer(&clientQualifier[6], true))
|
||||
platform->Message(HOST_MESSAGE, "Webserver: buffer not free!");
|
||||
strcpy(clientRequest, "index.htm"); // FIXME
|
||||
strcpy(clientRequest, "control.php"); // FIXME
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -515,7 +570,10 @@ void Webserver::spin()
|
|||
|
||||
if(writing)
|
||||
{
|
||||
WriteByte();
|
||||
if(inPHPFile)
|
||||
WritePHPByte();
|
||||
else
|
||||
WriteByte();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -524,7 +582,7 @@ void Webserver::spin()
|
|||
if (platform->ClientStatus() & AVAILABLE)
|
||||
{
|
||||
char c = platform->ClientRead();
|
||||
Serial.write(c);
|
||||
//Serial.write(c);
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so you can send a reply
|
||||
|
|
Reference in a new issue