ndt-dev - [ndt-dev] [ndt] r1150 committed - Added flash policy daemon
Subject: NDT-DEV email list created
List archive
- From:
- To:
- Subject: [ndt-dev] [ndt] r1150 committed - Added flash policy daemon
- Date: Wed, 12 Nov 2014 12:46:16 +0000
Revision: 1150
Author:
Date: Wed Nov 12 12:45:46 2014 UTC
Log: Added flash policy daemon
https://code.google.com/p/ndt/source/detail?r=1150
Added:
/branches/Issue162/flashpolicy.xml
/branches/Issue162/ndt-flashpolicyd
Modified:
/branches/Issue162/Makefile.am
/branches/Issue162/conf/ndt-init
/branches/Issue162/conf/ndt-sysconfig
/branches/Issue162/ndt.spec
=======================================
--- /dev/null
+++ /branches/Issue162/flashpolicy.xml Wed Nov 12 12:45:46 2014 UTC
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+ <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
+ <cross-domain-policy>
+ <site-control permitted-cross-domain-policies="master-only"/>
+ <allow-access-from domain="*" to-ports="*" />
+ </cross-domain-policy>
=======================================
--- /dev/null
+++ /branches/Issue162/ndt-flashpolicyd Wed Nov 12 12:45:46 2014 UTC
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# flashpolicyd.py
+# Simple socket policy file server for Flash
+#
+# Usage: flashpolicyd.py [--port=N] --file=FILE
+#
+# Logs to stderr
+# Requires Python 2.5 or later
+
+from __future__ import with_statement
+
+import sys
+import optparse
+import socket
+import thread
+import exceptions
+import contextlib
+
+VERSION = 0.1
+PORT = 843 # Listen on PORT.
+FILE = '/usr/local/ndt/flashpolicy.xml' # Full path to the default server policy file.
+
+class policy_server(object):
+ def __init__(self, port, path):
+ self.port = port
+ self.path = path
+ self.policy = self.read_policy(path)
+ self.log('Listening on port %d\n' % port)
+ try:
+ self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+ except AttributeError:
+ # AttributeError catches Python built without IPv6
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ except socket.error:
+ # socket.error catches OS with IPv6 disabled
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ self.sock.bind(('', port))
+ self.sock.listen(5)
+ def read_policy(self, path):
+ with file(path, 'rb') as f:
+ policy = f.read(10001)
+ if len(policy) > 10000:
+ raise exceptions.RuntimeError('File probably too large to be a policy file',
+ path)
+ if 'cross-domain-policy' not in policy:
+ raise exceptions.RuntimeError('Not a valid policy file',
+ path)
+ return policy
+ def run(self):
+ try:
+ while True:
+ thread.start_new_thread(self.handle, self.sock.accept())
+ except socket.error, e:
+ self.log('Error accepting connection: %s' % (e[1],))
+ def handle(self, conn, addr):
+ addrstr = '%s:%s' % (addr[0],addr[1])
+ try:
+ self.log('Connection from %s' % (addrstr,))
+ with contextlib.closing(conn):
+ # It's possible that we won't get the entire request in
+ # a single recv, but very unlikely.
+ request = conn.recv(1024).strip()
+ if request != '<policy-file-request/>\0':
+ self.log('Unrecognized request from %s: %s' % (addrstr, request))
+ return
+ self.log('Valid request received from %s' % (addrstr,))
+ conn.sendall(self.policy)
+ self.log('Sent policy file to %s' % (addrstr,))
+ except socket.error, e:
+ self.log('Error handling connection from %s: %s' % (addrstr, e[1]))
+ except Exception, e:
+ self.log('Error handling connection from %s: %s' % (addrstr, e[1]))
+ def log(self, str):
+ print >>sys.stderr, str
+
+def main():
+ try:
+ usage = "usage: %prog [options]"
+
+ parser = optparse.OptionParser(usage=usage)
+ parser.add_option("-f", "--file", dest="file", help="The flashpolicy.xml file that will be served", metavar="FILE", default = FILE)
+
+ (options, args) = parser.parse_args()
+
+ policy_server(PORT, options.file).run()
+ except Exception, e:
+ print >> sys.stderr, e
+ sys.exit(1)
+ except KeyboardInterrupt:
+ pass
+
+if __name__ == '__main__':
+ main()
=======================================
--- /branches/Issue162/Makefile.am Fri Nov 7 08:49:50 2014 UTC
+++ /branches/Issue162/Makefile.am Wed Nov 12 12:45:46 2014 UTC
@@ -41,9 +41,11 @@
tfw/Readme tfw/scenarios.py tfw/server.py tfw/traffics.py
tfw/widgets.py
ndtdir = $(prefix)/ndt
-ndt_DATA = admin_description.html admin.html \
+ndt_DATA = admin_description.html admin.html flashpolicy.xml \
copyright.html web100variables.html web100_variables
+sbin_SCRIPTS = ndt-flashpolicyd
+
sdatadir:
test -z "$(DESTDIR)$(ndtdir)/serverdata" || $(mkdir_p) "$(DESTDIR)$(ndtdir)/serverdata"
=======================================
--- /branches/Issue162/conf/ndt-init Fri Jun 20 14:26:21 2014 UTC
+++ /branches/Issue162/conf/ndt-init Wed Nov 12 12:45:46 2014 UTC
@@ -27,6 +27,7 @@
[ -f $path/web100srv ] || exit 0
[ -f $path/fakewww ] || exit 0
+[ -f $path/ndt-flashpolicyd ] || exit 0
RETVAL=0
@@ -70,6 +71,30 @@
echo "fakewww disabled - see /etc/sysconfig/ndt"
fi
}
+
+start_flashpolicyd ()
+{
+if [ ! $USE_FLASHPOLICYD = 0 ]
+then
+ if [ ! -n "`pidof -x $path/ndt-flashpolicyd`" ]; then
+ echo -n "Starting flashpolicyd:"
+ $path/ndt-flashpolicyd $FLASHPOLICYD_OPTIONS 2>/dev/null &
+ RETVAL=$?
+ if [ $RETVAL = 0 ]
+ then
+ success
+ touch /var/lock/subsys/ndt-flashpolicyd
+ else
+ failure
+ fi
+ echo
+ fi
+else
+ warning
+ echo "flashpolicyd disabled - see /etc/sysconfig/ndt"
+fi
+}
+
stop_web100srv ()
{
@@ -103,20 +128,46 @@
fi
}
+stop_flashpolicyd ()
+{
+ if [ ! $USE_FLASHPOLICYD = 0 ]
+ then
+ echo -n "Stopping flashpolicyd:"
+ killproc ndt-flashpolicyd -TERM
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ndt-flashpolicyd
+ else
+ status ndt-flashpolicyd 2>/dev/null
+ RETVAL=$?
+ if [ $RETVAL -eq 0 ]
+ then
+ warning
+ echo "flashpolicyd disabled, but is running"
+ else
+ success
+ echo "flashpolicyd disabled, not running"
+ fi
+ fi
+}
+
rhstatus() {
status web100srv
status fakewww
+ status ndt-flashpolicyd
}
stop() {
stop_web100srv
stop_fakewww
+ stop_flashpolicyd
}
start () {
start_web100srv
start_fakewww
+ start_flashpolicyd
}
restart() {
=======================================
--- /branches/Issue162/conf/ndt-sysconfig Fri Jun 20 14:26:21 2014 UTC
+++ /branches/Issue162/conf/ndt-sysconfig Wed Nov 12 12:45:46 2014 UTC
@@ -113,3 +113,10 @@
# extra options for fakewww - ignored unless USE_FAKEWWW is set to '1'
#FAKEWWW_OPTIONS="-f /index.html"
FAKEWWW_OPTIONS="-f /index.html -s -l /var/log/ndt/fakewww_access.log -e /var/log/ndt/fakewww_error.log"
+
+# Flash policy daemon options
+# -f FILE, --file=FILE The flashpolicy.xml file that will be served
+#
+# Whether to use the flash policy daemon; null or 0 to disable, 1 to enable
+USE_FLASHPOLICYD="1"
+FLASHPOLICYD_OPTIONS="-f /usr/ndt/flashpolicy.xml"
=======================================
--- /branches/Issue162/ndt.spec Fri Jun 27 13:41:49 2014 UTC
+++ /branches/Issue162/ndt.spec Wed Nov 12 12:45:46 2014 UTC
@@ -41,6 +41,7 @@
Requires: I2util, chkconfig, initscripts, shadow-utils, coreutils
Requires: web100_userland, libpcap
Requires: jansson
+Requires: python >= 2.5
%description server
NDT server that enables end users to run performance tests
- [ndt-dev] [ndt] r1150 committed - Added flash policy daemon, ndt, 11/12/2014
Archive powered by MHonArc 2.6.16.