Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
storjstatus-client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
James Coyle
storjstatus-client
Commits
c3e882de
Commit
c3e882de
authored
Mar 28, 2018
by
James Coyle
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'james-dev' into 'master'
James dev See merge request
!13
parents
c778c917
148d3463
Pipeline
#1242
failed with stages
in 5 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
149 additions
and
21 deletions
+149
-21
.gitlab-ci.yml
.gitlab-ci.yml
+11
-0
setup.py
setup.py
+2
-1
storjstatus/__init__.py
storjstatus/__init__.py
+3
-0
storjstatus/storjstatus_common.py
storjstatus/storjstatus_common.py
+23
-0
storjstatus/storjstatus_register.py
storjstatus/storjstatus_register.py
+71
-19
storjstatus/storjstatus_send.py
storjstatus/storjstatus_send.py
+24
-0
storjstatus/version.py
storjstatus/version.py
+1
-1
update-db.py
update-db.py
+14
-0
No files found.
.gitlab-ci.yml
View file @
c3e882de
...
...
@@ -11,12 +11,14 @@ stages:
-
set-env
-
deploy
-
cleanup
-
db
set-pypirc
:
stage
:
set-env
when
:
always
script
:
-
pip3 install crate
-
rm -rf ~/.pypirc
-
echo "[distutils]" >> ~/.pypirc
-
echo "index-servers=" >> ~/.pypirc
...
...
@@ -69,3 +71,12 @@ cleanup_pypirc:
-
rm -rf ~/.pypirc
tags
:
-
storjapi
update_db
:
stage
:
db
only
:
-
master
script
:
-
python3 update-db.py
tags
:
-
storjapi
setup.py
View file @
c3e882de
...
...
@@ -26,7 +26,8 @@ setup(name='storjstatus',
entry_points
=
{
'console_scripts'
:
[
'storjstatus-register=storjstatus:register'
,
'storjstatus-send=storjstatus:send'
'storjstatus-send=storjstatus:send'
,
'storjstatus-version=storjstatus:version'
]
}
)
storjstatus/__init__.py
View file @
c3e882de
...
...
@@ -8,3 +8,6 @@ def send():
def
register
():
storjstatus_register
.
init_register
()
def
version
():
print
(
"StorjStatus Client: "
+
storjstatus_common
.
get_version
())
storjstatus/storjstatus_common.py
View file @
c3e882de
...
...
@@ -7,6 +7,7 @@ import logging
CONFIGFILE
=
'/etc/storjstatus/config.json'
CONFIGREG
=
'Software\StorjStatus\StorjStatusClient\config'
APIENDPOINT
=
'https://www.storjstatus.com/api/'
log
=
None
...
...
@@ -40,6 +41,14 @@ def setup_logger():
log
=
ssLog
def
get_os_type
():
if
(
os
.
name
==
"posix"
):
return
""
elif
(
os
.
name
==
"nt"
):
return
"win"
else
:
return
"x"
def
cleanup_json
(
json
):
json
=
re
.
sub
(
r
'(?<!https:)//.*'
,
''
,
json
,
flags
=
re
.
MULTILINE
)
json
=
json
.
strip
().
replace
(
'
\r
'
,
''
).
replace
(
'
\n
'
,
''
)
...
...
@@ -48,6 +57,20 @@ def cleanup_json(json):
def
check_strojshare
():
if
get_os_type
()
==
"win"
:
return
check_strojshare_win
()
elif
get_os_type
()
==
"linux"
:
return
check_strojshare_linux
()
def
check_strojshare_win
():
result
=
subprocess_result
([
'storjshare'
,
'-V'
])
print
(
result
[
0
].
decode
(
'utf-8'
).
strip
())
return
"OK"
,
result
[
0
].
decode
(
'utf-8'
).
strip
()
def
check_strojshare_linux
():
result
=
subprocess_result
([
'which'
,
'storjshare'
])
if
'storjshare'
in
result
[
0
].
decode
(
'utf-8'
):
try
:
...
...
storjstatus/storjstatus_register.py
View file @
c3e882de
...
...
@@ -4,8 +4,10 @@ import argparse
import
getpass
import
json
import
os
from
os.path
import
expanduser
import
requests
import
socket
import
ctypes
from
crontab
import
CronTab
from
os
import
scandir
from
random
import
randint
...
...
@@ -48,34 +50,34 @@ def init_register():
name
=
name
or
guess_hostname
()
else
:
name
=
args
.
arg_name
print
(
'Using server name :'
+
name
)
print
(
'Using server name :'
+
name
+
'.'
)
if
not
args
.
arg_config_dir
:
config_dir
=
input
(
'Enter your Storjshare config directory ['
+
guess_config_dir
()
+
']: '
)
config_dir
=
config_dir
or
guess_config_dir
()
else
:
config_dir
=
args
.
arg_config_dir
print
(
'Using config directory :'
+
config_dir
)
print
(
'Using config directory :'
+
config_dir
+
'.'
)
# Final check on vars
if
not
email
or
len
(
email
)
<
5
:
print_error
(
'Email address is invalid'
)
print_error
(
'Email address is invalid
.
'
)
if
not
password
or
len
(
password
)
<
6
:
print_error
(
'Password is invalid'
)
print_error
(
'Password is invalid
.
'
)
if
not
name
or
len
(
name
)
<
3
:
print_error
(
'Server name must be at least 3 characters'
)
print_error
(
'Server name must be at least 3 characters
.
'
)
if
not
config_dir
or
len
(
config_dir
)
<
1
:
print_error
(
'Config Directory is invalid'
)
print_error
(
'Config Directory is invalid
.
'
)
if
not
os
.
path
.
isdir
(
config_dir
):
print_error
(
'Config Directory does not exist or is not a directory'
)
print_error
(
'Config Directory does not exist or is not a directory
.
'
)
path
,
dirs
,
files
=
os
.
walk
(
config_dir
).
__next__
()
if
(
len
(
files
)
<
1
):
print_error
(
'Unable to find any files in the Config Directory'
)
print_error
(
'Unable to find any files in the Config Directory
.
'
)
# Get api creds
key
,
secret
=
api_creds
(
email
,
password
)
...
...
@@ -89,24 +91,38 @@ def init_register():
cron_job
()
print
()
print
(
"Setup complete. You will see your statistics appear on your dashboard over the next
hour
"
)
print
(
"Setup complete. You will see your statistics appear on your dashboard over the next
30 mins.
"
)
def
checks
():
global
FORCE
if
os
.
geteuid
()
!=
0
:
print_error
(
'Please run this script with root privileges'
)
if
storjstatus_common
.
get_os_type
()
==
"x"
:
print_error
(
'Unsupported Os type.'
)
try
:
if
os
.
geteuid
()
!=
0
:
print_error
(
'Please run this script with root privileges.'
)
except
AttributeError
:
pass
try
:
if
ctypes
.
windll
.
shell32
.
IsUserAnAdmin
()
!=
1
:
print_error
(
'Please run this script with Administrator privileges.'
)
except
AttributeError
:
print_error
(
'Error checking user access level.'
)
if
FORCE
==
True
:
print
(
"Forcing regeneration of config and crontab. Note cron times may change."
)
elif
os
.
path
.
isfile
(
storjstatus_common
.
CONFIGFILE
):
print_error
(
'Server config file already exists'
)
print_error
(
'Server config file already exists
.
'
)
exit
(
1
)
# Check strojshare exists
code
,
result
=
storjstatus_common
.
check_strojshare
()
try
:
code
,
result
=
storjstatus_common
.
check_strojshare
()
except
FileNotFoundError
:
print_error
(
"Unable to find the Storj Share Daemon. Please ensure it's on your PATH variable."
)
if
code
!=
"OK"
:
print_error
(
result
,
False
)
...
...
@@ -114,8 +130,8 @@ def checks():
def
header
():
print
(
'####################################################'
)
print
(
'
StorjStatus Server Registration'
)
print
(
'
#
Version: '
+
storjstatus_common
.
get_version
())
print
(
' StorjStatus Server Registration'
)
print
(
' Version: '
+
storjstatus_common
.
get_version
())
print
(
'####################################################'
)
print
()
...
...
@@ -133,17 +149,29 @@ def cmdargs():
def
guess_config_dir
():
user
=
getpass
.
getuser
()
if
user
==
'root'
:
return
'/root/.config/storjshare/configs'
else
:
return
'/home/'
+
user
+
'/.config/storjshare/configs'
if
storjstatus_common
.
get_os_type
()
==
"win"
:
return
expanduser
(
"~"
)
+
'.storjshare\configs'
elif
storjstatus_common
.
get_os_type
()
==
"linux"
:
if
user
==
'root'
:
return
'/root/.config/storjshare/configs'
else
:
return
'/home/'
+
user
+
'/.config/storjshare/configs'
def
guess_hostname
():
return
socket
.
gethostname
()
def
save_settings
(
api_key
,
api_secret
,
server_guid
,
storj_config
):
if
storjstatus_common
.
get_os_type
()
==
"win"
:
save_settings_win
(
api_key
,
api_secret
,
server_guid
,
storj_config
)
elif
storjstatus_common
.
get_os_type
()
==
"linux"
:
save_settings_linux
(
api_key
,
api_secret
,
server_guid
,
storj_config
)
def
save_settings_linux
(
api_key
,
api_secret
,
server_guid
,
storj_config
):
settings
=
{
'api_key'
:
api_key
,
'api_secret'
:
api_secret
,
...
...
@@ -167,6 +195,20 @@ def save_settings(api_key, api_secret, server_guid, storj_config):
settings_file
.
close
()
def
save_settings_win
(
api_key
,
api_secret
,
server_guid
,
storj_config
):
try
:
import
winreg
local_machine
=
winreg
.
ConnectRegistry
(
None
,
winreg
.
HKEY_LOCAL_MACHINE
)
config
=
winreg
.
OpenKey
(
local_machine
,
storjstatus_common
.
CONFIGREG
)
winreg
.
SetValueEx
(
config
,
"api_key"
,
0
,
winreg
.
REG_SZ
,
api_key
)
winreg
.
SetValueEx
(
config
,
"api_secret"
,
0
,
winreg
.
REG_SZ
,
api_secret
)
winreg
.
SetValueEx
(
config
,
"server_guid"
,
0
,
winreg
.
REG_SZ
,
server_guid
)
winreg
.
SetValueEx
(
config
,
"storj_config"
,
0
,
winreg
.
REG_SZ
,
storj_config
)
except
AttributeError
:
print_error
(
"There was a problem writing to the Windows Registry"
)
def
api_creds
(
email
,
password
):
json_request
=
{
'email'
:
email
,
...
...
@@ -203,6 +245,16 @@ def server_guid(key, secret, name):
def
cron_job
():
if
storjstatus_common
.
get_os_type
()
==
"win"
:
print
()
print
(
'************* Windows scheduling unsupported ************'
)
print
()
print
(
'Please set up a manual schedule for "storjstatus-send" every 15 minutes.'
)
elif
storjstatus_common
.
get_os_type
()
==
"linux"
:
cron_job_linux
()
def
cron_job_linux
():
result
=
storjstatus_common
.
subprocess_result
([
'which'
,
'storjstatus-send'
])
if
'storjstatus-send'
in
result
[
0
].
decode
(
'utf-8'
):
...
...
storjstatus/storjstatus_send.py
View file @
c3e882de
...
...
@@ -170,6 +170,30 @@ def config_json():
def
load_settings
():
<<<<<<<
HEAD
if
storjstatus_common
.
get_os_type
()
==
"win"
:
return
load_settings_win
()
elif
storjstatus_common
.
get_os_type
()
==
"linux"
:
return
load_settings_linux
()
def
load_settings_win
():
try
:
import
winreg
local_machine
=
winreg
.
ConnectRegistry
(
None
,
winreg
.
HKEY_LOCAL_MACHINE
)
config
=
winreg
.
OpenKey
(
local_machine
,
storjstatus_common
.
CONFIGREG
)
APIKEY
=
winreg
.
QueryValueEx
(
config
,
'api_key'
)[
0
]
APISECRET
=
winreg
.
QueryValueEx
(
config
,
'api_secret'
)[
0
]
SERVERGUID
=
winreg
.
QueryValueEx
(
config
,
'server_guid'
)[
0
]
STORJCONFIG
=
winreg
.
QueryValueEx
(
config
,
'storj_config'
)[
0
]
except
AttributeError
:
print_error
(
'Error parsing Windows registry. Did you run storjstatus-register?'
)
def
load_settings_linux
():
=======
>>>>>>>
c778c9176753976ed977fc2bf64e632f499cdfa3
global
APIKEY
global
APISECRET
global
SERVERGUID
...
...
storjstatus/version.py
View file @
c3e882de
__version__
=
'0.
2.7
'
__version__
=
'0.
3.0
'
update-db.py
0 → 100644
View file @
c3e882de
import
os
import
setuptools
from
crate.client
import
connect
def
main
():
exec
(
open
(
'storjstatus/version.py'
).
read
())
print
(
"Updating database to version "
+
__VERSION__
)
connection
=
connect
(
'data2.jamescoyle.net:4200'
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"UPDATE storj.settings SET setting_value = '"
+
__VERSION__
+
"' WHERE setting_name = 'storjstatus-client-version' "
)
if
__name__
==
"__main__"
:
main
()
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