Browse Source

Maintenance: Drop unused client stat submission feature.

Martin Gruner 2 years ago
parent
commit
80111ff0e4

+ 0 - 239
app/assets/javascripts/app/lib/app_init/track.coffee

@@ -1,239 +0,0 @@
-# coffeelint: disable=no_backticks
-class App.Track
-  _instance = undefined
-
-  @init: ->
-    _instance ?= new _trackSingleton
-
-  @log: (area, level, args) ->
-    if _instance == undefined
-      _instance ?= new _trackSingleton
-    _instance.log(area, level, args)
-
-  @send: ->
-    if _instance == undefined
-      _instance ?= new _trackSingleton
-    _instance.send()
-
-  @force: (value) ->
-    if _instance == undefined
-      _instance ?= new _trackSingleton
-    _instance.force(value)
-
-  @_all: ->
-    if _instance == undefined
-      _instance ?= new _trackSingleton
-    _instance._all()
-
-class _trackSingleton
-  constructor: ->
-    @trackId = "track-#{new Date().getTime()}-#{Math.floor(Math.random() * 99999)}"
-    @browser = App.Browser.detection() if App.Browser
-    @data    = []
-#    @url     = 'http://localhost:3005/api/v1/ui'
-    @url      = 'https://log.zammad.com/api/v1/ui'
-    @logClick = true
-    @logAjax  = false
-
-    @forceSending = false
-
-    @log('start', 'notice', {})
-
-    # start initial submit 30 sec. later to avoid ie10 cookie issues
-    delay = =>
-      App.Interval.set @send, 60000
-    App.Delay.set delay, 30000
-
-    # log clicks
-    if @logClick
-      $(document).on(
-        'click'
-        (e) =>
-          w = window.screen.width
-          h = window.screen.height
-          aTag = $(e.target)
-          if !aTag.attr('href')
-            newTag = $(e.target).parents('a')
-            if newTag[0]
-              aTag = newTag
-          info =
-            level:   'notice'
-            href:    aTag.attr('href')
-            title:   aTag.attr('title')
-            text:    aTag.text()
-            clickX:  e.pageX
-            clickY:  e.pageY
-            screenX: w
-            screenY: h
-          @log('click', 'notice', info)
-      )
-
-    # log ajax calls
-    if @logAjax
-      $(document).on( 'ajaxComplete', ( e, request, settings ) =>
-
-        # do not log ui requests
-        if settings.url && settings.url.substr(settings.url.length-3,3) isnt '/ui'
-          level = 'notice'
-          responseText = ''
-          if request.status >= 400
-            level = 'error'
-            responseText = request.responseText
-
-          if settings.data
-
-            # add length limitation
-            if settings.data.length > 3000
-              settings.data = settings.data.substr(0,3000)
-
-            # delete passwords form data
-            if typeof settings.data is 'string'
-              settings.data = settings.data.replace(/"password":".+?"/gi, '"password":"xxx"')
-
-          @log(
-            'ajax.send',
-            level,
-            {
-              type:         settings.type
-              dataType:     settings.dataType
-              async:        settings.async
-              url:          settings.url
-              data:         settings.data
-              status:       request.status
-              responseText: responseText
-            }
-          )
-      )
-
-    $(window).on(
-      'beforeunload'
-      =>
-        @log('good bye', 'notice', {})
-        @send(false)
-        return
-    )
-
-  log: (facility, level, args) =>
-    return if !@shouldSend()
-    info =
-      time:     Math.round(new Date().getTime() / 1000)
-      facility: facility
-      level:    level
-      location: window.location.pathname + window.location.hash
-      message:  args
-    @data.push info
-
-  send: (async = true) =>
-    return if !@shouldSend()
-    return if _.isEmpty @data
-    newData = _.clone(@data)
-    @data = []
-    newDataNew = []
-    for item in newData
-      try
-
-        # check if strigify is possibe, prevent ajax errors
-        JSON.stringify(item)
-
-        newDataNew.push item
-      catch e
-        console.log 'error', e
-
-    App.Ajax.request(
-      type:   'POST'
-      url:    @url
-      async:  async
-      data:   JSON.stringify(
-        meta:
-          track_id: @trackId
-          host:     window.location.host
-          protocol: window.location.protocol
-        browser: @browser
-        log:     newDataNew
-      )
-      crossDomain: true
-      headers:
-        'X-Requested-With': 'XMLHttpRequest'
-      error: =>
-        for item in newDataNew
-          @data.push item
-    )
-
-  force: (value = true) ->
-    @forceSending = value
-
-  shouldSend: ->
-    return true if @forceSending
-    return false if App.Config.get('developer_mode')
-    return false if !App.Config.get('ui_send_client_stats')
-    true
-
-  _all: ->
-    @data
-
-`
-(function() {
-  window.getStackTrace = function() {
-    var stack
-    try {
-      throw new Error('')
-    }
-    catch (error) {
-      stack = error.stack || ''
-    }
-
-    stack = stack.split('\n').map(function (line) { return line.trim() })
-    return stack.splice(stack[0] == 'Error' ? 2 : 1)
-  }
-  window.onerrorOld = window.onerror
-  window.onerror = function(errorMsg, url, lineNumber, column, errorObj) {
-    var stack = ''
-    if (errorObj !== undefined && errorObj.stack) {
-      stack = "\n" + errorObj.stack
-    }
-    App.Track.log(
-      'console.error',
-      'error',
-      errorMsg + " - in " + url + ", line " + lineNumber + stack
-    )
-    if (window.onerrorOld) {
-      window.onerrorOld(errorMsg, url, lineNumber, column, errorObj)
-    }
-    return false
-  }
-
-  var console = window.console
-  if (!console) return
-  function intercept(method){
-    var original = console[method]
-    console[method] = function(){
-      App.Track.log(
-        'console.' + method,
-        method,
-        arguments
-      )
-      if (method == 'error') {
-        App.Track.log(
-          'traceback',
-          method,
-          window.getStackTrace().join('\n')
-        )
-      }
-
-      // do sneaky stuff
-      if (original.apply){
-        // Do this for normal browsers
-        original.apply(console, arguments)
-      }
-      else {
-        // Do this for IE
-        var message = Array.prototype.slice.apply(arguments).join(' ')
-        original(message)
-      }
-    }
-  }
-  var methods = ['debug', 'log', 'warn', 'error']
-  for (var i = 0; i < methods.length; i++)
-    intercept(methods[i])
-}).call(this);
-`

