I\'m using a MacBook pro. The professor asked for a Web Admin Page with a Main M
ID: 3915868 • Letter: I
Question
I'm using a MacBook pro.
The professor asked for a Web Admin Page with a Main Menu that displays:
1. File system Mantle/Dismantle
2. Add/Edit User
3. Active Users in the System
4. Internet Status
5. Processor of a particular user.
6. Exit
I've been instructed to use Apache, Perl, batch, awk as necessary.
Commands to be used (but not limited to): ps -ef | srd, dF, who -T, netstat, mount, fsck, add user.
If I could just get a draft of how I should be tackling this, that be key. I'm aware of commands and how they work in script, but I haven't touched Perl or apache just yet other than configuring it on my mac.
Explanation / Answer
To make a web-page you need four parts: Fron-end (HTML, CSS, JS etc), Back-end (PHP, Python, Java etc), Database (MySQL, MongoDB, Oracle etc), Server(Apache, Tomcat, Glassfish etc)
Apache comes in builtin with the MacOS, you just need to start it:
apachectl start
To change the virtual host of the default apache you will need to edit, "/etc/apache2/httpd.conf", and change it to the desired destination.
As you have successfully configured the Perl, let me tell you how to run a Perl script using apache. Save the files in "http://localhost/cgi-bin/file-name" directory and run it using "/Library/WebServer/CGI-Executables". To display a basic HTML page use:
#!/usr/bin/perl
print "Content-type: text/html; charset=iso-8859-1 ";
print "<html>";
print "<body>";
print "Test Page";
print "</body>";
print "</html>";
File system Mantle/Dismantle?
Open file using:
open(filehandle, pathname)?
Use "<" to overwrite files and "<<" to append in files:
e.g. - open (MYFILE, "<myfile.txt")
To delete files:
unlink $file;
To move/rename files:
use File::Copy qw(move);
move $old_name, $new_name;
To copy files:
use File::Copy qw(copy);
copy $old_file, $new_file;
2. Add/Edit User
To add user:
system("/usr/sbin/useradd $username -g users -c "$realname"")
To set password:
system(""/sbin/passwd "$username"")
3. Active Users in the System?
Run the code:
my $user = `stat -f%Su /dev/console`;
4. Internet Status
Simply do:
system(sprintf("ping -q -I %s -c 1 %s>/dev/null", $netdev, $ping));
5. Processor of a particular user.
For brief information,
open my $handle, "/proc/cpuinfo" or die "Can't open cpuinfo: $! ";
printf "CPUs: %d ", scalar (map /^processor/, <$handle>) ;
close $handle;
For detailed information,
use Sys::Info;
use Sys::Info::Constants qw( :device_cpu );
my $info = Sys::Info->new;
my $cpu = $info->device( CPU => %options );
printf "CPU: %s ", scalar($cpu->identify) || 'N/A';
printf "CPU speed is %s MHz ", $cpu->speed || 'N/A';
printf "There are %d CPUs " , $cpu->count || 1;
printf "CPU load: %s " , $cpu->load || 0;
6. Exit
Simply use:
exit;?