def RunService(service,serviceInterface,unusedCompatabilityArg=None,app=None): import signal, time from AccessGrid.hosting import SecureServer, InsecureServer from AccessGrid.interfaces.AGServiceManager_client import AGServiceManagerIW serviceName = service.GetName() # Initialize the service svc = Service.instance() svc.AddCmdLineOption(Option("-p", "--port", type="int", dest="port", default=9999, metavar="PORT", help="Set the port the service should run on.")) svc.AddCmdLineOption(Option("-s", "--serviceManagerUri", type="string", dest="serviceManagerUri", default=None, metavar="SERVICE_MANAGER_URL", help="URL of ServiceManager to register with")) svc.AddCmdLineOption(Option("-t", "--token", type="string", dest="token", default=None, metavar="TOKEN", help="Token to pass to service manager when registering")) svc.AddCmdLineOption(Option("--test", action='store_true', dest="test", default=None, metavar="TEST", help="Test service and then exit")) svc.Initialize(serviceName) log = svc.GetLog() Log.SetDefaultLevel(serviceName, Log.DEBUG) # Get options port = svc.GetOption("port") serviceManagerUri = svc.GetOption('serviceManagerUri') test = svc.GetOption('test') if test: from AccessGrid.NetworkLocation import MulticastNetworkLocation stream = StreamDescription('test stream', MulticastNetworkLocation('224.2.2.2',20000,1)) stream.capability = service.capabilities resources = service.GetResources() if len(resources) > 0: service.SetResource(resources[0]) service.SetStream(stream) return # Create the server if not app: app = GetDefaultApplication() hostname = app.GetHostname() server = None if svc.GetOption("secure"): server = SecureServer( (hostname, port) ) else: server = InsecureServer( (hostname, port) ) serviceInterface.impl = service serviceInterface.auth_method_name = None # Register the service interface with the server servicePath = '/Services/%s.%s' % (serviceName, str(GUID())) server.RegisterObject(serviceInterface, path = servicePath) # Start the server server.RunInThread() url = server.FindURLForObject(service) log.info("Starting Service URI: %s", url) print "Starting Service URI: %s" % url # Set service data service.SetServiceManagerUrl(serviceManagerUri) service.SetUri(url) # Register with the calling service manager if serviceManagerUri: log.debug("Registering with service manager; url=%s", serviceManagerUri) token = svc.GetOption('token') AGServiceManagerIW(serviceManagerUri).RegisterService(token,url) else: log.info("Service Manager does not exist for service %s"%(url)) # Register the signal handler so we can shut down cleanly # lambda is used to pass the service instance to the # signal handler signal.signal(signal.SIGINT, lambda signum,frame,service=service: SignalHandler(signum,frame,service)) # Loop main thread to catch signals while service.IsRunning(): time.sleep(1) # Shutdown the server server.Stop()
import sys import threading import urlparse import urllib import asyncore # Medusa from FTPS import filesys from FTPS import ftps_server # M2Crypto from M2Crypto import Rand, SSL from AccessGrid import Log log = Log.GetLogger('FTPSServer') Log.SetDefaultLevel('FTPSServer', Log.DEBUG) class authorizer: def __init__(self, root='/', authorizecb=None): self.root = root self.authorizecb = authorizecb def authorize(self, channel, username, password): channel.read_only = 0 if self.authorizecb and self.authorizecb(channel, username, password): return 1, 'Ok.', filesys.os_filesystem(self.root) else: return 0, 'Connection rejected.', None
from AccessGrid.AGParameter import OptionSetParameter from AccessGrid.Descriptions import AGServiceManagerDescription, AGServiceDescription from AccessGrid.Descriptions import NodeConfigDescription from AccessGrid.AGNodeService import AGNodeService from AccessGrid.interfaces.AGNodeService_client import AGNodeServiceIW from AccessGrid.AGServiceManager import AGServiceManager from AccessGrid.interfaces.AGServiceManager_client import AGServiceManagerIW from AccessGrid.interfaces.AGService_client import AGServiceIW from AccessGrid import Version from AccessGrid.Preferences import Preferences from AccessGrid.Utilities import BuildServiceUrl from AccessGrid import ServiceDiscovery log = Log.GetLogger(Log.NodeManagementUIClasses) Log.SetDefaultLevel(Log.NodeManagementUIClasses, Log.WARN) ### ### MENU DEFS ### ID_FILE_EXIT = 100 ID_FILE_LOAD_CONFIG = 101 ID_FILE_STORE_CONFIG = 102 ID_FILE_ATTACH = 800 ID_NODE_LEASH = 801 ID_NODE_BRIDGE = 802 ID_HOST_ADD = 300 ID_HOST_REMOVE = 301
from gov.lbl.dsd.bajjer import * import string, random import time import calendar import string from AccessGrid import Log #from AccessGrid.Platform.Config import UserConfig log = Log.GetLogger('JabberClient') Log.SetDefaultLevel('JabberClient', Log.DEBUG) # Generating random numbers between: start = 100000000 end = 999999999 AuthorizationFailure = stream.AuthorizationFailure class JabberClient: def __init__(self): #log.info("Connecting to Jabber Server '%s' ..." % host) #self._stream = stream.JabberClientStream(host, port=port, use_ssl=True) self.currentRoom = '' self.currentRoomId = '' self.to = '' self._auth_info = None self.email = None self.jid = None self.name = None self.resource = None
#!/usr/bin/python #----------------------------------------------------------------------------- # Name: InsecureVenueEventClient.py # Purpose: A group messaging service client that handles Access Grid # venue events. # Created: 2005/09/09 # RCS-ID: $Id: InsecureVenueEventClient.py,v 1.9 2007-10-20 02:47:21 douglask Exp $ # Copyright: (c) 2005,2006 # Licence: See COPYING.TXT #----------------------------------------------------------------------------- import sys, time from AccessGrid import Log log = Log.GetLogger(Log.EventClient) Log.SetDefaultLevel(Log.EventClient, Log.DEBUG) from AccessGrid.Descriptions import EventDescription from AccessGrid.XMLGroupMsgClient import XMLGroupMsgClient from AccessGrid.GroupMsgClient import GroupMsgClient class BaseVenueEventClient: ''' Sends and Receives Venue group events. Doesn't inherit from GroupMsgClientBase since RegisterEventCallback is different and uses different arguments than a standard Receive. ''' defaultGroupMsgClientClassList = [XMLGroupMsgClient, GroupMsgClient] def __init__(self, location, privateId, channel, groupMsgClientClassList=None): self.id = privateId
import sys import os import os.path import re import time from AccessGrid import Log from AccessGrid.Security.Utilities import IsExpired from M2Crypto import X509 from M2Crypto.RSA import RSAError import proxylib # lbl proxy generating code log = Log.GetLogger(Log.ProxyGen) Log.SetDefaultLevel(Log.ProxyGen, Log.DEBUG) class ProxyRequestError(Exception): """ Baseclass for proxy generation exceptions. """ pass class PassphraseRequestCancelled(ProxyRequestError): """ The user cancelled this request. """ pass
app.AddCmdLineOption(nsOption) # Initialize the application try: app.Initialize(Log.ServiceManager) except MissingDependencyError, e: print "Toolkit Initialization failed, exiting." print " Initialization Error: Missing Dependency: ", e sys.exit(-1) except Exception, e: print "Toolkit Initialization failed, exiting." print " Initialization Error: ", e sys.exit(-1) log = app.GetLog() Log.SetDefaultLevel(Log.ServiceManager, Log.DEBUG) port = app.GetOption("port") # Create the hosting environment hostname = app.GetHostname() if app.GetOption("secure"): context = Toolkit.GetDefaultApplication().GetContext() server = SecureServer((hostname, port), context) else: server = InsecureServer((hostname, port)) # Create the Service Manager gServiceManager = AGServiceManager(server) # Create the Service Manager Service
#!/usr/bin/python #----------------------------------------------------------------------------- # Name: GroupMsgService.py # Purpose: A Group Messaging service server. # Created: 2005/09/09 # RCS-ID: $Id: GroupMsgService.py,v 1.7 2007-04-26 21:29:23 turam Exp $ # Copyright: (c) 2005 # Licence: See COPYING.TXT #----------------------------------------------------------------------------- import time from AccessGrid import Log log = Log.GetLogger(Log.EventService) Log.SetDefaultLevel(Log.EventService, Log.DEBUG) import sys, struct from AccessGrid.GUID import GUID from twisted.internet.protocol import Protocol, ServerFactory from twisted.protocols.basic import Int32StringReceiver from twisted.internet import reactor from GroupMsgDefines import GroupDoesNotExistException, NotConnectedException, PackUByte, ERROR, ClientNotInGroupException class GroupMsgServiceProtocol(Int32StringReceiver): protocolVersion = 1 protocolIteration = 0 # to identify updates def __init__(self): self.groups = {} self.connections = {}
#!/usr/bin/python #----------------------------------------------------------------------------- # Name: GroupMsgClient.py # Purpose: A Group Messaging service client. # Created: 2005/09/09 # RCS-ID: $Id: GroupMsgClient.py,v 1.5 2006-02-10 05:19:29 turam Exp $ # Copyright: (c) 2005 # Licence: See COPYING.TXT #----------------------------------------------------------------------------- from AccessGrid import Log log = Log.GetLogger(Log.GroupMsgClient) Log.SetDefaultLevel(Log.GroupMsgClient, Log.DEBUG) from twisted.internet.protocol import ClientFactory from twisted.protocols.basic import Int32StringReceiver from GroupMsgDefines import GroupDoesNotExistException, NotConnectedException, UnspecifiedErrorException, IncompatibleVersionException, UnpackUByte, ERROR, ServerUnableToSendException, ClientNotInGroupException, GeneralReceivedErrorException import sys, time class GroupMsgClientProtocol(Int32StringReceiver): def connectionMade(self): # send handshake info which includes the group we'd like to join self.factory.startHandshake(self) def stringReceived(self, line): self.factory.linesReceived += 1 if self.factory.startedSending == False: self.ReceiveConnectResponse(line) else:
#!/usr/bin/env python import os import sys import urlparse import stat # add ftps to the list of protocols recognized by urlparse # as using a network location (allows urlparse to parse # ftps urls correctly) urlparse.uses_netloc.append('ftps') from AccessGrid import Log log = Log.GetLogger('FTPSClient') Log.SetDefaultLevel('FTPSClient', Log.DEBUG) from M2Crypto import SSL, ftpslib, threading # module defaults DEFAULT_PROTOCOL = 'sslv23' class UserCancelled(Exception): pass bytes_received = 0 def FTPSDownloadFile(url,destination, ssl_ctx=None,user=None,passw=None,
import shutil import resource from AccessGrid import Log from AccessGrid import Config from AccessGrid.Platform import AGTK_USER, AGTK_LOCATION, IsOSX, IsLinux, IsFreeBSD from AccessGrid.Version import GetVersion if IsLinux() or IsFreeBSD(): import fcntl import struct import glob log = Log.GetLogger(Log.Platform) Log.SetDefaultLevel(Log.Platform, Log.INFO) class AGTkConfig(Config.AGTkConfig): """ This class encapsulates a system configuration for the Access Grid Toolkit. This object provides primarily read-only access to configuration data that is created when the toolkit is installed. """ if IsFreeBSD(): AGTkBasePath = "/usr/local/etc/AccessGrid3" else: AGTkBasePath = "/etc/AccessGrid3" def instance(initIfNeeded=0):