Fix for DEV-41951 - reworking of whitelist so it's more usable.

master
callum 2009-11-30 17:13:41 -08:00
parent 8671bfb930
commit d90aea0ede
10 changed files with 182 additions and 123 deletions

View File

@ -57,7 +57,6 @@ LLFloaterMediaSettings::LLFloaterMediaSettings(const LLSD& key)
mMultipleMedia(false),
mMultipleValidMedia(false)
{
// LLUICtrlFactory::getInstance()->buildFloater(this, "floater_media_settings.xml");
}
////////////////////////////////////////////////////////////////////////////////
@ -210,7 +209,6 @@ void LLFloaterMediaSettings::clearValues( bool editable)
sInstance->mPanelMediaSettingsPermissions->clearValues(sInstance->mPanelMediaSettingsPermissions, editable);
}
////////////////////////////////////////////////////////////////////////////////
// static
void LLFloaterMediaSettings::onBtnOK( void* userdata )
@ -264,18 +262,3 @@ const std::string LLFloaterMediaSettings::getHomeUrl()
else
return std::string( "" );
}
////////////////////////////////////////////////////////////////////////////////
//
bool LLFloaterMediaSettings::passesWhiteList( const std::string& test_url )
{
// sanity check - don't think this can happen
if ( mPanelMediaSettingsSecurity )
// version in security dialog code is specialized so we pass in
// empty string for first parameter since it's not used
return mPanelMediaSettingsSecurity->passesWhiteList( "", test_url );
else
// this is all we can do
return false;
}

View File

@ -57,7 +57,7 @@ public:
void enableOkApplyBtns( bool enable );
LLPanelMediaSettingsSecurity* getPanelSecurity(){return mPanelMediaSettingsSecurity;};
const std::string getHomeUrl();
bool passesWhiteList( const std::string& test_url );
//bool passesWhiteList( const std::string& test_url );
bool mIdenticalHasMediaInfo;
bool mMultipleMedia;
@ -73,7 +73,6 @@ protected:
LLPanelMediaSettingsSecurity* mPanelMediaSettingsSecurity;
LLPanelMediaSettingsPermissions* mPanelMediaSettingsPermissions;
static void onBtnOK(void*);
static void onBtnCancel(void*);
static void onBtnApply(void*);

View File

@ -81,7 +81,7 @@ void LLFloaterWhiteListEntry::onBtnOK( void* userdata )
{
std::string white_list_item = self->mWhiteListEdit->getText();
panel->addWhiteListItem( white_list_item );
panel->addWhiteListEntry( white_list_item );
};
self->closeFloater();

View File

