Skip to content
Permalink
Browse files

Merge branch 'master' of https://github.com/Raggaer/castro

  • Loading branch information...
Raggaer committed May 26, 2019
2 parents b0365dc + bb1722f commit 72690b71f5ca41684e5503d81d93cf59b4ae7daa
@@ -15,12 +15,6 @@ Castro also ships with the documentation so you can view it offline. Everything

The documentation is also hosted at [castroaac.org](https://castroaac.org).

## Extensions

Castro ships with a very solid extension system. You can read more about it on the extensions part of the documentation.

There is a public plugin list hosted at [plugins.castroaac.org](https://plugins.castroaac.org)

## License

**Castro** is licensed under the **MIT** license.
@@ -339,9 +339,9 @@ func loadSubtopics(wg *sync.WaitGroup) {
util.Logger.Logger.Fatalf("Cannot compile application subtopic list: %v", err)
}

// Load extension subtopics
if err := lua.PageList.LoadExtensions(); err != nil {
util.Logger.Logger.Errorf("Cannot load extension subtopic list: %v", err)
// Compile extension pages files
if err := lua.CompiledPageList.CompileExtensions("pages"); err != nil {
util.Logger.Logger.Errorf("Cannot compile extension subtopic list: %v", err)
}

// Tell the wait group we are done
@@ -487,7 +487,12 @@ func connectDatabase() {
var err error

// Connect to the MySQL database
if database.DB, err = database.Open(lua.Config.GetGlobal("mysqlUser").String(), lua.Config.GetGlobal("mysqlPass").String(), lua.Config.GetGlobal("mysqlDatabase").String(), ""); err != nil {
if database.DB, err = database.Open(lua.Config.GetGlobal("mysqlUser").String(),
lua.Config.GetGlobal("mysqlPass").String(),
lua.Config.GetGlobal("mysqlHost").String(),
lua.Config.GetGlobal("mysqlPort").String(),
lua.Config.GetGlobal("mysqlDatabase").String(),
""); err != nil {
util.Logger.Logger.Fatalf("Cannot connect to MySQL database: %v", err)
}
}
@@ -58,12 +58,10 @@ func LuaPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
}

// Reload extension pages
if err := lua.PageList.LoadExtensions(); err != nil {
if err := lua.CompiledPageList.CompileExtensions("pages"); err != nil {

// If AAC is running on development mode log error
if util.Config.Configuration.IsDev() || util.Config.Configuration.IsLog() {
util.Logger.Logger.Errorf("Cannot load extension subtopic %v: %v", ps.ByName("page"), err)
}
// Log error
util.Logger.Logger.Errorf("Cannot reload extension subtopic %v: %v", ps.ByName("page"), err)
}

// Reload extension static list
@@ -12,12 +12,14 @@ import (
var DB *sqlx.DB

// Open creates a new connection to a MySQL database with the given credentials
func Open(username, password, db, params string) (*sqlx.DB, error) {
func Open(username, password, host, port, db, params string) (*sqlx.DB, error) {
// Connect to the given database
databaseHandle, err := sqlx.Connect("mysql", fmt.Sprintf(
"%v:%v@/%v?charset=utf8&parseTime=True&loc=Local"+params,
"%v:%v@(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local"+params,
username,
password,
host,
port,
db,
))

@@ -1,8 +1,8 @@
package lua

import (
lua "github.com/yuin/gopher-lua"
"github.com/raggaer/castro/app/util"
lua "github.com/yuin/gopher-lua"
)

// SetExtensionMetaTable sets the extension metatable for the given state
@@ -18,7 +18,7 @@ func SetExtensionMetaTable(luaState *lua.LState) {
// ReloadExtensions reloads all extensions
func ReloadExtensions(L *lua.LState) int {
// Reload extension pages
if err := PageList.LoadExtensions(); err != nil {
if err := CompiledPageList.CompileExtensions("pages"); err != nil {
L.RaiseError("Cannot reload extension page list: %v", err)
}

@@ -14,12 +14,6 @@ import (
)

var (
// PageList list of subtopic states
PageList = &stateList{
List: make(map[string][]*glua.LState),
Type: "page",
}

// WidgetList list of widget states
WidgetList = &stateList{
List: make(map[string][]*glua.LState),
@@ -85,6 +79,62 @@ func (s *compiledStateList) CompileFiles(dir string) error {
return nil
}

// CompileExtensions compiles extension lua files into function protos
func (s *compiledStateList) CompileExtensions(extType string) error {
s.rw.Lock()
defer s.rw.Unlock()

// Get extensions from database
rows, err := database.DB.Queryx(strings.Replace("SELECT extension_id FROM castro_extension_? WHERE enabled = 1", "?", extType, -1))

if err != nil {
return err
}

// Close rows
defer rows.Close()

// Loop rows
for rows.Next() {

// Hold extension id
var extensionID string

if err := rows.Scan(&extensionID); err != nil {
return err
}

dir := filepath.Join("extensions", extensionID, extType)

err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
if strings.HasSuffix(info.Name(), ".lua") {
// Compile lua file
proto, err := CompileLua(path)
if err != nil {
return err
}

// Set virtual path
path := strings.ToLower(strings.Replace(path, dir, extType, -1))

// Add to the list
s.List[path] = proto
}
return nil
})
if err != nil {
return err
}
}
return nil
}

// Get retrieves a compiled lua function proto
func (s *compiledStateList) Get(path string) (*glua.FunctionProto, error) {
path = strings.ToLower(path)
@@ -544,9 +544,10 @@ func installApplication(location string) error {
}

// Connect to database
conn, err := database.Open(
lua.Config.GetGlobal("mysqlUser").String(),
lua.Config.GetGlobal("mysqlPass").String(),
conn, err := database.Open(lua.Config.GetGlobal("mysqlUser").String(),
lua.Config.GetGlobal("mysqlPass").String(),
lua.Config.GetGlobal("mysqlHost").String(),
lua.Config.GetGlobal("mysqlPort").String(),
lua.Config.GetGlobal("mysqlDatabase").String(),
"&multiStatements=true",
)
@@ -23,7 +23,7 @@ <h3>Change account email</h3>
<input type="email" class="form-control" id="input-account-new-email" name="new-email" placeholder="New email">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Change</button>
<button type="submit" class="btn btn-primary btn-sm">Change</button>
</div>
</form>
{{ template "footer.html" . }}
@@ -24,7 +24,7 @@ <h3>Change account password</h3>
placeholder="New password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Change</button>
<button type="submit" class="btn btn-primary btn-sm">Change</button>
</div>
</form>
{{ template "footer.html" . }}
@@ -20,9 +20,9 @@ <h3>My shop checkouts</h3>
<td>{{ $element.amount }}</td>
<td>
{{ if $element.given }}
<button class="btn btn-success btn-xs">Given</button>
<button class="btn btn-success btn-sm">Given</button>
{{ else }}
<button class="btn btn-danger btn-xs">Waiting</button>
<button class="btn btn-danger btn-sm">Waiting</button>
{{ end }}
</td>
</tr>
@@ -37,7 +37,7 @@ <h3>Create a new character</h3>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Create</button>
<button type="submit" class="btn btn-sm btn-primary">Create</button>
</div>
</form>
{{ template "footer.html" . }}
@@ -19,7 +19,7 @@ <h3>Dashboard</h3>
<div class="alert alert-info" role="alert">
<strong>Pending deletion!</strong> The character {{ $character.name }} is pending deletion and will be deleted on {{ $character.deletion.Result }}.
<br>
<button class="btn btn-danger btn-xs" form="form-character-undelete" type="submit" name="undelete-character" value="{{ $character.name }}">Cancel</button>
<button class="btn btn-danger btn-sm" form="form-character-undelete" type="submit" name="undelete-character" value="{{ $character.name }}">Cancel</button>
</div>
{{ end }}
{{ end }}
@@ -34,9 +34,9 @@ <h3>Dashboard</h3>
<th>Two-factor</th>
<td>
{{ if .twofa }}
<button class="btn btn-success btn-xs">Enabled</button>
<button class="btn btn-success btn-sm">Enabled</button>
{{ else }}
<a role="button" href="{{ url "subtopic" "account" "twofa" "enable" }}" class="btn btn-danger btn-xs">Disabled</a>
<a role="button" href="{{ url "subtopic" "account" "twofa" "enable" }}" class="btn btn-danger btn-sm">Disabled</a>
{{ end }}
</td>
</tr>
@@ -72,15 +72,15 @@ <h3>Dashboard</h3>
<tr>
<th></th>
<td>
<a role="button" href="{{ url "subtopic" "account" "changepassword" }}" class="btn btn-xs btn-primary">
<a role="button" href="{{ url "subtopic" "account" "changepassword" }}" class="btn btn-sm btn-primary">
Change password
</a>
</td>
</tr>
<tr>
<th></th>
<td>
<a role="button" href="{{ url "subtopic" "account" "changemail" }}" class="btn btn-xs btn-default">
<a role="button" href="{{ url "subtopic" "account" "changemail" }}" class="btn btn-sm btn-default">
Change email
</a>
</td>
@@ -116,9 +116,9 @@ <h3>My Characters</h3>
<td>{{ $element.level }}</td>
<td>
{{ if eqNumber $element.deletion 0 }}
<button class="btn btn-xs btn-danger require-confirmation" type="submit" form="form-character-delete" name="delete-character" value="{{ $element.name }}">Delete</button>
<button class="btn btn-sm btn-danger require-confirmation" type="submit" form="form-character-delete" name="delete-character" value="{{ $element.name }}">Delete</button>
{{ else }}
<button class="btn btn-xs btn-default" form="form-character-undelete" type="submit" name="undelete-character" value="{{ $element.name }}">Cancel</button>
<button class="btn btn-sm btn-default" form="form-character-undelete" type="submit" name="undelete-character" value="{{ $element.name }}">Cancel</button>
{{ end }}
</td>
</tr>
@@ -28,7 +28,7 @@ <h3>Recover your acocunt name</h3>
</div>
{{ end }}
<div class="form-group">
<button type="submit" class="btn btn-primary">Recover</button>
<button type="submit" class="btn btn-primary btn-sm">Recover</button>
</div>
</form>
{{ template "footer.html" . }}
@@ -28,7 +28,7 @@ <h3>Recover your acocunt password</h3>
</div>
{{ end }}
<div class="form-group">
<button type="submit" class="btn btn-primary">Recover</button>
<button type="submit" class="btn btn-primary btn-sm">Recover</button>
</div>
</form>
{{ template "footer.html" . }}
@@ -21,7 +21,7 @@ <h3>Two-factor authentication</h3>
<input type="text" class="form-control" id="input-token" name="token" placeholder="Authenticator token">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Enable</button>
<button type="submit" class="btn btn-primary btn-sm">Enable</button>
</div>
</form>
{{ template "footer.html" . }}
@@ -16,15 +16,19 @@ <h3>Shop</h3>
</p>

{{ if .categories }}
<ul class="nav nav-tabs" role="tablist">
<ul class="nav nav-tabs" id="shopTab" role="tablist">
{{ range $index, $element := .categories }}
<li role="presentation" {{ if eq $index 0 }} class="active" {{ end }}>
<a href="#category-{{ $element.id }}" aria-controls="{{ $element.name }}" role="tab" data-toggle="tab">{{ $element.name }}</a>
<li role="presentation" {{ if eq $index 0 }} class="nav-item" {{ end }}>
{{ if eq $index 0 }}
<a class="nav-link active" href="#category-{{ $element.id }}" aria-controls="{{ $element.name }}" role="tab" data-toggle="tab" aria-selected="true">{{ $element.name }}</a>
{{ else }}
<a class="nav-link" href="#category-{{ $element.id }}" aria-controls="{{ $element.name }}" role="tab" data-toggle="tab" aria-selected="false">{{ $element.name }}</a>
{{ end }}
</li>
{{ end }}
<li role="presentation" class="pull-right">
<a href="#checkout" role="tab" aria-controls="checkout" data-toggle="tab">
<i class="glyphicon glyphicon-shopping-cart"></i> Checkout
<li role="presentation" class="nav-item pull-right">
<a class="nav-link" id="checkout-tab" href="#checkout" role="tab" aria-controls="checkout" data-toggle="tab" aria-selected="false">
<i class="fas fa-shopping-cart"></i> Checkout
</a>
</li>
</ul>

This file was deleted.

0 comments on commit 72690b7

Please sign in to comment.
You can’t perform that action at this time.