NodeMCU enduser setup module html file that creates another file - lua

I have created my own enduser_setup.html file nodemcu(for the enduser setup module: https://nodemcu.readthedocs.io/en/master/en/modules/enduser-setup/#enduser_setupstart).
I have added another field (beyond the ssid\password fileds):
<input id=result1 type=text autocorrect=off autocapitalize=none placeholder='Place ID' />
I want on submit to create a lua file (result1.lua) with the Get result of this field.
Tried with php:
<?php
$myfile = fopen("result1.lua", "w") or die("Unable to open file!");
$txt = $_GET["result1"];
fwrite($myfile, $txt);
fclose($myfile);
?>
Did not work :(

That is currently not possible with NodeMCU. However, there is a pending pull request that'll add this feature. It's likely going to be merged to the dev branch in the next days.

Related

Upload file using Jenkins Active Choices Reactive References plugin

I am using Jenkins Active Choice plugin. I want to provide a file upload function based on reference variable
The below setting allows me to enter text when i select reference parameter scan_type as vulnerability-Web
What i want is , instead of taking text input it should upload file , and content of the file should be assigned to SELENIUM_RECORDED_FILE
I tried using below groovy
if (scan_type.equals("Vulnerability-Web")) {
inputBox = "<body> <form action='upload.php' method='post' enctype='multipart/form-data'> Select file to upload: <input type='file' name='fileToUpload' id='fileToUpload'> </form>"
return inputBox
}
its adding file upload option but the file content is not stored in SELENIUM_RECORDED_FILE
Please let me know how can we achieve this
Reading through HERE, it looks like you must have
<input type="file" name="file">

doPost not working in Google app script

I came across various questions but none of them could solve my problem. I wrote a simple doPost() code in google app script:
function doPost(e){
Logger.log("Hello World");
}
Then I deployed it as a web app and pasted the url on hurl.it to make a post request. However, there is nothing being logged in the log and the response is 200 (Ok). I think it is not going inside this doPost() function. Can anyone guide as to what am I doing wrong here?
Your implementation does not meet all the requirements needed for a web app. Here's an excerpt from the documentation (link):
Requirements for web apps
A script can be published as a web app if it meets these requirements:
It contains a doGet(e) or doPost(e) function.
The function returns an HTML service HtmlOutput object or a content service TextOutput object.
Here are some examples:
function doGet(e) {
var params = JSON.stringify(e);
return HtmlService.createHtmlOutput(params);
}
function doPost(e) {
return ContentService.createTextOutput(JSON.stringify(e.parameter));
}
And just for completeness, you must also redeploy your web App as a new version every time you make changes to the code. Redeploying under an already existing version does not work, you have to make a new version for your changes to take hold.
Also using the standard Logger.log to trace changes within doGet(e) or doPost(e) is unreliable with web apps as they are executed asynchronously. I would recommend logging your output to a spreadsheet. There is an awesome script library called BetterLog that extends the Logger API to do just that; it can be found at the following link:
https://github.com/peterherrmann/BetterLog
UPDATE 2018-07-18
Apps Script now supports StackDriver Logging which is accessible from the Apps Scripts editor's View menu.
in order for the "exec" version of the published Web App URL to run with any new changes, you must publish a new version every time that you make a change to your script. It does not matter how small the change is. Instead of using Logger.log("Hello World"); I would write a value to a spreadsheet.
SpreadsheetApp.openById(id).getSheetByName(name).appendRow(['test']);
There are 2 different URL's for your Web App. One with 'dev' on the end and the other with 'exec' on the end. The 'dev' version is always the current code. The 'exec' version never changes unless you publish a new version.
I struggled with this for AWHILE NOW and I finally got lucky.
I use w3schools alot so I read fully on the form element and its attributes.
The ACTION attribute seems to be the key in getting doPost(e) to work for me and GAS.
Here's my HTML (removed opening and closing angle brackets)
<form
action="https://script.google.com/a/[org]/macros/s/[scriptID]/exec"
method="post" target="_blank" >
First name: input type="text" name="fname"<br>
Last name: input type="text" name="lname"<br>
input type="submit" value="Submit"
</form>
Here's my doPost ( the Logger ran as well as the new window displaying e.parameter)
function doPost(e){
Logger.log("I WAS RAN!!")
if(typeof e !== 'undefined') {
return ContentService.createTextOutput(JSON.stringify(e.parameter));
}
}
One of the reason can be you are using a Rest client like Postman. It won't work, though I don't know the reason why.
Try with a normal form like this and it will work:
<!DOCTYPE html>
<html>
<body>
<form action="https://script.google.com/macros/s/AKfyc.../exec">
First name:<br>
<input type="text" name="param1" value="ABC">
<br>
Last name:<br>
<input type="text" name="param2" value="XYZ">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

PHPEXCEL weird characters on form inputs

I need some help with PHPEXCEL library, everything works great, I'm successfully extracting my SQL query to excel5 file, I need to give this file to transport company in order to auto collect informations about packages, unfotunately the generated excel file has some ascii characters between each letter of the cell text, and when the excel file is imported you need to manually delete these charaters.
If I open the excel file, everything is fine I see: COMPANY NAME, If I open the excel file with notepad++, I see the cell values this way: C(NUL)O(NUL)M(NUL)P(NUL)A(NUL)N(NUL)Y N(NUL)A(NUL)M(NUL)E
If I open again the file with excel and save, then reopen with notepad++ I see COMPANY NAME.
So I do not understan why every time I create an excel file using PHPEXCEL my every letter of all words are filled with (nul) every letter.
So how do I prevent the generated excel file to include (nul) between every word????
Also if you open the original excel file generated from PHPExcel samples are also filled with (nul) and if you open and save it, the (nul) is gone.
Any help would be appreciated, thanks.
what is the (nul) ??? 0x00??? char(0)???
ok, here is the example:
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli')
die('Disponibile solo su browser');
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Solidus")
->setLastModifiedBy("Solidus")
->setTitle("Import web")
->setSubject("Import File")
->setDescription("n.a")
->setKeywords("n.a")
->setCategory("n.a");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValueExplicit("A1", "COMPANY")
->setCellValue('A2', 'SAMSUNG');
$objPHPExcel->getActiveSheet()->setTitle('DDT');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="TEST.xls"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Cache-Control: private',false);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_end_clean();
$objWriter->save('php://output');
As you can see from this little example, this scripts creates a file excel5 with 2 cells, A1 = COMPANY, A2 = SAMSUNG
when I send this file to the transport company, they import the file into their system, but as you can see from the picture, there is an weird character between each letter.
so I noticed every time I open the generated Excel5 with notepad++ file I get:
S(nul)A(nul)M(nul)S(nul)U(nul)N(nul)G
If I save the save with excel and then open it again with notepad++ I get:
SAMSUNG
and this file is ok for the transport company
so my question is, how should I avoid the file generated to contain thi '(nul) charachter between each letter????
some help?
weird characters
SAMSUNG
I found the soluion by myself, I explain just in case anyone has also this problem:
there is not way to change the way the excelfile is encoded by PHPEXCEL
so I figured out the problem was reading the file, I did some simulations and reproduce the problem, every time a read the file and put the result into inputs a get weird characters:
C�O�M�P�A�N�Y�
If I set the output enconding enconding as follows:
$excel->setOutputEncoding('UTF-8');
the file loads fine, so the problem was not creating the excel file, but reading the excel file.
If I print the variable with ECHO I get: "COMPANY",
if I put the variable on input as value I get: "C�O�M�P�A�N�Y�"
setting the output solves the problem, but I would like to know why the difference when I put the variable on input as value, thanks

Testing HTML5 File Upload with Capybara/Selenium Webdriver - Ruby

I have a simple modal that appears in which the user is shown the browse button to add the file to upload. Due to an unknown issue, be it the fact its an HTML5 file input therefore the browser adds its own functions to it, this has become a pain to test.
On my page I have:
<input type="file" id="photo_upload">
Capybara offers a solution out of the box which is:
attach_file <<upload_file_id>>, <<file_path>>
This behind the scenes executes a send_keys command to push the file_path into the path container for this input, however this simply did not work with my setup. I am running Firefox 25.0.1 on Windows 8. I tried both a relative path and a full path to this file, with forward and backslash combinations.
When I mean it did not work, I mean when my ajax script executes from clicking the button 'upload' next to it, it does not send any file object in the params.
I even tried to use capybara to send the file path directly:
find_field(<<upload_file_id>>).native.send_keys(<<file_path>>)
Next up, was to attempt to use selenium to push it in using:
element = driver.find_element(:id, <<upload_file_id>>)
element.send_keys <<file_path>>
Then I tried executing script to ensure the element was visible, and then setting it:
element = page.execute_script(
"document.getElementById('#{<<upload_file_id>>}').style.visibility = 'visible';
document.getElementById('#{<<upload_file_id>>}').style.height = '20px';
document.getElementById('#{<<upload_file_id>>}').style.width = '60px';
document.getElementById('#{<<upload_file_id>>}').style.opacity = 1; return
document.getElementById('#{<<upload_file_id>>}')")
find_field(field_locator).native.send_keys(<<file_path>>)
This didn't work either. Now I am completely stuck. All the help on here and google points to using the above, but it just simply does not work for my setup.
My options as far as I can see it are to use a windows automation script and jump out of capybara, run the script, and then continue, or to directly call the upload url either from capybara using a post or calling the js ajax that currently does it.
So I have solved it, and its not too ugly. I used the automation route via AutoIT. The bundle you download with AutoIT includes a script to exe converter and using the below script (I can not take credit for the script) I created an exe:
Local Const $dialogTitle = $CmdLine[2]
Local Const $timeout = 5
Local $windowFound = WinWait($dialogTitle, "", $timeout)
$windowFound = WinWait($dialogTitle, "", $timeout)
Local $windowHandle
If $windowFound Then
$windowHandle = WinGetHandle("[LAST]")
WinActivate($windowHandle)
ControlSetText($windowHandle, "", "[CLASS:Edit; INSTANCE:1]", $CmdLine[1])
ControlClick($windowHandle, "", "[CLASS:Button; TEXT:&Open]")
Else
MsgBox(0, "", "Could not find window.")
Exit 1
EndIf
In my capybara script, I merely run:
find_field(<<upload_file_id>>).click
system("<<full_path>>\\file_upload.exe \"#{<<file_path>>}\" \"File Upload\"")
and it works perfectly! In fact, I think I prefer the fact it exactly mimics what a user would be doing.

Expression Engine PHP & Embed & entry_id_from

I have the following line in a file that is building up a PHP array and writes it in a txt file on server.:
{exp:channel:entries channel="orders" entry_id_from="{embed:LAST_ID}" sort="desc" dynamic="no"}
AND another file that needs to take an id from database and THIS FILE must be embedded into the ACTION FILE ( the one with the line above ) and the ID to be put into the entry_id_from
LAST_ID file:
<?
include '!mysql.php';
$last_id = #mysql_result(mysql_query('SELECT comanda_id_end FROM output_comenzi ORDER BY id DESC'),0);
if(!$last_id) $last_id = 0;
echo $last_id;
?>
How can I make that the LAST_ID file to get PARSED, take the value and insert it into entry_id_from file? I want to somehow embed The Parsed Mysql File into the ARRay File.
Please help :)
Edited to make this work for PHP on output:
I double checked the EE parse order and it looks like you can make this work with EE parsing on output, but I am not 100% certain.
LAST ID File ('template_group/LAST_ID' EE template). Set to parse PHP on output (per your requirement).
<?
include '!mysql.php';
$last_id = #mysql_result(mysql_query('SELECT comanda_id_end FROM output_comenzi ORDER BY id DESC'),0);
if(!$last_id) $last_id = 0;
?>
// call our embedded template and pass our EE variable forward
{embed="template_group/EXPORT_ACTION_FILE" LAST_ID="<? echo $last_id; ?>"}
Your other file ('template_group/EXPORT_ACTION_FILE' EE template):
{exp:channel:entries channel="orders" entry_id_from="{embed:LAST_ID}" sort="desc" dynamic="no"}

Resources