ChrisSacrumCor commited on
Commit
6dc42f6
·
verified ·
1 Parent(s): 5d50a4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +496 -2
app.py CHANGED
@@ -405,7 +405,476 @@ sudo iptables-save > /etc/iptables/rules.v4 # Save rules
405
  else:
406
  return f"❌ Unknown tool: {tool_name}. Available: user_management, file_permissions, system_commands"
407
 
408
- def select_linux_tool_and_args(self, user_input: str) -> Dict[str, Any]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  """Analyze user input to select appropriate Linux tool and arguments"""
410
  user_lower = user_input.lower()
411
 
@@ -691,7 +1160,32 @@ sudo iptables-save > /etc/iptables/rules.v4 # Save rules
691
  result = self.execute_linux_tool(tool_selection["tool"], tool_selection["args"])
692
  response = result
693
 
694
- # Handle other servers (Terraform, Cisco)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
695
  else:
696
  # Try to get server information first
697
  try:
 
405
  else:
406
  return f"❌ Unknown tool: {tool_name}. Available: user_management, file_permissions, system_commands"
407
 
408
+ def execute_cisco_tool(self, tool_name: str, arguments: Dict[str, Any]) -> str:
409
+ """Execute Cisco MCP tools - based on actual server code"""
410
+
411
+ if tool_name == "vlan_management":
412
+ action = arguments.get("action", "create_vlan")
413
+ vlan_id = arguments.get("vlan_id", 100)
414
+ vlan_name = arguments.get("vlan_name", f"VLAN_{vlan_id}")
415
+ interface = arguments.get("interface", "")
416
+
417
+ if action == "create_vlan":
418
+ return f"""**Cisco VLAN Creation Commands:**
419
+
420
+ ```cisco
421
+ ! Create VLAN {vlan_id}
422
+ configure terminal
423
+ vlan {vlan_id}
424
+ name {vlan_name}
425
+ state active
426
+ exit
427
+ exit
428
+
429
+ ! Verify VLAN creation:
430
+ show vlan brief
431
+ show vlan id {vlan_id}
432
+ ```"""
433
+
434
+ elif action == "assign_vlan":
435
+ interface = interface or "GigabitEthernet0/1"
436
+ return f"""**Assign Interface to VLAN Commands:**
437
+
438
+ ```cisco
439
+ ! Assign interface {interface} to VLAN {vlan_id}
440
+ configure terminal
441
+ interface {interface}
442
+ switchport mode access
443
+ switchport access vlan {vlan_id}
444
+ no shutdown
445
+ exit
446
+ exit
447
+
448
+ ! Verify interface assignment:
449
+ show interfaces {interface} switchport
450
+ show vlan brief
451
+ ```"""
452
+
453
+ elif action == "show_vlan":
454
+ return f"""**VLAN Information Commands:**
455
+
456
+ ```cisco
457
+ ! VLAN Information Commands
458
+ show vlan brief
459
+ show vlan summary
460
+ show vlan id {vlan_id}
461
+ show interfaces status
462
+ show spanning-tree vlan brief
463
+ ```"""
464
+
465
+ elif action == "delete_vlan":
466
+ return f"""**Delete VLAN Commands:**
467
+
468
+ ```cisco
469
+ ! Delete VLAN {vlan_id}
470
+ configure terminal
471
+ no vlan {vlan_id}
472
+ exit
473
+
474
+ ! Verify VLAN deletion:
475
+ show vlan brief
476
+ ```"""
477
+
478
+ elif tool_name == "interface_configuration":
479
+ action = arguments.get("action", "configure_access")
480
+ interface = arguments.get("interface", "GigabitEthernet0/1")
481
+ vlan_id = arguments.get("vlan_id", 1)
482
+ ip_address = arguments.get("ip_address", "")
483
+ description = arguments.get("description", "")
484
+
485
+ if action == "configure_access":
486
+ return f"""**Configure Access Port Commands:**
487
+
488
+ ```cisco
489
+ ! Configure {interface} as access port for VLAN {vlan_id}
490
+ configure terminal
491
+ interface {interface}
492
+ {f' description {description}' if description else ''}
493
+ switchport mode access
494
+ switchport access vlan {vlan_id}
495
+ spanning-tree portfast
496
+ no shutdown
497
+ exit
498
+ exit
499
+
500
+ ! Verify configuration:
501
+ show interfaces {interface} switchport
502
+ show interfaces {interface} status
503
+ ```"""
504
+
505
+ elif action == "configure_trunk":
506
+ return f"""**Configure Trunk Port Commands:**
507
+
508
+ ```cisco
509
+ ! Configure {interface} as trunk port
510
+ configure terminal
511
+ interface {interface}
512
+ {f' description {description}' if description else ''}
513
+ switchport mode trunk
514
+ switchport trunk encapsulation dot1q
515
+ switchport trunk allowed vlan {vlan_id if vlan_id != 1 else 'all'}
516
+ no shutdown
517
+ exit
518
+ exit
519
+
520
+ ! Verify trunk configuration:
521
+ show interfaces {interface} trunk
522
+ show interfaces {interface} switchport
523
+ ```"""
524
+
525
+ elif action == "set_ip":
526
+ if not ip_address:
527
+ ip_address = "192.168.1.1"
528
+ subnet_mask = arguments.get("subnet_mask", "255.255.255.0")
529
+ return f"""**Configure IP Address Commands:**
530
+
531
+ ```cisco
532
+ ! Configure IP address on {interface}
533
+ configure terminal
534
+ interface {interface}
535
+ ip address {ip_address} {subnet_mask}
536
+ {f' description {description}' if description else ''}
537
+ no shutdown
538
+ exit
539
+ exit
540
+
541
+ ! Verify IP configuration:
542
+ show ip interface {interface}
543
+ show ip interface brief
544
+ ```"""
545
+
546
+ elif action == "shutdown":
547
+ return f"""**Shutdown Interface Commands:**
548
+
549
+ ```cisco
550
+ ! Shutdown interface {interface}
551
+ configure terminal
552
+ interface {interface}
553
+ shutdown
554
+ exit
555
+ exit
556
+
557
+ ! Verify interface status:
558
+ show interfaces {interface} status
559
+ ```"""
560
+
561
+ elif action == "no_shutdown":
562
+ return f"""**Enable Interface Commands:**
563
+
564
+ ```cisco
565
+ ! Enable interface {interface}
566
+ configure terminal
567
+ interface {interface}
568
+ no shutdown
569
+ exit
570
+ exit
571
+
572
+ ! Verify interface status:
573
+ show interfaces {interface} status
574
+ ```"""
575
+
576
+ elif tool_name == "routing_configuration":
577
+ protocol = arguments.get("protocol", "ospf")
578
+ action = arguments.get("action", "configure")
579
+ network = arguments.get("network", "192.168.1.0 0.0.0.255")
580
+ area = arguments.get("area", "0")
581
+ process_id = arguments.get("process_id", 1)
582
+ next_hop = arguments.get("next_hop", "192.168.1.1")
583
+
584
+ if protocol == "ospf":
585
+ if action == "configure":
586
+ return f"""**OSPF Configuration Commands:**
587
+
588
+ ```cisco
589
+ ! Configure OSPF process {process_id}
590
+ configure terminal
591
+ router ospf {process_id}
592
+ network {network} area {area}
593
+ router-id 1.1.1.1
594
+ exit
595
+ exit
596
+
597
+ ! Verify OSPF configuration:
598
+ show ip ospf
599
+ show ip ospf neighbor
600
+ show ip ospf database
601
+ ```"""
602
+ elif action == "show":
603
+ return f"""**OSPF Information Commands:**
604
+
605
+ ```cisco
606
+ ! OSPF Information Commands
607
+ show ip ospf
608
+ show ip ospf neighbor
609
+ show ip ospf database
610
+ show ip ospf interface
611
+ show ip route ospf
612
+ ```"""
613
+
614
+ elif protocol == "static":
615
+ if action == "configure":
616
+ return f"""**Static Route Configuration:**
617
+
618
+ ```cisco
619
+ ! Configure static route to {network}
620
+ configure terminal
621
+ ip route {network} {next_hop}
622
+ exit
623
+
624
+ ! Verify static route:
625
+ show ip route static
626
+ show ip route
627
+ ```"""
628
+
629
+ elif protocol == "eigrp":
630
+ if action == "configure":
631
+ return f"""**EIGRP Configuration Commands:**
632
+
633
+ ```cisco
634
+ ! Configure EIGRP AS {process_id}
635
+ configure terminal
636
+ router eigrp {process_id}
637
+ network {network}
638
+ no auto-summary
639
+ exit
640
+ exit
641
+
642
+ ! Verify EIGRP configuration:
643
+ show ip eigrp neighbors
644
+ show ip eigrp topology
645
+ ```"""
646
+
647
+ elif tool_name == "security_configuration":
648
+ feature = arguments.get("feature", "ssh")
649
+ action = arguments.get("action", "enable")
650
+ acl_number = arguments.get("acl_number", 100)
651
+ interface = arguments.get("interface", "GigabitEthernet0/1")
652
+
653
+ if feature == "ssh" and action == "enable":
654
+ return f"""**SSH Configuration Commands:**
655
+
656
+ ```cisco
657
+ ! Enable SSH access
658
+ configure terminal
659
+ hostname CiscoRouter
660
+ ip domain-name company.local
661
+ crypto key generate rsa general-keys modulus 2048
662
+ ip ssh version 2
663
+ ip ssh time-out 60
664
+ ip ssh authentication-retries 3
665
+
666
+ ! Configure user account
667
+ username admin privilege 15 secret cisco123
668
+
669
+ ! Configure VTY lines
670
+ line vty 0 4
671
+ transport input ssh
672
+ login local
673
+ exit
674
+ exit
675
+
676
+ ! Verify SSH configuration:
677
+ show ip ssh
678
+ show ssh
679
+ ```"""
680
+
681
+ elif feature == "acl" and action == "configure":
682
+ source_ip = arguments.get("source_ip", "192.168.1.0 0.0.0.255")
683
+ destination_ip = arguments.get("destination_ip", "any")
684
+ return f"""**Access Control List Configuration:**
685
+
686
+ ```cisco
687
+ ! Configure Access Control List {acl_number}
688
+ configure terminal
689
+ access-list {acl_number} permit ip {source_ip} {destination_ip}
690
+ access-list {acl_number} deny ip any any
691
+
692
+ ! Apply ACL to interface {interface}
693
+ interface {interface}
694
+ ip access-group {acl_number} in
695
+ exit
696
+ exit
697
+
698
+ ! Verify ACL:
699
+ show access-lists {acl_number}
700
+ show ip interface {interface}
701
+ ```"""
702
+
703
+ elif feature == "port_security" and action == "enable":
704
+ return f"""**Port Security Configuration:**
705
+
706
+ ```cisco
707
+ ! Enable port security on {interface}
708
+ configure terminal
709
+ interface {interface}
710
+ switchport mode access
711
+ switchport port-security
712
+ switchport port-security maximum 2
713
+ switchport port-security mac-address sticky
714
+ switchport port-security violation restrict
715
+ exit
716
+ exit
717
+
718
+ ! Verify port security:
719
+ show port-security interface {interface}
720
+ show port-security address
721
+ ```"""
722
+
723
+ elif tool_name == "troubleshooting":
724
+ category = arguments.get("category", "connectivity")
725
+ target = arguments.get("target", "8.8.8.8")
726
+ interface = arguments.get("interface", "")
727
+
728
+ if category == "connectivity":
729
+ return f"""**Connectivity Troubleshooting Commands:**
730
+
731
+ ```cisco
732
+ ! Connectivity Troubleshooting to {target}
733
+ ping {target}
734
+ traceroute {target}
735
+ show ip route
736
+ show arp
737
+ show ip interface brief
738
+
739
+ ! Extended ping test:
740
+ ping {target} repeat 100
741
+ ping {target} size 1500
742
+ ```"""
743
+
744
+ elif category == "interface":
745
+ return f"""**Interface Troubleshooting Commands:**
746
+
747
+ ```cisco
748
+ ! Interface Troubleshooting for {interface or 'all interfaces'}
749
+ {f'show interfaces {interface}' if interface else 'show interfaces'}
750
+ {f'show interfaces {interface} status' if interface else 'show interfaces status'}
751
+ {f'show controllers {interface}' if interface else 'show controllers'}
752
+ show ip interface brief
753
+
754
+ ! Interface statistics:
755
+ {f'show interfaces {interface} | include error' if interface else 'show interfaces | include error'}
756
+ ```"""
757
+
758
+ elif category == "routing":
759
+ return f"""**Routing Troubleshooting Commands:**
760
+
761
+ ```cisco
762
+ ! Routing Troubleshooting
763
+ show ip route
764
+ show ip protocols
765
+ show ip ospf neighbor
766
+ show ip eigrp neighbors
767
+ show cdp neighbors
768
+
769
+ ! Routing table analysis:
770
+ show ip route summary
771
+ show ip route {target if target else '0.0.0.0'}
772
+ ```"""
773
+
774
+ elif category == "switching":
775
+ return f"""**Switching Troubleshooting Commands:**
776
+
777
+ ```cisco
778
+ ! Switching Troubleshooting
779
+ show vlan brief
780
+ show interfaces status
781
+ show spanning-tree
782
+ show mac address-table
783
+ show cdp neighbors detail
784
+
785
+ ! Port and VLAN status:
786
+ show interfaces trunk
787
+ show spanning-tree blockedports
788
+ ```"""
789
+
790
+ elif category == "general":
791
+ return f"""**General Device Information Commands:**
792
+
793
+ ```cisco
794
+ ! General Device Information
795
+ show version
796
+ show running-config
797
+ show startup-config
798
+ show processes cpu
799
+ show memory
800
+ show environment
801
+ show logging
802
+
803
+ ! System status:
804
+ show clock
805
+ show users
806
+ show sessions
807
+ ```"""
808
+
809
+ else:
810
+ return f"❌ Unknown Cisco tool: {tool_name}. Available: vlan_management, interface_configuration, routing_configuration, security_configuration, troubleshooting"
811
+
812
+ def select_cisco_tool_and_args(self, user_input: str) -> Dict[str, Any]:
813
+ """Analyze user input to select appropriate Cisco tool and arguments based on actual server"""
814
+ user_lower = user_input.lower()
815
+
816
+ # VLAN management keywords
817
+ if any(word in user_lower for word in ["vlan", "create vlan", "assign vlan", "show vlan"]):
818
+ if "create" in user_lower:
819
+ return {"tool": "vlan_management", "args": {"action": "create_vlan", "vlan_id": 100, "vlan_name": "DATA_VLAN"}}
820
+ elif "assign" in user_lower:
821
+ return {"tool": "vlan_management", "args": {"action": "assign_vlan", "vlan_id": 100, "interface": "GigabitEthernet0/1"}}
822
+ elif "delete" in user_lower:
823
+ return {"tool": "vlan_management", "args": {"action": "delete_vlan", "vlan_id": 100}}
824
+ else:
825
+ return {"tool": "vlan_management", "args": {"action": "show_vlan"}}
826
+
827
+ # Interface configuration keywords
828
+ elif any(word in user_lower for word in ["interface", "port", "access", "trunk", "ethernet"]):
829
+ if "trunk" in user_lower:
830
+ return {"tool": "interface_configuration", "args": {"action": "configure_trunk", "interface": "GigabitEthernet0/1"}}
831
+ elif "ip" in user_lower or "address" in user_lower:
832
+ return {"tool": "interface_configuration", "args": {"action": "set_ip", "interface": "GigabitEthernet0/1", "ip_address": "192.168.1.1"}}
833
+ elif "shutdown" in user_lower:
834
+ return {"tool": "interface_configuration", "args": {"action": "shutdown", "interface": "GigabitEthernet0/1"}}
835
+ elif "enable" in user_lower or "no shutdown" in user_lower:
836
+ return {"tool": "interface_configuration", "args": {"action": "no_shutdown", "interface": "GigabitEthernet0/1"}}
837
+ else:
838
+ return {"tool": "interface_configuration", "args": {"action": "configure_access", "interface": "GigabitEthernet0/1", "vlan_id": 10}}
839
+
840
+ # Routing keywords
841
+ elif any(word in user_lower for word in ["routing", "route", "ospf", "eigrp", "static"]):
842
+ if "ospf" in user_lower:
843
+ return {"tool": "routing_configuration", "args": {"protocol": "ospf", "action": "configure", "network": "192.168.1.0 0.0.0.255"}}
844
+ elif "static" in user_lower:
845
+ return {"tool": "routing_configuration", "args": {"protocol": "static", "action": "configure", "network": "10.0.0.0 255.0.0.0", "next_hop": "192.168.1.1"}}
846
+ elif "eigrp" in user_lower:
847
+ return {"tool": "routing_configuration", "args": {"protocol": "eigrp", "action": "configure", "network": "192.168.1.0 0.0.0.255"}}
848
+ else:
849
+ return {"tool": "routing_configuration", "args": {"protocol": "ospf", "action": "show"}}
850
+
851
+ # Security keywords
852
+ elif any(word in user_lower for word in ["security", "ssh", "acl", "access-list", "port-security"]):
853
+ if "ssh" in user_lower:
854
+ return {"tool": "security_configuration", "args": {"feature": "ssh", "action": "enable"}}
855
+ elif "acl" in user_lower or "access-list" in user_lower:
856
+ return {"tool": "security_configuration", "args": {"feature": "acl", "action": "configure", "acl_number": 100}}
857
+ elif "port-security" in user_lower or "port security" in user_lower:
858
+ return {"tool": "security_configuration", "args": {"feature": "port_security", "action": "enable", "interface": "GigabitEthernet0/1"}}
859
+ else:
860
+ return {"tool": "security_configuration", "args": {"feature": "ssh", "action": "enable"}}
861
+
862
+ # Troubleshooting keywords
863
+ elif any(word in user_lower for word in ["troubleshoot", "debug", "ping", "traceroute", "show", "connectivity"]):
864
+ if "connectivity" in user_lower or "ping" in user_lower:
865
+ return {"tool": "troubleshooting", "args": {"category": "connectivity", "target": "8.8.8.8"}}
866
+ elif "interface" in user_lower:
867
+ return {"tool": "troubleshooting", "args": {"category": "interface"}}
868
+ elif "routing" in user_lower or "route" in user_lower:
869
+ return {"tool": "troubleshooting", "args": {"category": "routing"}}
870
+ elif "switching" in user_lower or "switch" in user_lower:
871
+ return {"tool": "troubleshooting", "args": {"category": "switching"}}
872
+ else:
873
+ return {"tool": "troubleshooting", "args": {"category": "general"}}
874
+
875
+ # Default - show help
876
+ else:
877
+ return {"tool": "help", "args": {}}
878
  """Analyze user input to select appropriate Linux tool and arguments"""
