free-range 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/free-range.rb +61 -53
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3d41efcb7e6ee1906179227559f6d004b2d07816b3aa230756f4b64f6f0327
|
4
|
+
data.tar.gz: f61a1feddd95066226602b0540c54efeada8a2846c6eb8ba297655a76240454d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb942063fff21ce9e3a80e1b6223986da7c2a6ff632d01eb05c2e9c2c1a00faaf6655cc544d5b74fcfe14e5dd64c933d581a016e78078c53d8308f98a1af488
|
7
|
+
data.tar.gz: ce98a667f77b4ee2cf0dccca0cba7655b18ae2251e4e5284051bb366f725f58fc55c47ccaeb01522e056e2d68658804ffb6aee6d5a19d28d4bd23d235c8e56c3
|
data/lib/free-range.rb
CHANGED
@@ -515,6 +515,47 @@ module FreeRange
|
|
515
515
|
end
|
516
516
|
end
|
517
517
|
|
518
|
+
# Обробляє VLAN для інтерфейсу та виводить результати
|
519
|
+
# @param config [Config] Configuration object with commands
|
520
|
+
# @param interface [String, nil] Interface name or nil for all interfaces
|
521
|
+
# @param subscribers_result [String] Result of subscribers command
|
522
|
+
# @param target [String] Target device hostname
|
523
|
+
# @param use_color [Boolean] Enable colored output
|
524
|
+
# @param debug [Boolean] Enable debug output
|
525
|
+
# @param table_mode [Boolean] Display VLAN distribution table
|
526
|
+
# @param table_png_mode [String, nil] Path to save PNG or nil
|
527
|
+
# @return [void]
|
528
|
+
def self.process_and_output(config, interface, subscribers_result, target, use_color, debug, table_mode, table_png_mode)
|
529
|
+
ranges = Ranges.new
|
530
|
+
vlans = Vlans.new
|
531
|
+
subscribers_result.each_line do |line|
|
532
|
+
if line.split.first =~ /dhcp(?:_[0-9a-fA-F.]+)?_([^:]+):(\d+)@#{Regexp.escape(target)}$/
|
533
|
+
subscriber_interface, vlan = $1, $2.to_i
|
534
|
+
if interface
|
535
|
+
vlans.add_vlan(vlan) if subscriber_interface == interface && vlan > 0
|
536
|
+
else
|
537
|
+
vlans.add_vlan(vlan) if vlan > 0
|
538
|
+
end
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
542
|
+
process_interface(config, interface, ranges, debug)
|
543
|
+
if debug
|
544
|
+
puts "\nІнтерфейс: #{interface}" if interface
|
545
|
+
Print.ranged(ranges)
|
546
|
+
Print.vlans(vlans)
|
547
|
+
Print.vlan_ranges(vlans)
|
548
|
+
puts
|
549
|
+
end
|
550
|
+
if table_png_mode
|
551
|
+
Print.table_png(ranges, vlans, table_png_mode, target, interface)
|
552
|
+
elsif table_mode
|
553
|
+
Print.table(ranges, vlans, use_color, target, interface)
|
554
|
+
else
|
555
|
+
Print.combined_ranges(ranges, vlans, use_color, target, interface)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
518
559
|
# Основна логіка виконання
|
519
560
|
# @return [void]
|
520
561
|
def self.run
|
@@ -562,7 +603,7 @@ module FreeRange
|
|
562
603
|
puts "Помилка: неможливо завантажити конфігураційний файл '#{config_file}'."
|
563
604
|
exit 1
|
564
605
|
rescue ArgumentError => e
|
565
|
-
puts "Помилка в
|
606
|
+
puts "Помилка в аргументах конфігураційного файлу '#{config_file}': #{e.message}"
|
566
607
|
exit 1
|
567
608
|
rescue StandardError => e
|
568
609
|
puts "Помилка в конфігураційному файлі '#{config_file}': #{e.message}"
|
@@ -590,6 +631,23 @@ module FreeRange
|
|
590
631
|
c.password = config.password if config.password
|
591
632
|
}
|
592
633
|
|
634
|
+
if debug
|
635
|
+
puts "[DEBUG] Values:"
|
636
|
+
puts "[DEBUG] use_color: #{use_color}"
|
637
|
+
puts "[DEBUG] table_mode: #{table_mode}"
|
638
|
+
puts "[DEBUG] table_png_mode: #{table_png_mode}"
|
639
|
+
puts "[DEBUG] interface: #{interface}"
|
640
|
+
puts "[DEBUG] ARGV[0]: #{ARGV[0]}"
|
641
|
+
puts "[DEBUG] target: #{target}"
|
642
|
+
puts "[DEBUG] login: #{login}"
|
643
|
+
puts "[DEBUG] config_file: #{config_file}"
|
644
|
+
puts "[DEBUG] config.username: #{config.username}"
|
645
|
+
puts "[DEBUG] config.password: #{config.password}"
|
646
|
+
puts "[DEBUG] config.ssh_command: #{config.ssh_command}"
|
647
|
+
puts "[DEBUG] config.subscribers_command: #{config.subscribers_command}"
|
648
|
+
puts "[DEBUG] config.command_interfaces: #{config.command_interfaces}"
|
649
|
+
end
|
650
|
+
|
593
651
|
subscribers_result = `#{config.subscribers_command}`.strip
|
594
652
|
if subscribers_result.empty?
|
595
653
|
puts "Помилка: результат subscribers_command порожній. Перевір шлях або доступ."
|
@@ -612,60 +670,10 @@ module FreeRange
|
|
612
670
|
end
|
613
671
|
|
614
672
|
interfaces.each do |intf|
|
615
|
-
|
616
|
-
vlans = Vlans.new
|
617
|
-
subscribers_result.each_line do |line|
|
618
|
-
if line.split.first =~ /dhcp(?:_[0-9a-fA-F.]+)?_([^:]+):(\d+)@#{Regexp.escape(target)}$/
|
619
|
-
subscriber_interface, vlan = $1, $2.to_i
|
620
|
-
vlans.add_vlan(vlan) if subscriber_interface == intf && vlan > 0
|
621
|
-
end
|
622
|
-
end
|
623
|
-
|
624
|
-
process_interface(config, intf, ranges, debug)
|
625
|
-
if debug
|
626
|
-
puts "\nІнтерфейс: #{intf}"
|
627
|
-
Print.ranged(ranges)
|
628
|
-
Print.vlans(vlans)
|
629
|
-
Print.vlan_ranges(vlans)
|
630
|
-
puts
|
631
|
-
end
|
632
|
-
if table_png_mode
|
633
|
-
Print.table_png(ranges, vlans, table_png_mode, target, intf)
|
634
|
-
elsif table_mode
|
635
|
-
Print.table(ranges, vlans, use_color, target, intf)
|
636
|
-
else
|
637
|
-
Print.combined_ranges(ranges, vlans, use_color, target, intf)
|
638
|
-
end
|
673
|
+
process_and_output(config, intf, subscribers_result, target, use_color, debug, table_mode, table_png_mode)
|
639
674
|
end
|
640
675
|
else
|
641
|
-
|
642
|
-
vlans = Vlans.new
|
643
|
-
subscribers_result.each_line do |line|
|
644
|
-
if line.split.first =~ /dhcp(?:_[0-9a-fA-F.]+)?_([^:]+):(\d+)@#{Regexp.escape(target)}$/
|
645
|
-
subscriber_interface, vlan = $1, $2.to_i
|
646
|
-
if interface
|
647
|
-
vlans.add_vlan(vlan) if subscriber_interface == interface && vlan > 0
|
648
|
-
else
|
649
|
-
vlans.add_vlan(vlan) if vlan > 0
|
650
|
-
end
|
651
|
-
end
|
652
|
-
end
|
653
|
-
|
654
|
-
process_interface(config, interface, ranges, debug)
|
655
|
-
if debug
|
656
|
-
puts "\nІнтерфейс: #{interface}" if interface
|
657
|
-
Print.ranged(ranges)
|
658
|
-
Print.vlans(vlans)
|
659
|
-
Print.vlan_ranges(vlans)
|
660
|
-
puts
|
661
|
-
end
|
662
|
-
if table_png_mode
|
663
|
-
Print.table_png(ranges, vlans, table_png_mode, target, interface)
|
664
|
-
elsif table_mode
|
665
|
-
Print.table(ranges, vlans, use_color, target, interface)
|
666
|
-
else
|
667
|
-
Print.combined_ranges(ranges, vlans, use_color, target, interface)
|
668
|
-
end
|
676
|
+
process_and_output(config, interface, subscribers_result, target, use_color, debug, table_mode, table_png_mode)
|
669
677
|
end
|
670
678
|
end
|
671
679
|
end
|