<commit_before>=begin
                  Arachni
  Copyright (c) 2010-2011 Tasos "Zapotek" Laskos <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end


module Arachni
module UI
module Web

module Addons

    #
    # Base class for all add-ons.
    #
    #
    # @author: Tasos "Zapotek" Laskos
    #                                      <<EMAIL>>
    #                                      <<EMAIL>>
    # @version: 0.1
    #
    class Base

        def initialize( settings, route )
            @settings = settings
            @route    = '/addons/' + route

            @settings.helpers do

                def present( tpl, args )
                    views = current_addon.path_views
                    trv = ( '../' * views.split( '/' ).size ) + views + tpl.to_s

                    erb_args = []
                    erb_args << { :layout => true }
                    erb_args << { :tpl => trv.to_sym, :addon => addons.by_name( current_addon_name ), :tpl_args => args }

                    erb :addon, *erb_args
                end

                def partial( tpl, args )
                    views = current_addon.path_views
                    trv = ( '../' * views.split( '/' ).size ) + views + tpl.to_s

                    erb_args = []
                    erb_args << { :layout => false }
                    erb_args << args

                    erb trv.to_sym, *erb_args
                end

                def current_addon_name
                    env['PATH_INFO'].scan( /\/addons\/(.*)\// ).flatten[0]
                end

                def current_addon
                    addons.running[current_addon_name]
                end

            end

        end

        def path_root
            @route
        end

        def path_views
            Options.instance.dir['lib'] + 'ui/web' + path_root + '/views/'
        end

        def run

        end

        #
        # This optional method allows you to specify the title which will be
        # used for the menu (in case you want it to be dynamic).
        #
        # @return   [String]
        #
        def title
            ''
        end


        #
        #
        # *DO NOT MESS WITH THE FOLLOWING METHODS*
        #
        #


        def settings
           @settings
        end

        def get( path, &block )
            settings.get( @route + path, &block )
        end

        def post( path, &block )
            settings.post( @route + path, &block )
        end

        def put( path, &block )
            settings.put( @route + path, &block )
        end

        def delete( path, &block )
            settings.delete( @route + path, &block )
        end

    end
end


#
# Add-on manager.
#
#
# @author: Tasos "Zapotek" Laskos
#                                      <<EMAIL>>
#                                      <<EMAIL>>
# @version: 0.1
#
class AddonManager

    include Utilities

    class Addon
        include DataMapper::Resource

        property :id,   Serial
        property :name, String
    end


    def initialize( opts, settings )
        @opts     = opts
        @settings = settings

        lib = @opts.dir['lib'] + 'ui/web/addons/'
        @@manager ||= ::Arachni::ComponentManager.new( lib, Addons )

        @@running ||= {}

        DataMapper::setup( :default, "sqlite3://#{@settings.db}/default.db" )
        DataMapper.finalize

        Addon.auto_upgrade!

        run( enabled )
    end

    #<commit_msg>* added path_addon() * current_addon_name(): converted the regex to non-greedy<commit_after>=begin
                  Arachni
  Copyright (c) 2010-2011 Tasos "Zapotek" Laskos <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end


module Arachni
module UI
module Web

module Addons

    #
    # Base class for all add-ons.
    #
    #
    # @author: Tasos "Zapotek" Laskos
    #                                      <<EMAIL>>
    #                                      <<EMAIL>>
    # @version: 0.1
    #
    class Base

        def initialize( settings, route )
            @settings = settings
            @route    = '/addons/' + route

            @settings.helpers do

                def present( tpl, args )
                    views = current_addon.path_views
                    trv = ( '../' * views.split( '/' ).size ) + views + tpl.to_s

                    erb_args = []
                    erb_args << { :layout => true }
                    erb_args << { :tpl => trv.to_sym, :addon => addons.by_name( current_addon_name ), :tpl_args => args }

                    erb :addon, *erb_args
                end

                def partial( tpl, args )
                    views = current_addon.path_views
                    trv = ( '../' * views.split( '/' ).size ) + views + tpl.to_s

                    erb_args = []
                    erb_args << { :layout => false }
                    erb_args << args

                    erb trv.to_sym, *erb_args
                end

                def current_addon_name
                    env['PATH_INFO'].scan( /\/addons\/(.*?)\// ).flatten[0]
                end

                def current_addon
                    addons.running[current_addon_name]
                end

            end

        end

        def path_root
            @route
        end

        def path_views
            path_addon + '/views/'
        end

        def path_addon
            Options.instance.dir['lib'] + 'ui/web' + path_root
        end

        def run

        end

        #
        # This optional method allows you to specify the title which will be
        # used for the menu (in case you want it to be dynamic).
        #
        # @return   [String]
        #
        def title
            ''
        end


        #
        #
        # *DO NOT MESS WITH THE FOLLOWING METHODS*
        #
        #


        def settings
           @settings
        end

        def get( path, &block )
            settings.get( @route + path, &block )
        end

        def post( path, &block )
            settings.post( @route + path, &block )
        end

        def put( path, &block )
            settings.put( @route + path, &block )
        end

        def delete( path, &block )
            settings.delete( @route + path, &block )
        end

    end
end


#
# Add-on manager.
#
#
# @author: Tasos "Zapotek" Laskos
#                                      <<EMAIL>>
#                                      <<EMAIL>>
# @version: 0.1
#
class AddonManager

    include Utilities

    class Addon
        include DataMapper::Resource

        property :id,   Serial
        property :name, String
    end

    class RestrictedComponentManager < Arachni::ComponentManager
        def paths
            cpaths = paths = Dir.glob( File.join( "#{@lib}", "*.rb" ) )
            return paths.reject { |path| helper?( path ) }
        end
    end

    def initialize( opts, settings )
        @opts     = opts
        @settings = settings

        lib = @opts.dir['lib'] + 'ui/web/addons/'
        @@manager ||= RestrictedComponentManager.new( lib, Addons )

        @@running ||= {}

        DataMapper::setup( :default, "sqlite3://#{@settings.db}/default.db" )
        DataMapper.finalize

        Addon.auto_upgrade!

        run( enabled )
    end

    #
{'fraction_non_alphanumeric': 0.10016047071409467, 'fraction_numerical': 0.004279219042524739, 'mean_word_length': 1.214031971580817, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6510545', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2068, 'n_words': 572}