def get(self): utils.check_ip(self.request) name = self.get_argument('f') if name.startswith('/') or name.find('..') >= 0: return text = file_manager.load_file(name) or '' self.write(text)
def post(self): utils.check_ip(self.request) text = self.get_body_argument('text') css = open('style.css', 'r').read() html = tools.make_html.make_html(text, css) #html = base64.b64encode(html) self.write(html)
def check_ip_and_gateway(self, args): if args.ip: if not utils.check_ip(args.ip): print("\nPlease check the format of IP...\n") sys.exit() if args.gateway: if not utils.check_ip(args.gateway): print("\nPlease check the format of Gateway...\n") sys.exit()
def test_check_ip(self): first_rack = create_rack('newline', 10) create_and_add_server(first_rack, '111.111.111.111', 128) good_ip = check_ip('222.222.222.222') self.assertEqual(good_ip, '222.222.222.222') with self.assertRaises(AttributeError): check_ip('222.222.222.asdfs') with self.assertRaises(AttributeError): check_ip('111.111.111.111')
def dispatch_request(self, *args, **kwargs): if not check_ip(request): return # We just return the content of the template return send_from_directory('templates/', self.action.pi_api_template)
def dispatch_request(self, *args, **kwargs): if not check_ip(request): return objResponse = {} # Template information objResponse['template_tag'] = ("" if self.action.pi_api_template == "" else md5Checksum('templates/' + self.action.pi_api_template)) for attribute in (u'only_logged_user', u'only_member_user', u'only_admin_user', u'only_orga_member_user', u'only_orga_admin_user', # User restrictions u'cache_time', u'cache_by_user', # Cache information u'user_info', u'json_only', 'no_template'): # Requested user infos + JSON-only if hasattr(self.action, u'pi_api_' + attribute): objResponse[attribute] = getattr(self.action, u'pi_api_' + attribute) # Add the cache headers response = make_response(object2json(objResponse, include_properties=False)) expires = datetime.utcnow() + timedelta(seconds=PI_META_CACHE) expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") response.headers['Expire'] = expires response.headers['Cache-Control'] = 'public, max-age=' + str(PI_META_CACHE) # Return the final response return response
def dispatch_request(self, *args, **kwargs): if not check_ip(request): return # Call the action result = self.action(request, *args, **kwargs) # Is it a redirect ? if isinstance(result, PlugItRedirect): response = make_response("") response.headers['EbuIo-PlugIt-Redirect'] = result.url if result.no_prefix: response.headers['EbuIo-PlugIt-Redirect-NoPrefix'] = 'True' return response elif isinstance(result, PlugItSendFile): response = send_file( result.filename, mimetype=result.mimetype, as_attachment=result.as_attachment, attachment_filename=result.attachment_filename) response.headers['EbuIo-PlugIt-ItAFile'] = 'True' return response return jsonify(result)
def create_bonding(self, node, bonding_name, mode, device_list, new_ip): bonding = action.IpService(node) if not self.modify_mode: connection = bonding.get_connection() if self.check_bonding_exist(f'vtel_{bonding_name}', connection): print(f"{bonding_name} already exists.") sys.exit() if not utils.check_ip(new_ip): sys.exit() lc_device_date = bonding.get_device_status() if not self.check_device(device_list, lc_device_date): sys.exit() if bonding.set_bonding(bonding_name, mode): gateway = f"{'.'.join(new_ip.split('.')[:3])}.1" bonding.modify_ip(bonding_name, new_ip, gateway) if mode == "802.3ad": bonding.add_bond_options(bonding_name, "xmit_hash_policy=layer3+4") bonding.add_bond_options(bonding_name, "miimon=100") bonding.add_bond_options(bonding_name, "lacp_rate=fast") for device in device_list: bonding_slave = bonding.add_bond_slave(bonding_name, device) if bonding_slave: bonding.up_ip_service(bonding_slave) else: print(f'Failed to add bond slave about {device}') bonding.up_ip_service(f'vtel_{bonding_name}')
def add_server(self, input_str): if not input_str: raise ValueError("无传参, 请重新输入") argv_list = input_str.split(" ") user, port = 'root', 22 ip = argv_list[0] if not check_ip(ip): print("{0} 不是ip".format(color_str(Color.RED, ip))) return try: opts = getopt(argv_list[1:], "u:p:") for cmd, arg in opts[0]: if cmd in ("-u", "--username"): user = arg elif cmd in ("-p", "--port"): port = arg except GetoptError: print( "输入错误, 输入格式为 ip [ -u ][ -p ]\nexample: 192.168.35.62 -u root -p 22" ) server = Server(ip, user=user, port=port) #测试能否连接 server.test_ssh() #无法连接则复制密钥 if not server.is_ok: generate_rsa() server.copy_ssh_id() self.modify_server_list(server=server)
def init_teams(teams: dict): req = [] for k in teams.keys(): if check_ip(teams[k]): req.append({"name": k, "ip": teams[k]}) else: return False if len(req) > 0: conn = MongoClient(MONGO_URL) conn.main.teams.delete_many({}) conn.main.teams.insert_many(req) conn.close() return True return False
def modify_bonding_ip(self, node, device, ip): bonding = action.IpService(node) if not self.modify_mode: if not utils.check_ip(ip): sys.exit() connection = bonding.get_connection() if not self.check_bonding_exist(f'vtel_{device}', connection): print(f"{device} does not exist. Do nothing.") sys.exit() lc_ip_data = bonding.get_bond_ip(device) if not self.check_bond_ip(ip, lc_ip_data): print("Change bonding IP.") gateway = f"{'.'.join(ip.split('.')[:3])}.1" bonding.modify_ip(device, ip, gateway) bonding.up_ip_service(f'vtel_{device}') else: if not self.modify_mode: print("Same bonding IP. Do nothing.")
def dispatch_request(self, *args, **kwargs): if not check_ip(request): return # Call the action result = self.action(request, *args, **kwargs) headers = {} if isinstance(result, PlugItSetSession): headers = result.things_to_set result = result.base def update_headers(): for (key, value) in headers.items(): response.headers['EbuIo-PlugIt-SetSession-' + key] = value # Is it a redirect ? if isinstance(result, PlugItRedirect): response = make_response("") response.headers['EbuIo-PlugIt-Redirect'] = result.url if result.no_prefix: response.headers['EbuIo-PlugIt-Redirect-NoPrefix'] = 'True' update_headers() return response elif isinstance(result, PlugItSendFile): response = send_file( result.filename, mimetype=result.mimetype, as_attachment=result.as_attachment, attachment_filename=result.attachment_filename) response.headers['EbuIo-PlugIt-ItAFile'] = 'True' update_headers() return response response = jsonify(result) update_headers() return response
def dispatch_request(self, *args, **kwargs): if not check_ip(request): return # Call the action result = self.action(request, *args, **kwargs) # Is it a redirect ? if isinstance(result, PlugItRedirect): response = make_response("") response.headers['EbuIo-PlugIt-Redirect'] = result.url if result.no_prefix: response.headers['EbuIo-PlugIt-Redirect-NoPrefix'] = 'True' return response elif isinstance(result, PlugItSendFile): response = send_file(result.filename, mimetype=result.mimetype, as_attachment=result.as_attachment, attachment_filename=result.attachment_filename) response.headers['EbuIo-PlugIt-ItAFile'] = 'True' return response return object2json(result, include_properties=False)
def dispatch_request(self, *args, **kwargs): if not check_ip(request): return objResponse = {} # Template information objResponse['template_tag'] = ( "" if self.action.pi_api_template == "" else md5Checksum('templates/' + self.action.pi_api_template)) for attribute in ( u'only_logged_user', u'only_member_user', u'only_admin_user', u'only_orga_member_user', u'only_orga_admin_user', # User restrictions u'cache_time', u'cache_by_user', # Cache information u'user_info', u'json_only', 'no_template'): # Requested user infos + JSON-only if hasattr(self.action, u'pi_api_' + attribute): objResponse[attribute] = getattr(self.action, u'pi_api_' + attribute) # Add the cache headers response = make_response(jsonify(objResponse)) expires = datetime.utcnow() + timedelta(seconds=PI_META_CACHE) expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") response.headers['Expire'] = expires response.headers['Cache-Control'] = 'public, max-age=' + str( PI_META_CACHE) # Return the final response return response
def _check_init_param(data): return check_ip(data["hostname"]) and check_port(data["port"])
def post(self): utils.check_ip(self.request) text = self.get_body_argument('text') name = self.get_body_argument('f') file_manager.save_file(name, text) self.write('OK')
def _check_init_param(data): return validateUser(data["jwt"]) and check_ip( data["host"]) and check_port(data["port"])
def _check_init_param(data): return check_ip(data["host"])
def get(self): utils.check_ip(self.request) file_names = file_manager.file_manager.get_file_names() self.render('main.html', files=json.dumps(file_names))