Get network knowledge base data
()
| 18760 | for hit in _glob.glob(pattern): |
| 18761 | real_hit = os.path.realpath(hit) |
| 18762 | if real_hit != real_base and not real_hit.startswith(real_base + os.sep): |
| 18763 | continue |
| 18764 | try: |
| 18765 | if os.path.isdir(real_hit) and not os.path.islink(real_hit): |
| 18766 | _shutil.rmtree(real_hit) |
| 18767 | else: |
| 18768 | os.remove(real_hit) |
| 18769 | removed += 1 |
| 18770 | except Exception as e: |
| 18771 | logger.warning(f"clear_files: could not remove {real_hit}: {e}") |
| 18772 | |
| 18773 | logger.info(f"Files cleared ({clear_type}): {removed} entries removed") |
| 18774 | return jsonify({ |
| 18775 | 'success': True, |
| 18776 | 'message': f'Files cleared successfully ({clear_type} clear, {removed} entries)' |
| 18777 | }) |
| 18778 | |
| 18779 | except Exception as e: |
| 18780 | logger.error(f"Error clearing files: {e}") |
| 18781 | return jsonify({'error': str(e)}), 500 |
| 18782 | |
| 18783 | # Legacy endpoint compatibility |
| 18784 | @app.route('/list_files') |
| 18785 | def legacy_list_files(): |
| 18786 | """Legacy endpoint for file listing""" |
| 18787 | try: |
| 18788 | path = request.args.get('path', '/') |
| 18789 | |
| 18790 | # Use the same logic as list_files_api but return legacy format |
| 18791 | if path == '/' or path == '': |
| 18792 | return jsonify([ |
| 18793 | {'name': 'data_stolen', 'is_directory': True, 'children': []}, |
| 18794 | {'name': 'scan_results', 'is_directory': True, 'children': []}, |
| 18795 | {'name': 'crackedpwd', 'is_directory': True, 'children': []}, |
| 18796 | {'name': 'vulnerabilities', 'is_directory': True, 'children': []}, |
| 18797 | {'name': 'logs', 'is_directory': True, 'children': []}, |
| 18798 | {'name': 'backups', 'is_directory': True, 'children': []}, |
| 18799 | {'name': 'uploads', 'is_directory': True, 'children': []} |
| 18800 | ]) |
| 18801 | |
| 18802 | # For other paths, use the web_utils function |
| 18803 | actual_path = "" |
| 18804 | if path.startswith('/data_stolen'): |
| 18805 | actual_path = shared_data.datastolendir |
| 18806 | elif path.startswith('/scan_results'): |
| 18807 | actual_path = shared_data.scan_results_dir |
| 18808 | elif path.startswith('/crackedpwd'): |
| 18809 | actual_path = shared_data.crackedpwddir |
| 18810 | elif path.startswith('/vulnerabilities'): |
| 18811 | actual_path = shared_data.vulnerabilities_dir |
| 18812 | elif path.startswith('/logs'): |
| 18813 | actual_path = shared_data.datadir + '/logs' |
| 18814 | elif path.startswith('/backups'): |
| 18815 | actual_path = shared_data.backupdir |
| 18816 | elif path.startswith('/uploads'): |
| 18817 | actual_path = shared_data.upload_dir |
| 18818 | |
| 18819 | if actual_path and os.path.exists(actual_path): |