mirror of https://github.com/gogits/gogs.git
Meaglith Ma
11 years ago
60 changed files with 503 additions and 243 deletions
@ -0,0 +1,26 @@ |
|||||||
|
### Binary install gogs on ubuntu 14.04 LTS |
||||||
|
|
||||||
|
### create user and install denpendency |
||||||
|
- sudo adduser git |
||||||
|
- sudo apt-get update |
||||||
|
- sudo apt-get upgrade |
||||||
|
- sudo apt-get install git |
||||||
|
- sudo apt-get install mysql-server |
||||||
|
|
||||||
|
### create the database |
||||||
|
- $mysql -u root -p |
||||||
|
- mysql> SET GLOBAL storage_engine = 'InnoDB'; |
||||||
|
- mysql> CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin; |
||||||
|
- mysql> GRANT ALL PRIVILEGES ON gogs.* TO 'root'@'localhost' IDENTIFIED BY 'password'; |
||||||
|
- mysql> FLUSH PRIVILEGES; |
||||||
|
- mysql> QUIT |
||||||
|
|
||||||
|
### install the gogs |
||||||
|
- mkdir gogs |
||||||
|
- cd gogs |
||||||
|
- curl -L http://gobuild.io/github.com/gogits/gogs/v0.3.0/linux/amd64 -o v0.3.0.zip |
||||||
|
- unzip v0.3.0.zip |
||||||
|
- ./start.sh |
||||||
|
|
||||||
|
> The up-to-date binary could be found at |
||||||
|
> http://gobuild.io/download/github.com/gogits/gogs |
@ -0,0 +1,48 @@ |
|||||||
|
##Install gogs under ubuntu 14.04 LTS 32bit from source code |
||||||
|
|
||||||
|
###Requirements |
||||||
|
- Go Programming Language: Version >= 1.2 |
||||||
|
- git(bash): Version >= 1.6.6(both server and client) |
||||||
|
- MySQL: Version >= 5.1 or PostgreSQL or NOTHING. |
||||||
|
|
||||||
|
### Create the user which will run git |
||||||
|
- sudo adduser git |
||||||
|
- su git |
||||||
|
|
||||||
|
### Install git and Mysql-server |
||||||
|
- sudo apt-get install git |
||||||
|
- sudo apt-get install mysql-server |
||||||
|
|
||||||
|
### Create database |
||||||
|
- $ mysql -u root -p |
||||||
|
- mysql> SET GLOBAL storage_engine = 'InnoDB'; |
||||||
|
- mysql> CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin; |
||||||
|
- mysql> GRANT ALL PRIVILEGES ON gogs.* TO 'root'@'localhost' IDENTIFIED BY 'pasword'; |
||||||
|
- mysql> FLUSH PRIVILEGES; |
||||||
|
- mysql> QUIT |
||||||
|
|
||||||
|
### install go from source |
||||||
|
- sudo apt-get install build-essential |
||||||
|
- sudo apt-get install mercurial |
||||||
|
- hg clone -r release https://go.googlecode.com/hg/ /home/git/golang/ |
||||||
|
|
||||||
|
|
||||||
|
- echo export GOROOT=/home/git/golang >>.bashrc |
||||||
|
- echo export GOARCH=386 >>.bashrc |
||||||
|
- echo export GOOS=linux >>.bashrc |
||||||
|
- echo export GOBIN= /home/git/golang/bin >>.bashrc |
||||||
|
- echo export GOPATH=$HOME/app/Go >>.bashrc |
||||||
|
- echo PATH=${PATH}: /$HOME/golang/bin >>.bashrc |
||||||
|
- cd $GOROOT/src |
||||||
|
- ./make.bash |
||||||
|
|
||||||
|
### Download and install dependencies |
||||||
|
- $ go get -u github.com/gogits/gogs |
||||||
|
|
||||||
|
### Build main program |
||||||
|
- $ cd $GOPATH/src/github.com/gogits/gogs |
||||||
|
- $ go build |
||||||
|
- $ ./start.sh |
||||||
|
|
||||||
|
### At present, you could access gogs from http://localhost:3000 |
||||||
|
|
@ -0,0 +1,38 @@ |
|||||||
|
// Copyright github.com/juju2013. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package models |
||||||
|
|
||||||
|
import ( |
||||||
|
"strings" |
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/auth/ldap" |
||||||
|
"github.com/gogits/gogs/modules/log" |
||||||
|
) |
||||||
|
|
||||||
|
// Query if name/passwd can login against the LDAP direcotry pool
|
||||||
|
// Create a local user if success
|
||||||
|
// Return the same LoginUserPlain semantic
|
||||||
|
func LoginUserLdap(name, passwd string) (*User, error) { |
||||||
|
mail, logged := ldap.LoginUser(name, passwd) |
||||||
|
if !logged { |
||||||
|
// user not in LDAP, do nothing
|
||||||
|
return nil, ErrUserNotExist |
||||||
|
} |
||||||
|
// fake a local user creation
|
||||||
|
user := User{ |
||||||
|
LowerName: strings.ToLower(name), |
||||||
|
Name: strings.ToLower(name), |
||||||
|
LoginType: 389, |
||||||
|
IsActive: true, |
||||||
|
Passwd: passwd, |
||||||
|
Email: mail} |
||||||
|
_, err := RegisterUser(&user) |
||||||
|
if err != nil { |
||||||
|
log.Debug("LDAP local user %s fond (%s) ", name, err) |
||||||
|
} |
||||||
|
// simulate local user login
|
||||||
|
localUser, err2 := GetUserByName(user.Name) |
||||||
|
return localUser, err2 |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
LDAP authentication |
||||||
|
=================== |
||||||
|
|
||||||
|
## Goal |
||||||
|
|
||||||
|
Authenticat user against LDAP directories |
||||||
|
|
||||||
|
It will bind with the user's login/pasword and query attributs ("mail" for instance) in a pool of directory servers |
||||||
|
|
||||||
|
The first OK wins. |
||||||
|
|
||||||
|
If there's connection error, the server will be disabled and won't be checked again |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
In the [security] section, set |
||||||
|
> LDAP_AUTH = true |
||||||
|
|
||||||
|
then for each LDAP source, set |
||||||
|
|
||||||
|
> [LdapSource-someuniquename] |
||||||
|
> name=canonicalName |
||||||
|
> host=hostname-or-ip |
||||||
|
> port=3268 # or regular LDAP port |
||||||
|
> # the following settings depend highly how you've configured your AD |
||||||
|
> basedn=dc=ACME,dc=COM |
||||||
|
> MSADSAFORMAT=%s@ACME.COM |
||||||
|
> filter=(&(objectClass=user)(sAMAccountName=%s)) |
||||||
|
|
||||||
|
### Limitation |
||||||
|
|
||||||
|
Only tested on an MS 2008R2 DC, using global catalog (TCP/3268) |
||||||
|
|
||||||
|
This MSAD is a mess. |
||||||
|
|
||||||
|
The way how one checks the directory (CN, DN etc...) may be highly depending local custom configuration |
||||||
|
|
||||||
|
### Todo |
||||||
|
* Define a timeout per server |
||||||
|
* Check servers marked as "Disabled" when they'll come back online |
||||||
|
* Find a more flexible way to define filter/MSADSAFORMAT/Attributes etc... maybe text/template ? |
||||||
|
* Check OpenLDAP server |
||||||
|
* SSL support ? |
@ -0,0 +1,86 @@ |
|||||||
|
// Copyright github.com/juju2013. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// package ldap provide functions & structure to query a LDAP ldap directory
|
||||||
|
// For now, it's mainly tested again an MS Active Directory service, see README.md for more information
|
||||||
|
package ldap |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"github.com/gogits/gogs/modules/log" |
||||||
|
goldap "github.com/juju2013/goldap" |
||||||
|
) |
||||||
|
|
||||||
|
// Basic LDAP authentication service
|
||||||
|
type ldapsource struct { |
||||||
|
Name string // canonical name (ie. corporate.ad)
|
||||||
|
Host string // LDAP host
|
||||||
|
Port int // port number
|
||||||
|
BaseDN string // Base DN
|
||||||
|
Attributes string // Attribut to search
|
||||||
|
Filter string // Query filter to validate entry
|
||||||
|
MsAdSAFormat string // in the case of MS AD Simple Authen, the format to use (see: http://msdn.microsoft.com/en-us/library/cc223499.aspx)
|
||||||
|
Enabled bool // if this source is disabled
|
||||||
|
} |
||||||
|
|
||||||
|
//Global LDAP directory pool
|
||||||
|
var ( |
||||||
|
Authensource []ldapsource |
||||||
|
) |
||||||
|
|
||||||
|
// Add a new source (LDAP directory) to the global pool
|
||||||
|
func AddSource(name string, host string, port int, basedn string, attributes string, filter string, msadsaformat string) { |
||||||
|
ldaphost := ldapsource{name, host, port, basedn, attributes, filter, msadsaformat, true} |
||||||
|
Authensource = append(Authensource, ldaphost) |
||||||
|
} |
||||||
|
|
||||||
|
//LoginUser : try to login an user to LDAP sources, return requested (attribut,true) if ok, ("",false) other wise
|
||||||
|
//First match wins
|
||||||
|
//Returns first attribute if exists
|
||||||
|
func LoginUser(name, passwd string) (a string, r bool) { |
||||||
|
r = false |
||||||
|
for _, ls := range Authensource { |
||||||
|
a, r = ls.searchEntry(name, passwd) |
||||||
|
if r { |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// searchEntry : search an LDAP source if an entry (name, passwd) is valide and in the specific filter
|
||||||
|
func (ls ldapsource) searchEntry(name, passwd string) (string, bool) { |
||||||
|
l, err := goldap.Dial("tcp", fmt.Sprintf("%s:%d", ls.Host, ls.Port)) |
||||||
|
if err != nil { |
||||||
|
log.Debug("LDAP Connect error, disabled source %s", ls.Host) |
||||||
|
ls.Enabled = false |
||||||
|
return "", false |
||||||
|
} |
||||||
|
defer l.Close() |
||||||
|
|
||||||
|
nx := fmt.Sprintf(ls.MsAdSAFormat, name) |
||||||
|
err = l.Bind(nx, passwd) |
||||||
|
if err != nil { |
||||||
|
log.Debug("LDAP Authan failed for %s, reason: %s", nx, err.Error()) |
||||||
|
return "", false |
||||||
|
} |
||||||
|
|
||||||
|
search := goldap.NewSearchRequest( |
||||||
|
ls.BaseDN, |
||||||
|
goldap.ScopeWholeSubtree, goldap.NeverDerefAliases, 0, 0, false, |
||||||
|
fmt.Sprintf(ls.Filter, name), |
||||||
|
[]string{ls.Attributes}, |
||||||
|
nil) |
||||||
|
sr, err := l.Search(search) |
||||||
|
if err != nil { |
||||||
|
log.Debug("LDAP Authen OK but not in filter %s", name) |
||||||
|
return "", false |
||||||
|
} |
||||||
|
log.Debug("LDAP Authen OK: %s", name) |
||||||
|
if len(sr.Entries) > 0 { |
||||||
|
r := sr.Entries[0].GetAttributeValue(ls.Attributes) |
||||||
|
return r, true |
||||||
|
} |
||||||
|
return "", true |
||||||
|
} |
After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 11 KiB |
@ -1,11 +1,11 @@ |
|||||||
<div id="user-setting-nav" class="col-md-3"> |
<div id="user-setting-nav" class="col-md-3"> |
||||||
<h4>Account Setting</h4> |
<h4>Account Settings</h4> |
||||||
<ul class="list-group"> |
<ul class="list-group"> |
||||||
<li class="list-group-item{{if .IsUserPageSetting}} list-group-item-success{{end}}"><a href="/user/setting">Account Profile</a></li> |
<li class="list-group-item{{if .IsUserPageSetting}} list-group-item-success{{end}}"><a href="/user/settings">Account Profile</a></li> |
||||||
<li class="list-group-item{{if .IsUserPageSettingSocial}} list-group-item-success{{end}}"><a href="/user/setting/social">Social Account</a></li> |
<li class="list-group-item{{if .IsUserPageSettingSocial}} list-group-item-success{{end}}"><a href="/user/settings/social">Social Account</a></li> |
||||||
<li class="list-group-item{{if .IsUserPageSettingPasswd}} list-group-item-success{{end}}"><a href="/user/setting/password">Password</a></li> |
<li class="list-group-item{{if .IsUserPageSettingPasswd}} list-group-item-success{{end}}"><a href="/user/settings/password">Password</a></li> |
||||||
<!-- <li class="list-group-item{{if .IsUserPageSettingNotify}} list-group-item-success{{end}}"><a href="/user/setting/notification">Notifications</a></li> --> |
<!-- <li class="list-group-item{{if .IsUserPageSettingNotify}} list-group-item-success{{end}}"><a href="/user/setting/notification">Notifications</a></li> --> |
||||||
<li class="list-group-item{{if .IsUserPageSettingSSH}} list-group-item-success{{end}}"><a href="/user/setting/ssh/">SSH Keys</a></li> |
<li class="list-group-item{{if .IsUserPageSettingSSH}} list-group-item-success{{end}}"><a href="/user/settings/ssh/">SSH Keys</a></li> |
||||||
<!-- <li class="list-group-item{{if .IsUserPageSettingSecurity}} list-group-item-success{{end}}"><a href="/user/setting/security">Security</a></li> --> |
<!-- <li class="list-group-item{{if .IsUserPageSettingSecurity}} list-group-item-success{{end}}"><a href="/user/setting/security">Security</a></li> --> |
||||||
<li class="list-group-item{{if .IsUserPageSettingDelete}} list-group-item-success{{end}}"><a href="/user/delete">Delete Account</a></li> |
<li class="list-group-item{{if .IsUserPageSettingDelete}} list-group-item-success{{end}}"><a href="/user/delete">Delete Account</a></li> |
||||||
</ul> |
</ul> |
||||||
|
@ -1,9 +0,0 @@ |
|||||||
command: go test -v {} |
|
||||||
include: ^.+_test\.go$ |
|
||||||
path: ./ |
|
||||||
depth: 1 |
|
||||||
verbose: true |
|
||||||
timeout: 1m |
|
||||||
reload: false |
|
||||||
html: test.html |
|
||||||
notify: [] |
|
@ -1,13 +0,0 @@ |
|||||||
## Gogs Test |
|
||||||
|
|
||||||
This is for developers. |
|
||||||
|
|
||||||
## Prepare Environment |
|
||||||
|
|
||||||
go get -u github.com/shxsun/travelexec |
|
||||||
# start gogs server |
|
||||||
gogs web |
|
||||||
|
|
||||||
## Start Testing |
|
||||||
|
|
||||||
travelexec |
|
@ -1,17 +0,0 @@ |
|||||||
package test |
|
||||||
|
|
||||||
import ( |
|
||||||
"net/http" |
|
||||||
"testing" |
|
||||||
) |
|
||||||
|
|
||||||
func TestMain(t *testing.T) { |
|
||||||
r, err := http.Get("http://localhost:3000/") |
|
||||||
if err != nil { |
|
||||||
t.Fatal(err) |
|
||||||
} |
|
||||||
defer r.Body.Close() |
|
||||||
if r.StatusCode != http.StatusOK { |
|
||||||
t.Error(r.StatusCode) |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue