replace windows cmd call to .bat for and web based GUI? - javascript

to upload new changes into our server i have to type something like
uploadTemplates.bat templateid userid password integrationorProductionVar + ENTER
Thas fine but first i need to navigate to the folder where the .bat is,
Question is: can i change all this for a more automatized GUI?? if so, how?
for example a Form asking
user, pass, templateid and integrationorPrdoductionVar (as a select) and it opens the .bat on the background ?

Well, you could do it in PHP if the PHP server runs on the machine where the .bat file is. In order to call a shell command, you can use system:
system("uploadTemplates.bat {$_POST['templateid']} {$_POST['userid']} {$_POST['password']} {$_POST['integrationorProductionVar']}");
Note that since this should run on the same system and is only to be used by you, you can get away with not sanitize your data, but normally, you want to escape your shell arguments with escapeshellarg and do as much checking as possible so that someone can't exploit this and run malicious commands on the system.

I'm presuming by this question you don't have much in the way of coding experience. JavaScript isn't a language that'll be much use for this.
Download yourself a copy of Visual Express and depending on how brave you're feeling, download either Visual Basic or C# and look at a couple of tutorials.
What you're after is very basic to implement and even without any experience at all would take you under an hour to create I reckon.

Related

Hide source code of Electron alteast 1 file.. Possible?

Hey so i started using Electron becouse of HTML/CSS/JS possibilites.
I have expirience mostly with PHP and some little with JS.
Was searching how to hide files of Electron (becouse .asar file can be unpacked) and its just stupid to put my MySQL server info in .js file and let users see that info..
Is there any way to hide atleast 1 .js file where i would put all necessery stuff like mysql connection and mysql managing?
I googled a lot about that some people say that Node.JS can to that but i cant find anywhere how to exacly do it?
Tried to switch to CEFSharp but cant realise how to interact between C# and Webpage (used webserver for template and php stuff but like how to tell C# that variable of A is A and use that C# variable for something)..
Hope somebody will help me, maybe its dumb question for some expirienced developers but i mostly work in PHP and i wanna learn new stuff..
Thanks!
Long story in short - no. In deep down, any code you ship in client to users should be considered to be revealed, just matter of how hard will it be. Instead of shipping important credential and obfuscate to not able to read it, application should be designed to be safe even if user reads whole code in client.
I'm not really any sort of expert on Electron. I'll assume that you will either create a login or a config file. In the first case you can use the database to determine if access is allowed. If you don't want to setup a login script then you can use a config.json file that is not part of the build file. There are a few node packages you can use - I believe one is "electron-storage" to help with the access to the database. Hope this helps.
Johnf

Is there any way to edit a local file through a web page without running server software?

I've a web working on a web page that's basically just a big table of links. I use javascript to read from a text file, parse it, and create a table based on that.
I'd like to be able to have a button on the page to add new a row of links and add them to the text file (or another file type if it's better).
I know you can accomplish this with php, node.js, and others, but all the methods I've found require server software to be running. Is there any way around this? For example, is there a way to use javascript to call a python script, or any other way?
The page is just for personal use, so I'd like to avoid running server software just to use it if possible. I know you can set it to download a text file, and you can save it in the same location, but I'd also like to avoid that.
From the research I've done, it doesn't seem possible, but I just thought I'd ask before I give up. Thanks in advance.
You can only read from files locally in browser with javascript.
This would be a huge security vulnerability if scripts in browsers could write files to your machine.

Possible Autoit-like JavaScript macros?

