Feature #569
closedUser inputs violation checking in Wizard
Added by Eric Hou over 14 years ago. Updated over 14 years ago.
100%
Description
There are many places need to do inputs violation checking in the wizard.
I will list out all of them later.
Thanks.
Updated by Amber Herold over 14 years ago
Please include error chacks for the clusterconfig.php file. refer to #595
Updated by Amber Herold over 14 years ago
- Target version changed from Appion/Leginon 2.0.1 to Appion/Leginon 2.0.2
Updated by Neil Voss over 14 years ago
- Target version changed from Appion/Leginon 2.0.2 to Appion/Leginon 2.1.0
Updated by Eric Hou over 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
Updated by Eric Hou over 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
Updated by Amber Herold over 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)
Updated by Amber Herold over 14 years ago
- Assignee changed from Amber Herold to Eric Hou
Updated by Eric Hou over 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.
Updated by Eric Hou over 14 years ago
- Assignee changed from Eric Hou to Amber Herold
Updated by Amber Herold over 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.
Updated by Amber Herold over 14 years ago
- Assignee changed from Amber Herold to Eric Hou
Updated by Amber Herold over 14 years ago
#^/[\w/\-]*$# - simplified path, requires a single / in front followed by any number of alphanumeric - or /.
Updated by Eric Hou over 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.
Updated by Eric Hou over 14 years ago
added "path_exit" and "forder_permission" in the the formValidator class. r14458
Updated by Eric Hou over 14 years ago
add validation for remote cluster and also validate the server has installed php ssh2 module. r14460
Updated by Eric Hou over 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
Updated by Eric Hou over 14 years ago
- Status changed from Assigned to In Code Review
- Assignee changed from Eric Hou to Amber Herold
Updated by Amber Herold over 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.
Updated by Amber Herold over 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.
Updated by Eric Hou over 14 years ago
- Status changed from In Code Review to In Test
- Assignee changed from Eric Hou to Amber Herold
Changed are ok.
Eric
Updated by Amber Herold over 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.
Updated by Eric Hou over 14 years ago
- Status changed from In Test to Assigned
Good Ideas. I will change it.
Thanks.
Eric
Updated by Eric Hou over 14 years ago
- Status changed from Assigned to In Test
Just change the logic for verifying the remote servers.
Thanks.
Eric
Updated by Eric Hou over 14 years ago
- Assignee changed from Eric Hou to Amber Herold
Updated by Amber Herold over 14 years ago
- Status changed from In Test to Closed