Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmechnich committed Nov 15, 2018
2 parents af7b0ba + ecfc0c3 commit ed5b160
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 23 deletions.
4 changes: 2 additions & 2 deletions SSVNCDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected function sendVncWindowToNuc($id, $vncclient)

$vnc_id = $vncclient["hostname"] . "-" . $id;

$db = new palma\DBConnector();
$db = new DBConnector();

// already existing in db?
$clients_in_db = array();
Expand Down Expand Up @@ -227,7 +227,7 @@ protected function sendVncWindowToNuc($id, $vncclient)
if (!(in_array($vnc_id, $clients_in_db))) {
// print("\n[Daemon]: insert $vnc_id into db");

$dt = new DateTime();
$dt = new \DateTime();
$date = $dt->format('Y-m-d H:i:s');

$window = array(
Expand Down
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
palma (1.4.2) unstable; urgency=medium

* forcefully overwrite PalMA configuration files for apache, nginx and php
* fixed timeout issues with nginx
* updated Debian package dependencies
* corrected namespaces in SSVNCDaemon.php

-- Jörg Mechnich <Joerg.Mechnich@bib.uni-mannheim.de> Thu, 15 Nov 2018 18:27:42 +0100

palma (1.4.1) unstable; urgency=medium

* fixed last_activity monitoring
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Homepage: https://github.com/UB-Mannheim/PalMA

Package: palma
Architecture: all
Depends: ${misc:Depends}, palma-nginx | palma-apache, midori | dwb, feh, libreoffice, ssvnc, x11vnc, zathura, wmctrl, xdotool, openbox, sqlite3, php, php-curl, php-gd, php-intl, php-sqlite3, php-mbstring, gettext, libavcodec-extra, xserver-xorg, unclutter
Depends: ${misc:Depends}, palma-nginx | palma-apache, midori | dwb, feh, libreoffice, ssvnc, x11vnc, zathura, wmctrl, xdotool, openbox, sqlite3, php, php-curl, php-gd, php-intl, php-sqlite3, php-mbstring, gettext, libavcodec-extra | libavcodec58 , xserver-xorg, unclutter
Description: PalMA – share a team monitor
PalMA enables people to share several contents on one monitor. Users
can display PDF files, office files, images, videos, websites and or
Expand Down
10 changes: 4 additions & 6 deletions debian/palma-apache.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ case "$1" in

# create php configuration for PalMA
confdir=/etc/php/${php_vers}/apache2/conf.d
if [ ! -e $confdir/palma.ini ]; then
mkdir -p $confdir
cat > $confdir/palma.ini <<EOF
mkdir -p $confdir
cat > $confdir/palma.ini <<EOF
upload_max_filesize = 10M
post_max_size = 10M
max_execution_time = 600
request_terminate_timeout = 600
EOF
else
echo "$confdir/palma.ini already exists, not overwriting"
fi

if test -x /usr/sbin/apache2; then
a2enmod rewrite
Expand Down
17 changes: 6 additions & 11 deletions debian/palma-nginx.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ case "$1" in

# create php configuration for PalMA
confdir=/etc/php/${php_vers}/fpm/conf.d
if [ ! -e $confdir/palma.ini ]; then
mkdir -p $confdir
cat > $confdir/palma.ini <<EOF
mkdir -p $confdir
cat > $confdir/palma.ini <<EOF
upload_max_filesize = 10M
post_max_size = 10M
max_execution_time = 600
request_terminate_timeout = 600
EOF
else
echo "$confdir/palma.ini already exists, not overwriting"
fi

# create nginx site configuration for PalMA
confdir=/etc/nginx/sites-available
if [ ! -e $confdir/palma ]; then
cat > $confdir/palma <<EOF
cat > $confdir/palma <<EOF
server {
listen 80 default_server;
listen [::]:80 default_server;
Expand All @@ -56,6 +53,7 @@ server {
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php${php_vers}-fpm.sock;
fastcgi_read_timeout 600;
# If you still use php5 uncomment these lines instead of the above:
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
Expand All @@ -65,9 +63,6 @@ server {
}
}
EOF
else
echo "$confdir/palma already exists, not overwriting"
fi

# enable site configuration
ln -sf ../sites-available/palma /etc/nginx/sites-enabled/palma
Expand Down
4 changes: 4 additions & 0 deletions examples/90-monitor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Section "Monitor"
Identifier "<default monitor>"
DisplaySize 677 381 # In millimeters
EndSection
1 change: 1 addition & 0 deletions examples/palma.nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ server {
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_read_timeout 600;

# If you still use php5 uncomment these lines instead of the above:
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
Expand Down
2 changes: 2 additions & 0 deletions examples/palma.php.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
upload_max_filesize = 10M
post_max_size = 10M
max_execution_time = 600
request_terminate_timeout = 600
6 changes: 3 additions & 3 deletions monitor/monitor
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ if path is None:
frags =[ i for i in path.split('/') if i and len(i) ]
if len(frags) != 2:
error("Malformed payload in URL: %s" % path)
action = base64.b64decode(frags.pop()).decode('utf-8')

action = base64.b64decode(frags.pop()).decode('utf-8').strip()
palma_host = frags.pop()

if not os.path.isdir(logdir):
os.mkdir(logdir)
logfile = palma_host + '.log'
with open(os.path.join(logdir,logfile), 'a') as f:
with open(os.path.join(logdir,logfile), 'a', encoding='utf-8') as f:
print(timestamp(), action, file=f)
174 changes: 174 additions & 0 deletions monitor/palma_analyze
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/usr/bin/env python3

import argparse, datetime, os, re, sys
from enum import Enum

class States(Enum):
NONE = 0
CONNECTED = 1
IDLE = 2


class PalmaSession(object):
def __init__(self, start):
self.__dict__ = {
'start': start,
'end': None,
'nuser': 0,
}


class PalmaLogfile(object):
def __init__(self, filename):
self.__dict__ = {
'filename': filename,
'data': {},
'lstamp': None,
'timeout': 60*60*6,
'state': States.IDLE,
'current': None,
'logtext': '',
}


def gapDetected(self, timestamp):
"""handle big gaps in logfiles ( > 6 hrs)."""
return self.lstamp and (timestamp - self.lstamp).total_seconds() > self.timeout


def newSession(self, timestamp):
if self.state is States.CONNECTED:
self.error(timestamp, "Parse error: already connected")
self.endSession()
self.current = PalmaSession(timestamp)
self.state = States.CONNECTED
self.addUser()


def addUser(self):
if not self.state is States.CONNECTED:
return
if not self.current:
return
self.current.nuser += 1


def endSession(self, timestamp=None, ignoreState=False):
if timestamp is None:
timestamp = self.lstamp
else:
if self.gapDetected(timestamp):
timestamp = self.lstamp
if not self.state is States.CONNECTED and not ignoreState:
return
if self.current:
self.current.end = timestamp
self.data[self.current.start] = self.current
self.current = None
self.state = States.IDLE


def error(self, timestamp, error):
print(self.filename, timestamp, error)
sys.exit(1)


def addLine(self, line):
if self.state is States.CONNECTED:
self.logtext += line


def printDetails(self,indent=" "*2):
for k,v in sorted(self.data.items(),key=lambda item: item[1].start):
length = v.end-v.start
print("%s%s length: %s %d user(s)" % (indent,k,length,v.nuser))


def printSummary(self):
totLength = datetime.timedelta()
totUsers = 0
for k,v in self.data.items():
totLength += v.end-v.start
totUsers += v.nuser
print("%-40s %8s %5d %20s" %
(os.path.basename(self.filename), len(self.data),
totUsers, totLength)
)


class PalmaAnalyzer(object):
def __init__(self):
self.__dict__ = {
'alldata': {},
}


def parseCmdLine(self):
parser = argparse.ArgumentParser(
description=os.path.basename(sys.argv[0]) +
' - analyze PalMA monitoring log files',
)
parser.add_argument("-s", "--summary", action="store_true",
help="print summary")
parser.add_argument("logfile", nargs='+',
help="at least one log file")
self.args = parser.parse_args()


def processFile(self,filename):
with open(filename,'r') as f:
print("Processing", filename)
logfile = PalmaLogfile(filename)
for line in f.readlines():
# skip empty lines
if not len(line.strip()): continue

tstamp = datetime.datetime.strptime(
line.split()[0], "%Y-%m-%dT%H:%M:%S"
)
if logfile.gapDetected(tstamp):
logfile.endSession()

if re.search(r"connecting first user",line):
logfile.newSession(tstamp)
elif re.search(r"logout.php: logout",line):
logfile.endSession(tstamp, ignoreState=True)
elif re.search(r"timeout reached",line):
logfile.endSession(tstamp, ignoreState=True)
elif re.search(r"last user disconnected",line):
logfile.endSession(tstamp, ignoreState=True)
elif re.search(r"bash_startx: starting login screen",line):
logfile.endSession(tstamp, ignoreState=True)
elif re.search(r"access granted for user",line):
logfile.addUser()
else:
logfile.addLine(line)
logfile.lstamp = tstamp
self.alldata[filename] = logfile


def run(self):
for logfile in self.args.logfile:
self.processFile(logfile)


def print(self):
if self.args.summary:
print("%-40s %-8s %-5s %-20s" %
("Station", "Sessions", "Users", "Total Time")
)
for station,logfile in sorted(self.alldata.items()):
logfile.printSummary()
else:
print()
for station,logfile in sorted(self.alldata.items()):
print(station)
logfile.printDetails()
print()


if __name__ == '__main__':
analyzer = PalmaAnalyzer()
analyzer.parseCmdLine()
analyzer.run()
analyzer.print()

0 comments on commit ed5b160

Please sign in to comment.