def handle_settings(self, client, params = None): if params == None: response = {'status':{}} simulator_form = SimulatorSettingsForm(initial={'master_ini': open("./services/web_ui/dav_store/config/grid_master.ini","r").read()}) main = render_to_string("opensim/read_settings.html", {'simulator_form':simulator_form,'map_form':self._get_map_form()}) return {'data':{'dom':{'main':main}}} else: if 'master_ini' in params: simulator_form = SimulatorSettingsForm(params) if simulator_form.is_valid(): infile = open("./services/web_ui/dav_store/config/grid_master.ini","w") infile.write(simulator_form.cleaned_data['master_ini']) response = {'status':{ 'code':'SETTINGS_UPDATE_OK', 'i18n':_('Simulator settings succesfully updated'), 'type': HWIOS.ws_realm._t['notify-info'] } } else: response = {'status':{ 'code':'INVALID_FORM', 'i18n':_('Invalid form'), 'type': HWIOS.ws_realm._t['notify-info'] } } elif 'center_z' in params: simulator_form = SimulatorSettingsForm(initial={'master_ini': open("./services/web_ui/dav_store/config/grid_master.ini","r").read()}) if 'osm' not in params: params['osm'] = False response = {'status':{}} map_form = MapSettingsForm(params) if map_form.is_valid(): service_config = HWIOS.services['tms'].config for section in service_config.sections(): for key,value in service_config.items(section): if key in params: service_config.set(section,key,params[key]) service_config.write(open(os.path.join(service_config.location,'service.ini'),'wb')) service_config.read(os.path.join(service_config.location,'service.ini')) response['status'] = { 'code':'CONFIG_UPDATE_OK', 'i18n':_('Configuration updated...'), 'type': HWIOS.ws_realm._t['notify-info'] } else: response['status'] = { 'code':'FORM_INVALID', 'i18n':_('Invalid form!'), 'type': HWIOS.ws_realm._t['notify-warning'] } Maps.update_client_settings() client_response, tpl_params = self._get_settings(client) client_response.update(response) _target_state = '/opensim/settings/' notify_others(client, client_response,'/opensim/settings/modified/', '^/opensim/settings/$', tpl_params, _target_state) publish_activity(client.profile, _('OpenSim Settings updated'),'/opensim/settings/',[0,0,4,0,0]) return client_response
def delete_regions(self, client, params = None): if params == None: dialog = render_to_string("opensim/delete_region_confirmation.html") defer.returnValue({'data':{'dom':{'dialog':dialog}}}) else: deleted_offline = [] deleted_online = [] for region_uuid in params: region = Regions().get_region(region_uuid) queued = Maps.render_cell(region['Location'].split(',')[0],region['Location'].split(',')[1]) result = yield HWIOS.pb_server.radmin_proxy(region['service_uuid'],'admin_delete_region',{'region_id':region_uuid}) if 'error' in result and result['error'] == 'SIM_OFFLINE': deleted_offline.append(result['error']) elif 'success' in result: deleted_online.append(result['success']) client_response, tpl_params = self._get_regions(client) client_response.update({ 'status':{ 'code':'DELETE_OK', 'i18n':_('Deleted: %(online)s online and %(offline)s offline region(s) ') % {'online':len(deleted_online),'offline':len(deleted_offline)}, 'type': HWIOS.ws_realm._t['notify-info'] }, }) notify_others(client, client_response,'/opensim/regions/modified/', '^/opensim/regions/$', tpl_params) publish_activity(client.profile, _('Region deleted'),'/opensim/regions/',[0,0,4,0,0]) defer.returnValue(client_response)
def edit_region(self, client, region_uuid, params = None): if params == None: region = Regions().get_region(region_uuid) data = {'sim_uuid': region['RegionUUID'], 'internal_ip_address':region['InternalAddress'], 'internal_ip_port':region['InternalPort'], 'external_host_name':region['ExternalHostName'], 'object_capacity':15000, 'sim_location_x':region['Location'].split(',')[0], 'sim_location_y':region['Location'].split(',')[1], 'name':region['name'], 'owner':None, 'service':region['service_uuid']} form = RegionForm(initial=data) main = render_to_string("opensim/edit_region.html", {'form':form,'region_uuid':region_uuid}) defer.returnValue({'data':{'dom':{'main':main}}}) else: response = {'status':{}} profile = Profile.objects.get(pk = params['owner']) radmin_params = { 'region_name':params['name'], 'region_id':region_uuid, 'region_x':params['sim_location_x'], 'region_y':params['sim_location_y'], 'region_master_uuid':profile.uuid, 'region_master_first':profile.first_name, 'region_master_last':profile.last_name, 'region_master_password':'******', 'public':'true', 'enable_voice':'true' } #clean old map-location with an opaque tile region_old = Regions().get_region(region_uuid) old_xy = [region_old['Location'].split(',')[0],region_old['Location'].split(',')[1]] queued = Maps.render_cell(old_xy[0],old_xy[1]) service_client = yield HWIOS.pb_server.search_service(params['service']) #if the service is not online, take the existing image tms_config = HWIOS.services['tms'].config if tms_config.getboolean('map','osm'): ztop = tms_config.get('map','osm_ztop') else: ztop = tms_config.get('map','raw_ztop') if service_client['service']['status'] == 'OFF': if tms_config.getboolean('service','ssl'): image_loc = 'https://%s:%s/tiles/%s/%s/%s.%s' % (HWIOS.config.get('general','uri'),tms_config.getint('service','port'), ztop ,old_xy[0],old_xy[1],tms_config.get('map','format')) else: image_loc = 'http://%s:%s/tiles/%s/%s/%s.%s' % (HWIOS.config.get('general','uri'),tms_config.getint('service','port'), ztop ,old_xy[0],old_xy[1],tms_config.get('map','format')) else: image_loc = 'http://%s:%s/index.php?method=regionImage%s' % (service_client['client'].peer.host, service_client['service']['port'], region_uuid.replace('-', '')) queued = Maps.render_cell(params['sim_location_x'],params['sim_location_y'],image_loc) pb_client = HWIOS.pb_server.search_client(params['service']) watchdog = yield pb_client.switch_watchdog(params['service'],'TRIGGER') result = yield HWIOS.pb_server.radmin_proxy(params['service'],'admin_shutdown',radmin_params) client_response, tpl_params = self._get_regions(client) if 'error' in result: if result['error'] == 'SIM_OFFLINE': client_response.update({'status': { 'code':'REGION_UPDATED', 'i18n':_('Updated region in offline simulator!'), 'type': HWIOS.ws_realm._t['notify-info'] } }) else: client_response.update({'status': { 'code':result['error'], 'i18n':_(result['error']), 'type': HWIOS.ws_realm._t['notify-error'] } }) else: client_response.update({'status': { 'code':'REGION_UPDATED', 'i18n':_('Region updated. Region service restarting with watchdog...'), 'type': HWIOS.ws_realm._t['notify-info'] } }) notify_others(client, client_response,'/opensim/regions/modified/', '^/opensim/regions/$', tpl_params) publish_activity(client.profile, _('Region modified'),'/opensim/regions/',[0,0,4,0,0]) defer.returnValue(client_response)
def _map_cb(params, region_uuid): service_client = HWIOS.pb_server.search_service(params['service']) image_loc = 'http://%s:%s/index.php?method=regionImage%s' % (service_client['client'].peer.host, service_client['service']['port'], region_uuid.replace('-', '')) queued = Maps.render_cell(params['sim_location_x'],params['sim_location_y'],image_loc)