Author Topic: My Code Editor for Creweb  (Read 2028 times)

Offline hells

  • Acquaintance
  • *
  • Posts: 11
    • View Profile
My Code Editor for Creweb
« on: April 28, 2012, 02:25:13 am »
I wanted to spruce up creweb with a bit of a nicer editor and some color coding. The results:



I used the following:

http://www.cdolivet.com/editarea/?page=editArea

I changed www/cgi/edit.c as follows:

Code: [Select]

#include <lib.h>
#include <daemons.h>
#include <sockets.h>

inherit LIB_DAEMON;
mapping UploadsMap = ([]);

void validate(){
    if(!master()->valid_apply(({ "SECURE", "ASSIST" })) &&
            strsrch(base_name(previous_object()), SOCKET_HTTP)){
        string offender = identify(previous_object(-1));
        debug("edit.c SECURITY VIOLATION: "+offender+" ",get_stack(),"red");
        log_file("security", "\n"+timestamp()+" edit.c breach: "+offender+" "+get_stack());
        error("edit.c SECURITY VIOLATION: "+offender+" "+get_stack());
    }
}

string eventGenerateEditor(string file, string name, string shib){
    mixed tmp;
    string ret = "File not found.";
    validate();
    tmp = WEB_SESSIONS_D->eventReadFile(file, name, shib);
    if(tmp){
        ret = "<script language=\"javascript\" type=\"text/javascript\" src=\"http://www.savsoul.com/js/edit_area_full.js\"></script>\n";
        ret += "<script language=\"javascript\" type=\"text/javascript\">\n";
        ret += "editAreaLoader.init({\n";
        ret += "    id : \"EditFile\" // textarea id\n";
        ret += "    ,syntax: \"c\" // syntax to be uses for highlighting\n";
        ret += "    ,start_highlight: true // to display with highlight mode on start-up\n";
        ret += "});\n";
        ret += "</script>\n";
        ret += "<FORM name=\"editform\" ACTION=\"/cgi/save.html\" METHOD=POST ENCTYPE=\"multipart/form-data\">";
        ret += "<div style=\"margin: 0px; padding: 0px;\"><p style=\"margin: 0px; padding: 0px; float: left\">Editing "+file+" - ";
        ret += "<INPUT accesskey=\"s\" TYPE=SUBMIT VALUE=\"submit\"> - ";       
        ret += "Write to a different file: <INPUT NAME=\"copy\" VALUE=\""+path_prefix(file)+"/\"SIZE=60\"></p>";
        ret += "<p style=\"margin: 0px; padding: 0px; float: right\"><a align=\"right\" href=\""+path_prefix(file)+"\">Back</a></p></div>";
        ret += "<TEXTAREA NAME=\"EditFile\" ID=\"EditFile\" style=\"width:100%;height:91%;\" wrap=\"off\">";
        ret += tmp;
        ret += "</TEXTAREA>";
        ret += "</FORM>";
        ret += "</body>";
    }
    return ret;
}

string gateway(string args) {
    object ob = previous_object();
    mapping cookie = ob->GetCookie();
    string current_page = ob->GetReferer();
    string ret = "";

    if(ENABLE_CREWEB){
        validate();

        ret += eventGenerateEditor(args, cookie["name"], cookie["shib"]);
    }
    else {
        ret += "CreWeb is disabled. To enable it: mudconfig creweb enable<br><br>";
    }
    ret += "<a href=\"/index.html\">Home</a><br>";
    ret += "<a href=\"http://dead-souls.net\">Dead Souls Home</a><br>";

    return ret;
}


To make life simpler I just put the .js files on my web server but they could be included. Just thought others might like to use this.

- Hells

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: My Code Editor for Creweb
« Reply #1 on: April 28, 2012, 01:28:34 pm »
sweet