~m15o/ichi

28709acb6819f12ed237f22d7fb29c568d1fc71e — m15o 4 months ago 1312df7
Add status cafe info and check to use key or not
M config/cfg.go => config/cfg.go +2 -0
@@ 18,6 18,7 @@ type (
		CheckPwdScript  string
		NewFolderScript string
		QuotaScript     string
		NeedsKey        bool
	}
)



@@ 37,5 38,6 @@ func New() *Config {
		CheckPwdScript:  os.Getenv("CHECK_PWD_SCRIPT"),
		NewFolderScript: os.Getenv("NEW_FOLDER_SCRIPT"),
		QuotaScript:     os.Getenv("QUOTA_SCRIPT"),
		NeedsKey:        os.Getenv("NEEDS_KEY") != "",
	}
}

M storage/homepage.go => storage/homepage.go +17 -0
@@ 52,6 52,23 @@ func (s *Storage) RecentlyModifiedHomepages() ([]model.Homepage, error) {
	return pages, nil
}

func (s *Storage) HomepagesActivity() ([]model.Homepage, error) {
	rows, err := s.db.Query("select author, title, description, updated_at from homepages order by updated_at desc limit 50")
	if err != nil {
		return nil, err
	}
	var pages []model.Homepage
	for rows.Next() {
		var page model.Homepage
		err := rows.Scan(&page.Author, &page.Title, &page.Description, &page.UpdatedAt)
		if err != nil {
			return pages, err
		}
		pages = append(pages, page)
	}
	return pages, nil
}

