diff --git a/core/app.cpp b/core/app.cpp index dc9798b..7e82d51 100755 --- a/core/app.cpp +++ b/core/app.cpp @@ -446,6 +446,7 @@ void App::ReadRequest() CheckRequestMethod(); CheckFCGIRole(); CheckSSL(); + SetSubdomain(); LogAccess(); @@ -531,6 +532,12 @@ void App::CheckSSL() } +void App::SetSubdomain() +{ + CreateSubdomain(config.base_url.c_str(), cur.request->env_http_host, cur.request->subdomain); +} + + void App::LogAccess() { log.PutDate(log1); diff --git a/core/app.h b/core/app.h index 7cbdc02..18079a0 100755 --- a/core/app.h +++ b/core/app.h @@ -146,6 +146,7 @@ private: void CheckRequestMethod(); void CheckFCGIRole(); void CheckSSL(); + void SetSubdomain(); void PrepareSessionCookie(); void AddDebugInfo(std::wstring & out); diff --git a/core/misc.h b/core/misc.h index 7f62fae..21c771d 100755 --- a/core/misc.h +++ b/core/misc.h @@ -711,4 +711,49 @@ void RemovePostFileTmp(PostFileTab & post_file_tab); +/* + short_str is removed from long_str (and a last dots are removed too) + and the result is stored in out + + sample: + short_str: "mydomain.tld" + long_str: "www.subdomain.mydomain.tld" + out: "www.subdomain" + + short_str: "mydomain.tld" + long_str: "otherdifferentstring" + out: "" +*/ +template +void CreateSubdomain(const StringType1 * short_str, const StringType2 * long_str, StringType3 & out) +{ +size_t i1, i2; + + out.clear(); + + for(i1=0 ; short_str[i1] != 0 ; ++i1); + for(i2=0 ; long_str[i2] != 0 ; ++i2); + + if( i1 >= i2 ) + return; + + // i1 is < i2 + + while( i1-- > 0 ) + { + i2 -= 1; + + if( short_str[i1] != long_str[i2] ) + return; // short_str is not a last substring of long_str + } + + while( i2>0 && long_str[i2-1] == '.' ) + i2 -= 1; + + for(i1=0 ; i1 < i2 ; ++i1) + out += long_str[i1]; +} + + + #endif diff --git a/core/request.cpp b/core/request.cpp index 802c625..8be1a13 100755 --- a/core/request.cpp +++ b/core/request.cpp @@ -86,6 +86,8 @@ void Request::Clear() start_time = 0; memset(&start_tm, 0, sizeof(start_tm)); + + subdomain.clear(); } diff --git a/core/request.h b/core/request.h index 410e23d..fdc5355 100755 --- a/core/request.h +++ b/core/request.h @@ -133,6 +133,10 @@ struct Request time_t start_time; tm start_tm; + // a subdomain + // subdomain = HTTP_HOST environment variable - config->base_url + std::wstring subdomain; + Request(); diff --git a/core/system.cpp b/core/system.cpp index 54a0535..ad46440 100755 --- a/core/system.cpp +++ b/core/system.cpp @@ -126,6 +126,13 @@ bool ssl = false; void System::RedirectTo(const Item & item, const wchar_t * postfix) { PutUrlProto(config->use_ssl, cur->request->redirect_to); + + if( !cur->request->subdomain.empty() ) + { + cur->request->redirect_to += cur->request->subdomain; + cur->request->redirect_to += '.'; + } + cur->request->redirect_to += config->base_url; if( item.type == Item::dir ) @@ -152,6 +159,13 @@ void System::RedirectTo(const Item & item, const wchar_t * postfix) void System::RedirectTo(long item_id, const wchar_t * postfix) { PutUrlProto(config->use_ssl, cur->request->redirect_to); + + if( !cur->request->subdomain.empty() ) + { + cur->request->redirect_to += cur->request->subdomain; + cur->request->redirect_to += '.'; + } + cur->request->redirect_to += config->base_url; Item * pdir = dirs.GetDir(item_id); @@ -193,6 +207,13 @@ void System::RedirectTo(long item_id, const wchar_t * postfix) void System::RedirectTo(const wchar_t * url) { PutUrlProto(config->use_ssl, cur->request->redirect_to); + + if( !cur->request->subdomain.empty() ) + { + cur->request->redirect_to += cur->request->subdomain; + cur->request->redirect_to += '.'; + } + cur->request->redirect_to += config->base_url; if( url[0] == '/' ) diff --git a/notify/notify.cpp b/notify/notify.cpp index 07b8a79..cc481e6 100755 --- a/notify/notify.cpp +++ b/notify/notify.cpp @@ -153,7 +153,7 @@ void Notify::CreateItemLink(const Item & item, std::wstring & item_link, std::ws { dirs->MakePath(item.id, tmp_path); item_link = config->url_proto; - item_link += config->base_url; + item_link += config->base_url; // !! IMPROVE ME what about subdomains? item_link += tmp_path; dir_link = item_link; } @@ -161,7 +161,7 @@ void Notify::CreateItemLink(const Item & item, std::wstring & item_link, std::ws { dirs->MakePath(item.parent_id, tmp_path); item_link = config->url_proto; - item_link += config->base_url; + item_link += config->base_url; // !! IMPROVE ME what about subdomains? item_link += tmp_path; dir_link = item_link; item_link += item.url; @@ -175,7 +175,7 @@ void Notify::CreateActivateLink(const std::wstring & name, long code, std::wstri wchar_t buff[50]; link = config->url_proto; - link += config->base_url; + link += config->base_url;// !! IMPROVE ME what about subdomains? link += L"/pw/activate/login:"; UrlEncode(name, link, false); link += L"/code:"; @@ -188,7 +188,7 @@ void Notify::CreateResetPasswordLink(const std::wstring & name, long code, std:: wchar_t buff[50]; link = config->url_proto; - link += config->base_url; + link += config->base_url;// !! IMPROVE ME what about subdomains? link += L"/pw/resetpassword/login:"; UrlEncode(name, link, false); link += L"/code:"; diff --git a/plugins/export/exportinfo.cpp b/plugins/export/exportinfo.cpp index 283e2f9..442328c 100755 --- a/plugins/export/exportinfo.cpp +++ b/plugins/export/exportinfo.cpp @@ -170,7 +170,7 @@ void ExportInfo::SendFile(const Item & item, bool thumb) { msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE; msg.url = config->url_proto; - msg.url += config->base_url; + msg.url += config->base_url;// !! IMPROVE ME what about subdomains? system->dirs.MakePath(item.parent_id, msg.url, false); msg.url += item.url; msg.path += L".php"; // !! do konfiga @@ -224,7 +224,7 @@ void ExportInfo::SendDir(const Item & item) msg.type = WINIX_PL_EXPORT_TYPE_CREATE_FILE; msg.url = config->url_proto; - msg.url += config->base_url; + msg.url += config->base_url;// !! IMPROVE ME what about subdomains? system->dirs.MakePath(item.id, msg.url, false); msg.path += L"index.html"; // !! do konfiga diff --git a/plugins/gallery/templates.cpp b/plugins/gallery/templates.cpp index 293c256..ddbb200 100755 --- a/plugins/gallery/templates.cpp +++ b/plugins/gallery/templates.cpp @@ -78,7 +78,7 @@ void gallery_tab_subject(Info & i) void gallery_tab_link(Info & i) { doc_proto(i); - i.out << config->base_url; + i.out << config->base_url;// !! IMPROVE ME what about subdomains? gallery_tab_dir(i); gallery_tab_url(i); } diff --git a/plugins/thread/createthread.cpp b/plugins/thread/createthread.cpp index bc99c01..8600aae 100755 --- a/plugins/thread/createthread.cpp +++ b/plugins/thread/createthread.cpp @@ -56,7 +56,7 @@ void CreateThread::SendNotify(const Item & item) notify_msg.code = WINIX_NOTIFY_CODE_ADD; notify_msg.template_index = thread_info->template_index; notify_msg.dir_link = config->url_proto; - notify_msg.dir_link += config->base_url; + notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains? system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false); notify_msg.item_link = notify_msg.dir_link; notify_msg.item_link += item.url; diff --git a/plugins/thread/reply.cpp b/plugins/thread/reply.cpp index 9d01b01..98a15b4 100755 --- a/plugins/thread/reply.cpp +++ b/plugins/thread/reply.cpp @@ -62,7 +62,7 @@ void Reply::SendNotify(const Item & item) notify_msg.code = WINIX_NOTIFY_CODE_REPLY; notify_msg.template_index = thread_info->template_index; notify_msg.dir_link = config->url_proto; - notify_msg.dir_link += config->base_url; + notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains? system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false); notify_msg.item_link = notify_msg.dir_link; notify_msg.item_link += item.url; diff --git a/plugins/ticket/createticket.cpp b/plugins/ticket/createticket.cpp index f3c4627..0d574fc 100755 --- a/plugins/ticket/createticket.cpp +++ b/plugins/ticket/createticket.cpp @@ -62,7 +62,7 @@ void CreateTicket::AddTicket(Ticket & ticket, Item & item) notify_msg.code = WINIX_NOTIFY_CODE_ADD; notify_msg.template_index = ticket_info->template_index; notify_msg.dir_link = config->url_proto; - notify_msg.dir_link += config->base_url; + notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains? system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false); notify_msg.item_link = notify_msg.dir_link; notify_msg.item_link += item.url; diff --git a/plugins/ticket/editticket.cpp b/plugins/ticket/editticket.cpp index 2d7ce42..cc6220b 100755 --- a/plugins/ticket/editticket.cpp +++ b/plugins/ticket/editticket.cpp @@ -67,7 +67,7 @@ void EditTicket::ChangeTicket(Ticket & ticket, Item & item) notify_msg.code = WINIX_NOTIFY_CODE_EDIT; notify_msg.template_index = ticket_info->template_index; notify_msg.dir_link = config->url_proto; - notify_msg.dir_link += config->base_url; + notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains? system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false); notify_msg.item_link = notify_msg.dir_link; notify_msg.item_link += item.url; diff --git a/templates/dir.cpp b/templates/dir.cpp index 2ddebc1..ff859d5 100755 --- a/templates/dir.cpp +++ b/templates/dir.cpp @@ -275,6 +275,10 @@ void dir_tab_url(Info & i) void dir_tab_link(Info & i) { doc_proto(i); + + if( !cur->request->subdomain.empty() ) + i.out << cur->request->subdomain << '.'; + i.out << config->base_url; for(size_t a = 0 ; a <= dir_index && a < cur->request->dir_tab.size() ; ++a) diff --git a/templates/doc.cpp b/templates/doc.cpp index 3983644..0834f52 100755 --- a/templates/doc.cpp +++ b/templates/doc.cpp @@ -75,6 +75,10 @@ void doc_proto_common(Info & i) void doc_base_url(Info & i) { doc_proto(i); + + if( !cur->request->subdomain.empty() ) + i.out << cur->request->subdomain << '.'; + i.out << config->base_url; } diff --git a/templates/item.cpp b/templates/item.cpp index 44a22c3..15c8748 100755 --- a/templates/item.cpp +++ b/templates/item.cpp @@ -165,6 +165,10 @@ void item_url_is(Info & i) void item_link(Info & i) { doc_proto(i); + + if( !cur->request->subdomain.empty() ) + i.out << cur->request->subdomain << '.'; + i.out << config->base_url; item_dir(i); item_url(i); @@ -500,6 +504,10 @@ void item_tab_link(Info & i) if( item_index < cur->request->item_tab.size() ) { doc_proto(i); + + if( !cur->request->subdomain.empty() ) + i.out << cur->request->subdomain << '.'; + i.out << config->base_url; item_tab_dir(i); item_tab_url(i); diff --git a/templates/login.cpp b/templates/login.cpp index d68dd29..cea0417 100755 --- a/templates/login.cpp +++ b/templates/login.cpp @@ -22,6 +22,9 @@ void login_path(Info & i) else i.out << config->url_proto; + if( !cur->request->subdomain.empty() ) + i.out << cur->request->subdomain << '.'; + i.out << config->base_url; if( system->HasReadExecAccessToPath(cur->request->dir_tab) )