Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
3fa8e384
Commit
3fa8e384
authored
Jun 07, 2014
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Plain Diff
improve hostname/IP default values
Merges branch 'mkropat-populate-hostname-ip'
parents
242cadeb
b60ca25e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
12 deletions
+63
-12
Vagrantfile
Vagrantfile
+1
-1
functions.sh
setup/functions.sh
+45
-0
start.sh
setup/start.sh
+6
-9
mail.py
tools/mail.py
+11
-2
No files found.
Vagrantfile
View file @
3fa8e384
...
...
@@ -18,7 +18,7 @@ Vagrant.configure("2") do |config|
# machine figure out its own public IP and it'll take a
# subdomain on our justtesting.email domain so we can get
# started quickly.
export PUBLIC_IP=auto
-web
export PUBLIC_IP=auto
export PUBLIC_HOSTNAME=auto-easy
export CSR_COUNTRY=US
...
...
setup/functions.sh
View file @
3fa8e384
...
...
@@ -19,6 +19,51 @@ function apt_install {
DEBIAN_FRONTEND
=
noninteractive apt-get
-qq
-y
install
$PACKAGES
>
/dev/null
;
}
function
get_default_hostname
{
# Guess the machine's hostname. It should be a fully qualified
# domain name suitable for DNS. None of these calls may provide
# the right value, but it's the best guess we can make.
set
--
$(
hostname
--fqdn
2>/dev/null
||
hostname
--all-fqdns
2>/dev/null
||
hostname
2>/dev/null
)
printf
'%s\n'
"
$1
"
# return this value
}
function
get_default_publicip
{
# Get the machine's public IP address. The machine might have
# an IP on a private network, but the IP address that we put
# into DNS must be one on the public Internet. Try a public
# API, but if that fails (maybe we don't have Internet access
# right now) then use the IP address that this machine knows
# itself as.
get_publicip_from_web_service
||
get_publicip_fallback
}
function
get_publicip_from_web_service
{
# This seems to be the most reliable way to determine the
# machine's public IP address: asking a very nice web API
# for how they see us. Thanks go out to icanhazip.com.
curl
--fail
--silent
icanhazip.com 2>/dev/null
}
function
get_publicip_fallback
{
# Return the IP address that this machine knows itself as.
# It certainly may not be the IP address that this machine
# operates as on the public Internet. The machine might
# have multiple addresses if it has multiple network adapters.
set
--
$(
hostname
--ip-address
2>/dev/null
)
\
$(
hostname
--all-ip-addresses
2>/dev/null
)
while
((
$#
))
&&
is_loopback_ip
"
$1
"
;
do
shift
done
printf
'%s\n'
"
$1
"
# return this value
}
function
is_loopback_ip
{
# helper for get_publicip_fallback
[[
"
$1
"
==
127.
*
]]
}
function
ufw_allow
{
if
[
-z
"
$DISABLE_FIREWALL
"
]
;
then
# ufw has completely unhelpful output
...
...
setup/start.sh
View file @
3fa8e384
...
...
@@ -2,6 +2,8 @@
# This is the entry point for configuring the system.
#####################################################
source
setup/functions.sh
# load our functions
# Check system setup.
if
[
"
`
lsb_release
-d
|
sed
's/.*:\s*//'
`
"
!=
"Ubuntu 14.04 LTS"
]
;
then
...
...
@@ -31,7 +33,7 @@ if [ -z "$PUBLIC_HOSTNAME" ]; then
if
[
-z
"
$DEFAULT_PUBLIC_HOSTNAME
"
]
;
then
# set a default on first run
DEFAULT_PUBLIC_HOSTNAME
=
`
hostname
`
DEFAULT_PUBLIC_HOSTNAME
=
`
get_default_
hostname
`
fi
read
-e
-i
"
$DEFAULT_PUBLIC_HOSTNAME
"
-p
"Hostname: "
PUBLIC_HOSTNAME
...
...
@@ -46,7 +48,7 @@ if [ -z "$PUBLIC_IP" ]; then
if
[
-z
"
$DEFAULT_PUBLIC_IP
"
]
;
then
# set a default on first run
DEFAULT_PUBLIC_IP
=
`
hostname
-i
`
DEFAULT_PUBLIC_IP
=
`
get_default_publicip
`
fi
read
-e
-i
"
$DEFAULT_PUBLIC_IP
"
-p
"Public IP: "
PUBLIC_IP
...
...
@@ -69,18 +71,13 @@ fi
# Automatic configuration, e.g. as used in our Vagrant configuration.
if
[
"
$PUBLIC_IP
"
==
"auto"
]
;
then
# Assume `hostname -i` gives the correct public IP address for the machine.
PUBLIC_IP
=
`
hostname
-i
`
echo
"IP Address:
$PUBLIC_IP
"
fi
if
[
"
$PUBLIC_IP
"
==
"auto-web"
]
;
then
# Use a public API to get our public IP address.
PUBLIC_IP
=
`
curl
-s
icanhazip.com
`
PUBLIC_IP
=
`
get_default_publicip
`
echo
"IP Address:
$PUBLIC_IP
"
fi
if
[
"
$PUBLIC_HOSTNAME
"
==
"auto-easy"
]
;
then
# Generate a probably-unique subdomain under our justtesting.email domain.
PUBLIC_HOSTNAME
=
m
`
hostname
-i
|
sha1sum
|
cut
-c1-5
`
.justtesting.email
PUBLIC_HOSTNAME
=
m
`
get_default_publicip
|
sha1sum
|
cut
-c1-5
`
.justtesting.email
echo
"Public Hostname:
$PUBLIC_HOSTNAME
"
fi
...
...
tools/mail.py
View file @
3fa8e384
#!/usr/bin/python3
import
sys
,
urllib
.
request
,
urllib
.
error
import
sys
,
getpass
,
urllib
.
request
,
urllib
.
error
def
mgmt
(
cmd
,
data
=
None
):
req
=
urllib
.
request
.
Request
(
'http://localhost:10222'
+
cmd
,
urllib
.
parse
.
urlencode
(
data
)
.
encode
(
"utf8"
)
if
data
else
None
)
...
...
@@ -11,6 +11,15 @@ def mgmt(cmd, data=None):
sys
.
exit
(
1
)
return
response
.
read
()
.
decode
(
'utf8'
)
def
read_password
():
first
=
getpass
.
getpass
(
'password: '
)
second
=
getpass
.
getpass
(
' (again): '
)
while
first
!=
second
:
print
(
'Passwords not the same. Try again.'
)
first
=
getpass
.
getpass
(
'password: '
)
second
=
getpass
.
getpass
(
' (again): '
)
return
first
if
len
(
sys
.
argv
)
<
2
:
print
(
"Usage: "
)
print
(
" tools/mail.py user (lists users)"
)
...
...
@@ -33,7 +42,7 @@ elif sys.argv[1] == "user" and sys.argv[2] in ("add", "password"):
email
=
input
(
"email: "
)
else
:
email
=
sys
.
argv
[
3
]
pw
=
input
(
"password: "
)
pw
=
read_password
(
)
else
:
email
,
pw
=
sys
.
argv
[
3
:
5
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment