PPTX - fehr.org
Download
Report
Transcript PPTX - fehr.org
Master your fehr
Part II
Lara Hopley
Jo van Schalkwyk
www.fehr.org
Where are we?
Part I: Some philosophy
Part II: Get it working
<tea>
Part III: The anatomy of fehr
Part IV: Experimentation
fehr.org
What do we do next?
1. Physically install fehr
2. Configure ‘insecure’ mode
• Chrome (Windows) has special
needs
3.
4.
5.
6.
7.
A preliminary to testing
Test Wholly in your browser
A brief peek at Wholly
Regression testing
Set two secure codes
fehr.org
8. Install WAMP | MAMP
9. Copy PHP files
10. Set a root password
11. Make the fehr database
12. An end-user
13. A vanilla user
14. Finally, a secure log-in!
A few conventions
File names italic_filename.pl
Code is monospaced
Stuff you type in is monospaced bold
Table names are in a BOLD serif font
fehr.org
1. Install fehr
1. Insert USB
2. Navigate to mac or windows directory
3. Copy over the fehr subdirectory:
• Mac: copy to ~/fehr
• Windows: copy to C:\fehr
fehr.org
2. Configure and test
Move to the command line (open a console)
fehr.org
Windows
1. Navigate to C:\fehr\serve
cd \fehr\serve
2. Activate the plugin:
regsvr32 npwowserve.dll
Mac
fehr.org
1. Navigate to ~/fehr/serve
cd ~/fehr/serve
2. Activate the plugin:
cp –R npwowserve.plugin
~/Library/Internet\ Plug-Ins/
Chrome I: (Windows)
fehr.org
Go to: https://chrome.google.com/webstore/category/apps
Search for: fehr npapi plugin
Install the extension
Allow access to file URLs.
Mac: No Chrome support yet.
http://nativeclient.googlecode.com/svn-history/r154/trunk/googleclient/native_client/documentation/getting_started.html
Chrome II: Install Python
Navigate to C:\fehr\INSTALL\python
Run the file python-2.7.11.msi
Open up a new command prompt
Type in: python --version
If this fails, you’ll need help with your path to Python
fehr.org
3. A command-line tweak
1. Navigate to fehr/serve/insecure/scripts
• Mac:
• Windows:
cd ~/fehr/serve/insecure/scripts
cd \fehr\serve\insecure\scripts
2. Look at the files there:
• Mac:
• Windows:
ls *.*
dir *.*
3. Open the file home.whole :
• Mac:
• Windows:
nano home.whole
notepad home.whole
fehr.org
…
1.
2.
3.
4.
fehr.org
Navigate
Look
Open
Insert the following line:
SAY <Hello World>
5. Save the file
4. Test Wholly in your browser
Mac: In Finder, navigate to ~/fehr/serve
• Open the file home.html using Safari (or
Firefox)
• Allow plugins and reload file
Windows: In File Explorer, navigate to
C:\fehr\serve
• Open the file home.html using Firefox
• Allow plugins and reload file
Press F7 to enter insecure mode.
fehr.org
Did this work?
If not, we have some fixing to do. Otherwise try …
▷ SAY HELP <HELP>
fehr.org
More impressive than it looks …
fehr.org
▷ HELP <HELP>
This involves loading a file from the local disk into the browser, and
displaying it!
The file is in my Markdown language (a simple form of Hypertext
Markup Language—HTML)
6. Regression tests
It’s nice to know that the language works
As I’ve built Wholly, I’ve written “regression tests” for each
command
These are all contained in the document tutorial_124.pdf
Say the following:
▷ RUN <tests/home>
(The pause at 28% involves loading 70,000 lines of data)
fehr.org
7. Set two secure codes
Mac: In Terminal type:
• uuidgen
• Copy the value (Highlight, command+C)
Windows:
•
•
•
•
•
•
Navigate to C:\fehr\INSTALL\guid
Run the program GUIDinstall.exe
Install at C:\fehr\guid\
Go to C:\fehr\guid\GUIDgen\
Run GUIDGEN.EXE
Choose “Registry format” | [New GUID] | [Copy]
fehr.org
Edit a Javascript file
At the console, navigate to fehr/serve/js
using Nano | Notepad, open single.js
Replace the LO magic code, along the lines of:
• MagicCode_LO = '{0AFD3B8F-D5AF-4c06-91E1-98694AD191AE}';
Trim out the hyphens (and in Windows, the {curly braces}
Generate a new, separate UUID (as before)
Replace the HI magic code
Save the file, but don’t exit your text editor yet.
fehr.org
Save under a new name
fehr.org
Mac: In Nano, save the same file as ~/fehr/serve/id.single
Windows: In Notepad, say File | Save as
•
•
•
•
Navigate to C:\fehr\serve
Under “Save as type”, choose All Files (*.*)
Enter id.single as the file name
We’re not finished
Delete everything in the file apart from the magic numbers and
quotes: '0AFD3B…AD191AE''1B81C3…27120CE18'
Make sure there are no trailing spaces, or extra lines.
Save the file once more. We’re done.
(The basic idea)
fehr.org
Even in “insecure mode” the browser page must know the secret
code, or things won’t run.
But in addition, part of this code is used by the server to establish
that the workstation is valid
This is just a tiny part of the security
We next install our database manager, MySQL.
8. Install WAMP | MAMP
Windows: In File Explorer, visit C:\fehr\INSTALL\wamp
• Unless you’re on a 32-bit machine, install:
wampserver3_x64_apache2.4.17_mysql5.7.9_php5.6.16_php7.0.0.exe
• When prompted
• yes to change to Mozilla Firefox, No to leave as notepad
• Run WAMP by double clicking the pink icon on your desktop, or
• Navigate to C:\wamp\ and run wampmanager.exe
• If a green icon doesn’t appear in the notification section of the
Windows taskbar, we’ll need to do some troubleshooting.
fehr.org
8. Install WAMP | MAMP
fehr.org
Mac: In Finder, visit ~/fehr/INSTALL/mamp
• Run the package there
• At installation choose [Custom install]
• Uncheck [MAMP Pro]
• Visit Applications (in Finder), find MAMP and double click on the
elephant icon.
• Before you start the servers, uncheck “Check for MAMP PRO”
8a. A quick command-line check
fehr.org
Mac: type in:
/Applications/MAMP/Library/bin/mysql --user=root –password
Enter the password “root”
Windows:
mysql --user=root --password
Hit Enter (No password yet)
Try the following, just to show it works:
show schemas;
quit;
9. Copy over PHP files
Mac: navigate to /Applications/MAMP/htdocs
mkdir logs
cp ~/fehr/lyx/php/*.php .
Windows: navigate to C:\wamp\www *
md public_html
md public_html\logs
copy C:\fehr\lyx\php\*.php public_html\
* (or C:\wamp64\www )
fehr.org
10. Set a root password
Choose a nice long password. Long is better than complex
Burn it into your soul
The following may be more painful than you might expect:
Windows:
•
•
•
•
•
Click on the green Wampserver icon
Launch PhpMyAdmin
Click on the Users tab
For root 127.0.0.1, Edit privileges and change the password
Click on Go
fehr.org
Set a root password (Mac)
fehr.org
In Terminal, say:
/Applications/MAMP/Library/bin/mysqladmin -u root -p
password NEWPASSWORD
(Replacing NEWPASSWORD by your actual password)
There, that wasn’t difficult, was it?
Well … there’s a bit more to do …
Mac root password II:
fehr.org
Use Nano to replace “root” with your new password (Look for –
proot) in:
•
•
•
•
•
/Applications/MAMP/bin/checkMysql.sh
/Applications/MAMP/bin/quickCheckMysqlUpgrade.sh
/Applications/MAMP/bin/repairMysql.sh
/Applications/MAMP/bin/stopMysql.sh
/Applications/MAMP/bin/upgradeMysql.sh
Do the same (look for ‘root’) in:
• /Applications/MAMP/bin/phpMyAdmin/config.inc.php
A tiny check
fehr.org
Stop and restart the server
Make sure you can still log in to MySQL from the command line
Mac: type in:
/Applications/MAMP/Library/bin/mysql --user=root –
password
Windows:
mysql --user=root --password
11. Make the fehr database
fehr.org
Log in at the command line as root
Mac:
create database fehr CHARACTER SET=utf8 COLLATE=utf8_general_ci;
use fehr;
source ~/fehr/lyx/sql/fehr.sql;
Windows:
create database fehr CHARACTER SET=utf8 COLLATE=utf8_general_ci;
use fehr;
source C:/fehr/lyx/sql/fehr.sql;
(One moment, caller …)
12. An end-user (you!)
fehr.org
Still in MySQL:
select * from users;
You can refine this:
select person, username from users;
Alter user details (choose your own id for ‘yourlogin’):
update users set username = '[email protected]' where
person = 2000;
12a. And a secure workstation
fehr.org
Still in MySQL, you want to paste in that LO magic code, along the
lines of:
You may wish to exit, compose the following in the editor of your
choice, copy it, and then paste it in after re-entering MySQL:
update WORKSTATIONS SET Hw_b =
UNHEX('0AFD3B8FD5AF4c0691E198694AD191AE') WHERE
workstation = 2003;
quit;
13. A vanilla user (almost done)
fehr.org
Run PhpMyAdmin
Go to the Users tab, and click on Add user
Under “User name” enter vanilla
•
•
•
•
•
Limit the host to Local (localhost)
Choose a long, difficult-to guess password (different from the root)
Keep it clear in your mind
Under Global privileges tick Select, Insert and Update but nothing else
Click [Go] at the bottom
Go to the Databases tab, check privileges for fehr
13a. Check vanilla access
fehr.org
Log in from the command line as vanilla:
Windows
mysql --user=vanilla --password
Mac
/Applications/MAMP/Library/bin/mysql --user=vanilla -password
use fehr;
select * from PEOPLE;
14. Finally, a ‘secure’ log-in
fehr.org
Go back to the PHP files (where you copied them to)
Windows: c:\wamp64\www\public_html
Mac: /Applications/MAMP/htdocs
Use Nano | Notepad to edit the file
SH_database_connect_dummy.php
Change the “password for vanilla” to the new password you have
remembered so well
Save the file as SH_database_connect.php
14a. Test your login
fehr.org
In your browser, open up the home page in fehr/serve
Actually log in with your user name and the password
PASSWORDGOESHERE
(this is the default password set in the database)
Challenge
Can you explain why you aren’t typing in the user as vanilla with that
password?
Where are we?
Part I: Some philosophy
Part II: Get it working
<tea>
Part III: The anatomy of fehr
Part IV: Experimentation
fehr.org
fehr.org
5. Wholly—a brief peek
fehr.org
Wholly is a simple (but powerful) language. Let’s explore briefly:
Factorial (!) can be defined many ways. Simply put:
10! = 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1
Let’s build this using Wholly
INCrement something. Type in…
▷ INC 9
(To submit your code, press Ctrl+Enter)
For help with the INC command, type in:
▷ SAY HELP <INC>
fehr.org
What does this do?
▷ SEQ 10
For help, try:
▷ SAY HELP <SEQ>
fehr.org
Let’s put this together
▷ INC _over_ SEQ 10
Now try:
▷ MUL _all_ INC _over_ SEQ 10
Simply 10!
fehr.org
Comparisons are odious. C:
fehr.org
int factorial(int n) {
int result = 1;
for (int i = 1; i <= n; ++i)
result *= i;
return result;
}
Wholly ▷ MUL _all_ INC _over_ SEQ 10
https://www.rosettacode.org/wiki/Factorial#Iterative_16
C (recursive)
fehr.org
int factorial(int n) {
return n == 0 ? 1 : n * factorial(n - 1);
}
https://www.rosettacode.org/wiki/Factorial#Iterative_16
Java (recursive)
fehr.org
public static long fact(final int n) {
if (n < 0){
System.err.println("No negative numbers");
return 0;
}
return (n < 2) ? 1 : n * fact(n - 1);
}
https://www.rosettacode.org/wiki/Factorial#Recursive_32
Python (functional)
fehr.org
from operator import mul
from functools import reduce
def factorial(n):
return reduce(mul, range(1,n+1), 1)
https://www.rosettacode.org/wiki/Factorial#Python
Now try:
▷ ▷ MUL _all_ INC _over_ SEQ 200
fehr.org