InPanel 1.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. inpanel/__init__.py +29 -0
  2. inpanel/acme.py +289 -0
  3. inpanel/aliyuncs.py +269 -0
  4. inpanel/app.py +514 -0
  5. inpanel/apt.py +223 -0
  6. inpanel/base.py +200 -0
  7. inpanel/config.py +139 -0
  8. inpanel/data/config.ini +29 -0
  9. inpanel/data/history +5 -0
  10. inpanel/data/runlogs.ini +12 -0
  11. inpanel/data/update_info.ini +4 -0
  12. inpanel/dnf.py +225 -0
  13. inpanel/lib/__init__.py +9 -0
  14. inpanel/lib/async_process.py +98 -0
  15. inpanel/lib/filelock.py +82 -0
  16. inpanel/lib/magic.py +233 -0
  17. inpanel/lib/pxssh.py +310 -0
  18. inpanel/lib/pyDes.py +867 -0
  19. inpanel/mod/__init__.py +0 -0
  20. inpanel/mod/apt.py +316 -0
  21. inpanel/mod/certificate.py +268 -0
  22. inpanel/mod/config.py +372 -0
  23. inpanel/mod/cron.py +315 -0
  24. inpanel/mod/disk.py +322 -0
  25. inpanel/mod/dnf.py +239 -0
  26. inpanel/mod/file.py +722 -0
  27. inpanel/mod/firewall.py +199 -0
  28. inpanel/mod/firewall_base.py +137 -0
  29. inpanel/mod/firewall_firewalld.py +170 -0
  30. inpanel/mod/firewall_iptables.py +176 -0
  31. inpanel/mod/firewall_macos.py +213 -0
  32. inpanel/mod/firewall_ufw.py +128 -0
  33. inpanel/mod/ftp.py +231 -0
  34. inpanel/mod/httpd.py +1205 -0
  35. inpanel/mod/lighttpd.py +26 -0
  36. inpanel/mod/login.py +98 -0
  37. inpanel/mod/mysql.py +577 -0
  38. inpanel/mod/named.py +26 -0
  39. inpanel/mod/nginx.py +2327 -0
  40. inpanel/mod/package.py +33 -0
  41. inpanel/mod/package_apt.py +62 -0
  42. inpanel/mod/package_base.py +77 -0
  43. inpanel/mod/package_dnf.py +62 -0
  44. inpanel/mod/package_map.py +366 -0
  45. inpanel/mod/package_yum.py +64 -0
  46. inpanel/mod/php.py +289 -0
  47. inpanel/mod/process.py +291 -0
  48. inpanel/mod/proftpd.py +26 -0
  49. inpanel/mod/pureftpd.py +26 -0
  50. inpanel/mod/query.py +108 -0
  51. inpanel/mod/server.py +1319 -0
  52. inpanel/mod/service.py +262 -0
  53. inpanel/mod/setting.py +228 -0
  54. inpanel/mod/shell.py +78 -0
  55. inpanel/mod/ssh.py +280 -0
  56. inpanel/mod/system.py +220 -0
  57. inpanel/mod/task.py +1337 -0
  58. inpanel/mod/ufw.py +14 -0
  59. inpanel/mod/user.py +306 -0
  60. inpanel/mod/vsftpd.py +67 -0
  61. inpanel/mod/yum.py +243 -0
  62. inpanel/plugins/__init__.py +10 -0
  63. inpanel/plugins/__pycache__/__init__.cpython-313.pyc +0 -0
  64. inpanel/plugins/acme/static/index.html +10 -0
  65. inpanel/plugins/acme/static/index.js +13 -0
  66. inpanel/plugins/shadowsocks-libev/__pycache__/info.cpython-313.pyc +0 -0
  67. inpanel/plugins/shadowsocks-libev/info.py +73 -0
  68. inpanel/plugins/shadowsocks-libev/static/index.html +70 -0
  69. inpanel/plugins/shadowsocks-libev/static/index.js +18 -0
  70. inpanel/public/css/global.css +138 -0
  71. inpanel/public/favicon.ico +0 -0
  72. inpanel/public/images/alipay.jpg +0 -0
  73. inpanel/public/images/loading.gif +0 -0
  74. inpanel/public/images/weixin.jpg +0 -0
  75. inpanel/public/index.html +94 -0
  76. inpanel/public/js/controllers/controllers.js +566 -0
  77. inpanel/public/js/controllers/database.js +590 -0
  78. inpanel/public/js/controllers/ecs.js +624 -0
  79. inpanel/public/js/controllers/file.js +940 -0
  80. inpanel/public/js/controllers/plugins.js +105 -0
  81. inpanel/public/js/controllers/service.js +1460 -0
  82. inpanel/public/js/controllers/site.js +1241 -0
  83. inpanel/public/js/controllers/utils.js +2319 -0
  84. inpanel/public/js/core.js +221 -0
  85. inpanel/public/js/directives.js +784 -0
  86. inpanel/public/js/filters.js +395 -0
  87. inpanel/public/js/services.js +257 -0
  88. inpanel/public/lib/angular/1.0.2/angular-resource.min.js +10 -0
  89. inpanel/public/lib/angular/1.0.2/angular.min.js +158 -0
  90. inpanel/public/lib/bootstrap/css/bootstrap-theme.css +587 -0
  91. inpanel/public/lib/bootstrap/css/bootstrap-theme.css.map +1 -0
  92. inpanel/public/lib/bootstrap/css/bootstrap-theme.min.css +6 -0
  93. inpanel/public/lib/bootstrap/css/bootstrap-theme.min.css.map +1 -0
  94. inpanel/public/lib/bootstrap/css/bootstrap.css +6757 -0
  95. inpanel/public/lib/bootstrap/css/bootstrap.css.map +1 -0
  96. inpanel/public/lib/bootstrap/css/bootstrap.min.css +6 -0
  97. inpanel/public/lib/bootstrap/css/bootstrap.min.css.map +1 -0
  98. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  99. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
  100. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  101. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  102. inpanel/public/lib/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
  103. inpanel/public/lib/bootstrap/img/glyphicons-halflings-white.png +0 -0
  104. inpanel/public/lib/bootstrap/img/glyphicons-halflings.png +0 -0
  105. inpanel/public/lib/bootstrap/js/bootstrap.js +2377 -0
  106. inpanel/public/lib/bootstrap/js/bootstrap.min.js +7 -0
  107. inpanel/public/lib/bootstrap/js/npm.js +13 -0
  108. inpanel/public/lib/codemirror/codemirror-compressed.js +1 -0
  109. inpanel/public/lib/codemirror/codemirror.css +173 -0
  110. inpanel/public/lib/jquery/jquery-1.12.4.min.js +5 -0
  111. inpanel/public/lib/md5/md5.js +379 -0
  112. inpanel/public/lib/md5/md5.min.js +1 -0
  113. inpanel/public/partials/database/index.html +172 -0
  114. inpanel/public/partials/database/mysql/dbedit.html +462 -0
  115. inpanel/public/partials/database/mysql/dbnew.html +348 -0
  116. inpanel/public/partials/database/mysql/useredit.html +310 -0
  117. inpanel/public/partials/database/mysql/usernew.html +97 -0
  118. inpanel/public/partials/directives/message.html +20 -0
  119. inpanel/public/partials/directives/navbar.html +25 -0
  120. inpanel/public/partials/directives/selector.html +57 -0
  121. inpanel/public/partials/directives/srvbase.html +72 -0
  122. inpanel/public/partials/directives/srvext.html +34 -0
  123. inpanel/public/partials/directives/srvfile.html +23 -0
  124. inpanel/public/partials/directives/srvinstall.html +34 -0
  125. inpanel/public/partials/directives/srvlog.html +23 -0
  126. inpanel/public/partials/directives/srvminiop.html +28 -0
  127. inpanel/public/partials/directives/srvuninstall.html +38 -0
  128. inpanel/public/partials/directives/srvupdate.html +30 -0
  129. inpanel/public/partials/ecs/account.html +156 -0
  130. inpanel/public/partials/ecs/ecs.html +198 -0
  131. inpanel/public/partials/ecs/index.html +40 -0
  132. inpanel/public/partials/ecs/setings.html +459 -0
  133. inpanel/public/partials/file/file.html +501 -0
  134. inpanel/public/partials/file/trash.html +95 -0
  135. inpanel/public/partials/ftp.html +36 -0
  136. inpanel/public/partials/log.html +83 -0
  137. inpanel/public/partials/login.html +79 -0
  138. inpanel/public/partials/logout.html +22 -0
  139. inpanel/public/partials/main.html +534 -0
  140. inpanel/public/partials/plugins/index.html +55 -0
  141. inpanel/public/partials/plugins/plugins.html +13 -0
  142. inpanel/public/partials/secure.html +13 -0
  143. inpanel/public/partials/service/apache.html +147 -0
  144. inpanel/public/partials/service/cron.html +71 -0
  145. inpanel/public/partials/service/index.html +293 -0
  146. inpanel/public/partials/service/iptables.html +40 -0
  147. inpanel/public/partials/service/lighttpd.html +63 -0
  148. inpanel/public/partials/service/mariadb.html +113 -0
  149. inpanel/public/partials/service/memcache.html +36 -0
  150. inpanel/public/partials/service/minio.html +44 -0
  151. inpanel/public/partials/service/mongodb.html +44 -0
  152. inpanel/public/partials/service/mysql.html +113 -0
  153. inpanel/public/partials/service/named.html +61 -0
  154. inpanel/public/partials/service/nginx.html +296 -0
  155. inpanel/public/partials/service/ntp.html +40 -0
  156. inpanel/public/partials/service/php.html +250 -0
  157. inpanel/public/partials/service/proftpd.html +59 -0
  158. inpanel/public/partials/service/pureftpd.html +59 -0
  159. inpanel/public/partials/service/redis.html +40 -0
  160. inpanel/public/partials/service/samba.html +58 -0
  161. inpanel/public/partials/service/sendmail.html +40 -0
  162. inpanel/public/partials/service/ssh.html +186 -0
  163. inpanel/public/partials/service/tomcat.html +65 -0
  164. inpanel/public/partials/service/vsftpd.html +195 -0
  165. inpanel/public/partials/setting.html +299 -0
  166. inpanel/public/partials/site/apache/site.html +277 -0
  167. inpanel/public/partials/site/index.html +344 -0
  168. inpanel/public/partials/site/nginx/site.html +558 -0
  169. inpanel/public/partials/sorry.html +19 -0
  170. inpanel/public/partials/storage/autofm.html +103 -0
  171. inpanel/public/partials/storage/backup.html +42 -0
  172. inpanel/public/partials/storage/index.html +360 -0
  173. inpanel/public/partials/storage/migrate.html +93 -0
  174. inpanel/public/partials/storage/movedata.html +98 -0
  175. inpanel/public/partials/storage/remote.html +77 -0
  176. inpanel/public/partials/utils/cron.html +486 -0
  177. inpanel/public/partials/utils/firewall.html +266 -0
  178. inpanel/public/partials/utils/index.html +193 -0
  179. inpanel/public/partials/utils/network.html +118 -0
  180. inpanel/public/partials/utils/process.html +239 -0
  181. inpanel/public/partials/utils/repository.html +373 -0
  182. inpanel/public/partials/utils/shell.html +28 -0
  183. inpanel/public/partials/utils/ssl.html +319 -0
  184. inpanel/public/partials/utils/time.html +109 -0
  185. inpanel/public/partials/utils/user.html +359 -0
  186. inpanel/public/robots.txt +2 -0
  187. inpanel/remote.py +109 -0
  188. inpanel/templates/file/preview.html +34 -0
  189. inpanel/templates/index.html +93 -0
  190. inpanel/utils.py +282 -0
  191. inpanel/web.py +1811 -0
  192. inpanel/yum.py +756 -0
  193. inpanel-1.2.1.dist-info/METADATA +399 -0
  194. inpanel-1.2.1.dist-info/RECORD +198 -0
  195. inpanel-1.2.1.dist-info/WHEEL +5 -0
  196. inpanel-1.2.1.dist-info/entry_points.txt +2 -0
  197. inpanel-1.2.1.dist-info/licenses/LICENSE +30 -0
  198. inpanel-1.2.1.dist-info/top_level.txt +1 -0
