1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2 * Copyright (C) 2003-2004 Martin Baehr
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * $Id: debug.pike.in,v 1.1 2008/03/31 13:39:57 exodusd Exp $
20 inherit "applauncher.pike";
22 inherit Tools.Hilfe.Evaluator;
24 class steam-shell : public applauncher.pike{
29 #define OBJ(o) _Server->get_module("filepath:tree")->path_to_object(o)
31 Stdio.Readline readln;
37 protected class StashHelp {
38 string help(string what) { return "Show STASH help"; }
40 void exec(Evaluator e, string line, array words,
42 line = words[1..]*" ";
43 function(array|string, mixed ... : void) write = e->safe_write;
46 list List Gates/Exits, Documents, Containers in the current Room.
47 goto Goto a Room using a full path to the Room.
48 title Set your own description.
49 room Describe the Room you are currently in.
50 look Look around the Room.
51 take Copy a object in your inventory.
52 gothrough Go through a gate.
53 create Create an object (File/Container/Exit) in current Room.
54 peek Peek through a container.
55 inventory(i) List your inventory.
56 edit Edit a file in the current Room.
57 hilfe Help for Hilfe commands.
66 write("List Gates/Exits, Documents, Containers in the current Room.\n");
69 write("Goto a Room using a full path to the Room.\n");
72 write("Set your own description.\n");
75 write("Describe the Room you are currently in.\n");
78 write("Look around the Room.\n");
81 write("Copy a object in your inventory.\n");
84 write("Go through a gate.\n");
87 write("Create an object (File/Container/Exit) in current Room.\n");
90 write("Peek through a container.\n");
94 write("Lists your inventory\n");
97 write("Edit a file in the current Room.\n");
101 write( documentation_help_me_more );
102 write("Type \"hilfe\" to get more help on Hilfe commands\n");
110 Initial version written by Fredrik Hübinette 1996-2000
111 Rewritten by Martin Nilsson 2002
115 write(stash_help_doc);
117 write("\n\nEnter \"help me more\" for further Hilfe help.\n\n");
127 void create(mapping _constants)
129 readln = Stdio.Readline();
130 p = ((program)"tab_completion.pmod")();
135 p->constants+=_constants; //For listing sTeam commands and objects on tab
136 constants = p->constants; //For running those commands
137 readln->get_input_controller()->bind("\t",p->handle_completions);
138 commands->help = StashHelp();
139 commands->hilfe = CommandHelp();
142 void add_constants(mapping a)
144 constants = constants + a;
146 /* void add_variables(mapping a)
148 variables = variables + a;
152 object _Server,users;
155 Stdio.Readline.History readline_history;
160 mixed a = conn->send_command(14, 0);
161 if(a=="sTeam connection lost.")
164 readln->set_prompt(getpath()+"~ ");
165 conn = ((program)"client_base.pike")();
167 if(conn->connect_server(options->host, options->port))
169 remove_call_out(ping);
171 if(str=conn->login(options->user, pw, 1))
173 _Server=conn->SteamObj(0);
174 users=_Server->get_module("users");
175 me = users->lookup(options->user);
176 handler->add_constants(assign(conn,_Server,users));
178 readln->set_prompt(getpath()+"> ");
184 object handler, conn;
186 int main(int argc, array argv)
189 _Server=conn->SteamObj(0);
190 users=_Server->get_module("users");
191 me = users->lookup(options->user);
192 all = assign(conn,_Server,users);
195 handler = Handler(all);
196 array history=(Stdio.read_file(options->historyfile)||"")/"\n";
200 readline_history=Stdio.Readline.History(512, history);
202 readln->enable_history(readline_history);
204 handler->add_input_line("start backend");
214 "gothrough" : gothrough,
215 "create" : create_ob,
217 "inventory" : inventory,
221 // Regexp.SimpleRegexp a = Regexp.SimpleRegexp("[a-zA-Z]* [\"|'][a-zA-Z _-]*[\"|']");
223 while((command=readln->read(
224 sprintf("%s", (handler->state->finishedp()?getstring(1):getstring(2))))))
228 Stdio.write_file(options->historyfile, readln->get_history()->encode());
229 command = String.trim_whites(command);
230 // if(a->match(command))
231 // command_arr = array_sscanf(command,"%s [\"|']%s[\"|']");
233 command_arr = command/" ";
234 if(myarray[command_arr[0]])
236 int num = sizeof(command_arr);
237 mixed result = catch {
239 myarray[command_arr[0]](command_arr[1]);
241 myarray[command_arr[0]](command_arr[1],command_arr[2]);
243 myarray[command_arr[0]]();
248 write("Wrong command.||maybe some bug.\n");
252 handler->add_input_line(command);
253 // array hist = handler->history->status()/"\n";
255 // if(search(hist[sizeof(hist)-3],"sTeam connection lost.")!=-1){
256 // handler->write("came in here\n");
259 handler->p->set(handler->variables);
262 // else { continue; }
264 handler->add_input_line("exit");
267 mapping init(array argv)
269 mapping options = ([ "file":"/etc/shadow" ]);
271 array opt=Getopt.find_all_options(argv,aggregate(
272 ({"file",Getopt.HAS_ARG,({"-f","--file"})}),
273 ({"host",Getopt.HAS_ARG,({"-h","--host"})}),
274 ({"user",Getopt.HAS_ARG,({"-u","--user"})}),
275 ({"port",Getopt.HAS_ARG,({"-p","--port"})}),
278 options->historyfile=getenv("HOME")+"/.steam_history";
280 foreach(opt, array option)
282 options[option[0]]=option[1];
285 options->host="127.0.0.1";
287 options->user="root";
291 options->port=(int)options->port;
293 string server_path = "/usr/local/lib/steam";
295 master()->add_include_path(server_path+"/server/include");
296 master()->add_program_path(server_path+"/server/");
297 master()->add_program_path(server_path+"/conf/");
298 master()->add_program_path(server_path+"/spm/");
299 master()->add_program_path(server_path+"/server/net/coal/");
301 conn = ((program)"client_base.pike")();
303 int start_time = time();
305 werror("Connecting to sTeam server...\n");
306 while ( !conn->connect_server(options->host, options->port) )
308 if ( time() - start_time > 120 )
310 throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()}));
312 werror("Failed to connect... still trying ... (server running ?)\n");
317 if(lower_case(options->user) == "guest")
322 //readln->set_echo( 0 );
325 pw = Input.read_password( sprintf("Password for %s@%s", options->user,
326 options->host), "steam" );
327 //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host));
329 while((err = catch(conn->login(options->user, pw, 1))) && --tries);
330 //readln->set_echo( 1 );
334 werror("Failed to log in!\nWrong Password!\n");
340 mapping assign(object conn, object _Server, object users)
344 "get_module" : _Server->get_module,
345 "get_factory" : _Server->get_factory,
347 "find_object" : conn->find_object,
349 "groups" : _Server->get_module("groups"),
350 "me" : users->lookup(options->user),
352 "create" : create_object,
359 "gothrough" : gothrough,
362 "_SECURITY" : _Server->get_module("security"),
363 "_FILEPATH" : _Server->get_module("filepath:tree"),
364 "_TYPES" : _Server->get_module("types"),
365 "_LOG" : _Server->get_module("log"),
366 "OBJ" : _Server->get_module("filepath:tree")->path_to_object,
367 "MODULE_USERS" : _Server->get_module("users"),
368 "MODULE_GROUPS" : _Server->get_module("groups"),
369 "MODULE_OBJECTS" : _Server->get_module("objects"),
370 "MODULE_SMTP" : _Server->get_module("smtp"),
371 "MODULE_URL" : _Server->get_module("url"),
372 "MODULE_ICONS" : _Server->get_module("icons"),
373 "SECURITY_CACHE" : _Server->get_module("Security:cache"),
374 "MODULE_SERVICE" : _Server->get_module("ServiceManager"),
375 "MOD" : _Server->get_module,
376 "USER" : _Server->get_module("users")->lookup,
377 "GROUP" : _Server->get_module("groups")->lookup,
378 "_ROOTROOM" : _Server->get_module("filepath:tree")->path_to_object("/"),
379 "_STEAMUSER" : _Server->get_module("users")->lookup("steam"),
380 "_ROOT" : _Server->get_module("users")->lookup("root"),
381 "_GUEST" : _Server->get_module("users")->lookup("guest"),
382 "_ADMIN" : _Server->get_module("users")->lookup("admin"),
383 "_WORLDUSER" : _Server->get_module("users")->lookup("everyone"),
384 "_AUTHORS" : _Server->get_module("users")->lookup("authors"),
385 "_REVIEWER" : _Server->get_module("users")->lookup("reviewer"),
386 "_BUILDER" : _Server->get_module("users")->lookup("builder"),
387 "_CODER" : _Server->get_module("users")->lookup("coder"),
391 // create new sTeam objects
392 // with code taken from the web script create.pike
393 mixed create_object(string|void objectclass, string|void name, void|string desc, void|mapping data)
395 if(!objectclass && !name)
397 write("Usage: create(string objectclass, string name, void|string desc, void|mapping data\n");
400 object _Server=conn->SteamObj(0);
404 if ( !stringp(objectclass))
405 return "No object type submitted";
407 factory = _Server->get_factory(objectclass);
413 return "exit_from missing";
417 return "link_to missing";
423 created = factory->execute(([ "name":name ])+ data );
426 created->set_attribute("OBJ_DESC", desc);
428 // if ( kind=="gallery" )
430 // created->set_acquire_attribute("xsl:content", 0);
431 // created->set_attribute("xsl:content",
432 // ([ _STEAMUSER:_FILEPATH->path_to_object("/stylesheets/gallery.xsl") ])
436 // created->move(this_user());
441 string getstring(int i)
443 // write("came in here\n");
444 string curpath = getpath();
447 else if(i==1&&(flag==0))
449 else if(i==2&&flag==1)
450 return curpath+">> ";
451 else if(i==2&&(flag==0))
452 return curpath+"~~ ";
455 int list(string what)
457 if(what==""||what==0)
459 write("Wrong usage\n");
463 array display = get_list(what);
464 if(sizeof(display)==0)
465 toappend = "There are no "+what+" in this room.\n";
466 else if (display[0]=="Invalid command")
471 toappend = "Here is a list of all "+what+" in the current room\n";
473 // The linux terminal has 80 characters. This character length is divided to 3 columns.
474 // The first two columns having char length of 27 and the last one having char length 26
476 foreach(display,string str)
480 write(sprintf("%-26s",str));
485 write(sprintf("%-27s",str));
493 array get_list(string what,string|object|void lpath)
497 array gates=({}),containers=({}),documents=({}),rooms = ({}),rest=({});
498 // mapping s = ([ ]);
501 pathobj = OBJ(getpath());
502 else if(stringp(lpath))
503 pathobj = OBJ(lpath);
504 else if(objectp(lpath))
506 // string pathfact = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME");
507 mixed all = pathobj->get_inventory_by_class(0x3cffffff); //CLASS_ALL
508 foreach(all, object obj)
510 string fact_name = _Server->get_factory(obj)->query_attribute("OBJ_NAME");
511 string obj_name = obj->query_attribute("OBJ_NAME");
512 // write("normally : "+obj_name+"\n");
513 if(fact_name=="Document.factory")
514 documents = Array.push(documents,obj_name);
515 // write(obj_name+"\n");
516 else if(fact_name=="Exit.factory"){
517 string fullgate = obj_name+" : "+obj->get_exit()->query_attribute("OBJ_NAME");
518 gates = Array.push(gates,fullgate);
519 // write("in gates : "+fullgate+"\n");
521 else if(fact_name=="Container.factory")
522 containers = Array.push(containers,obj_name);
523 // write("in containers : "+obj_name+"\n");
524 else if(fact_name=="Room.factory")
525 rooms = Array.push(rooms,obj_name);
527 rest = Array.push(rest, obj_name);
531 else if(what=="rooms")
533 else if(what=="containers")
535 else if(what=="files")
537 else if(what=="others")
540 return ({"Invalid command"});
544 int goto_room(string where)
548 //USER CANT GO TO A RUCKSACK. HE CAN JUST LOOK INSIDE RUCKSACK
549 /* if(where=="rucksack")
551 pathobj=users->lookup(options->user);
552 path="/home/~"+pathobj->query_attribute("OBJ_NAME");
553 roomname="Your rucksack";
558 pathobj = OBJ(where);
559 if(!pathobj) //Relative room checking
561 if(getpath()[-1]==47) //check last "/"
563 pathobj = OBJ(getpath()+where);
564 where=getpath()+where;
568 pathobj = OBJ(getpath()+"/"+where);
569 where=getpath()+"/"+where;
572 roomname = pathobj->query_attribute("OBJ_NAME");
573 string factory = _Server->get_factory(pathobj)->query_attribute("OBJ_NAME");
574 //DONT NEED THIS. NEED TO USE me->move() to these locations
575 // if(pathobj&&((factory=="Room.factory")||(factory=="User.factory")||(factory=="Container.factory")))
577 string oldpath = getpath();
580 write("You are now inside "+roomname+"\n");
585 write("Please specify path to room. Not a "+((factory/".")[0])+"\n");
586 me->move(OBJ(oldpath));
590 write("Please specify correct path to a room.\n");
593 // roomname = pathobj->query_attribute("OBJ_NAME");
594 // write("You are now inside "+roomname+"\n");
598 int set_title(string desc)
600 if(users->lookup(options->user)->set_attribute("OBJ_DESC",desc))
601 write("You are now described as - "+desc+"\n");
603 write("Cannot set description.\n");
609 // write("path : "+path+"\n");
610 object pathobj = OBJ(getpath());
611 string desc = pathobj->query_attribute("OBJ_DESC");
612 // write("desc : "+desc+"\n");
613 if((desc=="")||(Regexp.match("^ +$",desc)))
614 desc = "This room does not have a description yet.\n";
615 write("You are currently in "+pathobj->query_attribute("OBJ_NAME")+"\n"+desc+"\n");
619 int look(string|void str)
623 write("Just type in 'look' to look around you\n");
628 write("---------------\n");
630 write("---------------\n");
632 write("---------------\n");
634 write("---------------\n");
638 int take(string name)
641 if(getpath()[-1]==47) //check last "/"
642 fullpath = getpath()+name;
644 fullpath = getpath()+"/"+name;
645 object orig_file = OBJ(fullpath);
648 object dup_file = orig_file->duplicate();
650 write(name+" copied to your rucksack.\n");
653 write("Please mention a file in this room.");
657 int gothrough(string gatename)
659 string fullpath = "";
660 if(getpath()[-1]==47) //check last "/"
661 fullpath = getpath()+gatename;
663 fullpath = getpath()+"/"+gatename;
664 object gate = OBJ(fullpath);
667 object exit = gate->get_exit();
668 string exit_path1 = "",exit_path2 = "";
669 // exit_path1 = _Server->get_module("filepath:tree")->check_tilde(exit);
670 // exit_path2 = _Server->get_module("filepath:tree")->object_to_path(exit);
671 // if(exit_path1!="")
672 // goto_room(exit_path1);
673 // else if(exit_path2!="/void/"||exit_path2!="")
674 // goto_room(exit_path2);
676 // write("Problem with object_to_path\n");
677 exit_path1 = exit->query_attribute("OBJ_PATH"); //change to object_to_path
679 goto_room(exit_path1);
682 write(gatename+" is not reachable from current room\n");
686 int delete(string file_cont_name)
689 if(getpath()[-1]==47) //check last "/"
690 fullpath = getpath()+file_cont_name;
692 fullpath = getpath()+"/"+file_cont_name;
698 int create_ob(string type,string name)
700 string desc = readln->read("How would you describe it?\n");
702 type = String.capitalize(type);
705 object exit_to = OBJ(readln->read("Where do you want to exit to?(full path)\n"));
706 object exit_from = OBJ(getpath());
707 data = ([ "exit_from":exit_from, "exit_to":exit_to ]);
709 else if(type=="Link")
711 object link_to = OBJ(readln->read("Where does the link lead?\n"));
712 data = ([ "link_to":link_to ]);
714 object myobj = create_object(type,name,desc,data);
716 myobj->move(OBJ(getpath()));
721 int peek(string container)
723 string fullpath = "";
724 if(getpath()[-1]==47) //check last "/"
725 fullpath = getpath()+container;
727 fullpath = getpath()+"/"+container;
728 string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");
729 if(pathfact=="Room.factory")
731 write("Maybe you are looking for the command 'look'\n");
734 if(pathfact!="Container.factory")
736 write("You can't peek into a "+pathfact[0..sizeof(pathfact)-8]+"\n");
739 array conts = get_list("containers", fullpath);
740 array files = get_list("files", fullpath);
741 write("You peek into "+container+"\n\n");
742 display("containers", conts);
743 display("files", files);
746 void display(string type, array strs)
749 write("There are no "+type+" here\n");
750 else if(sizeof(strs)==1)
751 write("There is 1 "+type[0..sizeof(type)-2]+" here\n");
753 write("There are "+sizeof(strs)+" "+type+" here\n");
754 foreach(strs, string str)
758 write("\n-----------------------\n");
763 array conts = get_list("containers", me);
764 array files = get_list("files", me);
765 array others = get_list("others", me);
766 write("You check your inventory\n");
767 display("containers", conts);
768 display("files", files);
769 display("other files", others);
772 int editfile(string filename)
774 string fullpath = "";
775 if(getpath()[-1]==47) //check last "/"
776 fullpath = getpath()+filename;
778 fullpath = getpath()+"/"+filename;
779 string pathfact = _Server->get_factory(OBJ(fullpath))->query_attribute("OBJ_NAME");
780 if(pathfact=="Document.factory")
781 applaunch(OBJ(fullpath),exitnow);
783 write("You can't edit a "+pathfact[0..sizeof(pathfact)-8]);
792 return me->get_last_trail()->query_attribute("OBJ_PATH");
795 constant stash_help_doc = #"This is a sTeam Advanced Shell. All the STASH commands work with normal pike commands. Tab completion is available for both STASH commands and pike commands.\n\n";