+ 1 - 1
config/initializers/content_security_policy.rb

@@ -41,7 +41,7 @@ Rails.application.config.content_security_policy do |policy|
 
   policy.base_uri :self, base_uri
 
-  policy.default_src :self, :ws, :wss, 'https://log.zammad.com', 'https://images.zammad.com'
+  policy.default_src :self, :ws, :wss, 'https://images.zammad.com'
   policy.font_src    :self, :data
   policy.img_src     '*', :data
   policy.object_src  :none

+ 9 - 0
db/migrate/20220524130435_drop_setting_ui_send_client_stats.rb

@@ -0,0 +1,9 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+class DropSettingUiSendClientStats < ActiveRecord::Migration[6.1]
+  def change
+    return if !Setting.exists?(name: 'system_init_done')
+
+    Setting.find_by(name: 'ui_send_client_stats')&.destroy
+  end
+end

+ 0 - 27
db/seeds/settings.rb

@@ -571,33 +571,6 @@ Setting.create_if_not_exists(
   },
   frontend:    false
 )
-
-Setting.create_if_not_exists(
-  title:       __('Send client stats'),
-  name:        'ui_send_client_stats',
-  area:        'System::UI',
-  description: __('Send client stats/error message to central server to improve the usability.'),
-  options:     {
-    form: [
-      {
-        display: '',
-        null:    true,
-        name:    'ui_send_client_stats',
-        tag:     'boolean',
-        options: {
-          true  => 'yes',
-          false => 'no',
-        },
-      },
-    ],
-  },
-  state:       false,
-  preferences: {
-    prio:       1,
-    permission: ['admin.system'],
-  },
-  frontend:    true
-)
 Setting.create_if_not_exists(
   title:       __('Core Workflow Ajax Mode'),
   name:        'core_workflow_ajax_mode',

+ 0 - 8
i18n/zammad.pot

@@ -8135,14 +8135,6 @@ msgstr ""
 msgid "Send a message to all logged in users."
 msgstr ""
 
-#: db/seeds/settings.rb
-msgid "Send client stats"
-msgstr ""
-
-#: db/seeds/settings.rb
-msgid "Send client stats/error message to central server to improve the usability."
-msgstr ""
-
 #: db/seeds/settings.rb
 msgid "Send postmaster mail if mail too large"
 msgstr ""

+ 0 - 3
test/browser_test_helper.rb

@@ -201,9 +201,6 @@ class TestCase < ActiveSupport::TestCase
       instance.get(params[:url])
     end
 
-    # submit logs anyway
-    instance.execute_script('App.Track.force()')
-
     element = instance.find_elements(css: '#login input[name="username"]')[0]
     if !element