View | Details | Raw Unified | Return to bug 57504
Collapse All | Expand All

(-)a/schedule.py (-13 / +17 lines)
Lines 27-32 from samba.dcerpc import drsblobs Link Here
27
from samba.ndr import ndr_unpack, ndr_pack
27
from samba.ndr import ndr_unpack, ndr_pack
28
28
29
from samba.kcc.kcc_utils import new_connection_schedule
29
from samba.kcc.kcc_utils import new_connection_schedule
30
import time
30
31
31
32
32
class ScheduleException(Exception):
33
class ScheduleException(Exception):
Lines 57-77 def show_schedule(schedule, outf_write, print_legend=False): Link Here
57
    """
58
    """
58
59
59
    schedule_data = ndr_unpack(drsblobs.schedule, schedule).dataArray[0].slots
60
    schedule_data = ndr_unpack(drsblobs.schedule, schedule).dataArray[0].slots
61
    utc_offset_hours = time.localtime().tm_gmtoff // 3600
60
62
61
    days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
63
    days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
62
64
63
    outf_write("┌─" + ("─" * 2 + "┬") * 24 + "──" + "┐\n")
65
    outf_write("┌─" + ("─" * 2 + "┬" + "─────────") * 24 + "──" + "┐\n")
64
    header = "│D\\H│"
66
    header = "│D\\H│"
65
    for hour in range(1, 25):
67
    for hour in range(24):
66
        header += f"{hour:02d}│"
68
        next_hour = (hour + 1) % 24
69
        header += f"{hour:02d}:00-{next_hour:02d}:00│"
67
    outf_write(f"{header}\n")
70
    outf_write(f"{header}\n")
68
    outf_write("├─" + ("─" * 2 + "┼") * 24 + "──" + "┤\n")
71
    outf_write("├─" + ("─" * 2 + "┼" + "─────────") * 24 + "──" + "┤\n")
69
72
70
    for day_idx, day_name in enumerate(days):
73
    for day_idx, day_name in enumerate(days):
71
        day_row = f"│{day_name}│"
74
        day_row = f"│{day_name}│"
72
75
73
        for hour in range(24):
76
        for hour in range(24):
74
            byte_pos = (day_idx * 24 + hour + 7) % len(schedule_data)
77
            byte_pos = (((day_idx + 1) % 7) * 24 + hour - utc_offset_hours) % len(schedule_data)
75
78
76
            symbol = "  "
79
            symbol = "  "
77
80
Lines 82-104 def show_schedule(schedule, outf_write, print_legend=False): Link Here
82
                enabled_intervals = byte_val & 0x0F
85
                enabled_intervals = byte_val & 0x0F
83
86
84
                if enabled_intervals == 0x00:
87
                if enabled_intervals == 0x00:
85
                    symbol = "  "  # None
88
                    symbol = "       "  # None
86
                elif enabled_intervals == 0x01:
89
                elif enabled_intervals == 0x01:
87
                    symbol = "░░"  # Once per Hour (only first interval)
90
                    symbol = "     ░░"  # Once per Hour (only first interval)
88
                elif enabled_intervals == 0x05:
91
                elif enabled_intervals == 0x05:
89
                    symbol = "▒▒"  # Twice per Hour (first and third intervals)
92
                    symbol = "     ▒▒"  # Twice per Hour (first and third intervals)
90
                elif enabled_intervals == 0x0F:
93
                elif enabled_intervals == 0x0F:
91
                    symbol = "▓▓"  # Four Times per Hour (all intervals)
94
                    symbol = "     ▓▓"  # Four Times per Hour (all intervals)
92
            else:
95
            else:
93
                print(len(schedule_data), byte_pos)
96
                print(len(schedule_data), byte_pos)
94
97
95
            day_row += symbol + "│"
98
            day_row += symbol + "    │"
96
99
97
        outf_write(f"{day_row}\n")
100
        outf_write(f"{day_row}\n")
98
        if day_idx != 6:
101
        if day_idx != 6:
99
            outf_write("├─" + ("─" * 2 + "┼") * 24 + "──" + "┤\n")
102
            outf_write("├─" + ("─" * 2 + "┼" + "─────────") * 24 + "──" + "┤\n")
100
103
101
    outf_write("└─" + ("─" * 2 + "┴") * 24 + "──" + "┘\n\n")
104
    outf_write("└─" + ("─" * 2 + "┴" + "─────────") * 24 + "──" + "┘\n\n")
102
105
103
    if print_legend:
106
    if print_legend:
104
        outf_write("Legend:\n\n")
107
        outf_write("Legend:\n\n")
Lines 135-144 def set_schedule_slot(schedule, day, hour, slot): Link Here
135
    unpacked_schedule = ndr_unpack(drsblobs.schedule, schedule)
138
    unpacked_schedule = ndr_unpack(drsblobs.schedule, schedule)
136
139
137
    schedule_data = unpacked_schedule.dataArray[0].slots
140
    schedule_data = unpacked_schedule.dataArray[0].slots
141
    utc_offset_hours = time.localtime().tm_gmtoff // 3600
138
142
139
    day_index = day - 1
143
    day_index = day - 1
140
    hour_index = hour - 1
144
    hour_index = hour - 1
141
    data_index = (day_index * 24 + hour_index + 7) % len(schedule_data)
145
    data_index = (((day_index + 1) % 7) * 24 + hour - utc_offset_hours) % len(schedule_data)
142
146
143
    slot_values = [0x00, 0x01, 0x05, 0x0F]
147
    slot_values = [0x00, 0x01, 0x05, 0x0F]
144
    new_value = slot_values[slot]
148
    new_value = slot_values[slot]

Return to bug 57504