-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
383 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package api | ||
|
||
import ( | ||
"flag" | ||
"imap-sync/controller" | ||
"imap-sync/internal" | ||
|
||
"github.com/gin-gonic/gin" | ||
ginsession "github.com/go-session/gin-session" | ||
) | ||
|
||
var log = internal.Log | ||
var port = flag.String("port", "8080", "Port to listen on") | ||
|
||
func InitServer() { | ||
|
||
err := controller.InitDb() | ||
if err != nil { | ||
log.Error(err) | ||
} | ||
|
||
gin.SetMode(gin.ReleaseMode) | ||
router := gin.Default() | ||
|
||
router.Use(ginsession.New()) | ||
|
||
router.LoadHTMLGlob("templates/*") | ||
|
||
router.Static("/static", "./static/") | ||
|
||
router.GET("/", controller.HandleRoot) | ||
router.GET("/admin", controller.HandleAdmin) | ||
router.GET("/favicon.ico", func(ctx *gin.Context) { | ||
ctx.File("favicon.ico") | ||
}) | ||
router.GET("/login", controller.HandleLogin) | ||
|
||
go internal.InitQueue() | ||
// API endpoints | ||
router.GET("/api/queue", controller.HandleQueue) | ||
router.GET("/api/queuepoll", controller.HandleQueuePolling) | ||
router.GET("/api/pagination", controller.HandlePagination) | ||
router.POST("/api/validate", controller.HandleValidate) | ||
router.POST("/api/search", controller.HandleSearch) | ||
router.POST("/auth/login", controller.Login) | ||
|
||
log.Info("Server starting on http://localhost:" + *port) | ||
|
||
if err := router.Run(":" + *port); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package controller | ||
|
||
import ( | ||
"imap-sync/internal" | ||
"strconv" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HandlePagination(ctx *gin.Context) { | ||
index, _ := strconv.Atoi(ctx.Request.FormValue("page")) | ||
pages := internal.GetPagination(index) | ||
|
||
ctx.HTML(200, "pagination.html", pages) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package controller | ||
|
||
import ( | ||
"imap-sync/internal" | ||
"strconv" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HandleQueue(ctx *gin.Context) { | ||
index, _ := strconv.Atoi(ctx.Request.FormValue("page")) | ||
|
||
data := internal.GetQueueData(index) | ||
|
||
ctx.HTML(200, "tbody.html", data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package controller | ||
|
||
import ( | ||
"imap-sync/internal" | ||
"strconv" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HandleQueuePolling(ctx *gin.Context) { | ||
index, _ := strconv.Atoi(ctx.Request.FormValue("page")) | ||
|
||
data := internal.GetPollingData(index) | ||
|
||
ctx.HTML(200, "table.html", data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package controller | ||
|
||
import ( | ||
"flag" | ||
"imap-sync/internal" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
var ( | ||
source_server = flag.String("source_server", "", "Source server") | ||
source_account = flag.String("source_account", "", "Source account") | ||
source_password = flag.String("source_password", "", "Source password") | ||
destination_server = flag.String("destination_server", "", "Destination server") | ||
destination_account = flag.String("destination_account", "", "Destination account") | ||
destination_password = flag.String("destination_password", "", "Destination password") | ||
) | ||
|
||
func HandleRoot(ctx *gin.Context) { | ||
sourceDetails := internal.Credentials{ | ||
Server: *source_server, | ||
Account: *source_account, | ||
Password: *source_password, | ||
} | ||
|
||
destinationDetails := internal.Credentials{ | ||
Server: *destination_server, | ||
Account: *destination_account, | ||
Password: *destination_password, | ||
} | ||
|
||
data := struct { | ||
SourceDetails internal.Credentials | ||
DestinationDetails internal.Credentials | ||
}{ | ||
SourceDetails: sourceDetails, | ||
DestinationDetails: destinationDetails, | ||
} | ||
ctx.HTML(200, "index.html", data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package controller | ||
|
||
import ( | ||
"imap-sync/internal" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HandleSearch(ctx *gin.Context) { | ||
searchQuery := ctx.PostForm("search-input") | ||
|
||
if searchQuery == "" { | ||
HandleQueue(ctx) | ||
return | ||
} | ||
|
||
data := internal.GetSearchData(searchQuery) | ||
|
||
ctx.HTML(200, "tbody.html", data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package controller | ||
|
||
import ( | ||
"imap-sync/internal" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func handleSync(ctx *gin.Context) { | ||
sourceServer := ctx.PostForm("source_server") | ||
sourceAccount := ctx.PostForm("source_account") | ||
sourcePassword := ctx.PostForm("source_password") | ||
destinationServer := ctx.PostForm("destination_server") | ||
destinationAccount := ctx.PostForm("destination_account") | ||
destinationPassword := ctx.PostForm("destination_password") | ||
|
||
sourceDetails := internal.Credentials{ | ||
Server: sourceServer, | ||
Account: sourceAccount, | ||
Password: sourcePassword, | ||
} | ||
|
||
destinationDetails := internal.Credentials{ | ||
Server: destinationServer, | ||
Account: destinationAccount, | ||
Password: destinationPassword, | ||
} | ||
|
||
// Add to queue | ||
log.Infof("Adding %s to queue", sourceDetails.Account) | ||
internal.AddTask(sourceDetails, destinationDetails) | ||
|
||
// log.Infof("Syncing %s to %s", sourceDetails.Account, destinationDetails.Account) | ||
|
||
// err := syncIMAP(sourceDetails, destinationDetails) | ||
// if err != nil { | ||
// ctx.HTML(200, "error.html", err.Error()) | ||
// return | ||
// } | ||
// ctx.HTML(200, "success.html", "Synced "+sourceDetails.Account+" to "+destinationDetails.Account) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package controller | ||
|
||
import ( | ||
"imap-sync/internal" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HandleValidate(ctx *gin.Context) { | ||
|
||
sourceCreds := ctx.PostForm("source_creds") | ||
destCreds := ctx.PostForm("destination_creds") | ||
submitsync := ctx.PostForm("submit_sync") | ||
|
||
var Server, Account, Password string | ||
|
||
if sourceCreds != "" { | ||
Server = ctx.PostForm("source_server") | ||
Account = ctx.PostForm("source_account") | ||
Password = ctx.PostForm("source_password") | ||
} | ||
|
||
if destCreds != "" { | ||
Server = ctx.PostForm("destination_server") | ||
Account = ctx.PostForm("destination_account") | ||
Password = ctx.PostForm("destination_password") | ||
} | ||
|
||
if destCreds == "" && sourceCreds == "" && submitsync != "" { | ||
handleSync(ctx) | ||
return | ||
} | ||
|
||
creds := internal.Credentials{ | ||
Server: Server, | ||
Account: Account, | ||
Password: Password, | ||
} | ||
|
||
log.Infof("Validating credentials for: %s", creds.Account) | ||
|
||
err := internal.ValidateCredentials(creds) | ||
if err != nil { | ||
ctx.HTML(200, "error.html", err.Error()) | ||
return | ||
} | ||
ctx.HTML(200, "success.html", creds) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.