Get the session for current user only for env far fetch. Work on readme for 2.0

This commit is contained in:
Florian Mounier
2015-10-20 14:53:25 +02:00
parent a9c35d91f1
commit 5714b97c77
5 changed files with 55 additions and 14 deletions

View File

@@ -5,19 +5,48 @@
## Description ## Description
Butterfly is a tornado web server written in python which powers a full featured web terminal. Butterfly is a xterm compatible terminal that runs in your browser.
The js part is heavily based on [term.js](https://github.com/chjj/term.js/) which is heavily based on [jslinux](http://bellard.org/jslinux/).
## Features
* xterm compatible (support a lot of unused features!)
* Native browser scroll and search
* Theming in css / sass [(18 preset themes)](https://github.com/paradoxxxzero/butterfly-themes) endless possibilities!
* HTML in your terminal! cat images and use <table>!
* Multiple sessions support (à la screen -x) to simultaneously access a terminal from several places on the planet!
* Secure authentication with X509 certificates!
* 16,777,216 colors support!
* Keyboard text selection!
* Desktop notifications on terminal output!
* Geolocation from browser!
* May work on firefox too!
## Try it ## Try it
```bash ```bash
$ pip install butterfly $ pip install butterfly
$ butterfly.server.py $ pip install libsass # If you want to use themes
$ butterfly
```
A new tab should appear in your browser. Then type
```bash
$ butterfly help
``` ```
Then open [localhost:57575](http://localhost:57575) in your favorite browser and done. To get an overview of butterfly features.
## Run it as a server
```bash
$ butterfly.server.py --host=myhost --port=57575
```
The first time it will ask you to generate the certificates (see: [here](http://paradoxxxzero.github.io/2014/03/21/butterfly-with-ssl-auth.html))
## Run it with systemd (linux) ## Run it with systemd (linux)
@@ -31,6 +60,8 @@ Systemd provides a way to automatically activate daemons when needed (socket act
# systemctl start butterfly.socket # systemctl start butterfly.socket
``` ```
Don't forget to update the /etc/butterfly/butterfly.conf file with your server options (host, port, shell, ...)
## Contribute ## Contribute
and make the world better (or just butterfly). and make the world better (or just butterfly).
@@ -41,9 +72,12 @@ If you don't know what to do go to the github issues and pick one you like.
If you want to motivate me to continue working on this project you can tip me, see: http://paradoxxxzero.github.io/about/ If you want to motivate me to continue working on this project you can tip me, see: http://paradoxxxzero.github.io/about/
The dev requirements are coffee script and compass for the client side. Client side development use [grunt](http://gruntjs.com/) and [bower](http://bower.io/).
Run `python dev.py --debug --port=12345` and you are set (yes you can launch it from your regular butterfly instance)
## Credits
The js part is based on [term.js](https://github.com/chjj/term.js/) which is based on [jslinux](http://bellard.org/jslinux/).
## Author ## Author
[Florian Mounier](http://paradoxxxzero.github.io/) [Florian Mounier](http://paradoxxxzero.github.io/)

View File

@@ -14,7 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '2.0.0-beta8' __version__ = '2.0.0-beta9'
import os import os

View File

@@ -62,8 +62,7 @@
var alarm; var alarm;
alarm = function(data) { alarm = function(data) {
var message, note, notif; var message, note, notif;
message = clean_ansi(data.data); message = clean_ansi(data.data.slice(1));
console.log(message);
if (cond !== null && !cond.test(message)) { if (cond !== null && !cond.test(message)) {
return; return;
} }

View File

@@ -24,7 +24,6 @@ import struct
from logging import getLogger from logging import getLogger
from collections import namedtuple from collections import namedtuple
import subprocess import subprocess
import tornado.options
import re import re
log = getLogger('butterfly') log = getLogger('butterfly')
@@ -140,7 +139,7 @@ class Socket(object):
try: try:
line = get_procfs_socket_line(get_hex_ip_port(pn[:2])) line = get_procfs_socket_line(get_hex_ip_port(pn[:2]))
self.user = User(uid=int(line[7])) self.user = User(uid=int(line[7]))
self.env = get_socket_env(line[9]) self.env = get_socket_env(line[9], self.user)
except Exception: except Exception:
log.debug('procfs was no good, aight', exc_info=True) log.debug('procfs was no good, aight', exc_info=True)
@@ -203,7 +202,7 @@ def get_procfs_socket_line(hex_ip_port):
# Linux only browser environment far fetch # Linux only browser environment far fetch
def get_socket_env(inode): def get_socket_env(inode, user):
for pid in os.listdir("/proc/"): for pid in os.listdir("/proc/"):
if not pid.isdigit(): if not pid.isdigit():
continue continue
@@ -214,6 +213,16 @@ def get_socket_env(inode):
'gnome-session-binary', 'gnome-session-binary',
'startkde', 'startkde',
'xfce4-session']: 'xfce4-session']:
with open('/proc/%s/status' % pid) as e:
uid = None
for line in e.read().splitlines():
parts = line.split('\t')
if parts[0] == 'Uid:':
uid = int(parts[1])
break
if not uid or uid != user.uid:
continue
with open('/proc/%s/environ' % pid) as e: with open('/proc/%s/environ' % pid) as e:
keyvals = e.read().split('\x00') keyvals = e.read().split('\x00')
env = {} env = {}

View File

@@ -45,8 +45,7 @@ clean_ansi = (data) ->
setAlarm = (notification, cond) -> setAlarm = (notification, cond) ->
alarm = (data) -> alarm = (data) ->
message = clean_ansi data.data message = clean_ansi data.data.slice(1)
console.log message
return if cond isnt null and not cond.test(message) return if cond isnt null and not cond.test(message)
butterfly.body.classList.remove 'alarm' butterfly.body.classList.remove 'alarm'