/* This is the special environment used for running the "exec cmd=" * variety of SSI directives. */ static void add_ssi_vars(request_rec *r) { apr_table_t *e = r->subprocess_env; if (r->path_info && r->path_info[0] != '\0') { request_rec *pa_req; apr_table_setn(e, "PATH_INFO", ap_escape_shell_cmd(r->pool, r->path_info)); pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r, NULL); if (pa_req->filename) { apr_table_setn(e, "PATH_TRANSLATED", apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info, NULL)); } ap_destroy_sub_req(pa_req); } if (r->args) { char *arg_copy = apr_pstrdup(r->pool, r->args); apr_table_setn(e, "QUERY_STRING", r->args); ap_unescape_url(arg_copy); apr_table_setn(e, "QUERY_STRING_UNESCAPED", ap_escape_shell_cmd(r->pool, arg_copy)); } }
AP_DECLARE(void) ap_add_cgi_vars(request_rec *r) { apr_table_t *e = r->subprocess_env; apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1"); apr_table_setn(e, "SERVER_PROTOCOL", r->protocol); apr_table_setn(e, "REQUEST_METHOD", r->method); apr_table_setn(e, "QUERY_STRING", r->args ? r->args : ""); apr_table_setn(e, "REQUEST_URI", original_uri(r)); /* Note that the code below special-cases scripts run from includes, * because it "knows" that the sub_request has been hacked to have the * args and path_info of the original request, and not any that may have * come with the script URI in the include command. Ugh. */ if (!strcmp(r->protocol, "INCLUDED")) { apr_table_setn(e, "SCRIPT_NAME", r->uri); if (r->path_info && *r->path_info) { apr_table_setn(e, "PATH_INFO", r->path_info); } } else if (!r->path_info || !*r->path_info) { apr_table_setn(e, "SCRIPT_NAME", r->uri); } else { int path_info_start = ap_find_path_info(r->uri, r->path_info); apr_table_setn(e, "SCRIPT_NAME", apr_pstrndup(r->pool, r->uri, path_info_start)); apr_table_setn(e, "PATH_INFO", r->path_info); } if (r->path_info && r->path_info[0]) { /* * To get PATH_TRANSLATED, treat PATH_INFO as a URI path. * Need to re-escape it for this, since the entire URI was * un-escaped before we determined where the PATH_INFO began. */ request_rec *pa_req; pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r, NULL); if (pa_req->filename) { char *pt = apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info, NULL); #ifdef WIN32 /* We need to make this a real Windows path name */ apr_filepath_merge(&pt, "", pt, APR_FILEPATH_NATIVE, r->pool); #endif apr_table_setn(e, "PATH_TRANSLATED", pt); } ap_destroy_sub_req(pa_req); } }
/* do a sub-request to fetch properties for the target resource's URI. */ static void dav_do_prop_subreq(dav_propdb *propdb) { /* need to escape the uri that's in the resource struct because during * the property walker it's not encoded. */ const char *e_uri = ap_escape_uri(propdb->resource->pool, propdb->resource->uri); /* perform a "GET" on the resource's URI (note that the resource may not correspond to the current request!). */ propdb->subreq = ap_sub_req_lookup_uri(e_uri, propdb->r, NULL); }
/** * Runs the trust metric and generates an updated tmetric cache file **/ static int tmetric_index_serve (VirguleReq *vr) { apr_pool_t *p = vr->r->pool; Db *db = vr->db; apr_array_header_t *nodeinfo; int n_seeds, n_caps; int i; NodeInfo *ni; int status; Buffer *cb; char *cache_str; for (n_seeds = 0;; n_seeds++) if (!vr->priv->seeds[n_seeds]) break; for (n_caps = 0;; n_caps++) if (!vr->priv->caps[n_caps]) break; nodeinfo = tmetric_run (vr, vr->priv->seeds, n_seeds, vr->priv->caps, n_caps); qsort (nodeinfo->elts, nodeinfo->nelts, sizeof(NodeInfo), node_info_compare); cb = virgule_buffer_new (p); for (i = 0; i < nodeinfo->nelts; i++) { ni = &((NodeInfo *)(nodeinfo->elts))[i]; if (strcmp(((NodeInfo *)ni)->name, "-") == 0) { /* Skip the root node */ continue; } virgule_buffer_printf (cb, "%s %s\n", ap_escape_uri(vr->r->pool,ni->name), virgule_cert_level_to_name (vr, ni->level)); } cache_str = virgule_buffer_extract (cb); status = virgule_db_put (db, "tmetric/default", cache_str, strlen (cache_str)); if (status) return virgule_send_error_page (vr, vERROR, "tmetric", "Error writing tmetric cache."); else return virgule_send_error_page (vr, vINFO, "tmetric", "Wrote tmetric cache."); }
/** * Generate the resource used for later operations * First security checkings can be done here (like user mapping) * @param r The request coming from Apache * @param root_dir The root dir of the request (as configured in * Apache with Location) * @param label Used with version control. Not relevant. * @param use_checked_in Used with version control. Not relevant. * @param resource Where to put the generated resource * @return NULL on success. A dav_error instance if not. */ static dav_error *dav_ns_get_resource(request_rec *r, const char *root_dir, const char *label, int use_checked_in, dav_resource **resource) { char *sfn; dav_error *err; int len; /* Compose path */ len = strlen(root_dir); if (root_dir[len - 1] == '/') { char *tmp = apr_pstrdup(r->pool, root_dir); --len; tmp[len] = '\0'; root_dir = tmp; } sfn = r->parsed_uri.path ? r->parsed_uri.path : ""; /* Create resource */ err = dav_ns_internal_get_resource(r, sfn, NULL, resource); if (err) return err; /* Directories MUST finish with '/', so redirect if not */ len = strlen(sfn); if ((*resource)->collection && (len == 0 || sfn[len - 1] != '/')) { (*resource)->info->redirect = apr_pstrcat(r->pool, ap_escape_uri(r->pool, sfn), "/", r->args ? "?" : "", r->args ? r->args : "", NULL); (*resource)->uri = apr_pstrcat(r->pool, (*resource)->uri, "/", NULL); (*resource)->info->sfn = apr_pstrcat(r->pool, (*resource)->info->sfn, "/", NULL); } /* We are done here */ return NULL; }
static void article_render_reply (VirguleReq *vr, int art_num, int reply_num) { apr_pool_t *p = vr->r->pool; Buffer *b = vr->b; char *key; xmlDoc *doc; key = apr_psprintf (p, "articles/_%d/_%d/reply.xml", art_num, reply_num); doc = virgule_db_xml_get (p, vr->db, key); if (doc != NULL) { xmlNode *root = doc->xmlRootNode; char *author; char *title; char *body; char *date; author = virgule_xml_find_child_string (root, "author", "(no author)"); title = virgule_xml_find_child_string (root, "title", "(no title)"); body = virgule_xml_find_child_string (root, "body", "(no body)"); date = virgule_xml_find_child_string (root, "date", "(no date)"); virgule_render_cert_level_begin (vr, author, CERT_STYLE_MEDIUM); virgule_buffer_printf (b, "<a name=\"%u\"><b>%s</b></a>, posted %s by <a href=\"%s/person/%s/\">%s</a> <a href=\"#%u\" style=\"text-decoration: none\">»</a>\n", reply_num, title, virgule_render_date (vr, date, 1), vr->prefix, ap_escape_uri(vr->r->pool, author), author, reply_num); virgule_render_cert_level_text (vr, author); virgule_render_cert_level_end (vr, CERT_STYLE_MEDIUM); virgule_buffer_printf (b, "<blockquote>\n%s\n</blockquote>\n", body); } else { virgule_buffer_printf (b, "<p>Error reading <x>article</x> %d.\n", art_num); } }
static int check_speling(request_rec *r) { spconfig *cfg; char *good, *bad, *postgood, *url; apr_finfo_t dirent; int filoc, dotloc, urlen, pglen; apr_array_header_t *candidates = NULL; apr_dir_t *dir; cfg = ap_get_module_config(r->per_dir_config, &speling_module); if (!cfg->enabled) { return DECLINED; } /* We only want to worry about GETs */ if (r->method_number != M_GET) { return DECLINED; } /* We've already got a file of some kind or another */ if (r->finfo.filetype != APR_NOFILE) { return DECLINED; } /* Not a file request */ if (r->proxyreq || !r->filename) { return DECLINED; } /* This is a sub request - don't mess with it */ if (r->main) { return DECLINED; } /* * The request should end up looking like this: * r->uri: /correct-url/mispelling/more * r->filename: /correct-file/mispelling r->path_info: /more * * So we do this in steps. First break r->filename into two pieces */ filoc = ap_rind(r->filename, '/'); /* * Don't do anything if the request doesn't contain a slash, or * requests "/" */ if (filoc == -1 || strcmp(r->uri, "/") == 0) { return DECLINED; } /* good = /correct-file */ good = apr_pstrndup(r->pool, r->filename, filoc); /* bad = mispelling */ bad = apr_pstrdup(r->pool, r->filename + filoc + 1); /* postgood = mispelling/more */ postgood = apr_pstrcat(r->pool, bad, r->path_info, NULL); urlen = strlen(r->uri); pglen = strlen(postgood); /* Check to see if the URL pieces add up */ if (strcmp(postgood, r->uri + (urlen - pglen))) { return DECLINED; } /* url = /correct-url */ url = apr_pstrndup(r->pool, r->uri, (urlen - pglen)); /* Now open the directory and do ourselves a check... */ if (apr_dir_open(&dir, good, r->pool) != APR_SUCCESS) { /* Oops, not a directory... */ return DECLINED; } candidates = apr_array_make(r->pool, 2, sizeof(misspelled_file)); dotloc = ap_ind(bad, '.'); if (dotloc == -1) { dotloc = strlen(bad); } while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dir) == APR_SUCCESS) { sp_reason q; /* * If we end up with a "fixed" URL which is identical to the * requested one, we must have found a broken symlink or some such. * Do _not_ try to redirect this, it causes a loop! */ if (strcmp(bad, dirent.name) == 0) { apr_dir_close(dir); return OK; } /* * miscapitalization errors are checked first (like, e.g., lower case * file, upper case request) */ else if (strcasecmp(bad, dirent.name) == 0) { misspelled_file *sp_new; sp_new = (misspelled_file *) apr_array_push(candidates); sp_new->name = apr_pstrdup(r->pool, dirent.name); sp_new->quality = SP_MISCAPITALIZED; } /* * simple typing errors are checked next (like, e.g., * missing/extra/transposed char) */ else if ((cfg->check_case_only == 0) && ((q = spdist(bad, dirent.name)) != SP_VERYDIFFERENT)) { misspelled_file *sp_new; sp_new = (misspelled_file *) apr_array_push(candidates); sp_new->name = apr_pstrdup(r->pool, dirent.name); sp_new->quality = q; } /* * The spdist() should have found the majority of the misspelled * requests. It is of questionable use to continue looking for * files with the same base name, but potentially of totally wrong * type (index.html <-> index.db). * * If you're using MultiViews, and have a file named foobar.html, * which you refer to as "foobar", and someone tried to access * "Foobar", without CheckBasenameMatch, mod_speling won't find it, * because it won't find anything matching that spelling. * With the extension-munging, it would locate "foobar.html". */ else if ((cfg->check_case_only == 0) && (cfg->check_basename_match == 1)) { /* * Okay... we didn't find anything. Now we take out the hard-core * power tools. There are several cases here. Someone might have * entered a wrong extension (.htm instead of .html or vice * versa) or the document could be negotiated. At any rate, now * we just compare stuff before the first dot. If it matches, we * figure we got us a match. This can result in wrong things if * there are files of different content types but the same prefix * (e.g. foo.gif and foo.html) This code will pick the first one * it finds. Better than a Not Found, though. */ int entloc = ap_ind(dirent.name, '.'); if (entloc == -1) { entloc = strlen(dirent.name); } if ((dotloc == entloc) && !strncasecmp(bad, dirent.name, dotloc)) { misspelled_file *sp_new; sp_new = (misspelled_file *) apr_array_push(candidates); sp_new->name = apr_pstrdup(r->pool, dirent.name); sp_new->quality = SP_VERYDIFFERENT; } } } apr_dir_close(dir); if (candidates->nelts != 0) { /* Wow... we found us a mispelling. Construct a fixed url */ char *nuri; const char *ref; misspelled_file *variant = (misspelled_file *) candidates->elts; int i; ref = apr_table_get(r->headers_in, "Referer"); qsort((void *) candidates->elts, candidates->nelts, sizeof(misspelled_file), sort_by_quality); /* * Conditions for immediate redirection: * a) the first candidate was not found by stripping the suffix * AND b) there exists only one candidate OR the best match is not * ambiguous * then return a redirection right away. */ if (variant[0].quality != SP_VERYDIFFERENT && (candidates->nelts == 1 || variant[0].quality != variant[1].quality)) { nuri = ap_escape_uri(r->pool, apr_pstrcat(r->pool, url, variant[0].name, r->path_info, NULL)); if (r->parsed_uri.query) nuri = apr_pstrcat(r->pool, nuri, "?", r->parsed_uri.query, NULL); apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, nuri, r)); ap_log_rerror(APLOG_MARK, APLOG_INFO, APR_SUCCESS, r, ref ? "Fixed spelling: %s to %s from %s" : "Fixed spelling: %s to %s%s", r->uri, nuri, (ref ? ref : "")); return HTTP_MOVED_PERMANENTLY; } /* * Otherwise, a "[300] Multiple Choices" list with the variants is * returned. */ else { apr_pool_t *p; apr_table_t *notes; apr_pool_t *sub_pool; apr_array_header_t *t; apr_array_header_t *v; if (r->main == NULL) { p = r->pool; notes = r->notes; } else { p = r->main->pool; notes = r->main->notes; } if (apr_pool_create(&sub_pool, p) != APR_SUCCESS) return DECLINED; t = apr_array_make(sub_pool, candidates->nelts * 8 + 8, sizeof(char *)); v = apr_array_make(sub_pool, candidates->nelts * 5, sizeof(char *)); /* Generate the response text. */ *(const char **)apr_array_push(t) = "The document name you requested (<code>"; *(const char **)apr_array_push(t) = ap_escape_html(sub_pool, r->uri); *(const char **)apr_array_push(t) = "</code>) could not be found on this server.\n" "However, we found documents with names similar " "to the one you requested.<p>" "Available documents:\n<ul>\n"; for (i = 0; i < candidates->nelts; ++i) { char *vuri; const char *reason; reason = sp_reason_str[(int) (variant[i].quality)]; /* The format isn't very neat... */ vuri = apr_pstrcat(sub_pool, url, variant[i].name, r->path_info, (r->parsed_uri.query != NULL) ? "?" : "", (r->parsed_uri.query != NULL) ? r->parsed_uri.query : "", NULL); *(const char **)apr_array_push(v) = "\""; *(const char **)apr_array_push(v) = ap_escape_uri(sub_pool, vuri); *(const char **)apr_array_push(v) = "\";\""; *(const char **)apr_array_push(v) = reason; *(const char **)apr_array_push(v) = "\""; *(const char **)apr_array_push(t) = "<li><a href=\""; *(const char **)apr_array_push(t) = ap_escape_uri(sub_pool, vuri); *(const char **)apr_array_push(t) = "\">"; *(const char **)apr_array_push(t) = ap_escape_html(sub_pool, vuri); *(const char **)apr_array_push(t) = "</a> ("; *(const char **)apr_array_push(t) = reason; *(const char **)apr_array_push(t) = ")\n"; /* * when we have printed the "close matches" and there are * more "distant matches" (matched by stripping the suffix), * then we insert an additional separator text to suggest * that the user LOOK CLOSELY whether these are really the * files she wanted. */ if (i > 0 && i < candidates->nelts - 1 && variant[i].quality != SP_VERYDIFFERENT && variant[i + 1].quality == SP_VERYDIFFERENT) { *(const char **)apr_array_push(t) = "</ul>\nFurthermore, the following related " "documents were found:\n<ul>\n"; } } *(const char **)apr_array_push(t) = "</ul>\n"; /* If we know there was a referring page, add a note: */ if (ref != NULL) { *(const char **)apr_array_push(t) = "Please consider informing the owner of the " "<a href=\""; *(const char **)apr_array_push(t) = ap_escape_uri(sub_pool, ref); *(const char **)apr_array_push(t) = "\">referring page</a> " "about the broken link.\n"; } /* Pass our apr_table_t to http_protocol.c (see mod_negotiation): */ apr_table_setn(notes, "variant-list", apr_array_pstrcat(p, t, 0)); apr_table_mergen(r->subprocess_env, "VARIANTS", apr_array_pstrcat(p, v, ',')); apr_pool_destroy(sub_pool); ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, ref ? "Spelling fix: %s: %d candidates from %s" : "Spelling fix: %s: %d candidates%s", r->uri, candidates->nelts, (ref ? ref : "")); return HTTP_MULTIPLE_CHOICES; } } return OK; }
/** * generates a FOAF RDF document for the specified user and returns a pointer * to the xmlDoc. A NULL pointer is return on any error. */ xmlDocPtr virgule_foaf_person (VirguleReq *vr, char *u) { apr_pool_t *p = vr->r->pool; xmlDocPtr foaf, profile, staff; xmlNodePtr tree, ptree, tmpnode; char *givenname, *surname, *trustref; char *db_key, *name, *url, *foafuri, *label, *email, *emailsha1; db_key = virgule_acct_dbkey (vr, u); if (db_key == NULL) return NULL; profile = virgule_db_xml_get (p, vr->db, db_key); if (profile == NULL) return NULL; ptree = virgule_xml_find_child (profile->xmlRootNode, "info"); foaf = xmlNewDoc ((xmlChar *)"1.0"); if (foaf == NULL) return NULL; vr->r->content_type = "application/rdf+xml; charset=UTF-8"; foaf->xmlRootNode = xmlNewDocNode (foaf, NULL, (xmlChar *)"rdf:RDF", NULL); xmlSetProp (foaf->xmlRootNode, (xmlChar *)"xmlns:rdf", (xmlChar *)"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); xmlSetProp (foaf->xmlRootNode, (xmlChar *)"xmlns:rdfs", (xmlChar *)"http://www.w3.org/2000/01/rdf-schema#"); xmlSetProp (foaf->xmlRootNode, (xmlChar *)"xmlns:foaf", (xmlChar *)"http://xmlns.com/foaf/0.1/"); xmlSetProp (foaf->xmlRootNode, (xmlChar *)"xmlns:owl", (xmlChar *)"http://www.w3.org/2002/07/owl#"); givenname = virgule_xml_get_prop (p, ptree, (xmlChar *)"givenname"); surname = virgule_xml_get_prop (p, ptree, (xmlChar *)"surname"); if (givenname || surname) name = apr_pstrcat (p, givenname ? givenname : "", givenname ? " " : "", surname ? surname : "", NULL); else name = " "; tree = xmlNewChild (foaf->xmlRootNode, NULL, (xmlChar *)"foaf:PersonalProfileDocument", NULL); xmlSetProp (tree, (xmlChar *)"rdf:about", NULL); label = apr_pstrcat (p, vr->priv->site_name, " FOAF profile for ", name, NULL); xmlNewTextChild (tree, NULL, (xmlChar *)"rdfs:label", (xmlChar *)label); tmpnode = xmlNewChild (tree, NULL, (xmlChar *)"foaf:maker", NULL); xmlSetProp (tmpnode, (xmlChar *)"rdf:resource", (xmlChar *)"#me"); tmpnode = xmlNewChild (tree, NULL, (xmlChar *)"foaf:primaryTopic", NULL); xmlSetProp (tmpnode, (xmlChar *)"rdf:resource", (xmlChar *)"#me"); /* Express the user's trust rating in a Group section */ trustref = apr_pstrcat (p, "http://www.advogato.org/ns/trust#", virgule_req_get_tmetric_level (vr, u), NULL); tree = xmlNewChild (foaf->xmlRootNode, NULL, (xmlChar *)"foaf:Group", NULL); xmlSetProp (tree, (xmlChar *)"rdf:about", (xmlChar *)trustref); tmpnode = xmlNewChild (tree, NULL, (xmlChar *)"foaf:member", NULL); xmlSetProp (tmpnode, (xmlChar *)"rdf:resource", (xmlChar *)"#me"); foafuri = virgule_xml_get_prop (p, ptree, (xmlChar *)"foafuri"); if (foafuri != NULL && strlen(foafuri)) { tree = xmlNewChild (foaf->xmlRootNode, NULL, (xmlChar *)"rdf:Description", NULL); xmlSetProp (tree, (xmlChar *)"rdf:about", (xmlChar *)foafuri); tmpnode = xmlNewChild (tree, NULL, (xmlChar *)"owl:sameAs", NULL); xmlSetProp (tmpnode, (xmlChar *)"rdf:resource", (xmlChar *)"#me"); } /* Generate the Person section */ tree = xmlNewChild (foaf->xmlRootNode, NULL, (xmlChar *)"foaf:Person", NULL); xmlSetProp (tree, (xmlChar *)"rdf:about", (xmlChar *)"#me"); xmlNewTextChild (tree, NULL, (xmlChar *)"foaf:name", (xmlChar *)name); xmlNewTextChild (tree, NULL, (xmlChar *)"foaf:nick", (xmlChar *)u); email = virgule_xml_get_prop (p, ptree, (xmlChar *)"email"); if (email != NULL && *email != 0) { emailsha1 = virgule_sha1 (p, apr_psprintf (p, "mailto:%s", email)); xmlNewTextChild (tree, NULL, (xmlChar *)"foaf:mbox_sha1sum", (xmlChar *)emailsha1); } url = virgule_xml_get_prop (p, ptree, (xmlChar *)"url"); if (url == NULL) url = apr_pstrcat (p, vr->priv->base_uri, "/person/", ap_escape_uri(p, u), "/", NULL); tmpnode = xmlNewChild (tree, NULL, (xmlChar *)"foaf:homepage", NULL); xmlSetProp (tmpnode, (xmlChar *)"rdf:resource", (xmlChar *)url); url = apr_pstrcat (p, vr->priv->base_uri, "/person/", ap_escape_uri(p, u), "/diary.html", NULL); tmpnode = xmlNewChild (tree, NULL, (xmlChar *)"foaf:weblog", NULL); xmlSetProp (tmpnode, (xmlChar *)"rdf:resource", (xmlChar *)url); /* Convert outbound certs to foaf:knows properties */ ptree = virgule_xml_find_child (profile->xmlRootNode, "certs"); if (ptree) { xmlNodePtr cert, n1, n2; for (cert = ptree->children; cert != NULL; cert = cert->next) if (cert->type == XML_ELEMENT_NODE && !xmlStrcmp (cert->name, (xmlChar *)"cert")) { xmlChar *subject, *level; subject = xmlGetProp (cert, (xmlChar *)"subj"); level = xmlGetProp (cert, (xmlChar *)"level"); if (xmlStrcmp (level, (xmlChar *)virgule_cert_level_to_name (vr, 0))) { url = apr_pstrcat (p, vr->priv->base_uri, "/person/", ap_escape_uri(p, (char *)subject), "/foaf.rdf", NULL); n1 = xmlNewChild (tree, NULL, (xmlChar *)"foaf:knows", NULL); n1 = xmlNewChild (n1, NULL, (xmlChar *)"foaf:Person", NULL); xmlSetProp (n1, (xmlChar *)"rdf:about", (xmlChar *)apr_pstrcat(p, url, "#me", NULL)); xmlNewTextChild (n1, NULL, (xmlChar *)"foaf:nick", (xmlChar *)subject); url = apr_pstrcat (p, vr->priv->base_uri, "/person/", ap_escape_uri(p, (char *)subject), "/foaf.rdf", NULL); n2 = xmlNewChild (n1, NULL, (xmlChar *)"rdfs:seeAlso", NULL); xmlSetProp (n2, (xmlChar *)"rdf:resource", (xmlChar *)url); } } } /* Convert project staff associations to foaf:Project properties */ db_key = apr_psprintf (p, "acct/%s/staff-person.xml", u); staff = virgule_db_xml_get (p, vr->db, db_key); if (staff != NULL) { xmlNodePtr n1; for (ptree = staff->xmlRootNode->children; ptree != NULL; ptree = ptree->next) { char *name, *type; name = virgule_xml_get_prop (p, ptree, (xmlChar *)"name"); type = virgule_xml_get_prop (p, ptree, (xmlChar *)"type"); if (! !strcmp (type, "None")) { n1 = xmlNewChild (tree, NULL, (xmlChar *)"foaf:currentProject", NULL); url = apr_pstrcat (p, vr->priv->base_uri, "/proj/", ap_escape_uri(p, name), "/", NULL); xmlSetProp (n1, (xmlChar *)"rdf:resource", (xmlChar *)url); } } } return foaf; }
/** * Renders an article from the provided XML document **/ static void article_render_from_xml (VirguleReq *vr, int art_num, xmlDoc *doc, ArticleRenderStyle style) { Buffer *b = vr->b; xmlNode *root = doc->xmlRootNode; char *date; char *update; char *updatestr = ""; char *author; char *topic; char *title; char *lead; char *lead_a_open = ""; char *lead_a_close = ""; char *bmbox = ""; char *editstr = ""; int n_replies; char *article_dir; CertLevel cert_level; topic = virgule_xml_find_child_string (root, "topic", "(no topic)"); title = virgule_xml_find_child_string (root, "title", "(no title)"); date = virgule_xml_find_child_string (root, "date", "(no date)"); update = virgule_xml_find_child_string (root, "update", NULL); author = virgule_xml_find_child_string (root, "author", "(no author)"); lead = virgule_xml_find_child_string (root, "lead", "(no lead)"); if (vr->u != NULL) { if ((virgule_virgule_to_time_t(vr, date) + (vr->priv->article_days_to_edit * 86400)) > time(NULL) && (!strcmp(vr->u, author))) editstr = apr_psprintf (vr->r->pool, " [ <a href=\"/article/edit.html?key=%d\">Edit</a> ] ", art_num); } virgule_buffer_puts (b, "<div class=\"node\">"); if(vr->priv->use_article_topics) { virgule_buffer_puts (b, "<div class=\"tags\">"); article_render_topic (vr, topic); virgule_buffer_puts (b, "</div>"); } /* check if author is a special user */ if (virgule_user_is_special(vr,author)) cert_level = virgule_cert_num_levels (vr); else cert_level = virgule_cert_level_from_name(vr, virgule_req_get_tmetric_level (vr, author)); virgule_buffer_printf (b, "<h1 class=\"level%i\">", cert_level); if (style == ARTICLE_RENDER_LEAD && vr->priv->use_article_title_links) { lead_a_open = apr_psprintf (vr->r->pool,"<a href=\"%s/article/%d.html\">",vr->prefix,art_num); lead_a_close = "</a>"; } if (style == ARTICLE_RENDER_FULL) { char *bmurl = apr_psprintf (vr->r->pool, "%s/article/%d.html", vr->priv->base_uri, art_num); char *bmtitle = ap_escape_uri (vr->r->pool, title); bmbox = apr_psprintf (vr->r->pool, "<span class=\"bm\">" "<a href=\"javascript:void(0)\" onclick=\"sbm(event,'%s','%s')\">" "<img src=\"/images/share.png\" alt=\"Share This\" title=\"Share This\" /></a>" "</span>", bmurl, virgule_str_subst (vr->r->pool, bmtitle, "'", "%27")); } virgule_buffer_printf (b, "%s%s%s", lead_a_open, title, lead_a_close); if (update != NULL) updatestr = apr_psprintf (vr->r->pool, " (updated %s)", virgule_render_date (vr, update, 1)); virgule_buffer_printf (b, "</h1><h2>Posted %s%s by " "<a href=\"%s/person/%s/\">%s</a>%s %s</h2>\n", virgule_render_date (vr, date, 1), updatestr, vr->prefix, ap_escape_uri(vr->r->pool, author), author, editstr, bmbox); virgule_buffer_printf (b, "<p>%s</p>",lead); article_dir = apr_psprintf (vr->r->pool, "articles/_%d", art_num); n_replies = virgule_db_dir_max (vr->db, article_dir) + 1; if (style == ARTICLE_RENDER_FULL) { char *body; body = virgule_xml_find_child_string (root, "body", NULL); if (body) virgule_buffer_printf (b, "<p>%s</p>\n", body); article_render_replies (vr, art_num); if (virgule_req_ok_to_reply (vr)) { virgule_buffer_printf (b, "<hr><p>Post a reply to <x>article</x>: %s.</p>\n" "<form method=\"POST\" action=\"replysubmit.html\" accept-charset=\"UTF-8\">\n" "<p>Reply title: <br>\n" "<input type=\"text\" name=\"title\" size=\"50\" maxlength=\"60\"></p>\n" "<p> Body of reply: <br>\n" "<textarea name=\"body\" cols=\"72\" rows=\"16\" wrap=\"soft\">" "</textarea></p>\n" "<input type=\"hidden\" name=\"art_num\" value=\"%d\">\n" "<p><input type=\"submit\" name=\"post\" value=\"Post\">\n" "<input type=\"submit\" name=\"preview\" value=\"Preview\">\n" "</form>\n", title, art_num); virgule_render_acceptable_html (vr); } } else if (style == ARTICLE_RENDER_LEAD) { apr_pool_t *p = vr->r->pool; int n_new, lastread; n_new = -1; lastread = virgule_acct_get_lastread (vr, "articles", apr_psprintf(p, "%d", art_num)); if (lastread != -1) n_new = n_replies - lastread - 1; else if (vr->u != NULL) n_new = n_replies; virgule_buffer_printf (b, "<p><a href=\"%s/article/%d.html\">Read more...</a> (%d repl%s) ", vr->prefix, art_num, n_replies, n_replies == 1 ? "y" : "ies"); if (n_new > 0) virgule_buffer_printf (b, "(<a href=\"%s/article/%d.html#lastread\">%d new</a>) ", vr->prefix, art_num, n_new); virgule_buffer_puts (b, "</p>\n"); } virgule_buffer_puts (b, "</div>\n"); }
/* Manages the loadfactors and member status */ static int balancer_handler(request_rec *r) { void *sconf = r->server->module_config; proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module); proxy_balancer *balancer, *bsel = NULL; proxy_worker *worker, *wsel = NULL; apr_table_t *params = apr_table_make(r->pool, 10); int access_status; int i, n; const char *name; /* is this for us? */ if (strcmp(r->handler, "balancer-manager")) return DECLINED; r->allowed = (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) return DECLINED; if (r->args) { char *args = apr_pstrdup(r->pool, r->args); char *tok, *val; while (args && *args) { if ((val = ap_strchr(args, '='))) { *val++ = '\0'; if ((tok = ap_strchr(val, '&'))) *tok++ = '\0'; /* * Special case: workers are allowed path information */ if ((access_status = ap_unescape_url(val)) != OK) if (strcmp(args, "w") || (access_status != HTTP_NOT_FOUND)) return access_status; apr_table_setn(params, args, val); args = tok; } else return HTTP_BAD_REQUEST; } } /* Check that the supplied nonce matches this server's nonce; * otherwise ignore all parameters, to prevent a CSRF attack. */ if ((name = apr_table_get(params, "nonce")) == NULL || strcmp(balancer_nonce, name) != 0) { apr_table_clear(params); } if ((name = apr_table_get(params, "b"))) bsel = ap_proxy_get_balancer(r->pool, conf, apr_pstrcat(r->pool, "balancer://", name, NULL)); if ((name = apr_table_get(params, "w"))) { proxy_worker *ws; ws = ap_proxy_get_worker(r->pool, conf, name); if (bsel && ws) { worker = (proxy_worker *)bsel->workers->elts; for (n = 0; n < bsel->workers->nelts; n++) { if (strcasecmp(worker->name, ws->name) == 0) { wsel = worker; break; } ++worker; } } } /* First set the params */ /* * Note that it is not possible set the proxy_balancer because it is not * in shared memory. */ if (wsel) { const char *val; if ((val = apr_table_get(params, "lf"))) { int ival = atoi(val); if (ival >= 1 && ival <= 100) { wsel->s->lbfactor = ival; if (bsel) recalc_factors(bsel); } } if ((val = apr_table_get(params, "wr"))) { if (strlen(val) && strlen(val) < PROXY_WORKER_MAX_ROUTE_SIZ) strcpy(wsel->s->route, val); else *wsel->s->route = '\0'; } if ((val = apr_table_get(params, "rr"))) { if (strlen(val) && strlen(val) < PROXY_WORKER_MAX_ROUTE_SIZ) strcpy(wsel->s->redirect, val); else *wsel->s->redirect = '\0'; } if ((val = apr_table_get(params, "dw"))) { if (!strcasecmp(val, "Disable")) wsel->s->status |= PROXY_WORKER_DISABLED; else if (!strcasecmp(val, "Enable")) wsel->s->status &= ~PROXY_WORKER_DISABLED; } if ((val = apr_table_get(params, "ls"))) { int ival = atoi(val); if (ival >= 0 && ival <= 99) { wsel->s->lbset = ival; } } } if (apr_table_get(params, "xml")) { ap_set_content_type(r, "text/xml"); ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n", r); ap_rputs("<httpd:manager xmlns:httpd=\"http://httpd.apache.org\">\n", r); ap_rputs(" <httpd:balancers>\n", r); balancer = (proxy_balancer *)conf->balancers->elts; for (i = 0; i < conf->balancers->nelts; i++) { ap_rputs(" <httpd:balancer>\n", r); ap_rvputs(r, " <httpd:name>", balancer->name, "</httpd:name>\n", NULL); ap_rputs(" <httpd:workers>\n", r); worker = (proxy_worker *)balancer->workers->elts; for (n = 0; n < balancer->workers->nelts; n++) { ap_rputs(" <httpd:worker>\n", r); ap_rvputs(r, " <httpd:scheme>", worker->scheme, "</httpd:scheme>\n", NULL); ap_rvputs(r, " <httpd:hostname>", worker->hostname, "</httpd:hostname>\n", NULL); ap_rprintf(r, " <httpd:loadfactor>%d</httpd:loadfactor>\n", worker->s->lbfactor); ap_rputs(" </httpd:worker>\n", r); ++worker; } ap_rputs(" </httpd:workers>\n", r); ap_rputs(" </httpd:balancer>\n", r); ++balancer; } ap_rputs(" </httpd:balancers>\n", r); ap_rputs("</httpd:manager>", r); } else { ap_set_content_type(r, "text/html; charset=ISO-8859-1"); ap_rputs(DOCTYPE_HTML_3_2 "<html><head><title>Balancer Manager</title></head>\n", r); ap_rputs("<body><h1>Load Balancer Manager for ", r); ap_rvputs(r, ap_get_server_name(r), "</h1>\n\n", NULL); ap_rvputs(r, "<dl><dt>Server Version: ", ap_get_server_description(), "</dt>\n", NULL); ap_rvputs(r, "<dt>Server Built: ", ap_get_server_built(), "\n</dt></dl>\n", NULL); balancer = (proxy_balancer *)conf->balancers->elts; for (i = 0; i < conf->balancers->nelts; i++) { ap_rputs("<hr />\n<h3>LoadBalancer Status for ", r); ap_rvputs(r, balancer->name, "</h3>\n\n", NULL); ap_rputs("\n\n<table border=\"0\" style=\"text-align: left;\"><tr>" "<th>StickySession</th><th>Timeout</th><th>FailoverAttempts</th><th>Method</th>" "</tr>\n<tr>", r); if (balancer->sticky) { ap_rvputs(r, "<td>", balancer->sticky, NULL); } else { ap_rputs("<td> - ", r); } ap_rprintf(r, "</td><td>%" APR_TIME_T_FMT "</td>", apr_time_sec(balancer->timeout)); ap_rprintf(r, "<td>%d</td>\n", balancer->max_attempts); ap_rprintf(r, "<td>%s</td>\n", balancer->lbmethod->name); ap_rputs("</table>\n<br />", r); ap_rputs("\n\n<table border=\"0\" style=\"text-align: left;\"><tr>" "<th>Worker URL</th>" "<th>Route</th><th>RouteRedir</th>" "<th>Factor</th><th>Set</th><th>Status</th>" "<th>Elected</th><th>To</th><th>From</th>" "</tr>\n", r); worker = (proxy_worker *)balancer->workers->elts; for (n = 0; n < balancer->workers->nelts; n++) { char fbuf[50]; ap_rvputs(r, "<tr>\n<td><a href=\"", r->uri, "?b=", balancer->name + sizeof("balancer://") - 1, "&w=", ap_escape_uri(r->pool, worker->name), "&nonce=", balancer_nonce, "\">", NULL); ap_rvputs(r, worker->name, "</a></td>", NULL); ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route), NULL); ap_rvputs(r, "</td><td>", ap_escape_html(r->pool, worker->s->redirect), NULL); ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor); ap_rprintf(r, "<td>%d</td><td>", worker->s->lbset); if (worker->s->status & PROXY_WORKER_DISABLED) ap_rputs("Dis ", r); if (worker->s->status & PROXY_WORKER_IN_ERROR) ap_rputs("Err ", r); if (worker->s->status & PROXY_WORKER_STOPPED) ap_rputs("Stop ", r); if (worker->s->status & PROXY_WORKER_HOT_STANDBY) ap_rputs("Stby ", r); if (PROXY_WORKER_IS_USABLE(worker)) ap_rputs("Ok", r); if (!PROXY_WORKER_IS_INITIALIZED(worker)) ap_rputs("-", r); ap_rputs("</td>", r); ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td><td>", worker->s->elected); ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r); ap_rputs("</td><td>", r); ap_rputs(apr_strfsize(worker->s->read, fbuf), r); ap_rputs("</td></tr>\n", r); ++worker; } ap_rputs("</table>\n", r); ++balancer; } ap_rputs("<hr />\n", r); if (wsel && bsel) { ap_rputs("<h3>Edit worker settings for ", r); ap_rvputs(r, wsel->name, "</h3>\n", NULL); ap_rvputs(r, "<form method=\"GET\" action=\"", NULL); ap_rvputs(r, r->uri, "\">\n<dl>", NULL); ap_rputs("<table><tr><td>Load factor:</td><td><input name=\"lf\" type=text ", r); ap_rprintf(r, "value=\"%d\"></td></tr>\n", wsel->s->lbfactor); ap_rputs("<tr><td>LB Set:</td><td><input name=\"ls\" type=text ", r); ap_rprintf(r, "value=\"%d\"></td></tr>\n", wsel->s->lbset); ap_rputs("<tr><td>Route:</td><td><input name=\"wr\" type=text ", r); ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->route), NULL); ap_rputs("\"></td></tr>\n", r); ap_rputs("<tr><td>Route Redirect:</td><td><input name=\"rr\" type=text ", r); ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->redirect), NULL); ap_rputs("\"></td></tr>\n", r); ap_rputs("<tr><td>Status:</td><td>Disabled: <input name=\"dw\" value=\"Disable\" type=radio", r); if (wsel->s->status & PROXY_WORKER_DISABLED) ap_rputs(" checked", r); ap_rputs("> | Enabled: <input name=\"dw\" value=\"Enable\" type=radio", r); if (!(wsel->s->status & PROXY_WORKER_DISABLED)) ap_rputs(" checked", r); ap_rputs("></td></tr>\n", r); ap_rputs("<tr><td colspan=2><input type=submit value=\"Submit\"></td></tr>\n", r); ap_rvputs(r, "</table>\n<input type=hidden name=\"w\" ", NULL); ap_rvputs(r, "value=\"", ap_escape_uri(r->pool, wsel->name), "\">\n", NULL); ap_rvputs(r, "<input type=hidden name=\"b\" ", NULL); ap_rvputs(r, "value=\"", bsel->name + sizeof("balancer://") - 1, "\">\n", NULL); ap_rvputs(r, "<input type=hidden name=\"nonce\" value=\"", balancer_nonce, "\">\n", NULL); ap_rvputs(r, "</form>\n", NULL); ap_rputs("<hr />\n", r); } ap_rputs(ap_psignature("",r), r); ap_rputs("</body></html>\n", r); } return OK; }