inpanel/lib/pxssh.py ADDED
@@ -0,0 +1,310 @@
1
+ """This class extends pexpect.spawn to specialize setting up SSH connections.
2
+ This adds methods for login, logout, and expecting the shell prompt.
3
+
4
+ $Id: pxssh.py 487 2007-08-29 22:33:29Z noah $
5
+ """
6
+
7
+ from pexpect import *
8
+ import pexpect
9
+ import time
10
+
11
+ __all__ = ['ExceptionPxssh', 'pxssh']
12
+
13
+ # Exception classes used by this module.
14
+ class ExceptionPxssh(ExceptionPexpect):
15
+ """Raised for pxssh exceptions.
16
+ """
17
+
18
+ class pxssh (spawn):
19
+
20
+ """This class extends pexpect.spawn to specialize setting up SSH
21
+ connections. This adds methods for login, logout, and expecting the shell
22
+ prompt. It does various tricky things to handle many situations in the SSH
23
+ login process. For example, if the session is your first login, then pxssh
24
+ automatically accepts the remote certificate; or if you have public key
25
+ authentication setup then pxssh won't wait for the password prompt.
26
+
27
+ pxssh uses the shell prompt to synchronize output from the remote host. In
28
+ order to make this more robust it sets the shell prompt to something more
29
+ unique than just $ or #. This should work on most Borne/Bash or Csh style
30
+ shells.
31
+
32
+ Example that runs a few commands on a remote server and prints the result::
33
+
34
+ import pxssh
35
+ import getpass
36
+ try:
37
+ s = pxssh.pxssh()
38
+ hostname = input('hostname: ')
39
+ username = input('username: ')
40
+ password = getpass.getpass('password: ')
41
+ s.login (hostname, username, password)
42
+ s.sendline ('uptime') # run a command
43
+ s.prompt() # match the prompt
44
+ print(s.before) # print everything before the prompt.
45
+ s.sendline ('ls -l')
46
+ s.prompt()
47
+ print(s.before)
48
+ s.sendline ('df')
49
+ s.prompt()
50
+ print(s.before)
51
+ s.logout()
52
+ except pxssh.ExceptionPxssh as e:
53
+ print("pxssh failed on login.")
54
+ print(str(e))
55
+
56
+ Note that if you have ssh-agent running while doing development with pxssh
57
+ then this can lead to a lot of confusion. Many X display managers (xdm,
58
+ gdm, kdm, etc.) will automatically start a GUI agent. You may see a GUI
59
+ dialog box popup asking for a password during development. You should turn
60
+ off any key agents during testing. The 'force_password' attribute will turn
61
+ off public key authentication. This will only work if the remote SSH server
62
+ is configured to allow password logins. Example of using 'force_password'
63
+ attribute::
64
+
65
+ s = pxssh.pxssh()
66
+ s.force_password = True
67
+ hostname = input('hostname: ')
68
+ username = input('username: ')
69
+ password = getpass.getpass('password: ')
70
+ s.login (hostname, username, password)
71
+ """
72
+
73
+ def __init__ (self, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None):
74
+ spawn.__init__(self, None, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, cwd=cwd, env=env)
75
+
76
+ self.name = '<pxssh>'
77
+
78
+ #SUBTLE HACK ALERT! Note that the command to set the prompt uses a
79
+ #slightly different string than the regular expression to match it. This
80
+ #is because when you set the prompt the command will echo back, but we
81
+ #don't want to match the echoed command. So if we make the set command
82
+ #slightly different than the regex we eliminate the problem. To make the
83
+ #set command different we add a backslash in front of $. The $ doesn't
84
+ #need to be escaped, but it doesn't hurt and serves to make the set
85
+ #prompt command different than the regex.
86
+
87
+ # used to match the command-line prompt
88
+ self.UNIQUE_PROMPT = r"\[PEXPECT\][\$\#] "
89
+ self.PROMPT = self.UNIQUE_PROMPT
90
+
91
+ # used to set shell command-line prompt to UNIQUE_PROMPT.
92
+ self.PROMPT_SET_SH = "PS1='[PEXPECT]\\$ '"
93
+ self.PROMPT_SET_CSH = "set prompt='[PEXPECT]\\$ '"
94
+ self.SSH_OPTS = "-o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'"
95
+ # Disabling X11 forwarding gets rid of the annoying SSH_ASKPASS from
96
+ # displaying a GUI password dialog. I have not figured out how to
97
+ # disable only SSH_ASKPASS without also disabling X11 forwarding.
98
+ # Unsetting SSH_ASKPASS on the remote side doesn't disable it! Annoying!
99
+ #self.SSH_OPTS = "-x -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'"
100
+ self.force_password = False
101
+ self.auto_prompt_reset = True
102
+
103
+ def levenshtein_distance(self, a,b):
104
+
105
+ """This calculates the Levenshtein distance between a and b.
106
+ """
107
+
108
+ n, m = len(a), len(b)
109
+ if n > m:
110
+ a,b = b,a
111
+ n,m = m,n
112
+ current = range(n+1)
113
+ for i in range(1,m+1):
114
+ previous, current = current, [i]+[0]*n
115
+ for j in range(1,n+1):
116
+ add, delete = previous[j]+1, current[j-1]+1
117
+ change = previous[j-1]
118
+ if a[j-1] != b[i-1]:
119
+ change = change + 1
120
+ current[j] = min(add, delete, change)
121
+ return current[n]
122
+
123
+ def synch_original_prompt (self):
124
+
125
+ """This attempts to find the prompt. Basically, press enter and record
126
+ the response; press enter again and record the response; if the two
127
+ responses are similar then assume we are at the original prompt. """
128
+
129
+ # All of these timing pace values are magic.
130
+ # I came up with these based on what seemed reliable for
131
+ # connecting to a heavily loaded machine I have.
132
+ # If latency is worse than these values then this will fail.
133
+
134
+ # bug fix REF: http://python.6.n6.nabble.com/read-nonblocking-error-in-pxssh-td1330216.html
135
+ self.sendline()
136
+ time.sleep(0.5)
137
+ self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt
138
+ time.sleep(0.1)
139
+ self.sendline()
140
+ time.sleep(0.5)
141
+ x = self.read_nonblocking(size=1000,timeout=1)
142
+ time.sleep(0.1)
143
+ self.sendline()
144
+ time.sleep(0.5)
145
+ a = self.read_nonblocking(size=1000,timeout=1)
146
+ time.sleep(0.1)
147
+ self.sendline()
148
+ time.sleep(0.5)
149
+ b = self.read_nonblocking(size=1000,timeout=1)
150
+ ld = self.levenshtein_distance(a,b)
151
+ len_a = len(a)
152
+ if len_a == 0:
153
+ return False
154
+ if float(ld)/len_a < 0.4:
155
+ return True
156
+ return False
157
+
158
+ ### TODO: This is getting messy and I'm pretty sure this isn't perfect.
159
+ ### TODO: I need to draw a flow chart for this.
160
+ def login (self,server,username,password='',terminal_type='ansi',original_prompt=r"[#$]",login_timeout=10,port=None,auto_prompt_reset=True):
161
+
162
+ """This logs the user into the given server. It uses the
163
+ 'original_prompt' to try to find the prompt right after login. When it
164
+ finds the prompt it immediately tries to reset the prompt to something
165
+ more easily matched. The default 'original_prompt' is very optimistic
166
+ and is easily fooled. It's more reliable to try to match the original
167
+ prompt as exactly as possible to prevent false matches by server
168
+ strings such as the "Message Of The Day". On many systems you can
169
+ disable the MOTD on the remote server by creating a zero-length file
170
+ called "~/.hushlogin" on the remote server. If a prompt cannot be found
171
+ then this will not necessarily cause the login to fail. In the case of
172
+ a timeout when looking for the prompt we assume that the original
173
+ prompt was so weird that we could not match it, so we use a few tricks
174
+ to guess when we have reached the prompt. Then we hope for the best and
175
+ blindly try to reset the prompt to something more unique. If that fails
176
+ then login() raises an ExceptionPxssh exception.
177
+
178
+ In some situations it is not possible or desirable to reset the
179
+ original prompt. In this case, set 'auto_prompt_reset' to False to
180
+ inhibit setting the prompt to the UNIQUE_PROMPT. Remember that pxssh
181
+ uses a unique prompt in the prompt() method. If the original prompt is
182
+ not reset then this will disable the prompt() method unless you
183
+ manually set the PROMPT attribute. """
184
+
185
+ ssh_options = '-q'
186
+ if self.force_password:
187
+ ssh_options = ssh_options + ' ' + self.SSH_OPTS
188
+ if port is not None:
189
+ ssh_options = ssh_options + ' -p %s'%(str(port))
190
+ cmd = "ssh %s -l %s %s" % (ssh_options, username, server)
191
+
192
+ # This does not distinguish between a remote server 'password' prompt
193
+ # and a local ssh 'passphrase' prompt (for unlocking a private key).
194
+ spawn._spawn(self, cmd)
195
+ i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT, "(?i)connection closed by remote host"], timeout=login_timeout)
196
+
197
+ # First phase
198
+ if i==0:
199
+ # New certificate -- always accept it.
200
+ # This is what you get if SSH does not have the remote host's
201
+ # public key stored in the 'known_hosts' cache.
202
+ self.sendline("yes")
203
+ i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT])
204
+ if i==2: # password or passphrase
205
+ self.sendline(password)
206
+ i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT])
207
+ if i==4:
208
+ self.sendline(terminal_type)
209
+ i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT])
210
+
211
+ # Second phase
212
+ if i==0:
213
+ # This is weird. This should not happen twice in a row.
214
+ self.close()
215
+ raise ExceptionPxssh ('Weird error. Got "are you sure" prompt twice.')
216
+ elif i==1: # can occur if you have a public key pair set to authenticate.
217
+ ### TODO: May NOT be OK if expect() got tricked and matched a false prompt.
218
+ pass
219
+ elif i==2: # password prompt again
220
+ # For incorrect passwords, some ssh servers will
221
+ # ask for the password again, others return 'denied' right away.
222
+ # If we get the password prompt again then this means
223
+ # we didn't get the password right the first time.
224
+ self.close()
225
+ raise ExceptionPxssh ('password refused')
226
+ elif i==3: # permission denied -- password was bad.
227
+ self.close()
228
+ raise ExceptionPxssh ('permission denied')
229
+ elif i==4: # terminal type again? WTF?
230
+ self.close()
231
+ raise ExceptionPxssh ('Weird error. Got "terminal type" prompt twice.')
232
+ elif i==5: # Timeout
233
+ #This is tricky... I presume that we are at the command-line prompt.
234
+ #It may be that the shell prompt was so weird that we couldn't match
235
+ #it. Or it may be that we couldn't log in for some other reason. I
236
+ #can't be sure, but it's safe to guess that we did login because if
237
+ #I presume wrong and we are not logged in then this should be caught
238
+ #later when I try to set the shell prompt.
239
+ pass
240
+ elif i==6: # Connection closed by remote host
241
+ self.close()
242
+ raise ExceptionPxssh ('connection closed')
243
+ else: # Unexpected
244
+ self.close()
245
+ raise ExceptionPxssh ('unexpected login response')
246
+ if not self.synch_original_prompt():
247
+ self.close()
248
+ raise ExceptionPxssh ('could not synchronize with original prompt')
249
+ # We appear to be in.
250
+ # set shell prompt to something unique.
251
+ if auto_prompt_reset:
252
+ if not self.set_unique_prompt():
253
+ self.close()
254
+ raise ExceptionPxssh ('could not set shell prompt\n'+self.before)
255
+ return True
256
+
257
+ def logout (self):
258
+
259
+ """This sends exit to the remote shell. If there are stopped jobs then
260
+ this automatically sends exit twice. """
261
+
262
+ self.sendline("exit")
263
+ index = self.expect([EOF, "(?i)there are stopped jobs"])
264
+ if index==1:
265
+ self.sendline("exit")
266
+ self.expect(EOF)
267
+ self.close()
268
+
269
+ def prompt (self, timeout=20):
270
+
271
+ """This matches the shell prompt. This is little more than a short-cut
272
+ to the expect() method. This returns True if the shell prompt was
273
+ matched. This returns False if there was a timeout. Note that if you
274
+ called login() with auto_prompt_reset set to False then you should have
275
+ manually set the PROMPT attribute to a regex pattern for matching the
276
+ prompt. """
277
+
278
+ i = self.expect([self.PROMPT, TIMEOUT], timeout=timeout)
279
+ if i==1:
280
+ return False
281
+ return True
282
+
283
+ def set_unique_prompt (self):
284
+
285
+ """This sets the remote prompt to something more unique than # or $.
286
+ This makes it easier for the prompt() method to match the shell prompt
287
+ unambiguously. This method is called automatically by the login()
288
+ method, but you may want to call it manually if you somehow reset the
289
+ shell prompt. For example, if you 'su' to a different user then you
290
+ will need to manually reset the prompt. This sends shell commands to
291
+ the remote host to set the prompt, so this assumes the remote host is
292
+ ready to receive commands.
293
+
294
+ Alternatively, you may use your own prompt pattern. Just set the PROMPT
295
+ attribute to a regular expression that matches it. In this case you
296
+ should call login() with auto_prompt_reset=False; then set the PROMPT
297
+ attribute. After that the prompt() method will try to match your prompt
298
+ pattern."""
299
+
300
+ self.sendline ("unset PROMPT_COMMAND")
301
+ self.sendline (self.PROMPT_SET_SH) # sh-style
302
+ i = self.expect ([TIMEOUT, self.PROMPT], timeout=10)
303
+ if i == 0: # csh-style
304
+ self.sendline (self.PROMPT_SET_CSH)
305
+ i = self.expect ([TIMEOUT, self.PROMPT], timeout=10)
306
+ if i == 0:
307
+ return False
308
+ return True
309
+
310
+ # vi:ts=4:sw=4:expandtab:ft=python: