SSH with Javascript without GUI - javascript

What I want to make is a Operating System based on Ubuntu which will use the web
I want to make the items clickable. If you click on an app-icon, the application will open. I tried to use WebSockets, but they are'nt that easy to use.
I tried PHP, with exec(), popen(), system() and I tried ssh2 functions. Doesn't work or too slow.
I can't use a GUI like shellinabox, because I only want to connect to localhost and run some commands like 'firefox' or 'sensible-browser' or like 'gedit'. That's why I want help.
I googled the whole day and found nothing. I'm searching for a simple solution. Just a connection and just some commands. No extra GUI, just that simple things!
Thanks,
Amanush.
-------------------------------------------[SECOND QUESTION (EDIT)]------------
I made my own protocol and it's working well!
One last question. My html:
<html>
<body>
Open firefox
</body>
</html>
My .desktop file:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=/usr/bin/cloudjerun -c gedit
Name[en_US]=Gedit
Comment[en_US]=Small, easy-to-use program to access iTunesU media
Name=TunesViewer
Comment=Small, easy-to-use program to access iTunesU media
Icon=/usr/share/icons/hicolor/scalable/apps/tunesview.svg
Categories=Application;Network;
MimeType=x-scheme-handler/cloudje;
Comment[en_US.utf8]=Small, easy-to-use program to access iTunesU media
Tutorial: http://jarrpa.net/2011/10/28/creating-custom-url-handlers-in-ubuntu-11-04-11-10-gnome-3-0/
Ok, it's always executing gedit. The reason is the line Exec=/usr/bin/cloudjerun -c gedit.
That's cool, but I want to run firefox as well, with 'cloudje:firefox' in the HTML-file. How can I replace -'-c gedit' with '-c firefox', '-c skype' or '-c sensible-browser', automaticly?

I suggest you register a custom protocol handler for your OS on the machine.
ie.: mysweetos://launchapp/chromium
you can find info about this with a quick google of "registering a custom protocol handler linux"
You would have to write some software/script on the linux machine to receive this request and execute the required application.

This looks very similar, and could be a significant part of what you are trying to accomplish. Technical details here, looks like it requires GTK3.2+

Related

How to get the current foreground application in electron(Javascript)

