changed: upload function
select file type by the extension param: multi fixed: uptime function it showed incorrect uptime time (minuts were badly calculated) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@575 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
796985472a
commit
3c5a7cd664
|
@ -476,7 +476,7 @@ void Content::ReadAdditionalInfo()
|
|||
void Content::PrepareUrl(Item & item)
|
||||
{
|
||||
TrimWhite(item.url);
|
||||
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = item.subject; // if the subject is empty then the url will be corrected by CorrectUrlOnlyAllowedChar()
|
||||
|
||||
|
|
|
@ -110,8 +110,13 @@ class Content
|
|||
void PostFunCreateThreadLogAndRedirect();
|
||||
void PostFunCreateThread();
|
||||
|
||||
void UploadSaveFile();
|
||||
bool UploadCreatePath(std::string & path);
|
||||
void UploadSaveFile(const std::string & tmp_filename, const std::string & destination);
|
||||
void UploadMulti();
|
||||
void UploadSingle();
|
||||
bool FunUploadCheckAbuse();
|
||||
void PostFunUpload();
|
||||
std::string tmp_path, tmp_path2;
|
||||
|
||||
bool FunCreateTicketCheckAccess();
|
||||
void FunCreateTicket();
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "content.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/data.h"
|
||||
#include "../core/misc.h"
|
||||
|
||||
|
||||
|
||||
|
@ -38,37 +39,35 @@ return true;
|
|||
|
||||
|
||||
|
||||
void Content::UploadSaveFile()
|
||||
bool Content::UploadCreatePath(std::string & path)
|
||||
{
|
||||
static std::string path;
|
||||
struct stat sb;
|
||||
|
||||
path.clear();
|
||||
request.MakePath(path);
|
||||
|
||||
if( stat(path.c_str(), &sb) < 0 )
|
||||
if( !request.MakeDirsOnFS() )
|
||||
{
|
||||
if( !request.MakeDirsOnFS() )
|
||||
{
|
||||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
request.status = Error::permission_denied;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
path += '/';
|
||||
path += request.item.url;
|
||||
const std::string & tmp_filename = request.post_file_table.begin()->second.tmp_filename;
|
||||
|
||||
if( rename(tmp_filename.c_str(), path.c_str()) == 0 )
|
||||
|
||||
|
||||
void Content::UploadSaveFile(const std::string & tmp_filename, const std::string & destination)
|
||||
{
|
||||
if( rename(tmp_filename.c_str(), destination.c_str()) == 0 )
|
||||
{
|
||||
log << log1 << "Content: uploaded a new file: " << path << logend;
|
||||
log << log1 << "Content: uploaded a new file: " << destination << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
int err = errno;
|
||||
|
||||
// !! skasowac takze plik z bazy danych
|
||||
log << log1 << "Content: can't move the tmp file from: " << tmp_filename << ", to: " << path << ", ";
|
||||
// !! skasowac takze plik z bazy danych?
|
||||
log << log1 << "Content: can't move the tmp file from: " << tmp_filename << ", to: " << destination << ", ";
|
||||
log.SystemErr(err);
|
||||
log << logend;
|
||||
|
||||
|
@ -78,7 +77,120 @@ struct stat sb;
|
|||
|
||||
|
||||
|
||||
bool Content::FunUploadCheckAbuse()
|
||||
{
|
||||
if( !CheckRebus() )
|
||||
{
|
||||
request.status = Error::incorrect_rebus;
|
||||
request.session->done = Done::added_thread;
|
||||
request.session->done_status = Error::incorrect_rebus;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckGetPostTimes(4);
|
||||
|
||||
if( request.session->spam_score > 0 )
|
||||
{
|
||||
request.status = Error::spam;
|
||||
request.session->done = Done::added_thread;
|
||||
request.session->done_status = Error::spam;
|
||||
|
||||
log << log1 << "Content: ignoring due to suspected spamming" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::UploadMulti()
|
||||
{
|
||||
request.item.Clear(); // clearing and setting date
|
||||
request.item.parent_id = request.dir_table.back()->id;
|
||||
request.item.type = Item::file;
|
||||
request.item.privileges = 0644; // !! tymczasowo
|
||||
SetUser(request.item);
|
||||
|
||||
if( !UploadCreatePath(tmp_path) )
|
||||
return;
|
||||
|
||||
tmp_path2 = tmp_path; // remember the path
|
||||
|
||||
PostFileTable::iterator i = request.post_file_table.begin();
|
||||
|
||||
for( ; i != request.post_file_table.end() ; ++i)
|
||||
{
|
||||
const char * file_name = i->second.filename.c_str();
|
||||
|
||||
request.item.subject = file_name;
|
||||
request.item.url = file_name;
|
||||
request.item.static_auth = SelectFileType(file_name);
|
||||
|
||||
PrepareUrl(request.item);
|
||||
PostFunEmacsAdd(); // always adding a new item
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
tmp_path += '/';
|
||||
tmp_path += request.item.url; // item.url could have been changed
|
||||
|
||||
UploadSaveFile(i->second.tmp_filename, tmp_path);
|
||||
tmp_path = tmp_path2; // restoring the oryginal path
|
||||
}
|
||||
}
|
||||
|
||||
RedirectToLastDir();
|
||||
}
|
||||
|
||||
|
||||
void Content::UploadSingle()
|
||||
{
|
||||
std::string * new_subject = request.PostVar("subject");
|
||||
std::string * new_url = request.PostVar("url");
|
||||
bool has_subject = (new_subject && (*new_subject)[0] != 0 );
|
||||
bool has_url = (new_url && (*new_url)[0] != 0 );
|
||||
|
||||
ReadItem(request.item, Item::file); // ReadItem() changes the url if it is empty
|
||||
request.item.privileges = 0644; // !! tymczasowo
|
||||
|
||||
const char * file_name = request.post_file_table.begin()->second.filename.c_str();
|
||||
request.item.static_auth = SelectFileType(file_name);
|
||||
|
||||
if( !has_subject )
|
||||
request.item.subject = file_name;
|
||||
|
||||
if( !has_url )
|
||||
{
|
||||
request.item.url = file_name;
|
||||
PrepareUrl(request.item);
|
||||
}
|
||||
|
||||
PostFunEmacsAdd(); // always adding a new item
|
||||
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
const std::string & tmp_filename = request.post_file_table.begin()->second.tmp_filename;
|
||||
|
||||
if( !UploadCreatePath(tmp_path) )
|
||||
return;
|
||||
|
||||
tmp_path += '/';
|
||||
tmp_path += request.item.url; // item.url could have been changed
|
||||
|
||||
UploadSaveFile(tmp_filename, tmp_path);
|
||||
}
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
|
||||
// !! dodac usuwanie plikow statycznych przez rm
|
||||
void Content::PostFunUpload()
|
||||
{
|
||||
if( !FunUploadCheckAccess() )
|
||||
|
@ -89,23 +201,14 @@ void Content::PostFunUpload()
|
|||
request.status = Error::permission_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
// !! moze request.session->done_status trzeba ustawic na Error::ok na poczatku? (i podobnie w innych metodach, mkdir, emacs ...)
|
||||
ReadItem(request.item, Item::file);
|
||||
|
||||
// !! sprawdzanie rebusa?
|
||||
if( !FunUploadCheckAbuse() )
|
||||
return;
|
||||
|
||||
// !! tutaj w zaleznosci od rozszerzenia dobrac odpowiedni static_auth
|
||||
request.item.static_auth = Item::static_other;
|
||||
|
||||
PostFunEmacsAdd(); // always adding a new item
|
||||
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
UploadSaveFile();
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
RedirectTo(request.item);
|
||||
if( request.post_file_table.size() > 1 )
|
||||
UploadMulti();
|
||||
else
|
||||
UploadSingle();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -72,9 +72,10 @@ long content_id;
|
|||
// the direct url is the same but the prefix is: base_url_static_auth
|
||||
enum StaticAuth
|
||||
{
|
||||
static_none = 0,
|
||||
static_image = 1,
|
||||
static_other = 2
|
||||
static_none = 0,
|
||||
static_image = 1, /* png, gif, jpg - only types available to render by a web browser*/
|
||||
static_document = 2, /* pdf doc xls txt */
|
||||
static_other = 3
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,9 @@ return false;
|
|||
}
|
||||
|
||||
|
||||
|
||||
// this function checks how many dots there are in the url
|
||||
// if there are more than one (last) dot then the first dots will be changed into '_'
|
||||
void CorrectUrlDots(std::string & url)
|
||||
{
|
||||
size_t i = url.size();
|
||||
|
@ -73,7 +76,7 @@ void CorrectUrlChars(std::string & url)
|
|||
{
|
||||
std::string::iterator i;
|
||||
|
||||
for(i = url.begin(); i!=url.end() ; ++i)
|
||||
for(i=url.begin(); i != url.end() ; ++i)
|
||||
{
|
||||
if( !CorrectUrlChar(*i) )
|
||||
{
|
||||
|
@ -215,6 +218,9 @@ void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in)
|
|||
std::string::const_iterator i;
|
||||
int was_enter = 0; // how many enteres there were before
|
||||
|
||||
if( in.empty() )
|
||||
return;
|
||||
|
||||
out << "<p>";
|
||||
|
||||
// skipping first new line characters
|
||||
|
@ -485,15 +491,15 @@ return false;
|
|||
}
|
||||
|
||||
|
||||
bool EqualNoCase(const char * short_str, const char * long_str)
|
||||
bool EqualNoCase(const char * str1, const char * str2)
|
||||
{
|
||||
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
|
||||
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
|
||||
{
|
||||
++short_str;
|
||||
++long_str;
|
||||
++str1;
|
||||
++str2;
|
||||
}
|
||||
|
||||
if( *short_str == 0 && *long_str == 0 )
|
||||
if( *str1 == 0 && *str2 == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -555,3 +561,54 @@ bool IsFile(const std::string & file)
|
|||
{
|
||||
return IsFile(file.c_str());
|
||||
}
|
||||
|
||||
|
||||
// if there is not an extension it returns a pointer to the last '\0' character
|
||||
const char * GetFileExt(const char * name)
|
||||
{
|
||||
size_t i, ilast;
|
||||
|
||||
// looking for the end of the name
|
||||
for(i=0 ; name[i] != 0 ; ++i);
|
||||
|
||||
if( i == 0 )
|
||||
return name; // ops, the name is empty
|
||||
|
||||
// remember the end of the string
|
||||
ilast = i;
|
||||
|
||||
// looking for the last dot
|
||||
for(--i ; i>0 && name[i] != '.' ; --i);
|
||||
|
||||
if( name[i] != '.' )
|
||||
return name + ilast; // ops, there is not a dot
|
||||
|
||||
// the extensions starts from i+1
|
||||
// and can be empty (if the last character is a dot)
|
||||
|
||||
return name + i + 1;
|
||||
}
|
||||
|
||||
|
||||
Item::StaticAuth SelectFileType(const char * file_name)
|
||||
{
|
||||
const char * ext = GetFileExt(file_name);
|
||||
|
||||
// as an image we're using only those types which can be rendered
|
||||
// by a web browser
|
||||
if( EqualNoCase(ext, "jpg") ||
|
||||
EqualNoCase(ext, "gif") ||
|
||||
EqualNoCase(ext, "png") )
|
||||
return Item::static_image;
|
||||
|
||||
if( EqualNoCase(ext, "pdf") ||
|
||||
EqualNoCase(ext, "doc") ||
|
||||
EqualNoCase(ext, "xls") ||
|
||||
EqualNoCase(ext, "txt") ||
|
||||
EqualNoCase(ext, "ods") ||
|
||||
EqualNoCase(ext, "odt") )
|
||||
return Item::static_document;
|
||||
|
||||
return Item::static_other;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,12 +57,14 @@ const char * ToStr(int value);
|
|||
|
||||
bool IsSubString(const char * short_str, const char * long_str);
|
||||
bool IsSubStringNoCase(const char * short_str, const char * long_str);
|
||||
bool EqualNoCase(const char * short_str, const char * long_str);
|
||||
bool EqualNoCase(const char * str1, const char * str2);
|
||||
|
||||
bool ValidateEmail(const std::string & email);
|
||||
|
||||
bool IsFile(const char * file);
|
||||
bool IsFile(const std::string & file);
|
||||
|
||||
const char * GetFileExt(const char * name);
|
||||
Item::StaticAuth SelectFileType(const char * file_name);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -911,6 +911,7 @@ void Request::MakePath(std::string & path)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool Request::MakeDirsOnFS()
|
||||
{
|
||||
size_t i;
|
||||
|
@ -922,11 +923,13 @@ bool Request::MakeDirsOnFS()
|
|||
path += '/';
|
||||
path += dir_table[i]->url;
|
||||
|
||||
if( mkdir(path.c_str(), 0755) < 0 )
|
||||
if( !IsFile(path.c_str()) )
|
||||
{
|
||||
// oops
|
||||
log << log1 << "Request: can't create the directory on fs: " << path << logend;
|
||||
return false;
|
||||
if( mkdir(path.c_str(), 0755) < 0 )
|
||||
{
|
||||
log << log1 << "Request: can't create the directory on fs: " << path << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
[if-one mount_type_is_cms]<p class="withnext">{form_emacs_content_cms}</p>[end]
|
||||
[if-one mount_type_is_thread]<p class="withnext">{form_emacs_content_thread}</p>[end]
|
||||
[if-one mount_type_is_ticket]<p class="withnext">{form_emacs_content_ticket}</p>[end]
|
||||
|
||||
[is winix_function_is "upload"]
|
||||
<p class="withnext">{upload_content}</p>
|
||||
[else]
|
||||
[if-one mount_type_is_cms]<p class="withnext">{form_emacs_content_cms}</p>[end]
|
||||
[if-one mount_type_is_thread]<p class="withnext">{form_emacs_content_thread}</p>[end]
|
||||
[if-one mount_type_is_ticket]<p class="withnext">{form_emacs_content_ticket}</p>[end]
|
||||
[end]
|
||||
|
||||
<textarea class="multitext" rows="[if-one mount_type_is_cms]30[else]10[end]" cols="60" name="content">[item_content]</textarea>
|
||||
<textarea class="multitext" rows="[is winix_function_is "upload"]7[else][if-one mount_type_is_cms]30[else]10[end][end]" cols="60" name="content">[item_content]</textarea>
|
||||
|
||||
|
||||
<p class="withnext">{form_emacs_content_type}</p>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[if-one item_is]<h1>{edit}</h1>[else]<h1>{add}</h1>[end]
|
||||
<h1>{upload_header}</h1>
|
||||
|
||||
[include "err_abuse.html"]
|
||||
|
||||
|
@ -6,30 +6,29 @@
|
|||
<fieldset>
|
||||
<legend>{upload_form_legend}</legend>
|
||||
|
||||
<input type="file" name="fileupload">
|
||||
[is winix_function_param_is "multi"]
|
||||
|
||||
<p class="withnext">{upload_form_file_multi}</p>
|
||||
<input size="68" class="edit" type="file" name="fileupload1">
|
||||
<input size="68" class="edit" type="file" name="fileupload2">
|
||||
<input size="68" class="edit" type="file" name="fileupload3">
|
||||
<input size="68" class="edit" type="file" name="fileupload4">
|
||||
<input size="68" class="edit" type="file" name="fileupload5">
|
||||
|
||||
[if-one mount_type_is_cms]
|
||||
[else]
|
||||
|
||||
<p class="withnext">{upload_form_file}</p>
|
||||
<input size="68" class="edit" type="file" name="fileupload">
|
||||
|
||||
<p class="withnext">{title}:</p>
|
||||
<input class="edit" type="text" name="subject" value="[item_subject]">
|
||||
|
||||
<p class="withnext">{url}:</p>
|
||||
<p class="withnext">{suggested_url}:</p>
|
||||
<input class="edit" type="text" name="url" value="[item_url]">
|
||||
[end]
|
||||
|
||||
[if-one mount_type_is_thread]
|
||||
[is mount_thread_is "subject"]
|
||||
<p class="withnext">{title}:</p>
|
||||
<input class="edit" type="text" name="subject" value="[item_subject]">
|
||||
|
||||
<p class="withnext">{url}:</p>
|
||||
<input class="edit" type="text" name="url" value="[item_url]">
|
||||
[end]
|
||||
[include "fun_emacs_post.html"]
|
||||
|
||||
[end]
|
||||
|
||||
|
||||
<p class="withnext">{upload_content}:</p>
|
||||
<textarea class="multitext" rows="[if-one thread_is]10[else]30[end]" cols="60" name="content">[item_content]</textarea>
|
||||
|
||||
[if-no user_logged]
|
||||
<p class="withnext">{nick}:</p>
|
||||
|
@ -39,8 +38,7 @@
|
|||
<input class="edit" type="text" name="rebus">
|
||||
[end]
|
||||
|
||||
|
||||
<input class="submit" type="submit" value="[if-one item_is]{change}[else]{add}[end]">
|
||||
<input class="submit" type="submit" value="{upload_submit}">
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<h1>{uptime_header}</h1>
|
||||
|
||||
<p>[winix_cur_time], {uptime_up}
|
||||
<p>{uptime_current_time}: [winix_cur_time]<br>
|
||||
{uptime_up}:
|
||||
|
||||
[if-one uptime_more_than_one_day]
|
||||
[uptime_days] {uptime_days},
|
||||
[uptime_days] {uptime_days}
|
||||
[else]
|
||||
[uptime_hours],
|
||||
[uptime_hours]
|
||||
[end]
|
||||
<br>
|
||||
|
||||
[winix_users_logged] {uptime_users}
|
||||
{uptime_users}: [winix_users_logged]
|
||||
</p>
|
||||
|
||||
|
||||
|
|
|
@ -146,8 +146,12 @@ ticket_info_expected = Expected in
|
|||
ticket_info_progress = Progress
|
||||
ticket_reply_in_this_thread = Replay in this thread
|
||||
|
||||
upload_header = Upload a file
|
||||
upload_form_file = Browse for a file
|
||||
upload_form_file_multi = Browse for files
|
||||
upload_form_legend = Upload form
|
||||
upload_content = File description
|
||||
upload_submit = Upload
|
||||
|
||||
who_header = Sessions
|
||||
who_table_index = Ind.
|
||||
|
@ -169,7 +173,8 @@ admin_upload = Upload an image or file (upload)
|
|||
login_header = Login
|
||||
|
||||
uptime_header = Uptime
|
||||
uptime_up = up
|
||||
uptime_current_time = current time
|
||||
uptime_up = system running for
|
||||
uptime_users = users
|
||||
uptime_days = days
|
||||
|
||||
|
|
10
locale/pl
10
locale/pl
|
@ -145,8 +145,13 @@ ticket_info_expected = Oczekiwany w
|
|||
ticket_info_progress = Postêp prac
|
||||
ticket_reply_in_this_thread = Odpowiedz w tym w±tku
|
||||
|
||||
upload_header = Prześlij plik
|
||||
upload_form_file = Wybierz plik
|
||||
upload_form_file_multi = Wybierz pliki
|
||||
upload_form_legend = Formularz do wys³ania pliku
|
||||
upload_content = Opis pliku
|
||||
upload_submit = Wyślij
|
||||
|
||||
|
||||
who_header = Lista sesji
|
||||
who_table_index = L.p.
|
||||
|
@ -166,8 +171,9 @@ admin_upload = Wy
|
|||
|
||||
login_header = Logowanie
|
||||
|
||||
uptime_header = Uptime
|
||||
uptime_up = uruchomiony przez
|
||||
uptime_header = Czas pracy systemu
|
||||
uptime_current_time = aktualna godzina
|
||||
uptime_up = system uruchomiony przez
|
||||
uptime_users = zalogowanych u¿ytkowników
|
||||
uptime_days = dni
|
||||
|
||||
|
|
|
@ -107,7 +107,8 @@ void item_print_content(std::ostringstream & out, const std::string & content, I
|
|||
else
|
||||
if( content_type == Item::ct_bbcode )
|
||||
{
|
||||
out << content; // !! tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
||||
//out << content; // !! tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
||||
out << "bbcode is not implemented yet";
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_raw )
|
||||
|
@ -117,6 +118,11 @@ void item_print_content(std::ostringstream & out, const std::string & content, I
|
|||
}
|
||||
|
||||
|
||||
void item_content_is_empty(Info & i)
|
||||
{
|
||||
i.result = request.item.content.empty();
|
||||
}
|
||||
|
||||
void item_print_content(Info & i)
|
||||
{
|
||||
item_print_content(i.out, request.item.content, request.item.content_type);
|
||||
|
|
|
@ -185,6 +185,7 @@ void Templates::CreateFunctions()
|
|||
functions.Insert("item_id", item_id);
|
||||
functions.Insert("item_subject", item_subject);
|
||||
functions.Insert("item_subject_noescape", item_subject_noescape);
|
||||
functions.Insert("item_content_is_empty", item_content_is_empty);
|
||||
functions.Insert("item_content", item_content);
|
||||
functions.Insert("item_content_noescape", item_content_noescape);
|
||||
functions.Insert("item_content_type_is", item_content_type_is);
|
||||
|
|
|
@ -103,6 +103,7 @@ namespace TemplatesFunctions
|
|||
void item_content(Info & i);
|
||||
void item_content_noescape(Info & i);
|
||||
void item_content_type_is(Info & i);
|
||||
void item_content_is_empty(Info & i);
|
||||
void item_print_content(std::ostringstream & out, const std::string & content, Item::ContentType content_type);
|
||||
void item_print_content(Info & i);
|
||||
void item_privileges(Info & i);
|
||||
|
|
|
@ -44,9 +44,9 @@ char buf[50];
|
|||
time_t hour = min / 60;
|
||||
|
||||
if( hour == 0 && min == 0 )
|
||||
sprintf(buf, "%d:%02d:%02d", (int)hour, (int)min, (int)sec);
|
||||
sprintf(buf, "%d:%02d:%02d", (int)hour, (int)(min%60), (int)(sec%60));
|
||||
else
|
||||
sprintf(buf, "%d:%02d", (int)hour, (int)min);
|
||||
sprintf(buf, "%d:%02d", (int)hour, (int)(min%60));
|
||||
|
||||
i.out << buf;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue