Skip to content

Commit

Permalink
Merge pull request #2 from graniet/version-beta
Browse files Browse the repository at this point in the history
Version beta
  • Loading branch information
graniet committed Apr 27, 2019
2 parents ba88ed0 + 9b2f6ea commit 6fbebd6
Show file tree
Hide file tree
Showing 24 changed files with 966 additions and 35 deletions.
13 changes: 12 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
API_HOST=127.0.0.1
API_PORT=8888
API_VERBOSE=true
API_VERBOSE=true

DB_NAME="./opf.db"
DB_DRIVER=sqlite3
DB_HOST=
DB_USER=
DB_PASS=

OPERATIVE_HISTORY="/tmp/operative_framework.tmp"

INSTAGRAM_LOGIN=Usern4m3
INSTAGRAM_PASSWORD=P4ssw0rd
5 changes: 4 additions & 1 deletion api/api_module.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package api

import (
"net/http"
"encoding/json"
"github.com/gorilla/mux"
"net/http"
)

type Module struct{
Expand All @@ -13,6 +13,7 @@ type Module struct{
}

func (api *ARestFul) Modules(w http.ResponseWriter, r *http.Request){
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
var modules []Module
for _, module := range api.sess.Modules{
Expand All @@ -27,6 +28,7 @@ func (api *ARestFul) Modules(w http.ResponseWriter, r *http.Request){
}

func (api *ARestFul) RunModule(w http.ResponseWriter, r *http.Request){
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
_ = r.ParseForm()
if _, ok := r.Form["module"]; !ok{
Expand Down Expand Up @@ -69,6 +71,7 @@ func (api *ARestFul) RunModule(w http.ResponseWriter, r *http.Request){
}

func (api *ARestFul) Module(w http.ResponseWriter, r *http.Request){
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
param := mux.Vars(r)
mod, err := api.sess.SearchModule(param["module"])
Expand Down
11 changes: 10 additions & 1 deletion api/api_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ type ARestFul struct{
}

func PushARestFul(s *session.Session) *ARestFul{
c := core.Core{
Host: s.Config.Api.Host,
Port: s.Config.Api.Port,
Verbose: s.Config.Api.Verbose,
}
mod := ARestFul{
sess: s,
Core: core.PushCore(),
Core: &c,
}
mod.Server = &http.Server{
Addr: mod.Core.Host + ":" + mod.Core.Port,
Expand All @@ -27,11 +32,15 @@ func PushARestFul(s *session.Session) *ARestFul{

func (api *ARestFul) LoadRouter() *mux.Router{
r := mux.NewRouter()

r.HandleFunc("/api/sessions", api.Sessions).Methods("GET")

r.HandleFunc("/api/modules", api.Modules).Methods("GET")
r.HandleFunc("/api/modules/{module}", api.Module).Methods("GET")
r.HandleFunc("/api/modules", api.RunModule).Methods("POST")

r.HandleFunc("/api/targets", api.Targets).Methods("GET")
r.HandleFunc("/api/targets/type/{target_type}", api.TargetByType).Methods("GET")
r.HandleFunc("/api/targets/{target_id}", api.Target).Methods("GET")
r.HandleFunc("/api/targets/{target_id}/results", api.Results).Methods("GET")
r.HandleFunc("/api/targets/{target_id}/results/{result_id}", api.Result).Methods("GET")
Expand Down
24 changes: 24 additions & 0 deletions api/api_session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package api

import (
"encoding/json"
"net/http"
)

type OneSession struct{
Id int `json:"id"`
SessionName string `json:"session_id"`
}

func (OneSession) TableName() string{
return "sessions"
}

func (api *ARestFul) Sessions(w http.ResponseWriter, r *http.Request){
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
var sessions []OneSession
api.sess.Connection.ORM.Find(&sessions)
message := api.Core.PrintData("request executed", false, sessions)
_= json.NewEncoder(w).Encode(message)
}
12 changes: 12 additions & 0 deletions api/api_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ func (api *ARestFul) Target(w http.ResponseWriter, r *http.Request){

}

func (api *ARestFul) TargetByType(w http.ResponseWriter, r *http.Request){
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")

param := mux.Vars(r)
var targets []session.Target
api.sess.Connection.ORM.Where("target_type = ?", param["target_type"]).Where("session_id = ?", api.sess.GetId()).Find(&targets)
message := api.Core.PrintData("request executed", false, targets)
_ = json.NewEncoder(w).Encode(message)
return
}

func (api *ARestFul) Results(w http.ResponseWriter, r *http.Request){
w.Header().Set("Content-Type", "application/json")
get := mux.Vars(r)
Expand Down
10 changes: 0 additions & 10 deletions api/core/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package core

import "os"

type Core struct{
Host string
Port string
Expand All @@ -14,14 +12,6 @@ type ReturnMessage struct{
Error bool
}

func PushCore() *Core{
return &Core{
Host: os.Getenv("API_HOST"),
Port: os.Getenv("API_PORT"),
Verbose: os.Getenv("API_VERBOSE"),
}
}

func (c *Core) PrintData(mess string, e bool, data interface{}) ReturnMessage{
return ReturnMessage{
Message: mess,
Expand Down
35 changes: 35 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package config

type Config struct{
Api ApiConfig
Database DataBase
Common Common
Instagram Network
}

type Network struct{
Login string
Password string
Api ApiConfig
}

type DataBase struct{
Name string
User string
Pass string
Host string
Driver string
Port string
}

type Common struct{
HistoryFile string
}

type ApiConfig struct{
Host string
Port string
Key string
SKey string
Verbose string
}
33 changes: 33 additions & 0 deletions config/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package config

import (
"github.com/joho/godotenv"
"github.com/pkg/errors"
"os"
)

func ParseConfig() (Config, error){
conf := Config{}
err := godotenv.Load(".env")
if err != nil{
return Config{}, errors.New("Please rename/create .env file on root path.")
}


conf.Instagram.Login = os.Getenv("INSTAGRAM_LOGIN")
conf.Instagram.Password = os.Getenv("INSTAGRAM_PASSWORD")

conf.Api.Host = os.Getenv("API_HOST")
conf.Api.Port = os.Getenv("API_PORT")
conf.Api.Verbose = os.Getenv("API_VERBOSE")

conf.Common.HistoryFile = os.Getenv("OPERATIVE_HISTORY")

conf.Database.Driver = os.Getenv("DB_DRIVER")
conf.Database.Name = os.Getenv("DB_NAME")
conf.Database.Host = os.Getenv("DB_HOST")
conf.Database.User = os.Getenv("DB_USER")
conf.Database.Pass = os.Getenv("DB_PASS")

return conf, nil
}
18 changes: 16 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package engine

import (
"github.com/graniet/operative-framework/config"
"github.com/graniet/operative-framework/filters"
"github.com/graniet/operative-framework/modules"
"github.com/graniet/operative-framework/session"
"github.com/jinzhu/gorm"
"time"
)

func New() *session.Session{
db, err := gorm.Open("sqlite3", "./opf.db")
conf, err := config.ParseConfig()
if err != nil{
panic(err.Error())
}
db, err := gorm.Open(conf.Database.Driver, conf.Database.Name)
if err != nil {
panic(err.Error())
}
Expand All @@ -31,16 +37,22 @@ func New() *session.Session{
ORM: db,
Migrations: make(map[string]interface{}),
},
Config: conf,
}
s.Stream.Sess = &s
s.Connection.Migrate()
modules.LoadModules(&s)
filters.LoadFilters(&s)
db.Create(&s)
return &s
}

func Load(id int) *session.Session{
db, err := gorm.Open("sqlite3", "./opf.db")
conf, err := config.ParseConfig()
if err != nil{
panic(err.Error())
}
db, err := gorm.Open(conf.Database.Driver, conf.Database.Name)
if err != nil {
panic(err.Error())
}
Expand All @@ -58,13 +70,15 @@ func Load(id int) *session.Session{
ORM: db,
Migrations: make(map[string]interface{}),
},
Config:conf,
}
s.Connection.ORM.Where(&session.Session{
Id: id,
}).First(&s)
s.Stream.Sess = &s
s.Connection.Migrate()
modules.LoadModules(&s)
filters.LoadFilters(&s)

// Load targets now
var targets []*session.Target
Expand Down
12 changes: 12 additions & 0 deletions filters/filters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package filters

import (
"github.com/graniet/operative-framework/filters/phone_to_instagram"
"github.com/graniet/operative-framework/filters/say_hello"
"github.com/graniet/operative-framework/session"
)

func LoadFilters(s *session.Session){
s.Filters = append(s.Filters, say_hello.PushSayHelloFilter(s))
s.Filters = append(s.Filters, phone_to_instagram.PushPhoneToInstagramFilter(s))
}
77 changes: 77 additions & 0 deletions filters/phone_to_instagram/phone_to_instagram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package phone_to_instagram

import (
"fmt"
"github.com/graniet/go-pretty/table"
"github.com/graniet/operative-framework/session"
"gopkg.in/ahmdrz/goinsta.v2"
"os"
)

type PhoneToInstagram struct{
session.SessionFilter
Sess *session.Session
}

func PushPhoneToInstagramFilter(s *session.Session) *PhoneToInstagram{
mod := PhoneToInstagram{
Sess: s,
}
mod.AddModule("phone_generator")
return &mod
}

func (filter *PhoneToInstagram) Name() string{
return "phone_to_instagram"
}

func (filter *PhoneToInstagram) Description() string{
return "Find result of phone_generator module in instagram network."
}

func (filter *PhoneToInstagram) Author() string{
return "Tristan Granier"
}

func (filter *PhoneToInstagram) Start(mod session.Module){
insta := goinsta.New(filter.Sess.Config.Instagram.Login, filter.Sess.Config.Instagram.Password)

if err := insta.Login(); err != nil {
fmt.Println(err)
return
}

var Contacts []goinsta.Contact
Contacts = append(Contacts, goinsta.Contact{
Numbers: mod.GetResults(),
})
syncAwser, err := insta.Contacts.SyncContacts(&Contacts)
if err != nil{
fmt.Println(err.Error())
return
}

t := filter.Sess.Stream.GenerateTable()
t.SetOutputMirror(os.Stdout)
t.SetAllowedColumnLengths([]int{0,0,0,50})
t.AppendHeader(table.Row{
"Username",
"isPrivate",
"isVerified",
"Picture",

})
if len(syncAwser.Users) > 0{
for _,users := range syncAwser.Users{
t.AppendRow(table.Row{
users.Username,
users.IsPrivate,
users.IsVerified,
users.ProfilePicURL,
})
}
}

filter.Sess.Stream.Render(t)

}
Loading

0 comments on commit 6fbebd6

Please sign in to comment.