The title says it all. Is there a way to write macros in JavaScript to achieve a similar functionality to that of Autoit? I just would want to manipulate files on my own computer (offline) and could easily do it with autoit, but since I am currently learning JavaScript -- plan to develop in Node.js -- I figure it wouldn't hurt to get the extra practice.
Thanks guys!
Use an application which supports JavaScript as a shell scripting language, such as the following:
JsRoboKey
PowershellJS
PowerChakra
RemoteNodeJS
JScript + WSH
JavaScript Shell Scripting with JSC
QtScript: QScriptEngine
Part I: How to Choose a JavaScript Engine for iOS and Android Development - OpenAphid-Engine
nodejs has a module which do autoit things --
nodejs install autoit
var au = require('autoit');
au.Init();
au.Run("notepad.exe");
au.WinWait("[Class:Notepad]");
au.Send("Hello, autoit & nodejs!");
NodeJS is a very powerfull platform, it is extensible and opensource.
There is no problem to run local scripts to do everything you need using JavaScript (see standard FileSystem library docs). You can also try to look in NPM(NodeJS package manager).
Assuming you have AutoIt installed (say in folder C:\AU3) and this folder in the PATH, you can add
extension '.AU3' to the PATHEXT environment variable, and create an AutoIt script called, say,
hello.au3 with just a silly line:
MsgBox(0, "Warning", "Hello, World!")
Now, simply typing the command 'hello' will execute the script, displaying the silly message in a modal message box.
Next, create an equally silly Node.js script, say, MyWarn.js - in the same folder:
var oCP = require("child_process");
console.log("Starting...");
var oNP = oCP.execSync("hello");
console.log("Done.");
Assuming Node is also in the PATH, try this command:
node MyWarn
So ... we get the benefits of Node (for its jit), and the benefits of AutoIt (for its GUI handling.)
The problem is getting the two to communicate. Personally, I use a RamDisk to pass small files...
Javascript can't write to a file on your local machine remotely.. Its almost the same as HTML in a view model.
It can however perform some executions of other scripts via AJAX for example. But thats on server again.
It might be worth a look to read on server && client side differences.
im not 100% sure but node might offer another outlet on this but it would still be server side.. Not locally.
The Server - This party is responsible for serving pages and handling the logic | Code behind.
The Client - This party requests pages from the Server, and displays them to the user. On most cases, the client is a web browser.
The User - The user uses the Client in order to surf the web, fill in forms, watch videos online, etc.

Can I save a file which will be generated from php code on server side using only javascript/C/C++ and no browser opened?

What is the best way to save a file from internet on javascript and/or C and/or even C++?
I saw this same question for C# and Java, but nothing to this three languages, so here is the question.
Hey, not so easy. The url point to some http://xx.xxxx.com/p.php?pid=staticetctectc....
I guess is php code which produce a nice gif in my browser. I just want to save this gif. Without opening browser. It is possible to do with javascript/C/C++?
Most near answer I found is this.
Thanks in any advice.
You can easily do this with JavaScript using Node.js. Here is a link to an example: http://www.hacksparrow.com/using-node-js-to-download-files.html
You could also do it from the command line using wget or curl. They are both available on pretty much every platform you can imagine.
For C++, you could do it like in Downloading File in Qt From URL. If you do not want to depend on Qt, libcurl is also an option.
For JavaScript, the method described in File Download Using JavaScript should work.

Is it possible to use a web page as a user interface to a program written in python, running locally, without a web server?

I have a program written in python, and I would like to make it easy to enter parameter values for this program through a GUI. I realise that I could create a GUI using python tools, but I am interested in using a html / javascript page and have the javascript code call my python script when the user clicks a button to run. Something like;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "../scripts/python_script.py", true);
xmlhttp.send();
Currently, when I do that, I just get back the text in the python script, but it doesn't actually run. Ideally the python script would run in the background without blocking further input to the web page, and as the script produces it's different result files (png images), these would be displayed in the browser. Clearly, I could do this using a web server (and I may end up doing this eventually anyway, hence the html interface), but I am wondering if it is possible to do so without one. That way I could package the html page and the python script together and give them to someone who could then go and run the program on their computer without needing to start a web server. Is this possible?
If it is not, is there an alternative way do achieve a similar result? Could I embed a small server into a python script that displays the html page when it starts up, and then responds to an XMLHttpRequest to start the python script? If I did this, would the user have to start the script, and then go to the specified address in their browser as a separate action?
EDIT: I got a quick solution working using SimpleHTTPServer, but I had a look at bottle and I'll probably try something using that as well. Thanks for your help.
First of all, using something like bottle it is pretty simple to make a web server to run your script. Look at http://bottlepy.org/docs/dev/
A good starting point is the code at http://bottlepy.org/docs/dev/tutorial.html#http-request-methods but you would put up a form asking for parameters rather than a login form. Then just run your Python script, capture the output and send it back in the return statement.
This question Capture subprocess output shows you two ways to run your main script depending on whether you want to show the output progressively or all at the end.
You'd need to bundle some kind of webserver with the application. If it is not intended for deployment I would go for something like bottle.py. It's a micro web framework that has its own development server. Other micro/mini frameworks probably pack their own webserver with them for development purposes (web2py, flask, ..).
If you want something more serious you'd probably need some better web server. If that's the case - have a look at this reddit discussion.

Categories