Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Mgt is a MVC mini-framework, modeled after rails. Like Rails, Mgt is built using Ruby. The framework also comes with a minified ORM.
Mgt is ligthweight and hence fit for simple and quick applications. It makes available some of the great features of rails.
Add this line to your application's Gemfile:
gem 'mgt'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mgt
When creating a new Mgt app, a few things need to be setup and a few rules adhered to. Mgt basically follows the same folder structure as a typical rails app with all of the model, view and controller code packed inside of an app folder, configuration based code placed inside a config folder and the main database file in a db folder.
View a sample app built using mgt framework Here
Routing with Mgt deals with directing requests to the appropriate controllers. A sample route file is:
mgt supports GET, DELETE, PATCH, POST, PUT requests.
TodoApplication.routes.draw do
get "/users", to: "users#index"
get "/users/new", to: "users#new"
post "/users", to: "users#create"
get "/users/:id", to: "users#show"
get "/users/:id/edit", to: "users#edit"
patch "/users/:id", to: "users#update"
put "/users/:id", to: "users#update"
delete "/users/:id", to: "users#destroy"
end
All models to be used with the Hemp framework are to inherit from the ActiveRecord class provided by Mgt, in order to access the rich ORM functionalities provided. The ActiveRecord class acts as an interface between the model class and its database representation. A sample model file is provided below:
class Fellow < Hemp::BaseRecord
table :users
property :id, type: :integer, primary_key: true
property :first_name, type: :text, nullable: false
property :email, type: :boolean, nullable: false
create_table
end
The table
method provided stores the table name used while creating the table record in the database.
The property
method is provided to declare table columns, and their attributes. The first argument to property
is the column name, while subsequent hash arguments are used to provide information about attributes.
The type
argument represents the data type of the column. Supported data types by Hemp are:
The primary_key
argument is used to specify that the column should be used as the primary key of the table. If this is an integer, the value is auto-incremented by the database.
The nullable
argument is used to specify whether a column should have null values, or not.
While creating models, the id property declaration is optional. If this is is not provided, the Hemp ORM adds it automatically, and sets it as the primary key. Thus, it should only be set if you'd like to use a different type as the primary key.
On passing in the table name, and its properties, a call should be made to the create_table
method to persist the model to database by creating the table.
Controllers are key to the MVC structure, as they handle receiving requests, interacting with the database, and providing responses. Controllers are placed in the controllers folder, which is nested in the app folder.
All controllers should inherit from the BaseController class provided by Hemp to inherit methods which simplify accessing request parameters and returning responses by rendering views.
A sample structure for a controller file is:
class UsersController < Mgt::BaseController
def index
@users = User.all
end
def new
end
def show
fellow
render :show_full
end
def destroy
fellow.destroy
redirect_to "/"
end
end
Instance variables set by the controllers are passed to the routes while rendering responses.
Explicitly calling render
to render template files is optional. If it's not called by the controller action, then it's done automatically by the framework with an argument that's the same name as the action. Thus, you can decide to call render
explicitly when you want to render a view with a name different from the action.
Currently, view templates are handled through the Tilt gem, with the Erubis template engine. See https://github.com/rtomayko/tilt for more details.
View templates are mapped to controller actions and must assume the same nomenclature as their respective actions.Erbuis is used as the templating engine and files which are views are required to have the .erb file extension after the .html extension. Views are placed inside the app/views
folder. A view to be rendered for the new action in the UsersController for example is saved as new.html.erb
in the users folder, nested in the views folder.
The Hemp framework has a few dependencies. These are listed below, with links to source pages for each.
Test files are placed inside the spec folder and have been split into two sub folders, one for unit tests and the other for integration tests. You can run the tests from your command line client by typing rspec spec
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Limitations
This version of the gem does not
support model relationships. implement callbacks. support migration generation. generate a schema.
To contribute to this work:
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that mgt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.