@ -59,6 +59,8 @@
#include "llfloatermediasettings.h"
#include "llfloatertools.h"
#include "lltrans.h"
#include "lltextbox.h"
#include "llpanelmediasettingssecurity.h"
const char *CHECKERBOARD_DATA_URL = "data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22100%%22 height=%22100%%22 %3E%3Cdefs%3E%3Cpattern id=%22checker%22 patternUnits=%22userSpaceOnUse%22 x=%220%22 y=%220%22 width=%22128%22 height=%22128%22 viewBox=%220 0 128 128%22 %3E%3Crect x=%220%22 y=%220%22 width=%2264%22 height=%2264%22 fill=%22#ddddff%22 /%3E%3Crect x=%2264%22 y=%2264%22 width=%2264%22 height=%2264%22 fill=%22#ddddff%22 /%3E%3C/pattern%3E%3C/defs%3E%3Crect x=%220%22 y=%220%22 width=%22100%%22 height=%22100%%22 fill=%22url(#checker)%22 /%3E%3C/svg%3E";
@ -98,10 +100,12 @@ BOOL LLPanelMediaSettingsGeneral::postBuild()
mHomeURL = getChild< LLLineEditor >( LLMediaEntry::HOME_URL_KEY );
mWidthPixels = getChild< LLSpinCtrl >( LLMediaEntry::WIDTH_PIXELS_KEY );
mPreviewMedia = getChild<LLMediaCtrl>("preview_media");
mFailWhiteListText = getChild<LLTextBox>( "home_fails_whitelist_label" );
// watch commit action for HOME URL
childSetCommitCallback( LLMediaEntry::HOME_URL_KEY, onCommitHomeURL, this);
childSetCommitCallback( "current_url_reset_btn",onBtnResetCurrentUrl, this);
// interrogates controls and updates widgets as required
updateMediaPreview();
@ -121,6 +125,11 @@ void LLPanelMediaSettingsGeneral::draw()
// housekeeping
LLPanel::draw();
// TODO: we need to call this repeatedly until the floater panels are fully
// created but once we have a valid answer, we should stop looking here - the
// commit callback will handle it
checkHomeUrlPassesWhitelist();
// enable/disable pixel values image entry based on auto scale checkbox
if ( mAutoScale->getValue().asBoolean() == false )
{
@ -250,10 +259,6 @@ void LLPanelMediaSettingsGeneral::initValues( void* userdata, const LLSD& media_
LLPanelMediaSettingsGeneral *self =(LLPanelMediaSettingsGeneral *)userdata;
self->mMediaEditable = editable;
//llinfos << "---------------" << llendl;
//llinfos << ll_pretty_print_sd(media_settings) << llendl;
//llinfos << "---------------" << llendl;
if ( LLPanelMediaSettingsGeneral::isMultiple() )
{
self->clearValues(self, self->mMediaEditable);
@ -316,7 +321,7 @@ void LLPanelMediaSettingsGeneral::initValues( void* userdata, const LLSD& media_
data_set[ i ].ctrl_ptr->setTentative( media_settings[ tentative_key ].asBoolean() );
};
};
// interrogates controls and updates widgets as required
self->updateMediaPreview();
}
@ -354,21 +359,36 @@ void LLPanelMediaSettingsGeneral::onClose(bool app_quitting)
}
}
////////////////////////////////////////////////////////////////////////////////
//
void LLPanelMediaSettingsGeneral::checkHomeUrlPassesWhitelist()
{
// parent floater has not constructed the security panel yet
if ( mParent->getPanelSecurity() == 0 )
return;
std::string home_url = getHomeUrl();
if ( home_url.empty() || mParent->getPanelSecurity()->urlPassesWhiteList( home_url ) )
{
// Home URL is empty or passes the white list so hide the warning message
mFailWhiteListText->setVisible( false );
}
else
{
// Home URL does not pass the white list so show the warning message
mFailWhiteListText->setVisible( true );
};
}
////////////////////////////////////////////////////////////////////////////////
// static
void LLPanelMediaSettingsGeneral::onCommitHomeURL( LLUICtrl* ctrl, void *userdata )
{
LLPanelMediaSettingsGeneral* self =(LLPanelMediaSettingsGeneral *)userdata;
// check url user is trying to enter for home URL will pass whitelist
// and decline to accept it if it doesn't.
std::string home_url = self->mHomeURL->getValue().asString();
if ( ! self->mParent->passesWhiteList( home_url ) )
{
LLNotificationsUtil::add("WhiteListInvalidatesHomeUrl");
return;
};
// check home url passes whitelist and display warning if not
self->checkHomeUrlPassesWhitelist();
self->updateMediaPreview();
}
@ -461,7 +481,7 @@ bool LLPanelMediaSettingsGeneral::navigateHomeSelectedFace(bool only_if_current_
selected_objects->getSelectedTEValue( &functor_navigate_media, all_face_media_navigated );
// Note: we don't update the 'current URL' field until the media data itself changes
return all_face_media_navigated;
}
@ -477,7 +497,6 @@ const std::string LLPanelMediaSettingsGeneral::getHomeUrl()
void LLPanelMediaSettingsGeneral::updateCurrentUrl()
{
// Get the current URL from the selection
const LLMediaEntry default_media_data;
std::string value_str = default_media_data.getCurrentURL();
struct functor_getter_current_url : public LLSelectedTEGetFunctor< std::string >

View File

@ -42,6 +42,7 @@ class LLLineEditor;
class LLSpinCtrl;
class LLTextureCtrl;
class LLMediaCtrl;
class LLTextBox;
class LLFloaterMediaSettings;
class LLPanelMediaSettingsGeneral : public LLPanel
@ -87,6 +88,8 @@ private:
static bool isMultiple();
void checkHomeUrlPassesWhitelist();
LLComboBox* mControls;
LLCheckBoxCtrl* mAutoLoop;
LLCheckBoxCtrl* mFirstClick;
@ -98,6 +101,7 @@ private:
LLLineEditor* mHomeURL;
LLLineEditor* mCurrentURL;
LLMediaCtrl* mPreviewMedia;
LLTextBox* mFailWhiteListText;
};
#endif // LL_LLPANELMEDIAMEDIASETTINGSGENERAL_H

View File

