How to change computer setting remotely - javascript

I would like to setup a web server on my HTPC that I can use to handle various tasks such as changing the default audio output or adjusting the display to output to only one screen without having to actually touch the machine.
While I understand the actual programming may be difficult itself, my main focus is learning how one can go about handling various events. I have initially set up a IIS server and created a site to handle all the events on my HTPC. The site is only accessible through the intranet and knowledge of the specific port. Ideally, the solution would be that you access the HTPC local ip address with the specified port and are presented with options(buttons) to either set default audio device, display etc. (This will probably involve some html programming but it is feasible to leverage a java script or is asp.net the language I should write in)
Any help would be appreciative as I know its possible to set up a server to handle events/requests - I just don't know where to begin or what to start reading up on.

if it can be done via the command line, generally it can be done via asp (on the server).
you need to give the application pool that the website will be running under permissions on your computer to be able to carry out the tasks (if you're lazy and don't care about security make it run as you)
you then simple need to write a process that starts up either a cmd process or powershell instance in the button click event handler.
For powershell, i've followed Jeff Murrs example in the past and had success.
For command line processes it is similar but you use System.Diagnostics.Process.
This should be enough for you to research and hopefully get something

Related

Client side scripting VS server side code

I am new to this field. If I want to hide parts of my webpage, should I use client side scripts of server side codes (or both)?
Because one of the teachers told me that you can't only rely on Javascript, because people can prevent Javascript by using "Do not allow any site to run Javascript".
If the data is sent to the client, the client will always have a way to see it. For example, JavaScript enabled or not, you can always open Chromes developer console and inspect the document, or pick view source from the main menu.
The only way to keep information from a client is to not send it to them in the first place. This has to be done server side.
Still, you should seriously consider asking yourself if you have anything truly worth hiding. For the most part, silly, inexplicable attempts to hide page source just leads to massive user inconvenience, like disabling context menus and such, and never actually works. Never understood why folks thought that was a good idea.
On the other hand, things like authentication and authorization, database interaction, etc. you would want or have to do server side.
As for generating actual content, just for presentation not for the purpose of "hiding" things, generally it's a mix of both, the balance just depends on the application. You'll have to make the call during design and development.

Write PDF files from Web-App to USB-Stick

I am concerned with the feasibility of this:
On a pre-configured machine I will have a Web-Application pre-installed, next to an Apache-Suite. So client and server are the same!
In this Web-Application Users can drag and drop PDF-Files to an USB-Icon.
Then the Web-App should write the dropped PDF to an attached USB-Stick.
I have never done something like this (writing to USB), so I am fairly insecure.
And I am well aware of the browser-restrictions concerning JavaScript and Filesystem-Access, but...
after researching a bit I found out, that there might be some possible and
relevant (I'm a Web-Platform-Guy) solutions to this:
Make a "Chrome App" with USB-Permission (does this really work?)
Use PHP to find the USB and then write to it (how would that work under Windows?)
Use some Flash as middle man (not preferred)
Now I'd like to know:
Has anyone some good experience with before mentioned possibilities?
Has anybody ever done something similar? Did it work? Which path did you choose?
How would I know which drive the USB is mounted, and how would I get sure?
What other possible solutions to this problem are there?
You have a website ('client-side' user interface) and a back-end server ('server-side') running on the same machine. This gives you 2 options:
Client-side: Download a file through the browser via HTTP GET and let the user choose where they save it.
Server-side: Build your USB interactions into the back-end (Node.js) code, as #mcgraphix suggests.
Interacting with the USB on the server-side provides the most flexibility. Furthermore, there are a number of libraries that you can leverage. Head to npmjs.org and consider, among others, the following Node.js server-side packages:
usb-detection
usb
With the server-side approach, initiate a Webservice request when the user completes the drag & drop action on the client, and implement the USB interaction within the server (Express.js or similar) method which services the request.
If the letter of the stick is known then writing a file from PHP will be simple
file_put_contents( 'E:\\folder\\file.pdf', $data );
Update
You can read a list of drives into a dropdown and allow a user to select a default drive to write to
https://stackoverflow.com/a/8210132/696535
Your question is more an architecture question than a code specific question.
Your web app (if you insist on a web app) should have two major components, a server side component that can be given arbitrary commands, and a client side component (javascript using XMLHttpRequest) that can make requests to the server side component to execute said arbitrary commands.
So your server side component, the component that serves your web page should have some server side code that can write your pdf to the file system, it should probably generate the pdf file as well rather than doing that on the web browser.
Which technology you use is up to you, whether that's PHP, .Net, Node.js etc...
The general gist is you want a server side framework that deals with HTTP requests, in your case probably a post request from the client side containing the encoded pdf, and responds accordingly. Bind a particular http route to trigger your save logic.
Your http post request to the server will contain your payload which is the pdf file to a particular path, e.g. http://localhost/savepdf that whichever technology stack http listens to (you'll need to configure that)
Your server side component should read the incoming data, decode it as appropriate then make a file system request to write the received payload to disk.

send command via tcp ip through javascript

I want to achieve following functionality and need the help for the same:
I have one server on which there is device connected that prints some bar codes based on pre-formatted command given to it.
Currently there is one desktop application which generates the command and does the job.
Now I want to do this via web, meaning there will be one webpage (say .aspx) and I want to achieve this by javascript.
I am able to generate the pre-formatted command required for printing but I don't know how to send the command to server, whether socket tcp ip or something else.
I have tried using node.js, socket.io, json-socket etc. but nothing is working,
If javascript is a fixed requirement, then no I don't think you'll find a direct solution. You will need to create an intermediary service that will translate websocket protocol to the tcp/ip protocol your software communicates on. I found a package called Websockify that has implementations of this kind of bridge in a few different languages.
Although if you are open to using Flash on the front end, and can meet the security requirements on your backend connection, then Flash socket API could work. I believe Java applets can also manage this.
I don't believe this is possible to do from inside a web browser. If it were it would be a huge security vulnerability (think about it, you visit an attackers page and all of a sudden your printer starts printing and every shared directory on your network fills to the brim with junk data).
You could run the command on the server (node/.net/anything else...) and have the web platform talk to the server to kick the process off. But that sounds kind of like what you already have set up...
Alternately, if you can change the software on the connected device you could try to give it an HTTP endpoint which responds to POSTs.

VB.NET and RESTful service

I'm trying to build a simple VB.NET/Express 2012 windows application that will be able to receive a POST or JSON object with two parameters:
an XML document
an array or object of parameters
It will get its data from a front-end through JavaScript. That on itself makes a query to the back-end getting the needed info and will then trigger a print task on the local machine where this software is running using a local port to 'talk' to the local application.
I'm just looking for the components to use or some simple examples. Preferably I'd like to run a background TCP listening service that works on it's own (possibly a threaded task inside the application) and fires an event when needed.
Please, remember that it has to be made on the Express version of Visual Studio. I do not have all the extended possibilities the regular Studio has.
All the help is appreciated.
BTW, I've found This thread and this one, but they don't seem to going in the direction I'm wanting to go, as in that they run a continuous loop that seems to disable any and all other input or interaction unless you quit (kill) the application.
[edit]
I'm not creating a web application/server - I'm using a PHP solution for that. It's supposed to be a sort-of printserver.
[/edit]

Write a serverside c++/openGL App, that is accessible via JavaScript

I am currently having an idea where I want to save an image from a c++/openGL application on demand from a browser. So basically I would like to run the application itself on the server and have a simple communication layer like this:
JS -> tell application to do calculations (and maybe pass a string or some simple data)
application -> tell JS when finished and maybe send a link, text or something as simple as that.
I don't really have alot of experience with webservers and as such don't know if that is possible at all (it's just my naive thinking). And note: I am not talking about a webGL application, I just want to have simple communication between a c++ serverside application, and the user.
Any ideas how to do that?
Thanks alot!
Basically no matter what your language/framework you choose for your web server, you just need a interface that is callable from your browser JS, and you can do whatever you want in the server once it recieves the call.
Most likely any web service interface exposed from the server.
Just need to safeguard your server not to get DoS since it sounds like it's a huge process.
As far as I know, JavaScript (at least when embedded in HTML) is executed on your local machine and not on the server so that there is IMHO no way to directly start your server-application using JS.
PHP for example is executed on the server-side and so you could use e.g. the php system function to call your C++/OpenGL application on the server - initiated on demand through a web-browser.
When the call is finished you could then directly present the image.
Well you could always use the cgi interface to invoke your application
and have it save that image somewhere accessible to the webserver.
Then have your js load that via ajax.
Or make a cgi App that talks to the app and then serves a small
page with the pic in it.
[EDIT]
Answering the comments:
CGI is not complex to learn, it is mostly a simple convention
you can follow. I think it would give you the maximum of
flexibility. I don't know which php mods allow you to leave the cozy protection of the server-application and interact with other stuff on your server.

Categories

Resources