Changeset - 6a5a15855897
[Not reviewed]
version_5
0 5 0
Dennis Fink - 10 years ago 2015-08-26 18:32:29
dennis.fink@c3l.lu
Remove status from model

tor_status was renamed to status. Because people are only interested in if the
tor process is actually running!
5 files changed with 5 insertions and 16 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/model.py
Show inline comments
 
@@ -66,49 +66,48 @@ class ServerDecoder(json.JSONDecoder):
 
    def decode(self, json_string):
 

	
 
        default_obj = super().decode(json_string)
 

	
 
        for key in ('ip', 'ip6'):
 
            if key in default_obj:
 
                current_app.logger.debug('{}: {}'.format(key, default_obj[key]))
 
                default_obj[key] = ipaddress.ip_address(default_obj[key])
 

	
 
        current_app.logger.debug('Loading last_updated')
 
        default_obj['last_updated'] = datetime.fromtimestamp(
 
            strict_rfc3339.rfc3339_to_timestamp(default_obj['last_updated'])
 
        )
 

	
 
        return default_obj
 

	
 

	
 
class Server:
 

	
 
    def __init__(self, *args, **kwargs):
 

	
 
        self.name = kwargs['name']
 
        self.type = kwargs['type']
 
        self.status = kwargs.get('status')
 
        self.tor_status = kwargs.get('tor_status')
 
        self.fingerprint = kwargs['fingerprint']
 
        self.last_updated = kwargs['last_updated']
 
        self.country = kwargs['country']
 
        self.bandwith = kwargs.get('bandwith')
 

	
 
        if self.type == 'bridge':
 
            self.obfs = kwargs.get('obfs')
 
            self.fteproxy = kwargs.get('fteproxy')
 
            self.flashproxy = kwargs.get('flashproxy')
 
            self.meek = kwargs.get('meek')
 
        else:
 
            self.ip = kwargs['ip']
 

	
 
            if 'ip6' in kwargs:
 
                self.ip6 = kwargs['ip6']
 

	
 
            default_weights = {
 
                '1_week': None,
 
                '1_month': None,
 
                '3_months': None,
 
                '1_year': None,
 
                '5_years': None
 
            }
 

	
 
@@ -214,28 +213,26 @@ class Server:
 
        except requests.HTTPError as e:
 
            raise e
 
        else:
 
            data = data.json()['relays'][0]
 

	
 
        self.mean_consensus_weight = calculate_weight(data['consensus_weight'])
 
        self.mean_exit_probability = calculate_weight(data['exit_probability'])
 
        self.mean_guard_probability = calculate_weight(
 
            data['guard_probability']
 
        )
 
        self.mean_middle_probability = calculate_weight(
 
            data['middle_probability']
 
        )
 
        self.mean_consensus_weight_fraction = calculate_weight(
 
            data['consensus_weight_fraction']
 
        )
 

	
 
    def check_status(self):
 

	
 
        now = datetime.utcnow()
 
        delta = now - self.last_updated
 

	
 
        if delta.seconds >= 3600:
 
            self.status = False
 
            self.tor_status = False
 
            return False
 
        else:
 
            return True
 
        elif delta.seconds >= 600:
 
            self.status = None
ennstatus/api/schema/server.json
Show inline comments
 
