Project

General

Profile

Actions

Feature #569

closed

User inputs violation checking in Wizard

Added by Eric Hou almost 14 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
High
Assignee:
Amber Herold
Category:
-
Target version:
Start date:
05/26/2010
Due date:
% Done:

100%

Estimated time:

Description

There are many places need to do inputs violation checking in the wizard.
I will list out all of them later.

Thanks.


Related issues 4 (0 open4 closed)

Related to Appion - Bug #524: Outgoing email not working, authorization errorDuplicateEric Hou05/20/2010

Actions
Related to Appion - Feature #722: Add SMTP validation to the setup wizard.ClosedAmber Herold07/07/2010

Actions
Related to Appion - Feature #723: Add database connection tester to the setup wizard.ClosedEric Hou07/07/2010

Actions
Related to Appion - Bug #656: Add MRC2ANY to config.php wizardClosedAmber Herold06/14/2010

Actions
Actions #1

Updated by Amber Herold almost 14 years ago

Please include error chacks for the clusterconfig.php file. refer to #595

Actions #2

Updated by Amber Herold almost 14 years ago

  • Target version changed from Appion/Leginon 2.0.1 to Appion/Leginon 2.0.2
Actions #3

Updated by Neil Voss almost 14 years ago

  • Target version changed from Appion/Leginon 2.0.2 to Appion/Leginon 2.1.0
Actions #4

Updated by Amber Herold almost 14 years ago

  • Priority changed from Normal to High
Actions #5

Updated by Eric Hou almost 14 years ago

  • % Done changed from 0 to 50

Wrote a class call formValidator.php.
This class can be used for any user input form. It is under myamiweb/inc folder.
I have detail document for how to use it inside of the file.

Thanks.

Eric

Actions #6

Updated by Eric Hou almost 14 years ago

  • Assignee changed from Eric Hou to Amber Herold

Hi Amber, Please find out the regular expression for "float" and "path".

Thanks.

Eric

Actions #7

Updated by Amber Herold almost 14 years ago

Here are a few to look at. I was thinking it may not make much sense to say a float must have a certain number of decimal places. When someone is typing in a number they should be able to type 1.1234 or 1. or 1 or 1.12 and we can do with it whatever we need to do.

Floats

^\d*\.?\d{0,2}$ - float with a max of 2 decimal places. May omit point. (make the 2 a variable)
^\d*\.\d{2}$ - float with exactly 2 decimal places. May not omit point.
^\d*\.?\d*$ - float with any number of decimal places. May omit point.
^[+|-]{0,1}\d*\.?\d*$ - float with any number of decimal places. May omit point. May begin with positive or negative sign.

None handle comas(,). If you want comas you can do something like this: ^[+|-]{0,1}[\d,]*\.?\d*$ but it allows things like +,,,.

Paths

^((\.\./|/)+(\.\./|[\w/\-\\])*(\.\w+)*)$ - Path that must begin with / or ../ then allows alpha/num, underscore, dash and ../ with optional file extensions.
^((\.\./|[\w/\-\\])*(\.\w+)*)$ - Path that does NOT require / or ../ in the front then allows alpha/num, underscore, dash and ../ with optional file extensions.

URL - may need it sometime?

^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$ - url requires http (not perfect but a starting point from RegExLib.com)
Actions #8

Updated by Amber Herold almost 14 years ago

  • Assignee changed from Amber Herold to Eric Hou
Actions #9

Updated by Eric Hou almost 14 years ago

Hi Amber!

The regular expressions do not work for me.
Try to go to : http://www.spaweditor.com/scripts/regex/index.php.
This is a php tester.

Select "preg_match"

Thanks.

Actions #10

Updated by Eric Hou almost 14 years ago

  • Assignee changed from Eric Hou to Amber Herold
Actions #11

Updated by Amber Herold almost 14 years ago

They all work for me. What strings are breaking?
One problem might be that what I listed does not have delimiters defined which are required for using preg_match. For example, the floats could use / as delimiters:
/^[+|-]{0,1}\d*\.?\d*$/