879
  user_lower = user_input.lower()
880
 
 
1160
  result = self.execute_linux_tool(tool_selection["tool"], tool_selection["args"])
1161
  response = result
1162
 
1163
+ # Handle Cisco server specifically (full functionality)
1164
+ elif selected_server == "cisco":
1165
+ tool_selection = self.select_cisco_tool_and_args(user_input)
1166
+
1167
+ if tool_selection["tool"] == "help":
1168
+ response = """**Available Cisco MCP Tools:**
1169
+
1170
+ 🏷️ **vlan_management**: Create, delete, assign, and show VLANs
1171
+ 🌐 **interface_configuration**: Configure access/trunk ports, IP addresses, shutdown/enable
1172
+ 🛣️ **routing_configuration**: Set up OSPF, EIGRP, static routes
1173
+ 🔒 **security_configuration**: Configure SSH, ACLs, port security
1174
+ 🔧 **troubleshooting**: Network connectivity, interface, routing, switching diagnostics
1175
+
1176
+ **Example commands you can ask for:**
1177
+ - "Create a VLAN" or "Show VLAN information"
1178
+ - "Configure interface as access port" or "Set up trunk port"
1179
+ - "Configure OSPF routing" or "Set up static routes"
1180
+ - "Enable SSH access" or "Configure ACL"
1181
+ - "Troubleshoot connectivity" or "Check interface status"
1182
+ """
1183
+ else:
1184
+ # Execute the selected Cisco tool
1185
+ result = self.execute_cisco_tool(tool_selection["tool"], tool_selection["args"])
1186
+ response = result
1187
+
1188
+ # Handle other servers (Terraform)
1189
  else:
1190
  # Try to get server information first
1191
  try: