XyloSiteMonitor

Check-in [192d391275]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added the ability to disable ipv6 if wanted
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 192d391275f35ce7c4b8b9d9ee84a29c08caf19368aef825f4b9c4e044548a6f
User & Date: xylon 2019-10-08 19:38:03
Context
2019-10-09
17:34
Fixed formatting bug in email titles Leaf check-in: 691fa11203 user: xylon tags: trunk
2019-10-08
19:38
Added the ability to disable ipv6 if wanted check-in: 192d391275 user: xylon tags: trunk
2019-05-14
19:51
Add a TODO check-in: 3cee1060a6 user: xylon tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to definitions_example.yml.

15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
    - action: redirect
      protocols:
        - no-TLS
        - TLS
- name: This site passes its tests
  expected string: Freed Computer
  canonical address: http://www.freedcomputer.net/

  urls:
  - url: www.freedcomputer.net
    tests:
    - action: return string
      protocols:
        - TLS
        - no-TLS
  - url: freedcomputer.net
    tests:
    - action: redirect
      protocols:
        - TLS
        - no-TLS







>













15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    - action: redirect
      protocols:
        - no-TLS
        - TLS
- name: This site passes its tests
  expected string: Freed Computer
  canonical address: http://www.freedcomputer.net/
  ipv6: false
  urls:
  - url: www.freedcomputer.net
    tests:
    - action: return string
      protocols:
        - TLS
        - no-TLS
  - url: freedcomputer.net
    tests:
    - action: redirect
      protocols:
        - TLS
        - no-TLS

Changes to xylositemonitor.py.

51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
...
162
163
164
165
166
167
168










169
170
171
172
173
174
175
...
179
180
181
182
183
184
185












186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# don't even try to open sitesfile unless it's there
if not os.path.isfile(sitesfile):
    print('Initialisation Error! Cannot find sitesfile at "' + sitesfile +
          '"\nPlease place it here or specify location with --sites-file=')
    sys.exit()

with open(sitesfile, 'r') as stream:
    sites = yaml.load(stream)

def send_mail(subject):

    import smtplib
    from email.mime.text import MIMEText

    msg = MIMEText(mail_body)
    msg['Subject'] = annotation + ': ' + subject
    msg['To'] = mailto
    msg['From'] = "xylositemonitor"
................................................................................
        ex_string = ""  # if this var is needed it will be validated and fail later :)

    try:
        can_address = site["canonical address"]
    except KeyError:
        can_address = ""  # if this var is needed it will be validated and fail later :)











    for urldef in site["urls"]:
        url = urldef["url"]
        if url[:7] == "http://" or url[:8] == "https://":
            config_fail('Do not specify protocol in url.')

        for test in urldef["tests"]:
            action = test["action"]
................................................................................
                    prefix = "https://"
                elif protocol == "no-TLS":
                    prefix = "http://"
                else:
                    config_fail('Supported protocols are "TLS" and "no-TLS".')

                for ipver in ("IPv4", "IPv6",):












                    if mailto:
                        mail_body += ipver + ', does "' + url + '" ' + \
                        action + ' over "' + protocol + '"?' + "\n"
                    else:
                        print(ipver + ', does "' + url + '" ' +
                              action + ' over "' + protocol + '"?')

                    if ipver == "IPv4":
                        curliptype = pycurl.IPRESOLVE_V4
                    elif ipver == "IPv6":
                        curliptype = pycurl.IPRESOLVE_V6

                    buffer = BytesIO()
                    c = pycurl.Curl()
                    c.setopt(c.URL, prefix + url)
                    c.setopt(c.FOLLOWLOCATION, False)
                    c.setopt(c.TIMEOUT, 8)
                    c.setopt(c.ACCEPT_ENCODING, "")
                    c.setopt(c.USERAGENT, "xylositemonitor")







|


>







 







>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>







<
<
<
<
<







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215





216
217
218
219
220
221
222
# don't even try to open sitesfile unless it's there
if not os.path.isfile(sitesfile):
    print('Initialisation Error! Cannot find sitesfile at "' + sitesfile +
          '"\nPlease place it here or specify location with --sites-file=')
    sys.exit()

with open(sitesfile, 'r') as stream:
    sites = yaml.safe_load(stream)

def send_mail(subject):
    """this function uses a global called mail_body"""
    import smtplib
    from email.mime.text import MIMEText

    msg = MIMEText(mail_body)
    msg['Subject'] = annotation + ': ' + subject
    msg['To'] = mailto
    msg['From'] = "xylositemonitor"
................................................................................
        ex_string = ""  # if this var is needed it will be validated and fail later :)

    try:
        can_address = site["canonical address"]
    except KeyError:
        can_address = ""  # if this var is needed it will be validated and fail later :)

    try:
        testipv4 = site["ipv4"]
    except KeyError:
        testipv4 = True

    try:
        testipv6 = site["ipv6"]
    except KeyError:
        testipv6 = True

    for urldef in site["urls"]:
        url = urldef["url"]
        if url[:7] == "http://" or url[:8] == "https://":
            config_fail('Do not specify protocol in url.')

        for test in urldef["tests"]:
            action = test["action"]
................................................................................
                    prefix = "https://"
                elif protocol == "no-TLS":
                    prefix = "http://"
                else:
                    config_fail('Supported protocols are "TLS" and "no-TLS".')

                for ipver in ("IPv4", "IPv6",):
                    if ipver == "IPv4":
                        if not testipv4:
                            continue
                        
                        curliptype = pycurl.IPRESOLVE_V4
                        
                    elif ipver == "IPv6":
                        if not testipv6:
                            continue
                        
                        curliptype = pycurl.IPRESOLVE_V6

                    if mailto:
                        mail_body += ipver + ', does "' + url + '" ' + \
                        action + ' over "' + protocol + '"?' + "\n"
                    else:
                        print(ipver + ', does "' + url + '" ' +
                              action + ' over "' + protocol + '"?')






                    buffer = BytesIO()
                    c = pycurl.Curl()
                    c.setopt(c.URL, prefix + url)
                    c.setopt(c.FOLLOWLOCATION, False)
                    c.setopt(c.TIMEOUT, 8)
                    c.setopt(c.ACCEPT_ENCODING, "")
                    c.setopt(c.USERAGENT, "xylositemonitor")