{
 
    "title": "Relay/Exit schema",
 
    "$schema": "http://json-schema.org/draft-04/schema#",
 
    "type": "object",
 
    "properties": {
 
        "name": {
 
            "type": "string"
 
        },
 
        "status": {
 
            "$ref": "#/definitions/status_data"
 
        },
 
        "tor_status": {
 
            "$ref": "#/definitions/status_data"
 
        },
 
        "country": {
 
            "type": "string",
 
            "enum": [
 
                "Afghanistan", "Aland Islands", "Albania", "Algeria", 
 
                "American Samoa", "Andorra", "Angola", "Anguilla",
 
                "Anonymous Proxy", "Antarctica", "Antigua and Barbuda",
 
                "Argentina", "Armenia", "Aruba", "Asia/Pacific Region",
 
                "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain",
 
                "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize",
 
                "Benin", "Bermuda", "Bhutan", "Bolivia",
 
                "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina",
 
                "Botswana", "Bouvet Island", "Brazil",
 
                "British Indian Ocean Territory", "Brunei Darussalam",
 
                "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
 
                "Cameroon", "Canada", "Cape Verde", "Cayman Islands",
 
                "Central African Republic", "Chad", "Chile", "China",
 
                "Christmas Island", "Cocos (Keeling) Islands", "Colombia",
 
                "Comoros", "Congo", "Congo, The Democratic Republic of the",
 
                "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia",
 
                "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti",
 
                "Dominica", "Dominican Republic", "Ecuador", "Egypt",
 
                "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia",
 
                "Ethiopia", "Europe", "Falkland Islands (Malvinas)",
 
                "Faroe Islands", "Fiji", "Finland", "France",
 
@@ -87,49 +84,48 @@
 
            ]
 
        },
 
        "fingerprint": {
 
            "type": "string",
 
            "pattern": "^[a-zA-Z0-9]{40}$"
 
        },
 
        "last_updated": {
 
            "type": "string",
 
            "format": "date-time"
 
        },
 
        "bandwith": {
 
            "type": [
 
                "string",
 
                "null"
 
            ],
 
            "default": null
 
        },
 
        "type": {
 
            "type": "string"
 
        }
 
    },
 
    "required": [
 
        "name",
 
        "status",
 
        "tor_status",
 
        "last_updated",
 
        "country",
 
        "fingerprint",
 
        "type"
 
    ],
 
    "definitions": {
 
        "weights": {
 
            "type": "object",
 
            "properties": {
 
                "1_week": {
 
                    "$ref": "#/definitions/weights_data"
 
                },
 
                "1_month": {
 
                    "$ref": "#/definitions/weights_data"
 
                },
 
                "3_months": {
 
                    "$ref": "#/definitions/weights_data"
 
                },
 
                "1_year": {
 
                    "$ref": "#/definitions/weights_data"
 
                },
 
                "5_years": {
 
                    "$ref": "#/definitions/weights_data"
 
                }
ennstatus/api/views.py
Show inline comments
 
@@ -40,49 +40,48 @@ def update():
 
        return 'No JSON data supplied!\n', 400, {'Content-Type': 'text/plain'}
 

	
 
    if 'ip' in data:
 
        ip = data['ip']
 
    elif 'ip6' in data:
 
        ip = data['ip6']
 
    else:
 
        ip = request.remote_addr
 

	
 
    try:
 
        ip = ipaddress.ip_address(ip)
 
    except ipaddress.AddressValueError:
 
        return 'IP not allowed!\n', 403, {'Content-Type': 'text/plain'}
 

	
 
    if ip.version == 4:
 
        data['country'] = gi4.country_name_by_addr(str(ip))
 
    elif ip.version == 6:
 
        data['country'] = gi6.country_name_by_addr(str(ip))
 
    else:
 
        data['country'] = None
 

	
 
    data['last_updated'] = strict_rfc3339.timestamp_to_rfc3339_utcoffset(
 
        datetime.utcnow().timestamp()
 
    )
 
    data['status'] = True
 

	
 
    try:
 
        server = Server.from_json(json.dumps(data))
 
    except Exception as e:
 
        current_app.logger.warning(' '.join([str(e), str(data)]))
 
        return str(e), 409, {'Content-Type': 'text/plain'}
 

	
 
    if server.type in ('exit', 'relay'):
 
        server.update_weights()
 

	
 
    try:
 
        server.save()
 
    except Exception as e:
 
        current_app.logger.error(str(e))
 
        return str(e), 500, {'Content-Type': 'text/plain'}
 

	
 
    current_app.logger.info('Return result')
 
    return (server.json(), 201,
 
            {'Location': '/api/export/json/single?server_name=%s'
 
             % server.name})
 

	
 

	
 
@api_page.route('/export', defaults={'server_type': 'all',
 
                                     'export_format': 'json'})
ennstatus/templates/api/export/xml/server.xml
Show inline comments
 
<server>
 
    <type>{{ server.type }}</type>
 
    <name>{{ server.name }}</name>
 
    <status>{{ server.status }}</status>
 
    <tor_status>{{ server.tor_status }}</tor_status>
 
    <country>{{ server.country }}</country>
 
    <last_updated>{{ server.last_updated }}</last_updated>
 
    <fingerprint>{{ serverfingerprint }}</fingerprint>
 
    {% if server.type == 'bridge' %}
 
    <obfs>{{ server.obfs }}</obfs>
 
    <fteproxy>{{ server.fteproxy }}</fteproxy>
 
    <flashproxy>{{ server.flashproxy }}</flashproxy>
 
    <meek>{{ server.meek }}</meek>
 
    {% else %}
 
    <ip>{{ server.ip }}</ip>
 
      {% if 'ip6' in server %}
 
        <ip6>{{ server.ip6</ip6>
 
      {% endif %}
 
    {% endif %}
 
  </server>
ennstatus/templates/status/macros.html
Show inline comments
 
@@ -29,78 +29,76 @@
 
  {% else %}
 
    {% set url_type = 'bridge' %}
 
  {% endif %}
 
  {% if '.onion' in request.url_root %}
 
    {% set url_root = '//%s' % config['ENNSTATUS_GLOBE_ONION_ADDRESS'] %}
 
  {% elif '.bit' in request.url_root %}
 
    {% set url_root = '//%s' % config['ENNSTATUS_GLOBE_BIT_ADDRESS'] %}
 
  {% else %}
 
    {% set url_root = '//globe.enn.lu' %}
 
  {% endif %}
 
  <a href="{{ url_root }}/#/{{ url_type }}/{{ fingerprint }}">{{ fingerprint|upper}}</a>
 
{% endmacro %}
 

	
 
{% macro create_name(name) %}
 
  <a href="http://{{ name|lower }}.enn.lu">{{ name }}</a>
 
{% endmacro %}
 

	
 
{% macro create_date(date) %}
 
  {{ moment(date).format(config['ENNSTATUS_MOMENTJS_FORMAT']) }}
 
  <noscript>{{ date.strftime(config['ENNSTATUS_STRFTIME_FORMAT']) }}</noscript>
 
{% endmacro %}
 

	
 
{% macro create_server_table(server_type, servers) %}
 
  {% if server_type in ('exit', 'relay') %}
 
    {% set headers = ('#', 'Name', 'IP', 'IP6', 'Server Status', 'Tor Status', 'Country', 'Fingerprint', 'Last Updated <noscript>(UTC)</noscript>') %}
 
    {% set headers = ('#', 'Name', 'IP', 'IP6', 'Tor Status', 'Country', 'Fingerprint', 'Last Updated <noscript>(UTC)</noscript>') %}
 
  {% else %}
 
    {% set headers = ('#', 'Name', 'Server Status', 'Tor Status', 'Country', 'Fingerprint', 'OBFS', 'FTEProxy', 'Flashproxy', 'meek', 'Last Updated <noscript>(UTC)</noscript>') %}
 
    {% set headers = ('#', 'Name', 'Tor Status', 'Country', 'Fingerprint', 'OBFS', 'FTEProxy', 'Flashproxy', 'meek', 'Last Updated <noscript>(UTC)</noscript>') %}
 
  {% endif %}
 
  <h2>{{ server_type|title }}</h2>
 
  <table class="table table-bordered table-striped sortable">
 
    <thead>
 
      <tr>
 
        {% for name in headers %}
 
          <th>{{ name|safe }}</th>
 
        {% endfor %}
 
      </tr>
 
    </thead>
 
    <tbody>
 
      {% for server in servers|sort(attribute='name')|sort(attribute='country') %}
 
      <tr {% if server.name in config['ENNSTATUS_BRIDGE_PROGRAM'] %}class="info"{% endif %}>
 
          <td>{{ loop.index }}</td>
 
          {% if server_type in ('exit', 'relay') %}
 
            <td>{{ create_name(server.name) }}</td>
 
            <td>{{ server.ip }}</td>
 
            <td>{{ server.ip6 or 'N/A' }}</td>
 
          {% else %}
 
            <td>
 
              {% if server.name in config['ENNSTATUS_BRIDGE_PROGRAM'] %}
 
                <a href="{{ url_for('root.bridgeprogram') }}">{{ server.name }}</a>
 
              {% else %}
 
                {{ server.name }}
 
              {% endif %}
 
            </td>
 
          {% endif %}
 
          {% for status in (server.status, server.tor_status) %}
 
            <td>{{ colorize_status(status) }}</td>
 
          {% endfor %}
 
          <td>{{ colorize_status(server.status) }}</td>
 
          <td>{{ create_country(server.country) }}</td>
 
          <td>{{ create_fingerprint(server.fingerprint, server.type) }}</td>
 
          {% if server_type == 'bridge' %}
 
            <td>{{ colorize_obfs(server.obfs) }}</td>
 
            <td>{{ colorize_obfs(server.fteproxy) }}</td>
 
            <td>{{ colorize_obfs(server.flashproxy) }}</td>
 
            <td>{{ colorize_obfs(server.meek) }}</td>
 
          {% endif %}
 
          <td>{{ create_date(server.last_updated) }}
 
          </td>
 
        </tr>
 
      {% endfor %}
 
    </tbody>
 
  </table>
 
  {% if server_type == 'bridge' %}
 
    <div class="alert alert-info alert-dismissible" role="alert">
 
      <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
 
      <p>See our <a class="alert-link" href="{{ url_for('root.bridgeprogram') }}">bridge program</a>, if you want to fund some bridges!</p>
 
    </div>
 
  {% endif %}
 
{% endmacro %}
0 comments (0 inline, 0 general)