最初版本
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import os
|
||||
import paramiko
|
||||
|
||||
pw = os.environ["DEPLOY_PASSWORD"]
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect("20.191.152.26", username="wakka", password=pw, timeout=30)
|
||||
|
||||
fix = r"""
|
||||
sudo docker exec guest-chat bundle exec rails runner "
|
||||
email = 'admin@localhost.local'
|
||||
user = User.find_by(email: email)
|
||||
if user
|
||||
user.confirm if user.respond_to?(:confirm)
|
||||
user.update!(confirmed_at: Time.current) if user.respond_to?(:confirmed_at) && user.confirmed_at.nil?
|
||||
puts \"confirmed user id=#{user.id} confirmed_at=#{user.confirmed_at}\"
|
||||
else
|
||||
puts 'user not found'
|
||||
end
|
||||
"
|
||||
"""
|
||||
|
||||
print(">>> confirm admin user")
|
||||
_, o, e = c.exec_command(fix, timeout=120)
|
||||
print(o.read().decode())
|
||||
print(e.read().decode())
|
||||
|
||||
# test guest-chat/new with csrf
|
||||
test = r"""
|
||||
python3 <<'PY'
|
||||
import re, json, urllib.request
|
||||
|
||||
req = urllib.request.Request('http://127.0.0.1:7777/guest-customer-service')
|
||||
with urllib.request.urlopen(req, timeout=15) as r:
|
||||
html = r.read().decode()
|
||||
m = re.search(r'"csrf_token":\s*"([^"]+)"', html)
|
||||
csrf = m.group(1) if m else ''
|
||||
print('csrf', csrf[:20] + '...')
|
||||
|
||||
post = urllib.request.Request(
|
||||
'http://127.0.0.1:7777/guest-chat/new',
|
||||
data=b'{}',
|
||||
headers={'Content-Type': 'application/json', 'X-CSRF-Token': csrf},
|
||||
method='POST',
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(post, timeout=30) as r:
|
||||
body = r.read().decode()
|
||||
print('status', r.status)
|
||||
print('body', body[:300])
|
||||
except Exception as e:
|
||||
if hasattr(e, 'read'):
|
||||
print('error', e.read().decode()[:400])
|
||||
else:
|
||||
print('error', e)
|
||||
PY
|
||||
"""
|
||||
|
||||
print(">>> test guest-chat/new")
|
||||
_, o, e = c.exec_command(test, timeout=60)
|
||||
print(o.read().decode())
|
||||
print(e.read().decode())
|
||||
c.close()
|
||||
Reference in New Issue
Block a user