// ========================================================================== // METHOD yumsource::resolvedeps // ========================================================================== void yumsource::resolvealldeps (value &list) { value depargs; string id = ""; depargs.newval() = "/usr/bin/yum"; depargs.newval() = "-C"; depargs.newval() = "deplist"; foreach (update, list) { depargs.newval() = update.id(); } systemprocess depp (depargs, true); depp.run (); APP->log (log::info, "yum-src", "Resolving dependencies: %S", id.str()); while (! depp.eof()) { string line = depp.gets(); if (line.strlen()) { if (line.strncmp ("package:", 8) == 0) { line = line.mid (9); line.cropat (' '); line.cropatlast ('.'); // remove architecture if (list.exists(line)) id = line; else id = ""; } if (id.strlen() && line.strncmp (" provider:", 12) == 0) { line = line.mid (13); line.cropat (' '); line.cropatlast ('.'); // remove architecture if ((id != line.str()) && (list.exists (line.str()))) { if (! list[line.str()]["deps"].exists (id)) { list[line.str()]["deps"][id] = true; } /* if (! list[id]["deps"].exists (line)) { list[id]["deps"][line] = true; }*/ } } } } depp.serialize(); }
// ========================================================================== // METHOD IconRequestHandler::run // ========================================================================== int IconRequestHandler::run (string &uri, string &postbody, value &inhdr, string &out, value &outhdr, value &env, tcpsocket &s) { bool isdown = (uri.strstr ("/down/") >= 0); string uuid = uri.copyafterlast ("/"); uuid.cropat ('.'); app->log (log::debug, "httpicon", "Request for <%s>" %format (uuid)); if (inhdr.exists ("If-Modified-Since")) { s.puts ("HTTP/1.1 304 NOT CHANGED\r\n" "Connection: %s\r\n" "Content-length: 0\r\n\r\n" %format (env["keepalive"].bval() ? "keep-alive" : "close")); env["sentbytes"] = 0; return -304; } if (! app->mdb->classExistsUUID (uuid)) { string orgpath; if (isdown) { orgpath = "/var/openpanel/http/images/icons/down_%s.png" %format (uuid); } else { orgpath = "/var/openpanel/http/images/icons/%s.png" %format (uuid); } if (fs.exists (orgpath)) { out = fs.load (orgpath); outhdr["Content-type"] = "image/png"; return 200; } return 404; } CoreClass &c = app->mdb->getClassUUID (uuid); string path; if (isdown) { path = "%s/down_%s" %format (c.module.path, c.icon); } else { path = "%s/%s" %format (c.module.path, c.icon); } app->log (log::debug, "httpicon", "Loading %s" %format (path)); if (! fs.exists (path)) return 404; outhdr["Content-type"] = "image/png"; out = fs.load (path); return 200; }
// ========================================================================== // METHOD rhnsource::resolvedeps // ========================================================================== void rhnsource::resolvedeps (const statstring &id, value &list) { value depargs; depargs.newval() = "/usr/bin/up2date"; depargs.newval() = "--dry-run"; depargs.newval() = "-u"; depargs.newval() = id; int listno = 0; bool inlist = false; systemprocess depp (depargs, true); depp.run (); while (! depp.eof()) { string line = depp.gets(); if (line.strlen() && (line.strncmp ("------", 6) == 0)) { listno++; if (listno == 3) inlist = true; } if (inlist) { line = line.cutat (' '); if ((line.strlen()) && (id != line.str()) && (list.exists (line.str()))) { if (! list[line.str()]["deps"].exists (id)) { list[line.str()]["deps"][id] = true; }/* if (! list[id]["deps"].exists (line)) { list[id]["deps"][line] = true; }*/ } } } depp.serialize(); }
// ========================================================================== // METHOD aptsource::resolvedeps // ========================================================================== void aptsource::resolvedeps (const statstring &id, value &list) { value depargs; depargs.newval() = "/usr/bin/apt-get"; depargs.newval() = "-s"; depargs.newval() = "install"; depargs.newval() = id; systemprocess depp (depargs, true); depp.run (); APP->log (log::info, "apt-src", "Resolving dependencies: %S", id.str()); while (! depp.eof()) { string line = depp.gets(); if (line.strlen()) { if (line.strncmp ("Inst ", 5) == 0) { line = line.mid (5); line.cropat (' '); if ((id != line.str()) && (list.exists (line.str()))) { if (! list[line.str()]["deps"].exists (id)) { list[line.str()]["deps"][id] = true; } /* if (! list[id]["deps"].exists (line)) { list[id]["deps"][line] = true; }*/ } } } } depp.serialize(); }
// ========================================================================== // METHOD RPCRequestHandler::run // ========================================================================== int RPCRequestHandler::run (string &uri, string &postbody, value &inhdr, string &out, value &outhdr, value &env, tcpsocket &s) { try { DEBUG.storeFile ("RPCRequestHandler","postbody", postbody, "run"); CORE->log (log::debug, "RPC", "handle: %S %!" %format (uri, inhdr)); value indata; value res; string origin = "rpc"; uid_t uid = 0; RPCHandler hdl (sdb); indata.fromjson (postbody); if (inhdr.exists ("X-OpenCORE-Origin")) { origin = inhdr["X-OpenCORE-Origin"]; } CORE->log (log::debug, "RPC", "body: %!" %format (indata)); // Set up credentials if available s.getcredentials(); CORE->log (log::debug, "RPC", "credentials: %d %d %d", s.peer_uid, s.peer_gid, s.peer_pid); if (s.peer_pid == 0) { string peer_name = s.peer_name; if (peer_name == "127.0.0.1") { if (inhdr.exists ("X-Forwarded-For")) { peer_name = inhdr["X-Forwarded-For"]; } } if (origin.strchr ('/') >0) origin = origin.cutat ('/'); if (! origin) origin = "RPC"; origin.strcat ("/src=%s" %format (peer_name)); env["ip"] = s.peer_name = peer_name; } if (indata.exists ("header") && indata["header"].exists ("command")) { uri.strcat ("/%s" %format (indata["header"]["command"])); } res = hdl.handle (indata, s.peer_uid, origin); out = res.tojson (); if (inhdr.exists ("Accept-Encoding")) { string ae = inhdr["Accept-Encoding"]; if (ae.strstr ("deflate") >= 0) { unsigned long reslen = (out.strlen() * 1.05) + 12; char buf[reslen]; if (compress2 ((Bytef*) buf, &reslen, (const Bytef*) out.str(), out.strlen(), 4) == Z_OK) { outhdr["Content-Encoding"] = "deflate"; out.strcpy (buf+2, reslen-2); } else { log::write (log::warning, "RPC", "Compress error"); } } } outhdr["Content-type"] = "application/json"; } catch (...) { log::write (log::error, "RPC", "Exception caught"); } return HTTP_OK; }