def api_change_password(self, request, old_password, new_password, *args, **kwargs): c = CPClient() if not c.has_account(): return {"status": False, "message": "Account is not registred"} if old_password != c.account_password: return {"status": False, "message": "Invalid password"} c.change_password(new_password) return {"status": True, "message": "Password has been changed"}
def api_attach_account(self, request, name, password): c = CPClient() if c.has_account(): self.response_forbidden() try: c.attach_account(name, password) except CPClient.Error, why: return {"status": False, "message": str(why)}
def handle_upgrade(status, log, quiet=False): cp = CPClient() if not cp.has_system(): die("System is not registred", quiet) if log: with open(log) as f: log = f.read() try: cp.upgrade(status, log) except CPClient.Error, why: die("RPC Error: %s" % why, quiet)
def api_save_system(self, request, name, type=None, description=None, *args, **kwargs): c = CPClient() if c.has_system(): try: c.update_system(name, type, description=description) except CPClient.Error, why: return {"status": False, "message": str(why)}
def api_about(self, request): if config.features.cpclient: cp = CPClient() return { "logo_url": config.customization.logo_url, "brand": config.brand, "version": version.version, "installation": config.installation_name, "system_id": cp.system_uuid, "copyright": "2007-%d, The NOC Project" % datetime.date.today().year, } else: return { "logo_url": config.customization.logo_url, "brand": config.brand, "version": version.version, "installation": config.installation_name, "copyright": "2007-%d, %s" % (datetime.date.today().year, config.brand), }
def main(): parser = OptionParser() parser.add_option("--public", dest="public", action="store_true", default=False, help="Create public paste"), parser.add_option("-s", "--subject", dest="subject", action="store", help="Create paste subject") parser.add_option("-e", "--expire", dest="expire", action="store", help="Set expiration time") parser.add_option("-q", "--quiet", dest="quiet", action="store_true") parser.add_option("-v", "--verbose", dest="verbose", action="store_true") options, args = parser.parse_args() if options.verbose: logging.basicConfig(level=logging.DEBUG) elif options.quiet: logging.basicConfig(level=logging.CRITICAL) else: logging.basicConfig() cp = CPClient() quiet = bool(options.quiet) if not cp.has_system(): die("System is not registred", quiet) if args: data = [] for a in args: with open(a) as f: data += [f.read()] data = "".join(data) else: data = sys.stdin.read() print( cp.create_paste( subject=options.subject, data=data, syntax=None, ttl=parse_ttl(options.expire), public=bool(options.public), )["url"])
def view_desktop(self, request): """ Render application root template """ cp = CPClient() ext_apps = [ a for a in self.site.apps if isinstance(self.site.apps[a], ExtApplication) ] apps = [a.split(".") for a in sorted(ext_apps)] # Prepare settings favicon_url = config.customization.favicon_url if favicon_url.endswith(".png"): favicon_mime = "image/png" elif favicon_url.endswith(".jpg") or favicon_url.endswith(".jpeg"): favicon_mime = "image/jpeg" else: favicon_mime = None if request.user.is_authenticated(): enable_search = Permission.has_perm(request.user, "main:search:launch") else: enable_search = False setup = { "system_uuid": cp.system_uuid, "installation_name": config.installation_name, "theme": config.web.theme, "logo_url": config.customization.logo_url, "logo_width": config.customization.logo_width, "logo_height": config.customization.logo_height, "brand": version.brand, "branding_color": config.customization.branding_color, "branding_background_color": config.customization.branding_background_color, "favicon_url": favicon_url, "favicon_mime": favicon_mime, "debug_js": False, "gitlab_url": config.gitlab_url, "collections_allow_sharing": config.collections.allow_sharing, "collections_project_id": config.collections.project_id, "enable_gis_base_osm": config.gis.enable_osm, "enable_gis_base_google_sat": config.gis.enable_google_sat, "enable_gis_base_google_roadmap": config.gis.enable_google_roadmap, "trace_extjs_events": False, "preview_theme": config.customization.preview_theme, "enable_search": enable_search, "help_base_url": config.help.base_url, "help_branch": config.help.branch, "help_language": config.help.language, "enable_remote_system_last_extract_info": config.web.enable_remote_system_last_extract_info, "timezone": config.timezone, } return self.render(request, "desktop.html", language=self.get_language(request), apps=apps, setup=setup)
def api_about(self, request): cp = CPClient() return { "version": get_version(), "installation": config.get("customization", "installation_name"), "system_id": cp.system_uuid, "copyright": "2007-%d, The NOC Project" % datetime.date.today().year }
def api_settings(self, request): cp = CPClient() # Prepare settings favicon_url = config.customization.favicon_url if favicon_url.endswith(".png"): favicon_mime = "image/png" elif favicon_url.endswith(".jpg") or favicon_url.endswith(".jpeg"): favicon_mime = "image/jpeg" else: favicon_mime = None if request.user.is_authenticated(): enable_search = Permission.has_perm(request.user, "main:search:launch") else: enable_search = False language = self.get_language(request) return { "system_uuid": cp.system_uuid or None, "brand": version.brand, "installation_name": config.installation_name, "preview_theme": config.customization.preview_theme, "language": language, "logo_url": config.customization.logo_url, "logo_width": config.customization.logo_width, "logo_height": config.customization.logo_height, "branding_color": config.customization.branding_color, "branding_background_color": config.customization.branding_background_color, "favicon_mime": favicon_mime, "favicon_url": favicon_url, "enable_search": enable_search, "gitlab_url": config.gitlab_url, "collections": { "allow_sharing": config.collections.allow_sharing, "project_id": config.collections.project_id, }, "gis": { "base": { "enable_osm": config.gis.enable_osm, "enable_google_sat": config.gis.enable_google_sat, "enable_google_roadmap": config.gis.enable_google_roadmap, } }, "traceExtJSEvents": False, "helpUrl": config.help.base_url, "helpBranch": config.help.branch, "helpLanguage": config.help.language, "timezone": config.timezone, "enable_remote_system_last_extract_info": config.web.enable_remote_system_last_extract_info, "theme": config.web.theme, }
def report(self): logger.info("Reporting crashinfo %s", self.uuid) if self.status not in ("N", "r"): raise CPClient.Error("Cannot share not-new crashinfo") cp = CPClient() if not cp.has_system(): raise CPClient.Error("System is not registred") ci = self.json ci["comment"] = self.comment ci["priority"] = self.priority cp.report_crashinfo(ci) self.status = "R" self.save()
def api_save_account(self, request, name, email, password=None, org=None, country=None, language=None, *args, **kwargs): industries = [ k[4:] for k in kwargs if k.startswith("ind_") and kwargs[k] ] c = CPClient() if c.has_account(): try: c.update_account(name, email, country=country, language=language, org=org, industries=industries) except CPClient.Error, why: return {"status": False, "message": str(why)}
def api_get(self, request): c = CPClient() data = {} if c.has_account(): data["account"] = c.account_info() for i in data["account"].get("industries", []): data["account"]["ind_%s" % i] = True if c.has_system(): data["system"] = c.system_info() return data
def api_save_system(self, request, name, type=None, description=None, *args, **kwargs): c = CPClient() if c.has_system(): try: c.update_system(name, type, description=description) except CPClient.Error as e: return {"status": False, "message": str(e)} else: # Create account try: c.create_system(name, type, description=description) except CPClient.Error as e: return {"status": False, "message": str(e)} return {"status": True, "message": "System saved"}
def view_desktop(self, request): """ Render application root template """ cp = CPClient() ext_apps = [a for a in self.site.apps if isinstance(self.site.apps[a], ExtApplication) or\ isinstance(self.site.apps[a], ModelApplication)] apps = [a.split(".") for a in sorted(ext_apps)] # Prepare settings favicon_url = config.get("customization", "favicon_url") if favicon_url.endswith(".png"): favicon_mime = "image/png" elif favicon_url.endswith(".jpg") or favicon_url.endswith(".jpeg"): favicon_mime = "image/jpeg" else: favicon_mime = None setup = { "system_uuid": cp.system_uuid, "installation_name": config.get("customization", "installation_name"), "logo_url": config.get("customization", "logo_url"), "logo_width": config.get("customization", "logo_width"), "logo_height": config.get("customization", "logo_height"), "branding_color": config.get("customization", "branding_color"), "branding_background_color": config.get("customization", "branding_background_color"), "favicon_url": favicon_url, "favicon_mime": favicon_mime, "debug_js": config.getboolean("main", "debug_js"), "install_collection": config.getboolean("develop", "install_collection"), "enable_gis_base_osm": config.getboolean("gis", "enable_osm"), "enable_gis_base_google_sat": config.getboolean("gis", "enable_google_sat"), "enable_gis_base_google_roadmap": config.getboolean("gis", "enable_google_roadmap"), "trace_extjs_events": config.getboolean("main", "trace_extjs_events"), "preview_theme": self.get_preview_theme(request) } theme = self.get_theme(request) return self.render( request, "desktop.html", apps=apps, setup=setup, theme=theme, theme_css=self.themes[theme]["css"], theme_js=self.themes[theme]["js"] )