Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Add Helix.Software macro
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomassaro committed Oct 11, 2017
1 parent 8732ec8 commit 8efe8db
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 171 deletions.
19 changes: 10 additions & 9 deletions lib/software/model/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ defmodule Helix.Software.Model.File do
alias Ecto.Changeset
alias HELL.Constant
alias Helix.Software.Model.FileModule
alias Helix.Software.Model.SoftwareType
alias Helix.Software.Model.Software
alias Helix.Software.Model.Storage

@type t :: t_of_type(SoftwareType.type)
@type t :: t_of_type(Software.type)

@type t_of_type(type) :: %__MODULE__{
file_id: id,
name: name,
path: path,
full_path: full_path,
file_size: size,
type: SoftwareType.t,
type: Software.Type.t,
software_type: type,
storage_id: Storage.id,
storage: term,
Expand All @@ -30,11 +30,12 @@ defmodule Helix.Software.Model.File do
crypto_version: crypto_version
}

@type extension :: String.t
@type path :: String.t
@type full_path :: path
@type name :: String.t
@type size :: pos_integer
@type type :: SoftwareType.type
@type type :: Software.type
@type crypto_version :: nil | pos_integer
@type modules :: FileModule.t

Expand All @@ -44,7 +45,7 @@ defmodule Helix.Software.Model.File do
name: name,
path: path,
file_size: size,
software_type: SoftwareType.type,
software_type: Software.type,
storage_id: Storage.idtb
}

Expand All @@ -62,7 +63,7 @@ defmodule Helix.Software.Model.File do

@required_fields ~w/name path file_size software_type storage_id/a

@software_types Map.keys(SoftwareType.possible_types())
@software_types Software.Type.all()

schema "files" do
field :file_id, ID,
Expand All @@ -78,9 +79,9 @@ defmodule Helix.Software.Model.File do

field :full_path, :string

belongs_to :type, SoftwareType,
belongs_to :type, Software.Type,
foreign_key: :software_type,
references: :software_type,
references: :type,
define_field: false
belongs_to :storage, Storage,
foreign_key: :storage_id,
Expand Down Expand Up @@ -178,7 +179,7 @@ defmodule Helix.Software.Model.File do
path = get_field(changeset, :path)
name = get_field(changeset, :name)
software_type = get_field(changeset, :software_type)
extension = SoftwareType.possible_types()[software_type].extension
extension = Software.Type.get(software_type).extension

full_path = path <> "/" <> name <> "." <> extension

Expand Down
4 changes: 2 additions & 2 deletions lib/software/model/file_module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Helix.Software.Model.FileModule do
alias HELL.Constant
alias Helix.Software.Model.File
alias Helix.Software.Model.FileModule.Data, as: FileModuleData
alias Helix.Software.Model.SoftwareModule
alias Helix.Software.Model.Software

@type t :: %{
name => FileModuleData.t
Expand Down Expand Up @@ -87,7 +87,7 @@ defmodule Helix.Software.Model.FileModule do
def generic_validations(changeset) do
changeset
|> validate_number(:version, greater_than: 0)
|> validate_inclusion(:name, SoftwareModule.possible_modules())
|> validate_inclusion(:name, Software.Module.all())
end

@spec format(schema) ::
Expand Down
57 changes: 57 additions & 0 deletions lib/software/model/software.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
defmodule Helix.Software.Model.Software do

use Helix.Software

software \
type: :cracker,
extension: "crc",
modules: [:bruteforce, :overflow]

software \
type: :firewall,
extension: "fwl",
modules: [:fwl_active, :fwl_passive]

software \
type: :text,
extension: "txt"

software \
type: :exploit,
extension: "exp",
modules: [:ftp, :ssh]

software \
type: :hasher,
extension: "hash",
modules: [:password]

software \
type: :log_forger,
extension: "logf",
modules: [:log_create, :log_edit]

software \
type: :log_recover,
extension: "logr",
modules: [:log_recover]

software \
type: :encryptor,
extension: "enc",
modules: [:enc_file, :enc_log, :enc_connection, :enc_process]

software \
type: :decryptor,
extension: "dec",
modules: [:dec_file, :dec_log, :dec_connection, :dec_process]

software \
type: :anymap,
extension: "map",
modules: [:map_geo, :map_net]

software \
type: :crypto_key,
extension: "key"
end
42 changes: 0 additions & 42 deletions lib/software/model/software_module.ex

This file was deleted.

99 changes: 0 additions & 99 deletions lib/software/model/software_type.ex

This file was deleted.

Loading

0 comments on commit 8efe8db

Please sign in to comment.