@ -46,8 +46,10 @@
#include "llsdutil.h"
#include "llselectmgr.h"
#include "llmediaentry.h"
#include "lltextbox.h"
#include "llfloaterwhitelistentry.h"
#include "llfloatermediasettings.h"
////////////////////////////////////////////////////////////////////////////////
//
LLPanelMediaSettingsSecurity::LLPanelMediaSettingsSecurity() :
@ -55,9 +57,9 @@ LLPanelMediaSettingsSecurity::LLPanelMediaSettingsSecurity() :
{
mCommitCallbackRegistrar.add("Media.whitelistAdd", boost::bind(&LLPanelMediaSettingsSecurity::onBtnAdd, this));
mCommitCallbackRegistrar.add("Media.whitelistDelete", boost::bind(&LLPanelMediaSettingsSecurity::onBtnDel, this));
// build dialog from XML
LLUICtrlFactory::getInstance()->buildPanel(this, "panel_media_settings_security.xml");
}
////////////////////////////////////////////////////////////////////////////////
@ -66,6 +68,7 @@ BOOL LLPanelMediaSettingsSecurity::postBuild()
{
mEnableWhiteList = getChild< LLCheckBoxCtrl >( LLMediaEntry::WHITELIST_ENABLE_KEY );
mWhiteListList = getChild< LLScrollListCtrl >( LLMediaEntry::WHITELIST_KEY );
mHomeUrlFailsWhiteListText = getChild<LLTextBox>( "home_url_fails_whitelist" );
setDefaultBtn("whitelist_add");
@ -84,30 +87,6 @@ void LLPanelMediaSettingsSecurity::draw()
{
// housekeeping
LLPanel::draw();
// if list is empty, disable DEL button and checkbox to enable use of list
if ( mWhiteListList->isEmpty() )
{
childSetEnabled( "whitelist_del", false );
childSetEnabled( LLMediaEntry::WHITELIST_KEY, false );
childSetEnabled( LLMediaEntry::WHITELIST_ENABLE_KEY, false );
}
else
{
childSetEnabled( "whitelist_del", true );
childSetEnabled( LLMediaEntry::WHITELIST_KEY, true );
childSetEnabled( LLMediaEntry::WHITELIST_ENABLE_KEY, true );
};
// if nothing is selected, disable DEL button
if ( mWhiteListList->getSelectedValue().asString().empty() )
{
childSetEnabled( "whitelist_del", false );
}
else
{
childSetEnabled( "whitelist_del", true );
};
}
////////////////////////////////////////////////////////////////////////////////
@ -179,9 +158,8 @@ void LLPanelMediaSettingsSecurity::initValues( void* userdata, const LLSD& media
LLSD::array_iterator iter = url_list.beginArray();
while( iter != url_list.endArray() )
{
// TODO: is iter guaranteed to be valid here?
std::string url = *iter;
list->addSimpleElement( url );
std::string entry = *iter;
self->addWhiteListEntry( entry );
++iter;
};
};
@ -216,15 +194,18 @@ void LLPanelMediaSettingsSecurity::getValues( LLSD &fill_me_in )
fill_me_in[LLMediaEntry::WHITELIST_ENABLE_KEY] = mEnableWhiteList->getValue();
// iterate over white list and extract items
std::vector< LLScrollListItem* > white_list_items = mWhiteListList->getAllData();
std::vector< LLScrollListItem* >::iterator iter = white_list_items.begin();
std::vector< LLScrollListItem* > whitelist_items = mWhiteListList->getAllData();
std::vector< LLScrollListItem* >::iterator iter = whitelist_items.begin();
// *NOTE: need actually set the key to be an emptyArray(), or the merge
// we do with this LLSD will think there's nothing to change.
fill_me_in[LLMediaEntry::WHITELIST_KEY] = LLSD::emptyArray();
while( iter != white_list_items.end() )
while( iter != whitelist_items.end() )
{
std::string white_list_url = (*iter)->getValue().asString();
fill_me_in[ LLMediaEntry::WHITELIST_KEY ].append( white_list_url );
LLScrollListCell* cell = (*iter)->getColumn( ENTRY_COLUMN );
std::string whitelist_url = cell->getValue().asString();
fill_me_in[ LLMediaEntry::WHITELIST_KEY ].append( whitelist_url );
++iter;
};
}
@ -260,11 +241,8 @@ const std::string LLPanelMediaSettingsSecurity::makeValidUrl( const std::string&
///////////////////////////////////////////////////////////////////////////////
// wrapper for testing a URL against the whitelist. We grab entries from
// white list list box widget and build a list to test against. Can also
// optionally pass the URL that you are trying to add to the widget since
// it won't be added until this call returns.
bool LLPanelMediaSettingsSecurity::passesWhiteList( const std::string& added_url,
const std::string& test_url )
// white list list box widget and build a list to test against.
bool LLPanelMediaSettingsSecurity::urlPassesWhiteList( const std::string& test_url )
{
// the checkUrlAgainstWhitelist(..) function works on a vector
// of strings for the white list entries - in this panel, the white list
@ -273,20 +251,18 @@ bool LLPanelMediaSettingsSecurity::passesWhiteList( const std::string& added_url
whitelist_strings.clear(); // may not be required - I forget what the spec says.
// step through whitelist widget entries and grab them as strings
std::vector< LLScrollListItem* > white_list_items = mWhiteListList->getAllData();
std::vector< LLScrollListItem* >::iterator iter = white_list_items.begin();
while( iter != white_list_items.end() )
std::vector< LLScrollListItem* > whitelist_items = mWhiteListList->getAllData();
std::vector< LLScrollListItem* >::iterator iter = whitelist_items.begin();
while( iter != whitelist_items.end() )
{
const std::string whitelist_url = (*iter)->getValue().asString();
LLScrollListCell* cell = (*iter)->getColumn( ENTRY_COLUMN );
std::string whitelist_url = cell->getValue().asString();
whitelist_strings.push_back( whitelist_url );
++iter;
};
// add in the URL that might be added to the whitelist so we can test that too
if ( added_url.length() )
whitelist_strings.push_back( added_url );
// possible the URL is just a fragment so we validize it
const std::string valid_url = makeValidUrl( test_url );
@ -296,32 +272,68 @@ bool LLPanelMediaSettingsSecurity::passesWhiteList( const std::string& added_url
///////////////////////////////////////////////////////////////////////////////
//
void LLPanelMediaSettingsSecurity::addWhiteListItem(const std::string& url)
void LLPanelMediaSettingsSecurity::updateWhitelistEnableStatus()
{
// grab home URL from the general panel (via the parent floater)
// get the value for home URL and make it a valid URL
const std::string valid_url = makeValidUrl( mParent->getHomeUrl() );
// now check to see if the home url passes the whitelist in its entirity
if ( urlPassesWhiteList( valid_url ) )
{
mEnableWhiteList->setEnabled( true );
mHomeUrlFailsWhiteListText->setVisible( false );
}
else
{
mEnableWhiteList->set( false );
mEnableWhiteList->setEnabled( false );
mHomeUrlFailsWhiteListText->setVisible( true );
};
}
///////////////////////////////////////////////////////////////////////////////
// Add an entry to the whitelist scrollbox and indicate if the current
// home URL passes this entry or not using an icon
void LLPanelMediaSettingsSecurity::addWhiteListEntry( const std::string& entry )
{
// grab the home url
std::string home_url( "" );
if ( mParent )
home_url = mParent->getHomeUrl();
// if the home URL is blank (user hasn't entered it yet) then
// don't bother to check if it passes the white list
if ( home_url.empty() )
{
mWhiteListList->addSimpleElement( url );
return;
};
// try to make a valid URL based on what the user entered - missing scheme for example
const std::string valid_url = makeValidUrl( home_url );
// if the URL passes the white list, add it
if ( passesWhiteList( url, home_url ) )
// check the home url against this single whitelist entry
std::vector< std::string > whitelist_entries;
whitelist_entries.push_back( entry );
bool home_url_passes_entry = LLMediaEntry::checkUrlAgainstWhitelist( valid_url, whitelist_entries );
// build an icon cell based on whether or not the home url pases it or not
LLSD row;
if ( home_url_passes_entry || home_url.empty() )
{
mWhiteListList->addSimpleElement( url );
row[ "columns" ][ ICON_COLUMN ][ "type" ] = "icon";
row[ "columns" ][ ICON_COLUMN ][ "value" ] = "";
row[ "columns" ][ ICON_COLUMN ][ "width" ] = 20;
}
else
// display a message indicating you can't do that
{
LLNotificationsUtil::add("WhiteListInvalidatesHomeUrl");
row[ "columns" ][ ICON_COLUMN ][ "type" ] = "icon";
row[ "columns" ][ ICON_COLUMN ][ "value" ] = "parcel_color_EXP";
row[ "columns" ][ ICON_COLUMN ][ "width" ] = 20;
};
}
// always add in the entry itself
row[ "columns" ][ ENTRY_COLUMN ][ "type" ] = "text";
row[ "columns" ][ ENTRY_COLUMN ][ "value" ] = entry;
// add to the white list scroll box
mWhiteListList->addElement( row );
// update whitelist enable checkbox based on whether the home url passes the whitelist
updateWhitelistEnableStatus();
};
///////////////////////////////////////////////////////////////////////////////
// static
@ -337,6 +349,9 @@ void LLPanelMediaSettingsSecurity::onBtnDel( void* userdata )
LLPanelMediaSettingsSecurity *self =(LLPanelMediaSettingsSecurity *)userdata;
self->mWhiteListList->deleteSelectedItems();
// contents of whitelist changed so recheck it against home url
self->updateWhitelistEnableStatus();
}
////////////////////////////////////////////////////////////////////////////////
@ -345,4 +360,3 @@ void LLPanelMediaSettingsSecurity::setParent( LLFloaterMediaSettings* parent )
{
mParent = parent;
};

View File

@ -37,6 +37,7 @@
class LLCheckBoxCtrl;
class LLScrollListCtrl;
class LLTextBox;
class LLFloaterMediaSettings;
class LLPanelMediaSettingsSecurity : public LLPanel
@ -58,18 +59,27 @@ public:
static void initValues( void* userdata, const LLSD& media_settings,bool editable );
static void clearValues( void* userdata, bool editable);
void addWhiteListItem(const std::string& url);
void addWhiteListEntry( const std::string& url );
void setParent( LLFloaterMediaSettings* parent );
bool urlPassesWhiteList( const std::string& test_url );
const std::string makeValidUrl( const std::string& src_url );
bool passesWhiteList( const std::string& added_url, const std::string& test_url );
protected:
LLFloaterMediaSettings* mParent;
private:
enum ColumnIndex
{
ICON_COLUMN = 0,
ENTRY_COLUMN = 1,
};
LLCheckBoxCtrl* mEnableWhiteList;
LLScrollListCtrl* mWhiteListList;
LLTextBox* mHomeUrlFailsWhiteListText;
void updateWhitelistEnableStatus();
static void onBtnAdd(void*);
static void onBtnDel(void*);
};

View File

@ -586,20 +586,7 @@ To place the media on only one face, choose Select Texture and click on the desi
notext="Cancel"
yestext="OK"/>
</notification>
<notification
icon="alertmodal.tga"
name="WhiteListInvalidatesHomeUrl"
type="alertmodal">
Adding this entry to the whitelist will invalidate the home URL you
specified for this instance of media. You are not allowed to do this
so the entry cannot be added to the whitelist.
<usetemplate
name="okbutton"
yestext="Ok"/>
</notification>
<notification
icon="alertmodal.tga"
name="MustBeInParcel"

View File

@ -10,17 +10,27 @@
name="Media Settings General"
help_topic = "media_settings_general"
width="365">
<text
bottom_delta="-17"
follows="top|left"
height="15"
left="10"
<text
bottom_delta="-25"
follows="top|left"
height="15"
left="10"
name="home_label">
Home URL:
</text>
<text
visible="false"
bottom_delta="0"
follows="top|left"
height="15"
left_delta="64"
text_color="red"
name="home_fails_whitelist_label">
(This URL does not pass the specified whitelist)
</text>
<line_editor
bottom_delta="-21"
bottom_delta="-24"
enabled="true"
follows="left|top"
font="SansSerif"

View File

@ -30,8 +30,28 @@
name="whitelist"
width="315"
enabled="true" />
<icon
bottom_delta="-23"
right="-35"
width="16"
height="16"
image_name="parcel_color_EXP"
mouse_opaque="true"
follows="top|left"
name="parcel_color_EXP"
/>
<text
visible="true"
follows="top|left"
height="15"
left="30"
bottom_delta="0"
text_color="0.4 0.4 0.4 1.0"
name="home_url_fails_some_items_in_whitelist">
Entries that the home URL fails against are marked:
</text>
<button
bottom_delta="-30"
bottom_delta="-36"
follows="top|left"
height="20"
label="Add"
@ -54,4 +74,17 @@
<button.commit_callback
function="Media.whitelistDelete"/>
</button>
<text
visible="true"
bottom_delta="-75"
follows="top|left"
height="40"
left="30"
text_color="0.6 0.0 0.0 1.0"
name="home_url_fails_whitelist">
Warning: the home URL specified in the General tab
fails to pass this whitelist. It has been disabled
until a valid entry has been added.
</text>
</panel>