Changeset 1184:03073d3aa649
- Timestamp:
- 09/15/06 13:29:18 (7 years ago)
- Branch:
- default
- Location:
- sage/server/notebook
- Files:
-
- 5 edited
-
css.py (modified) (1 diff)
-
js.py (modified) (6 diffs)
-
notebook.py (modified) (8 diffs)
-
server.py (modified) (16 diffs)
-
worksheet.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/server/notebook/css.py
r1183 r1184 1127 1127 width: 100%; 1128 1128 } 1129 1130 span.red{ 1131 color:red; 1132 } 1133 1129 1134 1130 1135 -
sage/server/notebook/js.py
r1183 r1184 75 75 var sub_introspecting = false; 76 76 77 var worksheet_id=0; // The current worksheet. Where else does this get set? 77 // Info about the current worksheet. These get set in notebook.py 78 var worksheet_id=0; 79 var worksheet_filename=''; 80 var worksheet_name=''; 78 81 79 82 var id_to_delete=-1; … … 107 110 var in_slide_mode = false; //whether or not we're in slideshow mode 108 111 var slide_hidden = false; //whether the current slide has the hidden input class 112 113 var worksheet_locked; 109 114 110 115 /////////////////////////////////////////////////////////////////// … … 488 493 /////////////////////////////////////////////////////////////////// 489 494 490 function add_worksheet(name ) {495 function add_worksheet(name,pass) { 491 496 async_request('async_obj_add_worksheet', '/add_worksheet', 492 add_worksheet_callback, 'name='+name )493 } 494 495 function add_worksheet_callback(status, response_text) {497 add_worksheet_callback, 'name='+name+'&passcode='+pass) 498 } 499 500 function add_worksheet_callback(status,response_text) { 496 501 if (status == "success") { 497 502 /* expect response_text to encode a pair consisting of … … 606 611 var add_worksheet_box = get_element('new_worksheet_box'); 607 612 name = add_worksheet_box.value; 613 var add_worksheet_pass = get_element('new_worksheet_pass'); 614 pass = add_worksheet_pass.value; 608 615 add_worksheet_box.value = ''; 609 add_worksheet(name); 616 add_worksheet_pass.value = ''; 617 add_worksheet(name,pass); 610 618 } 611 619 … … 630 638 } 631 639 640 function unlock_worksheet() { 641 lock = get_element("worksheet_lock"); 642 lock.innerHTML = 'Enter Passcode: <input onKeyPress="return unlock_worksheet_submit(event,value);" id="lock_input">'; 643 lock.innerHTML+= '<span id="unlock_error" class="red"></span>'; 644 lock_input = get_element("lock_input"); 645 lock_input.focus(); 646 } 647 648 function unlock_worksheet_submit(e,passcode) { 649 if(is_submit(e)) { 650 document.cookie = "ws_"+worksheet_name+"_passcode="+passcode; 651 async_request('async_unlock', '/unlock_worksheet', unlock_worksheet_callback, 'worksheet_id='+worksheet_id); 652 return false; 653 } 654 return true; 655 } 656 657 function unlock_worksheet_callback(status, response_text) { 658 if(status == 'success' && response_text == 'ok') { 659 lock = get_element("worksheet_lock"); 660 lock.parentNode.removeChild(lock); 661 worksheet_locked = false; 662 } else { 663 lock_input = get_element("lock_input"); 664 lock_input.value = ""; 665 lock_input.focus(); 666 txt = get_element('unlock_error'); 667 if(txt) 668 txt.innerHTML = 'incorrect'; 669 } 670 } 632 671 633 672 /////////////////////////////////////////////////////////////////// … … 1025 1064 1026 1065 function evaluate_cell(id, action) { 1066 if(worksheet_locked) { 1067 alert("This worksheet is locked. Click on the word [locked] next to the worksheet name to unlock it.") 1068 return; 1069 } 1070 1027 1071 active_cell_list = active_cell_list.concat([id]); 1028 1072 -
sage/server/notebook/notebook.py
r1183 r1184 561 561 return set([W.id() for W in self.__worksheets.itervalues()]) 562 562 563 def create_new_worksheet(self, name='untitled' ):563 def create_new_worksheet(self, name='untitled', passcode=''): 564 564 if name in self.__worksheets.keys(): 565 565 raise KeyError, 'name (=%s) already taken.'%name 566 566 name = str(name) 567 passcode = str(passcode) 567 568 wids = self.worksheet_ids() 568 569 id = 0 … … 573 574 raise ValueError, 'there can be at most %s worksheets'%MAX_WORKSHEETS 574 575 self.__next_worksheet_id += 1 575 W = worksheet.Worksheet(name, self, id, system=self.system() )576 W = worksheet.Worksheet(name, self, id, system=self.system(), passcode=passcode) 576 577 self.__worksheets[name] = W 577 578 return W … … 718 719 return head 719 720 720 def _html_body(self, worksheet_id, show_debug=False ):721 def _html_body(self, worksheet_id, show_debug=False, worksheet_authorized=False): 721 722 worksheet = self.get_worksheet_with_id(worksheet_id) 722 723 if worksheet.computing(): … … 727 728 add_new_worksheet_menu = """ 728 729 <div class="add_new_worksheet_menu" id="add_worksheet_menu"> 729 <input id="new_worksheet_box" class="add_new_worksheet_menu"730 Name: <input id="new_worksheet_box" class="add_new_worksheet_menu" 730 731 onKeyPress="if(is_submit(event)) process_new_worksheet_menu_submit();"></input> 732 Pass: <input id="new_worksheet_pass" class="add_new_worksheet_menu" 733 onKeyPress="if(is_submit(event)) process_new_worksheet_menu_submit();"></input> 734 731 735 <button class="add_new_worksheet_menu" onClick="process_new_worksheet_menu_submit();">add</button> 732 <span class="X" onClick="hide_add_new_worksheet_menu()">X</span>736 <span class="X" onClick="hide_add_new_worksheet_menu()">X</span> 733 737 </div> 734 738 """ … … 790 794 body += " onFocus='debug_focus();' onBlur='debug_blur();'></textarea>" 791 795 body += "</div>" 792 body += worksheet.html( )796 body += worksheet.html(authorized = worksheet_authorized) + '\n</div>\n' 793 797 794 798 # The blank space given by '<br>'*15 is needed so the input doesn't get … … 818 822 body += '<script language=javascript>focus(%s)</script>\n'%(worksheet[0].id()) 819 823 body += '<script language=javascript>jsmath_init();</script>\n' 824 825 if worksheet_authorized: 826 body += '<script language=javascript>worksheet_locked=false;</script>' 827 else: 828 body += '<script language=javascript>worksheet_locked=true;</script>' 820 829 821 830 if worksheet.computing(): … … 953 962 """%(css.css(self.color()),js.javascript()) 954 963 955 def html(self, worksheet_id=None, authorized=False, show_debug=False ):964 def html(self, worksheet_id=None, authorized=False, show_debug=False, worksheet_authorized=False): 956 965 if worksheet_id is None: 957 966 W = self.default_worksheet() … … 965 974 966 975 if authorized: 967 body = self._html_body(worksheet_id,show_debug=show_debug )976 body = self._html_body(worksheet_id,show_debug=show_debug, worksheet_authorized=worksheet_authorized) 968 977 else: 969 978 body = self._html_authorize() 970 979 971 body += '<script language=javascript>worksheet_id=%s; worksheet_filename="%s" </script>'%(worksheet_id, W.filename())980 body += '<script language=javascript>worksheet_id=%s; worksheet_filename="%s"; worksheet_name="%s";</script>'%(worksheet_id, W.filename(), W.name()) 972 981 973 982 head = self._html_head(worksheet_id) -
sage/server/notebook/server.py
r1097 r1184 61 61 typ = C['type'][0] 62 62 W = notebook.get_worksheet_that_has_cell_with_id(id) 63 cell = W.get_cell_with_id(id) 64 cell.set_cell_output_type(typ) 63 if self.auth_worksheet(W): 64 cell = W.get_cell_with_id(id) 65 cell.set_cell_output_type(typ) 65 66 66 67 def hide_all(self): … … 68 69 id = int(C['worksheet_id'][0]) 69 70 W = notebook.get_worksheet_with_id(id) 70 W.hide_all() 71 if self.auth_worksheet(W): 72 W.hide_all() 71 73 72 74 def restart_sage(self): … … 74 76 id = int(C['worksheet_id'][0]) 75 77 W = notebook.get_worksheet_with_id(id) 76 W.restart_sage() 77 self.wfile.write('done') 78 if self.auth_worksheet(W): 79 W.restart_sage() 80 self.wfile.write('done') 78 81 79 82 def show_all(self): 80 83 C = self.get_postvars() 81 84 id = int(C['worksheet_id'][0]) 82 W = notebook.get_worksheet_with_id(id) 83 W.show_all() 85 if self.auth_worksheet(W): 86 W = notebook.get_worksheet_with_id(id) 87 W.show_all() 84 88 85 89 def eval_cell(self, newcell=False, introspect=False): … … 90 94 verbose('%s: %s'%(id, input_text)) 91 95 W = notebook.get_worksheet_that_has_cell_with_id(id) 96 if not self.auth_worksheet(W): 97 return 98 92 99 cell = W.get_cell_with_id(id) 93 100 if not introspect: … … 118 125 119 126 W = notebook.get_worksheet_that_has_cell_with_id(id) 127 if not self.auth_worksheet(W): 128 return 129 120 130 cell = W.get_cell_with_id(id) 121 131 #TB: this tends to obliterate long cells -- if the user doesn't submit between … … 135 145 verbose("Adding new cell before cell with id %s"%id) 136 146 W = notebook.get_worksheet_that_has_cell_with_id(id) 147 if not self.auth_worksheet(W): 148 return 149 137 150 cell = W.new_cell_before(id) 138 151 #notebook.save() … … 145 158 verbose("Adding new cell after cell with id %s"%id) 146 159 W = notebook.get_worksheet_that_has_cell_with_id(id) 160 if not self.auth_worksheet(W): 161 return 162 147 163 cell = W.new_cell_after(id) 148 164 #notebook.save() … … 155 171 verbose("Deleting cell with id %s"%id) 156 172 W = notebook.get_worksheet_that_has_cell_with_id(id) 173 if not self.auth_worksheet(W): 174 return 175 157 176 if len(W) <= 1 or W.is_last_id_and_previous_is_nonempty(id): 158 177 self.wfile.write('ignore') … … 219 238 C = self.get_postvars() 220 239 worksheet_id = int(C['worksheet_id'][0]) 221 worksheet = notebook.get_worksheet_with_id(worksheet_id) 222 t = worksheet.interrupt() 240 W = notebook.get_worksheet_with_id(worksheet_id) 241 if not self.auth_worksheet(W): 242 return 243 244 t = W.interrupt() 223 245 if t: 224 246 self.wfile.write('ok') … … 229 251 C = self.get_postvars() 230 252 worksheet_name = C['name'][0] 231 try: 232 W = notebook.create_new_worksheet(worksheet_name) 253 passcode = C['passcode'][0] 254 try: 255 W = notebook.create_new_worksheet(worksheet_name, passcode) 233 256 except ValueError, msg: 234 257 print msg … … 238 261 self.wfile.write(new_worksheet_list + SEP + str(W.name())) 239 262 263 def auth_worksheet(self, W): 264 n = W.name() 265 passcode = '' 266 if self.cookie.has_key('ws_%s_passcode'%n): 267 passcode = self.cookie['ws_%s_passcode'%n].value 268 return W.auth(passcode) 269 270 def unlock_worksheet(self): 271 C = self.get_postvars() 272 worksheet_id = int(C['worksheet_id'][0]) 273 W = notebook.get_worksheet_with_id(worksheet_id) 274 if not self.auth_worksheet(W): 275 self.wfile.write('failed') 276 else: 277 self.wfile.write('ok') 278 240 279 def delete_worksheet(self): 241 280 C = self.get_postvars() 242 281 worksheet_name = C['name'][0] 282 W = notebook.get_worksheet_with_name(worksheet_name) 283 if not self.auth_worksheet(W): 284 return 285 243 286 try: 244 287 W = notebook.delete_worksheet(worksheet_name) … … 450 493 def show_page(self, worksheet_id=None,show_debug=False): 451 494 self.send_head() 495 W = notebook.get_worksheet_with_id(worksheet_id) 452 496 self.wfile.write(notebook.html(worksheet_id=worksheet_id, 453 497 authorized=self.authorize(), 454 show_debug=show_debug)) 498 show_debug=show_debug, 499 worksheet_authorized = self.auth_worksheet(W))) 455 500 456 501 … … 463 508 def do_GET(self): 464 509 verbose("GET: " + self.path) 510 self.get_cookie() 465 511 # The question mark hack here is so that images will be reloaded when 466 512 # the async request requests the output text for a computation. … … 499 545 self.file_not_found() 500 546 501 def authorize(self):547 def get_cookie(self): 502 548 self.cookie=Cookie.SimpleCookie() 503 549 if self.headers.has_key('cookie'): 504 550 self.cookie=Cookie.SimpleCookie(self.headers.getheader("cookie")) 551 552 def authorize(self): 505 553 username = password = ""; 506 554 if self.cookie.has_key('username'): … … 511 559 512 560 def do_POST(self): 561 self.get_cookie() 513 562 content_type, post_dict = cgi.parse_header(self.headers.getheader('content-type')) 514 563 verbose("POST: %s"%post_dict) … … 567 616 elif self.path[-17:] == '/delete_worksheet': 568 617 self.delete_worksheet() 618 elif self.path[-17:] == '/unlock_worksheet': 619 self.unlock_worksheet() 569 620 # elif self.path == '/upload_worksheet': 570 621 # self.upload_worksheet_local_file() -
sage/server/notebook/worksheet.py
r1178 r1184 43 43 44 44 class Worksheet: 45 def __init__(self, name, notebook, id, system=None ):45 def __init__(self, name, notebook, id, system=None, passcode = ''): 46 46 name = ' '.join(name.split()) 47 47 self.__id = id … … 50 50 self.__name = name 51 51 self.__notebook = notebook 52 self.__passcode = passcode 52 53 dir = list(name) 53 54 for i in range(len(dir)): … … 81 82 for C in self.__cells: 82 83 C.set_worksheet(self) 84 85 def passcode(self): 86 try: 87 return self.__passcode 88 except AttributeError: 89 self.__passcode = '' 90 return '' 83 91 84 92 def filename(self): … … 537 545 return self.__notebook.format_completions_as_html(id, rows) 538 546 539 540 541 547 def auth(self, passcode): 548 if self.passcode() == '': 549 return True 550 else: 551 return self.passcode() == passcode 542 552 543 553 def _strip_synchro_from_start_of_output(self, s): … … 1051 1061 return s 1052 1062 1053 def html(self, include_title=True, do_print=False ):1063 def html(self, include_title=True, do_print=False, authorized=False): 1054 1064 n = len(self.__cells) 1055 1065 s = '' … … 1061 1071 else: 1062 1072 system ='' 1063 s += '<div class="worksheet_title">Worksheet: %s%s</div>\n'%(self.name(),system) 1073 if not authorized: 1074 lock_text = ' <span id="worksheet_lock" class="locked" onClick="unlock_worksheet()">[locked]</span>' 1075 else: 1076 lock_text = '' 1077 1078 s += '<div class="worksheet_title">Worksheet: %s%s%s</div>\n'%(self.name(),system,lock_text) 1064 1079 D = self.__notebook.defaults() 1065 1080 ncols = D['word_wrap_cols']
Note: See TracChangeset
for help on using the changeset viewer.