How can I detect if, for example, a browser is currently open?
I need this in my electron-application.
ty :)
I've found nothing like this online.
I've only found how I can check which window is open from the windows I have in my own application, but I need to know, what else is opened.
It should be something like this:
if(Application.isOpen('Google Chrome'){}
Unless someone has built a specific electron api to do this (which I can't find), then from electron...no. However, the beauty of electron being built with node.js, means that any node module should be able to do the job for you.
For example, ps-list should be able to get you all currently running processes.
psList().then(processes => {
console.log(processes)
})
Which gives a list for me, including:
Just be aware that you need node access from the electron thread attempting to use this lib.
This can easily be abstracted to do a name search in the list for you to get your desired functionality.
You can use find-process in case you need to search by given name, name pattern or pid.

using command line in javascript

I know there are lots of questions about this already, but i cant seem to find one that works for me.
I am trying to launch a local file from a local html using cmd to pass command to launch file but it does not seem to work.
This is what i used so far:
<script type="text/javascript" language="javascript">
function RunFile() {
window.open('C:/Windows/System32/cmd.exe /c START %temp%/file.cpl');
}
</script>
someone pls help with this.
Lets just asume i can do this on IE window.open('C:/Windows/System32/cmd.exe); and it will open cmd.
My question is how do i pass some extra argument to make the cmd open my file from another location e.g. window.open('C:/Windows/System32/cmd.exe /c START %temp%/file.cpl');
You cannot run a program using a browser. You might be confused with Windows Scripting JScript, check: https://en.wikipedia.org/wiki/JScript
You may run apps using that (in windows shell). Check this: https://stackoverflow.com/a/15351708/1082061
You could do this using server-side binary execution on Nodejs using child_process.
Pro: Easy to use, just need a simple AJAX call to trigger execution from client to Node server.
Cons: Need to use a server instead of a single HTML page.

Run exe file with jQuery or JavaScript

I want to know if there is a way to open a exe file from client side with jQuery or JavaScript.
I tried with windows.open("..") but it didn't work.
First off, Dalorzo is correct - you cannot escape the sandbox of a browser without earning lots of money. Recently Pinky Pie won over $60k from Google for performing such a task on Google Chrome.
http://blog.chromium.org/2012/05/tale-of-two-pwnies-part-1.html
However, sometimes I ask questions to try to find out-of-the-box solutions, so I'm assuming that you have a legitimate use-case for this question. I can help you think of a "hack" solution if you have a legitimate use for this. I'll probably get downvoted to oblivion for this response, but theoretically you could do this...
Back in college, I took a computer forensics class in which I wrote a chat web application which would forensically clean a user's computer from having ever accessed the chat webpage. This was done through the user running an executable they could download from the site. However, I wanted to have the users to not have to run the executable every time so I wanted a sandbox escape like you're asking about.
It's messy, but if your users are a participating party they can modify their computer to allow executables to be run from Chrome webpages.
Please Note: This will make your computer less secure, I only ever did it on Virtual Machines or Lab Machines. Reconsider whether you actually wanna try this or not.
Step One: Create a Chrome custom browser:
This is the python that I eventually compiled to a packed *.exe that accomplished creating a Google Chrome custom browser.
import sqlite3 as lite
con = lite.connect('C:\Users\USERNAME\AppData\Local\Google\Chrome\User Data\Default\Web Data')
c = con.cursor()
#idmax = c.execute('SELECT MAX(id) FROM keywords')
#c.execute("INSERT INTO keywords VALUES('cleanupeverybodyeverywhere','cleanupeverybodyeverywhere','','forensichat://C:>Windows>System32>calc.exe',0,'',0,0,'',0,'',0,0,'',0,'','','','','','','','','')")
c.execute("SELECT * FROM keywords WHERE short_name='cleanupeverybodyeverywhere'")
foo = c.fetchall()
if foo == []:
c.execute("INSERT INTO keywords (short_name,keyword,url,favicon_url) VALUES ('cleanupeverybodyeverywhere','cleanupeverybodyeverywhere','forensichat://C:>Windows>System32>calc.exe','')")
con.commit()
con.close()
Note that now when I open a Chrome tab and use the custom browser cleanupeverybodyeverywhere to run the key forensichat and it will open calc.exe as proof of concept.
Step Two: Modify your Windows Registry:
import _winreg as wreg
import getpass
user = getpass.getuser()
key = wreg.CreateKey(wreg.HKEY_CLASSES_ROOT, '')
wreg.SetValue(key,'forensichat',wreg.REG_SZ,'URL:forensichat Protocol')
# Create new subkey
kkey = wreg.CreateKey(wreg.HKEY_CLASSES_ROOT, 'forensichat')
wreg.SetValueEx(kkey, 'URL Protocol', 0, wreg.REG_SZ,'')
# Create new value
wreg.CreateKey(wreg.HKEY_CLASSES_ROOT,"forensichat\shell")
nkey = wreg.CreateKey(wreg.HKEY_CLASSES_ROOT,"forensichat\shell\open")
wreg.SetValue(nkey,"command",wreg.REG_SZ,'C:\Users\\'+user+'\Downloads\\forensicleaner.exe')
key.Close()
Note that I'm creating a key called forensichat which will run the exe found in the user's Downloads folder.
Of course, I ended up cleaning this all up and packing it so Anti-Virus wouldn't flag it, next thing I know Google Chrome has marked the site lol. It's still up if you wanna check it out - check Secure Chat and Repeat Customer. Chrome will flag it, but there's obviously ways around that.

Distinguish between different linux distros in nodejs

Basically I want to be able to run different code depending on what os you have.
I've found out that the os.platform() function will return "win32", "win64", "darwin", or "linux" (possibly others?), but I can't seem to get any more specific information.
Ideally I want to be able to tell if Gnome, Unity, KDE, or some other desktop environment is being used.
Getting the active desktop environment/window manager is not a node-specific problem. There are different approaches (some better than others) that include using pgrep to check running process names against known DE/WM binary names and using other tools such as HardInfo or wmctrl.
What I ended up using was a bash scripts from mscottnielsen. It seems to use the best of many different commands to find out what desktop environment is being used. Unfortunetally, it's kind of hard to figure out the exact string that gets outputed by it (It doesn't say anywhere what strings get outputed), but other then that it does the job.
See the script here.

path- and other problems using node.JS and Socket.IO

I'm using node.JS in VirtualBox on a TurnkeyLinux hosted by Windows. I was following the instructions here. node.JS is living in /root/node. Although I can run simple examples successfully I'm having a hard time figuring out certain things, cause I'm not a Linux-guy normally. I wanted to use socket.io.
I managed installing node.JS itself using git and tried that with Express and Socket.IO too. (e.g. git clone git://github.com/LearnBoost/Socket.IO.git). It seems to work, but I can't find that stuff anywhere! Was in /root/node when calling git, expecting changes in the lib-folder...
node.JS is using the CommonJS module system. In the Socket.IO example io = require('../') is used to import Socket.IO which looks pretty strange to me. Other expamples on the web are referring to './Socket.IO-node'. As a module is just a JS-file following certain rules I would expect sth like a path to such a file, as I found http.js in /root/node/lib.
By the way, looking at the server.js example: Is there a certain reason using var for http, but not for the rest of the variables (url, fs, io, sys)?
On clientside the first line on "How to use" Socket.IO is: io.setPath(...). setPath is not mentioned anywhere else on the page. Where should it point to, relative to what?
I've found no information about stoping/restarting node using the shell. Probably it's so obvious, that it's never mentioned anywhere ;)
Thanks for helping out.
The git-version that comes with the Turnkey-Core these days is quite outdated. Maybe this is causing problems. I worked around using my git on windows and WinSCP ;)
There is an inbuild automatism that index.js is used by default like index.html is used by default on webservers. So '../' is pointing to index.js in the parent folder, which then exports the listener of socket.io. Guillermo Rauch has put an index.js in the socket.io-folder now, so sth like './lib/socket.io/' is working. Note that there are examples out there with sth like './socket.io/socket.io.js', but socket.io.js doesn't exist anymore for some good reasons.
Of course the var is used for all variables. I've seen the commas as semicolons. Maybe I should change my screen-resolution ;)
It comes clear when looking at the example. setPath points to the folder where socket.io.js and it's lib-directory lives, relative to the html-file that uses it. This is needed for the flash-sockets to work.
Well, it's not that simple. You may look up the PID usind 'ps ux' and then 'kill' the process using the PID. A better way is using upstart. Or you do it by code using autorestart.

Categories