We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
v2 removal on restore does not cover HTTPS services
The logic added in https://github.com/freedomofpress/securedrop/pull/5677 to disable v2 onion services when a backup is restored to a Focal server does not remove config lines for HTTPS services (port 443), potentially resulting in a broken configuration.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `install_files/ansible-base/roles/restore/files/disable_v2.py`
Content:
```
1 #!/usr/bin/env python3
2 # To execute on prod:
3 # python3 disable_v2.py /etc/tor/torrc /etc/tor/torrc
4 # To execute for testing locally:
5 # python3 disable_v2.py /etc/tor/torrc /tmp/dumytorrc
6 import sys
7 
8 
9 def filter_v2(filename):
10     # Read the file
11     with open(filename) as f:
12         data = f.readlines()
13     # We will store the filtered lines to result
14     result = []
15 
16     i = 0
17     while i < len(data):
18         line = data[i]
19         if line == "HiddenServiceDir /var/lib/tor/services/source\n":
20             i += 1
21             while data[i].strip() == "":
22                 i += 1
23             line = data[i]
24             if line == "HiddenServiceVersion 2\n":
25                 i += 1
26                 line = data[i]
27                 while data[i].strip() == "":
28                     i += 1
29                 line = data[i]
30                 if line == "HiddenServicePort 80 127.0.0.1:80\n":
31                     i += 1
32                     continue
33         # Now check for journalist
34         if line == "HiddenServiceDir /var/lib/tor/services/journalist\n":
35             i += 1
36             while data[i].strip() == "":
37                 i += 1
38             line = data[i]
39             if line == "HiddenServiceVersion 2\n":
40                 i += 1
41                 line = data[i]
42                 while data[i].strip() == "":
43                     i += 1
44                 line = data[i]
45                 if line == "HiddenServicePort 80 127.0.0.1:8080\n":
46                     i += 1
47                     line = data[i]
48                     while data[i].strip() == "":
49                         i += 1
50                     line = data[i]
51                     if line == "HiddenServiceAuthorizeClient stealth journalist\n":
52                         i += 1
53                         continue
54         # Now the v2 ssh access
55         if line == "HiddenServiceDir /var/lib/tor/services/ssh\n":
56             i += 1
57             while data[i].strip() == "":
58                 i += 1
59             line = data[i]
60             if line == "HiddenServiceVersion 2\n":
61                 i += 1
62                 line = data[i]
63                 while data[i].strip() == "":
64                     i += 1
65                 line = data[i]
66                 if line == "HiddenServicePort 22 127.0.0.1:22\n":
67                     i += 1
68                     line = data[i]
69                     while data[i].strip() == "":
70                         i += 1
71                     line = data[i]
72                     if line == "HiddenServiceAuthorizeClient stealth admin\n":
73                         i += 1
74                         continue
75 
76         result.append(line)
77         i += 1
78 
79     # Now return the result
80     return result
81 
82 
83 if __name__ == "__main__":
84     filename = sys.argv[1]
85     outputfilename = sys.argv[2]
86     result = filter_v2(filename)
87     with open(outputfilename, "w") as fobj:
88         for line in result:
89             fobj.write(line)
90
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/install_files/ansible-base/roles/restore/files/disable_v2.py b/install_files/ansible-base/roles/restore/files/disable_v2.py
deleted file mode 100644
--- a/install_files/ansible-base/roles/restore/files/disable_v2.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/usr/bin/env python3
-# To execute on prod:
-# python3 disable_v2.py /etc/tor/torrc /etc/tor/torrc
-# To execute for testing locally:
-# python3 disable_v2.py /etc/tor/torrc /tmp/dumytorrc
-import sys
-
-
-def filter_v2(filename):
-    # Read the file
-    with open(filename) as f:
-        data = f.readlines()
-    # We will store the filtered lines to result
-    result = []
-
-    i = 0
-    while i < len(data):
-        line = data[i]
-        if line == "HiddenServiceDir /var/lib/tor/services/source\n":
-            i += 1
-            while data[i].strip() == "":
-                i += 1
-            line = data[i]
-            if line == "HiddenServiceVersion 2\n":
-                i += 1
-                line = data[i]
-                while data[i].strip() == "":
-                    i += 1
-                line = data[i]
-                if line == "HiddenServicePort 80 127.0.0.1:80\n":
-                    i += 1
-                    continue
-        # Now check for journalist
-        if line == "HiddenServiceDir /var/lib/tor/services/journalist\n":
-            i += 1
-            while data[i].strip() == "":
-                i += 1
-            line = data[i]
-            if line == "HiddenServiceVersion 2\n":
-                i += 1
-                line = data[i]
-                while data[i].strip() == "":
-                    i += 1
-                line = data[i]
-                if line == "HiddenServicePort 80 127.0.0.1:8080\n":
-                    i += 1
-                    line = data[i]
-                    while data[i].strip() == "":
-                        i += 1
-                    line = data[i]
-                    if line == "HiddenServiceAuthorizeClient stealth journalist\n":
-                        i += 1
-                        continue
-        # Now the v2 ssh access
-        if line == "HiddenServiceDir /var/lib/tor/services/ssh\n":
-            i += 1
-            while data[i].strip() == "":
-                i += 1
-            line = data[i]
-            if line == "HiddenServiceVersion 2\n":
-                i += 1
-                line = data[i]
-                while data[i].strip() == "":
-                    i += 1
-                line = data[i]
-                if line == "HiddenServicePort 22 127.0.0.1:22\n":
-                    i += 1
-                    line = data[i]
-                    while data[i].strip() == "":
-                        i += 1
-                    line = data[i]
-                    if line == "HiddenServiceAuthorizeClient stealth admin\n":
-                        i += 1
-                        continue
-
-        result.append(line)
-        i += 1
-
-    # Now return the result
-    return result
-
-
-if __name__ == "__main__":
-    filename = sys.argv[1]
-    outputfilename = sys.argv[2]
-    result = filter_v2(filename)
-    with open(outputfilename, "w") as fobj:
-        for line in result:
-            fobj.write(line)

{"golden_diff": "diff --git a/install_files/ansible-base/roles/restore/files/disable_v2.py b/install_files/ansible-base/roles/restore/files/disable_v2.py\ndeleted file mode 100644\n--- a/install_files/ansible-base/roles/restore/files/disable_v2.py\n+++ /dev/null\n@@ -1,89 +0,0 @@\n-#!/usr/bin/env python3\n-# To execute on prod:\n-# python3 disable_v2.py /etc/tor/torrc /etc/tor/torrc\n-# To execute for testing locally:\n-# python3 disable_v2.py /etc/tor/torrc /tmp/dumytorrc\n-import sys\n-\n-\n-def filter_v2(filename):\n-    # Read the file\n-    with open(filename) as f:\n-        data = f.readlines()\n-    # We will store the filtered lines to result\n-    result = []\n-\n-    i = 0\n-    while i < len(data):\n-        line = data[i]\n-        if line == \"HiddenServiceDir /var/lib/tor/services/source\\n\":\n-            i += 1\n-            while data[i].strip() == \"\":\n-                i += 1\n-            line = data[i]\n-            if line == \"HiddenServiceVersion 2\\n\":\n-                i += 1\n-                line = data[i]\n-                while data[i].strip() == \"\":\n-                    i += 1\n-                line = data[i]\n-                if line == \"HiddenServicePort 80 127.0.0.1:80\\n\":\n-                    i += 1\n-                    continue\n-        # Now check for journalist\n-        if line == \"HiddenServiceDir /var/lib/tor/services/journalist\\n\":\n-            i += 1\n-            while data[i].strip() == \"\":\n-                i += 1\n-            line = data[i]\n-            if line == \"HiddenServiceVersion 2\\n\":\n-                i += 1\n-                line = data[i]\n-                while data[i].strip() == \"\":\n-                    i += 1\n-                line = data[i]\n-                if line == \"HiddenServicePort 80 127.0.0.1:8080\\n\":\n-                    i += 1\n-                    line = data[i]\n-                    while data[i].strip() == \"\":\n-                        i += 1\n-                    line = data[i]\n-                    if line == \"HiddenServiceAuthorizeClient stealth journalist\\n\":\n-                        i += 1\n-                        continue\n-        # Now the v2 ssh access\n-        if line == \"HiddenServiceDir /var/lib/tor/services/ssh\\n\":\n-            i += 1\n-            while data[i].strip() == \"\":\n-                i += 1\n-            line = data[i]\n-            if line == \"HiddenServiceVersion 2\\n\":\n-                i += 1\n-                line = data[i]\n-                while data[i].strip() == \"\":\n-                    i += 1\n-                line = data[i]\n-                if line == \"HiddenServicePort 22 127.0.0.1:22\\n\":\n-                    i += 1\n-                    line = data[i]\n-                    while data[i].strip() == \"\":\n-                        i += 1\n-                    line = data[i]\n-                    if line == \"HiddenServiceAuthorizeClient stealth admin\\n\":\n-                        i += 1\n-                        continue\n-\n-        result.append(line)\n-        i += 1\n-\n-    # Now return the result\n-    return result\n-\n-\n-if __name__ == \"__main__\":\n-    filename = sys.argv[1]\n-    outputfilename = sys.argv[2]\n-    result = filter_v2(filename)\n-    with open(outputfilename, \"w\") as fobj:\n-        for line in result:\n-            fobj.write(line)\n", "issue": "v2 removal on restore does not cover HTTPS services\nThe logic added in https://github.com/freedomofpress/securedrop/pull/5677 to disable v2 onion services when a backup is restored to a Focal server does not remove config lines for HTTPS services (port 443), potentially resulting in a broken configuration.\n", "before_files": [{"content": "#!/usr/bin/env python3\n# To execute on prod:\n# python3 disable_v2.py /etc/tor/torrc /etc/tor/torrc\n# To execute for testing locally:\n# python3 disable_v2.py /etc/tor/torrc /tmp/dumytorrc\nimport sys\n\n\ndef filter_v2(filename):\n    # Read the file\n    with open(filename) as f:\n        data = f.readlines()\n    # We will store the filtered lines to result\n    result = []\n\n    i = 0\n    while i < len(data):\n        line = data[i]\n        if line == \"HiddenServiceDir /var/lib/tor/services/source\\n\":\n            i += 1\n            while data[i].strip() == \"\":\n                i += 1\n            line = data[i]\n            if line == \"HiddenServiceVersion 2\\n\":\n                i += 1\n                line = data[i]\n                while data[i].strip() == \"\":\n                    i += 1\n                line = data[i]\n                if line == \"HiddenServicePort 80 127.0.0.1:80\\n\":\n                    i += 1\n                    continue\n        # Now check for journalist\n        if line == \"HiddenServiceDir /var/lib/tor/services/journalist\\n\":\n            i += 1\n            while data[i].strip() == \"\":\n                i += 1\n            line = data[i]\n            if line == \"HiddenServiceVersion 2\\n\":\n                i += 1\n                line = data[i]\n                while data[i].strip() == \"\":\n                    i += 1\n                line = data[i]\n                if line == \"HiddenServicePort 80 127.0.0.1:8080\\n\":\n                    i += 1\n                    line = data[i]\n                    while data[i].strip() == \"\":\n                        i += 1\n                    line = data[i]\n                    if line == \"HiddenServiceAuthorizeClient stealth journalist\\n\":\n                        i += 1\n                        continue\n        # Now the v2 ssh access\n        if line == \"HiddenServiceDir /var/lib/tor/services/ssh\\n\":\n            i += 1\n            while data[i].strip() == \"\":\n                i += 1\n            line = data[i]\n            if line == \"HiddenServiceVersion 2\\n\":\n                i += 1\n                line = data[i]\n                while data[i].strip() == \"\":\n                    i += 1\n                line = data[i]\n                if line == \"HiddenServicePort 22 127.0.0.1:22\\n\":\n                    i += 1\n                    line = data[i]\n                    while data[i].strip() == \"\":\n                        i += 1\n                    line = data[i]\n                    if line == \"HiddenServiceAuthorizeClient stealth admin\\n\":\n                        i += 1\n                        continue\n\n        result.append(line)\n        i += 1\n\n    # Now return the result\n    return result\n\n\nif __name__ == \"__main__\":\n    filename = sys.argv[1]\n    outputfilename = sys.argv[2]\n    result = filter_v2(filename)\n    with open(outputfilename, \"w\") as fobj:\n        for line in result:\n            fobj.write(line)\n", "path": "install_files/ansible-base/roles/restore/files/disable_v2.py"}], "after_files": [{"content": null, "path": "install_files/ansible-base/roles/restore/files/disable_v2.py"}]}