# # # patch "Makefile" # from [3147afbcc39c6b212cd75483bdd3abb67436c3d3] # to [4824a169590731705ffd38494111634660cb0fbe] # # patch "README" # from [2a7eac09189238d777b069ee9c3a13e6c280414f] # to [40866c93a1145e0577f5833c7d3902eec4cec515] # # patch "hostconfig.dist" # from [4f0007567e3c414b7f514dc834c4e9c907a01643] # to [f353906ddc6dce3d2dd08875066556d31880d820] # # patch "install" # from [8d334db6bc20eb5016eaccd674e97869eef1e7d2] # to [30ca34fec4e2029e20a4702f07e05ab249eefc97] # # patch "usher.cc" # from [267d6aeb1e056e70d60446c997edb39dd32bce8d] # to [26b4efedf05795ec674114086ff65e94248eb8ae] # ============================================================ --- Makefile 3147afbcc39c6b212cd75483bdd3abb67436c3d3 +++ Makefile 4824a169590731705ffd38494111634660cb0fbe @@ -1,15 +1,11 @@ -.PHONY: all install +.PHONY: all install forced-install -all: +all: usher.webhost usher.webhost: usher.cc -ifeq ($(DB),odbc) - g++ usher.cc -DUSE_ODBC -o usher.webhost -g -Wall `odbc_config --cflags --libs` -else - g++ usher.cc -o usher.webhost -g -Wall `pkg-config libpqxx --cflags --libs` -endif + g++ usher.cc -o usher.webhost -g -Wall -install: +install: usher.webhost ./install -forced-install: +forced-install: usher.webhost ./install --force-conffiles ============================================================ --- README 2a7eac09189238d777b069ee9c3a13e6c280414f +++ README 40866c93a1145e0577f5833c7d3902eec4cec515 @@ -1,14 +1,9 @@ Install ------- -Make sure you have mod_python and mod_php. -The postgres backend needs postgresql, libpqxx and php-pgsql. +Make sure you have mod_python and mod_php. You also need libphp-adodb and +a database. The install defaults assume postgres. -do either - make usher.webhost -to build usher with direct postgresql support, or - make usher.webhost DB=odbc -to build usher with odbc support make install ============================================================ --- hostconfig.dist 4f0007567e3c414b7f514dc834c4e9c907a01643 +++ hostconfig.dist f353906ddc6dce3d2dd08875066556d31880d820 @@ -1,7 +1,6 @@ userpass "username" "password" adodb_path "/usr/share/adodb/adodb.inc.php" dbstring "postgres://DBUSER:address@hidden/DBNAME" -odbc_dsn "ODBCDSN" admin "127.0.0.5:12345" hostkey "address@hidden" ============================================================ --- install 8d334db6bc20eb5016eaccd674e97869eef1e7d2 +++ install 30ca34fec4e2029e20a4702f07e05ab249eefc97 @@ -137,6 +137,7 @@ -e "s!CONFDIR!$CONFDIR!" \ -e "s!USHERUSER!$USHERUSER!" \ < webhost.initscript > /etc/init.d/$NAME.new + chmod a+x /etc/init.d/$NAME.new install_file /etc/init.d/$NAME /bin/false sed -e "s!GRAPH_DIR!$GRAPHDIR!" \ @@ -166,7 +167,7 @@ if psql -c "\d" $DBNAME 2>/dev/null >/dev/null; then : else - createuser -A -D -P DBUSER + createuser -A -D -P $DBUSER createdb $DBNAME sed -e "s!DBUSER!$DBUSER!" < schema.sql | psql -f- $DBNAME fi ============================================================ --- usher.cc 267d6aeb1e056e70d60446c997edb39dd32bce8d +++ usher.cc 26b4efedf05795ec674114086ff65e94248eb8ae @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -84,13 +85,6 @@ #include #include -#if defined(USE_ODBC) -#include -#include -#else -#include -#endif - #include using std::vector; @@ -109,8 +103,6 @@ string hostname; string project_dir; -string dbstring; -string odbcdsn; // defaults, overridden by command line int listenport = 4691; @@ -147,224 +139,20 @@ errstr(std::string const & s, int e): name(s), err(e) {} }; -#if defined(USE_ODBC) - -class UsherODBC -{ -public: - - UsherODBC(): - henv(0), - hdbc(0), - connected(false) - { - } - - ~UsherODBC() - { - if (connected) - { - SQLDisconnect(hdbc); - SQLFreeConnect(hdbc); - SQLFreeEnv(henv); - } - } - - set get_project_names(string const & user, - string const & pass, - string const & host, - string const & db, - string const & dsn) - { - set names; - if (!connect(user,pass,host,db,dsn)) - return names; - - SQLHSTMT hstmt; - if (error(SQLAllocStmt(hdbc, &hstmt))) - { - cerr << "SQLAllocStmt failed \n"; - return names; - } - - SQLRETURN res = SQLExecDirect(hstmt, (SQLCHAR *)"SELECT name FROM projects", SQL_NTS); - if (error(res) && SQL_NO_DATA!=res) - { - cerr << "SQLExecDirect failed \n"; - SQLFreeStmt(hstmt, SQL_DROP); - return names; - } - - char pname[1024]; - SQLLEN nullind; - if (error(SQLBindCol(hstmt, 1, SQL_C_CHAR, pname, sizeof(pname), &nullind))) - { - cerr << "SQLBindCol failed \n"; - SQLFreeStmt(hstmt, SQL_DROP); - return names; - } - - while ( !error(SQLFetch(hstmt))) - names.insert(pname); - - SQLFreeStmt(hstmt, SQL_DROP); - return names; - } - - -private: - - static inline bool error(SQLRETURN retcode) - { - // for us, SQL_NO_DATA is also considered an error - return retcode != SQL_SUCCESS && - retcode != SQL_SUCCESS_WITH_INFO; - } - - bool connect(string const & user, - string const & pass, - string const & host, - string const & db, - string const & dsn) - { - if (connected) - return true; - - if (error(SQLAllocEnv(&henv))) - { - cerr << "SQLAllocEnv failed \n"; - return false; - } - - if (error(SQLAllocConnect(henv,&hdbc))) - { - cerr << "SQLAllocConnect failed \n"; - SQLFreeEnv(henv); - return false; - } - - string fulldsn("DRIVER="); - fulldsn += dsn + ";"; - fulldsn += "UID="+user+ ";"; - fulldsn += "PWD="+pass+ ";"; - fulldsn += "SERVER="+host+ ";"; - fulldsn += "DATABASE="+db+ ";"; - - SQLCHAR buf[1024]; - SQLSMALLINT olen; - if (error(SQLDriverConnect(hdbc, NULL, - (SQLCHAR *)fulldsn.c_str(), SQL_NTS, - buf, sizeof(buf), - &olen, - SQL_DRIVER_NOPROMPT))) - { - cerr << "SQLDriverConnect failed \n"; - SQLFreeConnect(hdbc); - SQLFreeEnv(henv); - return false; - } - - connected = true; - return true; - } - -private: - SQLHENV henv; - SQLHDBC hdbc; - bool connected; -}; - -#else - -set get_project_names_postgres(string const & user, - string const & pass, - string const & host, - string const & db, - vector const & opts) -{ - string dbstring; - if (!user.empty()) { - dbstring += ("user="+user); - } - if (!pass.empty()) { - dbstring += (dbstring.empty()?"":" ") + ("password='"+pass+"'"); - } - if (!host.empty()) { - dbstring += (dbstring.empty()?"":" ") + ("host="+host); - } - if (!db.empty()) { - dbstring += (dbstring.empty()?"":" ") + ("dbname="+db); - } - for(vector::const_iterator i = opts.begin(); i != opts.end(); ++i) { - if(dbstring.size()) - dbstring += " "; - dbstring += *i; - } - set names; - pqxx::connection conn(dbstring); - pqxx::work w(conn, "trx"); - pqxx::result r = w.exec("SELECT name FROM projects"); - for(unsigned int i = 0; i < r.size(); ++i) { - string n = r[i][0].c_str(); - if(!n.empty()) - names.insert(n); - } - w.commit(); - return names; -} -#endif - -// dbstring looks like: -// $driver://$username:address@hidden/$database?options[=value] set get_project_names() { - string str(dbstring); - string driver, user, pass, host, db; - vector opts; - - size_t off = str.find("://"); - driver = str.substr(0, off); - str = str.substr(off+3); - off = str.find_first_of(":@/"); - if (str[off] == ':' || str[off] == '@') { - user = str.substr(0, off); - char c = str[off]; - str = str.substr(off+1); - if (c == ':') { - off = str.find("@"); - pass = str.substr(0, off); - str = str.substr(off+1); - } - off = str.find("/"); + set out; + DIR *projdir = opendir(project_dir.c_str()); + if (!projdir) { + std::cerr<<"Cannot scan project directory '"<d_name, ".") && strcmp(d->d_name, "..")) + out.insert(d->d_name); } - -#if defined(USE_ODBC) - UsherODBC uodb; - return uodb.get_project_names(user, pass, host, db, odbcdsn); -#else - if (driver == "postgres") - return get_project_names_postgres(user, pass, host, db, opts); - - std::cerr<<"Confusing db string.\n"; - return set(); -#endif + closedir(projdir); + return out; } int tosserr(int ret, std::string const & name) @@ -1588,10 +1376,6 @@ hostname = readtok(cf).s; } else if(tok.s == "project_dir") { project_dir = readtok(cf).s; - } else if(tok.s == "dbstring") { - dbstring = readtok(cf).s; - } else if(tok.s == "odbc_driver") { - odbcdsn = readtok(cf).s; } else if(tok.s == "admin") { admin.initialize(readtok(cf).s); } else if(tok.s == "listen") {