The path and url is better with a hash(#) as the delimiter. For the URL, since we are using # we need to escape the # that occurs in the actual expression.
#^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$\#\=~])*$#

Also, I think that your original expressions should be modified slightly. For example:
/[^0-9]/ --> /^[0-9]$/
/[^A-Za-z]/ --> /^[A-Za-z]$/
/[^A-Za-z ]/ --> /^[A-Za-z ]$/
/[^A-Za-z0-9 ]/ --> /^[A-Za-z0-9 ]$/

This way, rather than looking for something that does not fit the pattern, you look for something that does fit the pattern. Then if preg_match does NOT find a match, validateReq() returns false, if it does find a match it returns true. This will keep things more consistent and easier to write more complicated regular expressions.

Actions #12

Updated by Amber Herold almost 14 years ago

  • Assignee changed from Amber Herold to Eric Hou
Actions #13

Updated by Amber Herold almost 14 years ago

#^/[\w/\-]*$# - simplified path, requires a single / in front followed by any number of alphanumeric - or /.

Actions #14

Updated by Eric Hou almost 14 years ago

  • % Done changed from 50 to 70

There is a bug in the regular expression for float. The regular expression allow empty input.
I just fixed it at r14457.

Actions #15

Updated by Eric Hou almost 14 years ago

added "path_exit" and "forder_permission" in the the formValidator class. r14458

Actions #16

Updated by Eric Hou almost 14 years ago

add validation for remote cluster and also validate the server has installed php ssh2 module. r14460

Actions #17

Updated by Eric Hou almost 14 years ago

  • % Done changed from 70 to 100

added validations for last step (step 4) in the wizard. r14463

To test.
Go through the wizard, and try to input wrong inputs. The wizard will display error message for each input.

Thanks.

Eric

Actions #18

Updated by Eric Hou almost 14 years ago

  • Status changed from Assigned to In Code Review
  • Assignee changed from Eric Hou to Amber Herold
Actions #19

Updated by Amber Herold almost 14 years ago

Great work!

Will check in changes after I install ssh2 on fly so I can complete testing.

Fixed

I updated some names. Changed forder to folder and exit to exist. Corrected some error messages.

Testing:

received this message when supplied an incorrect DB server name or otherwise can't connect (password or username wrong):
Warning: mysql_close(): no MySQL-Link resource supplied in /home/amber/amiworkspace/myami/myamiweb/inc/mysql.inc on line 79

Similar warnings are displayed when other errors occur as well.
Warning: mkdir() [function.mkdir]: Permission denied in /home/amber/amiworkspace/myami/myamiweb/inc/formValidator.php on line 329

Warning: mkdir() [function.mkdir]: No such file or directory in /home/amber/amiworkspace/myami/myamiweb/inc/formValidator.php on line 329

It would be nice to capture these messages and maybe send them to a log file rather than the UI if there is a way to do that.

Suggestions

Would it be possible to use

exec('/usr/bin/which mrc2any', $pathToMrc2any)

in the php file to detect and fill this field in automatically for the user? It could still be editable in case it needs to be changed or the which command fails to return anything.

Actions #20

Updated by Amber Herold almost 14 years ago

  • Assignee changed from Amber Herold to Eric Hou

Eric,
please check my changes. In addition to typo fixing, got rid of the warnings that were noted earlier.

Also, "which" command will not work from PHP b/c the wwwrun user does not have a shell. Other commands will work like find, but that's just not as clean.

Actions #21

Updated by Eric Hou almost 14 years ago

  • Status changed from In Code Review to In Test
  • Assignee changed from Eric Hou to Amber Herold

Changed are ok.

Eric

Actions #22

Updated by Amber Herold almost 14 years ago

  • Assignee changed from Amber Herold to Eric Hou

Eric, there is one problem that caused me to waste more time than I would like to admit...
In step 4, if the Image Processing Host information is not correct, the test to connect to it via SSH fails and the wizard gives an error message:

PHP 'ssh2' module is required to setup local cluster.

I spent time trying to troubleshoot the ssh2 installation rather than realizing that I had forgotten to add the processing host name.

What do you think about first validating that the processing host field is not empty and then if the connection fails changing the error message to:

Unable to connect to the processing host via ssh2. Please confirm the processing host information is correct and the ssh2 module is installed on the web server.

Actions #23

Updated by Eric Hou almost 14 years ago

  • Status changed from In Test to Assigned

Good Ideas. I will change it.

Thanks.

Eric

Actions #24

Updated by Eric Hou almost 14 years ago

  • Status changed from Assigned to In Test

Just change the logic for verifying the remote servers.

Thanks.

Eric

Actions #25

Updated by Eric Hou almost 14 years ago

  • Assignee changed from Eric Hou to Amber Herold
Actions #26

Updated by Amber Herold over 13 years ago

Tested. Looks good.

Actions #27

Updated by Amber Herold over 13 years ago

  • Status changed from In Test to Closed
Actions

Also available in: Atom PDF