func (s *Storage) Homepages() ([]model.Homepage, error) {
	rows, err := s.db.Query("select author, title, description, updated_at from homepages order by updated_at desc")
	if err != nil {

M web/handler/handler.go => web/handler/handler.go +1 -0
@@ 87,6 87,7 @@ func New(cfg *config.Config, sess *session.Session, host string, data *storage.S
			if strings.Contains(r.Host, host) {
				user := strings.Replace(r.Host, "."+host, "", 1)
				dir := path.Join(cfg.SitesDirectory, user)
				w.Header().Set("Access-Control-Allow-Origin", "*")
				http.FileServer(http.Dir(dir)).ServeHTTP(w, r)
			}
			// Error

M web/handler/html.go => web/handler/html.go +6 -1
@@ 217,6 217,7 @@ var TplMap = map[string]string{
            <li><a href="#title">Give a TITLE to your home</a></li>
            <li><a href="#description">Give a DESCRIPTION to your home</a></li>
            <li><a href="#favicon">Add a FAVICON to your home</a></li>
            <li><a href="#status">Add your status at the top of your homepage</a></li>
            <li><a href="#badge">Add ichi's badge</a></li>
            <li><a href="#sftp">Use SFTP to manage your files</a></li>
        </ol>


@@ 258,6 259,8 @@ var TplMap = map[string]string{
    <pre>&lt;a href=&quot;https://ichi.city&quot;&gt;
    &lt;img src=&quot;https://ichi.city/banner.png&quot; alt=&quot;ichi&quot;/&gt;
&lt;/a&gt;</pre>
    <h3 id="status">Add your status at the top of your homepage</h3>
    <p>You can use <a href="https://status.cafe">Status Cafe</a> to add a widget at the top of your homepage that will show your latest status. Have a look at <a href="https://m15o.ichi.city">my homepage</a> to see what it could look like!</p>
    <h3 id="sftp">Use SFTP to manage your files</h3>
    <p>SFTP is an awesome internet protocol that allows you to edit your files locally on your computer, using any editor you'd like, and transfer them directly to ichi's server. To do that, you need an SFTP client. You could use any SFTP client, but if you don't have any I suggest to go with <a href="https://filezilla-project.org/" target="_blank">FileZilla</a>.</p>
    <p>Use the credentials you've registered with to connect to ichi's SFTP server. Use sftp://ichi.city as the host.</p>


@@ 442,13 445,15 @@ var TplMap = map[string]string{
            <label for="password-confirm">Confirm password</label>
            <input type="password" id="password-confirm" name="password-confirm" required/>
        </div>
        {{ if .needsKey }}
        <p>
            <a href="https://gumroad.com/l/YccHL" target="_blank">Buy a key</a> to get access instantly, or send an email to ichi@posteo.net.
        </p>
        <div class="field">
            <label for="password-confirm">Key</label>
            <label for="key">Key</label>
            <input type="text" id="key" name="key" required/>
        </div>
        {{ end }}
        <br>
        <input type="submit" value="Submit">
    </form>

M web/handler/html/help.html => web/handler/html/help.html +3 -0
@@ 15,6 15,7 @@
            <li><a href="#title">Give a TITLE to your home</a></li>
            <li><a href="#description">Give a DESCRIPTION to your home</a></li>
            <li><a href="#favicon">Add a FAVICON to your home</a></li>
            <li><a href="#status">Add your status at the top of your homepage</a></li>
            <li><a href="#badge">Add ichi's badge</a></li>
            <li><a href="#sftp">Use SFTP to manage your files</a></li>
        </ol>


@@ 56,6 57,8 @@
    <pre>&lt;a href=&quot;https://ichi.city&quot;&gt;
    &lt;img src=&quot;https://ichi.city/banner.png&quot; alt=&quot;ichi&quot;/&gt;
&lt;/a&gt;</pre>
    <h3 id="status">Add your status at the top of your homepage</h3>
    <p>You can use <a href="https://status.cafe">Status Cafe</a> to add a widget at the top of your homepage that will show your latest status. Have a look at <a href="https://m15o.ichi.city">my homepage</a> to see what it could look like!</p>
    <h3 id="sftp">Use SFTP to manage your files</h3>
    <p>SFTP is an awesome internet protocol that allows you to edit your files locally on your computer, using any editor you'd like, and transfer them directly to ichi's server. To do that, you need an SFTP client. You could use any SFTP client, but if you don't have any I suggest to go with <a href="https://filezilla-project.org/" target="_blank">FileZilla</a>.</p>
    <p>Use the credentials you've registered with to connect to ichi's SFTP server. Use sftp://ichi.city as the host.</p>

M web/handler/html/register.html => web/handler/html/register.html +3 -1
@@ 17,13 17,15 @@
            <label for="password-confirm">Confirm password</label>
            <input type="password" id="password-confirm" name="password-confirm" required/>
        </div>
        {{ if .needsKey }}
        <p>
            <a href="https://gumroad.com/l/YccHL" target="_blank">Buy a key</a> to get access instantly, or send an email to ichi@posteo.net.
        </p>
        <div class="field">
            <label for="password-confirm">Key</label>
            <label for="key">Key</label>
            <input type="text" id="key" name="key" required/>
        </div>
        {{ end }}
        <br>
        <input type="submit" value="Submit">
    </form>

M web/handler/index_show.go => web/handler/index_show.go +6 -0
@@ 9,6 9,11 @@ import (
	"strings"
)

type Update struct {
	UpdatedAgo string
	Author     string
}

func (h *Handler) showIndexView(w http.ResponseWriter, r *http.Request) {
	user, _ := h.sess.Get(r)
	pages, err := h.storage.RecentlyModifiedHomepages()


@@ 45,6 50,7 @@ func (h *Handler) showIndexView(w http.ResponseWriter, r *http.Request) {
	sort.Slice(files, func(i, j int) bool {
		return files[i].UpdatedAt.After(files[j].UpdatedAt)
	})

	if len(files) > 50 {
		files = files[:50]
	}

M web/handler/register.go => web/handler/register.go +6 -4
@@ 31,7 31,7 @@ func (h *Handler) handleRegister(w http.ResponseWriter, r *http.Request) {
func (h *Handler) showRegisterView(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	case "GET":
		h.renderLayout(w, "register", nil, "")
		h.renderLayout(w, "register", map[string]interface{}{"needsKey": h.cfg.NeedsKey}, "")
	}
}



@@ 121,9 121,11 @@ func (h *Handler) register(w http.ResponseWriter, r *http.Request) {
			showError(err)
			return
		}
		if err := verifyKey(f.Key); err != nil {
			showError(err)
			return
		if h.cfg.NeedsKey {
			if err := verifyKey(f.Key); err != nil {
				showError(err)
				return
			}
		}
		// Here we need to run the script
		err := exec.Command(h.cfg.NewUserScript, f.Username, f.Password, h.cfg.Group, h.cfg.SitesDirectory).Run()