December 6, 201411 yr I'm attempting to convert one of my older plugins to work with beta12. When I try to invoke the settings, the following error is displayed below the settings page banner, which reads "TFTP Server": Parse error: syntax error, unexpected '=' in /usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php(274) : eval()'d code on line 5 As far as I can determine, the error is being reported on the $tftp-hpa_cfg = parse_ini_file( "/boot/config/plugins/tftp-hpa/tftp-hpa.cfg"); line in the following snippet from my .plg file: <FILE Name="/usr/local/emhttp/plugins/&name;/Tftp-hpa.page"> <INLINE> <![CDATA[ Title="TFTP Server" Menu="NetworkServices" Icon="tftp-hpa.png" Version="2014.12.06" Author="Peter Bell" --- <?php shell_exec('php /usr/local/emhttp/plugins/tftp-hpa/Tftp-hpa.php'); ?> ]]> </INLINE> </FILE> <!-- Here is the PHP code for the tftp-hpa webGui configuration page. This is a simple page that defines a couple controls for the user and indicates whether tftp-hpa is running or not. It also illustrates the method by which the control script can be invoked by emhttp, and the use of javascript to dynamically enable/disable form elements. --> <FILE Name="/usr/local/emhttp/plugins/tftp-hpa/Tftp-hpa.php"> <INLINE> <![CDATA[ <?PHP $tftp-hpa_cfg = parse_ini_file( "/boot/config/plugins/tftp-hpa/tftp-hpa.cfg"); $tftp-hpa_running = file_exists( "/var/run/tftp-hpa/tftp-hpa.pid") ? "yes" : "no"; ?> I'm not familiat with php, so can anyone suggest what might be causing the error.
December 6, 201411 yr It is recommended to use the function parse_plugin_cfg(<plugin-name>) to read the settings file. Your example would look like: $tftp-hpa_cfg = parse_plugin_file("tftp-hpa"); To write settings use the update.php action method in a form statement, for example: <form markdown="1" name="tftp_hpa_settings" method="POST" action="/update.php" target="progressFrame"> <input type="hidden" name="#file" value="tftp-hpa/tftp-hpa.cfg"> There is problably a syntax error in your current PHP file (maybe a missing ';' character), but it can not be determined from your snippet.
December 7, 201411 yr Author Thanks for the responses - much appreciated. Okay, I'll post the entire php - it's not very long. This old FORTRAN hack is a little embarassed because, while he understands the rudiments of html, he's made no efforts to learn php and simply borrows/adapts code from other plugins. I am a little surprised at the suggestion that the problem may be caused by a syntax error further down the code - can an error there reflect back to an earlier statement? I identified the statement where the error is reported simply by adding blank lines in the file and watching whether the line number, reported in the error, changes. As you can see, the code I've borrowed from does use update.php to write the settings: <FILE Name="/usr/local/emhttp/plugins/&name;/Tftp-hpa.page"> <INLINE> <![CDATA[ Title="TFTP Server" Menu="NetworkServices" Icon="tftp-hpa.png" Version="2014.12.06" Author="Peter Bell" --- <?php shell_exec('php /usr/local/emhttp/plugins/tftp-hpa/Tftp-hpa.php'); ?> ]]> </INLINE> </FILE> <!-- Here is the PHP code for the tftp-hpa webGui configuration page. This is a simple page that defines a couple controls for the user and indicates whether tftp-hpa is running or not. It also illustrates the method by which the control script can be invoked by emhttp, and the use of javascript to dynamically enable/disable form elements. --> <FILE Name="/usr/local/emhttp/plugins/tftp-hpa/Tftp-hpa.php"> <INLINE> <![CDATA[ <?PHP $tftp-hpa_cfg = parse_ini_file( "/boot/config/plugins/tftp-hpa/tftp-hpa.cfg"); $tftp-hpa_running = file_exists( "/var/run/tftp-hpa/tftp-hpa.pid") ? "yes" : "no"; ?> <!-- When this form is submitted, emhttp will see a GET request like this: "GET /update.htm?cmd=/etc/rc.d/rc.tftp-hpa&arg1=enable&arg2=/usr/local/tftp-hpa&runCmd=Apply" (Actually arg1 can be 'enable' or 'disable' and arg2 is the directory in the form box, provided the field is not disabled.) The 'runCmd=Apply' tells emhttp to run the command given by 'cmd' with arguments 'arg1', 'arg2', ... In this case it will run: "/etc/rc.d/rc.tftp-hpa enable /usr/local/tftp-hpa" The output of this command will show up in the 'progress frame' of the webpage. We have thus constructed the form to control tftp-hpa via the rc.tftp-hpa script. --> <? if ($tftp-hpa_running=="yes"): ?> <p class=ContentTitle>tftp-hpa Server is running</p> <? endif; ?> <form name="tftp-hpa_settings" method="POST" action="/update.htm" target="progressFrame"> <input type="hidden" name="cmd" value="/etc/rc.d/rc.tftp-hpa"> <table class="settings"> <tr> <td>Enable tftp-hpa:</td> <td><select name="arg1" size="1"> <?=mk_option($tftp-hpa_cfg['SERVICE'], "disable", "No");?> <?=mk_option($tftp-hpa_cfg['SERVICE'], "enable", "Yes");?> </select></td> </tr> <tr> <td></td> <td><input type="submit" name="runCmd" value="Apply"> <button type="button" onClick="done();">Done</button> </td></tr> </table> </form> ]]> </INLINE> </FILE>
December 7, 201411 yr Author I believe it's the class= ContentTitle should be class="ContentTitle" Thanks for the advice - I'm sure that using the quotes is, strictly, correct. However, the error still occurs, and it's reported against the $tftp-hpa_cfg = parse_ini_file( "/boot/config/plugins/tftp-hpa/tftp-hpa.cfg"); line. I tried a little experiment ... I deleted everything within the <?PHP><?> tags, and the statements dependant on them - the if/endif and the mk_option lines. The php then runs cleanly (although, functionally, broken). I still conclude, therefore, that the parse error is occuring on the two lines within the <?PHP><?> tags. I now realise/remember that the code I've borrowed comes from Tom's original LogitechMediaServer specimen .plg file (no quotes on ContentTitle!). I'll go and do a closer comparison between the original and my tftp code. Edit to add: Closer inspection has not identified any error introduced between original and copy. Further, I know that my tftp-hpa plugin has been working on v5 and earlier v6 betas - I've only had to modify it now because of the new .page/.php file concatenation. So, I'm pretty well convinced that identical code worked in earlier releases of unRAID and it has only started to fail recently. I only created my tftp-hpa plugin on April 6 this year, and it worked then (and more recently). Could it be that this code is incompatible with the newly introduced parsing in dynamix?
December 7, 201411 yr this is plugin for tftp unraid http://pastebin.com/M3zY5Ui9 (source code) Screen - https://www.dropbox.com/s/elg7r4b6gq7lqdb/Zrzut%20ekranu%202014-12-07%2008.04.01.png?dl=0 for beta12 add this to go file - to fix webui of this plugin echo "" >> /usr/local/emhttp/plugins/tftp/tftp.page echo "---" >> /usr/local/emhttp/plugins/tftp/tftp.page echo "" >> /usr/local/emhttp/plugins/tftp/tftp.page cat /usr/local/emhttp/plugins/tftp/tftp.php >> /usr/local/emhttp/plugins/tftp/tftp.page rm -f /usr/local/emhttp/plugins/tftp/tftp.php sed -i 's!\r!!g' /usr/local/emhttp/plugins/tftp/tftp.page
December 7, 201411 yr Author Hi, I guess that you're the same piotrasd as on the TBSDTV forum? this is plugin for tftp unraid http://pastebin.com/M3zY5Ui9 (source code) Screen - https://www.dropbox.com/s/elg7r4b6gq7lqdb/Zrzut%20ekranu%202014-12-07%2008.04.01.png?dl=0 for beta12 add this to go file - to fix webui of this plugin echo "" >> /usr/local/emhttp/plugins/tftp/tftp.page echo "---" >> /usr/local/emhttp/plugins/tftp/tftp.page echo "" >> /usr/local/emhttp/plugins/tftp/tftp.page cat /usr/local/emhttp/plugins/tftp/tftp.php >> /usr/local/emhttp/plugins/tftp/tftp.page rm -f /usr/local/emhttp/plugins/tftp/tftp.php sed -i 's!\r!!g' /usr/local/emhttp/plugins/tftp/tftp.page I've already made mine fully compatible with the new plugin manager, which this version isn't. I see that the ww version uses a very similar construct in the php so, I'm guessing that it will suffer exactly the same problem as mine does when converted to the new .page/.php combined file, using that additional script in the go file. Still, I'll give it a go and see how I get on - thanks.
December 7, 201411 yr Author Okay, I've found a solution to my problem. The parser cannot cope with hyphens in the two defined names ... if I change $tftp-hpa $tftp_hpa in these two lines: $tftp-hpa_cfg = parse_ini_file( "/boot/config/plugins/tftp-hpa/tftp-hpa.cfg"); $tftp-hpa_running = file_exists( "/var/run/tftp-hpa/tftp-hpa.pid") ? "yes" : "no"; , and in the three susequent references, then my code works. As far as I am aware, the names as I had them originally, are perfectly legal php, so it is my belief that the parsing is broken.
December 7, 201411 yr No, the minus sign is not allowed in a variable name, because PHP treats that as a substraction action, in other words, it tries to do: $tftp - hpa_cfg As you indicated yourself, replace it with an underscore and it is fine. The newer PHP version 5.4 in unRAID gives much better error reporting than the old version 5.2 did, you can also say; the newer version is much stricter .
December 7, 201411 yr Author No, the minus sign is not allowed in a variable name, because PHP treats that as a substraction action, in other words, it tries to do: $tftp - hpa_cfg As you indicated yourself, replace it with an underscore and it is fine. The newer PHP version 5.4 in unRAID gives much better error reporting than the old version 5.2 did, you can also say; the newer version is much stricter . Well, it used to work okay! ... but thanks for confirming that it's not legal!
Archived
This topic is now archived and is closed to further replies.