Commit d2c982b3 authored by dinesh's avatar dinesh

commiting ccan web pages

parent 2e0ef31d
<?php
session_start();
if($_SESSION["slogged"] == false) {
header('Location: login.php?referer=approval.php?accountid='.$_GET['accountid']);
exit();
}
include('logo.html');
include('menulist.html');
include('configuration');
$accountid = $_GET['accountid'];
$username = $_SESSION['susername'];
if(!isset($_POST['submit']) && !isset($_POST['cancel']))
{
//checking for admin rites
$handle = sqlite3_open($db) or die("Could not open database");
$query = "SELECT * FROM users where username=\"$username\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$row = sqlite3_fetch_array($result);
if ($row["admin"] == "false") {
echo "<div align=\"center\">You donot have a rite to approve users</div>";
exit();
}
//extracting user information
$query = "SELECT * FROM users where username=\"$accountid\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
if (($row = sqlite3_fetch_array($result)) == '') {
echo "<div align=\"center\">Not a valid account id</div>";
exit();
}
$name = $row["name"];
$email = $row["email"];
$website = $row["website"];
$desc = $row["description"];
if($row["approved"] == "true") {
$query = "SELECT * FROM approval where approved=\"$accountid\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$row = sqlite3_fetch_array($result);
echo "<div align=\"center\"> Already <b>$accountid</b> is approved by <b>".$row["approvedby"]."</b>...</div>";
exit();
}
?>
<h3 class="firstheader" align="center">Approval</h3>
<form method="post" action="approval.php?accountid=<?=$accountid?>" >
<table align="center" border="0" cellpadding="10" bgcolor="gray">
<tr align="left" bgcolor="lightgray">
<td> <p>Full name: </td><td><?=$name;?></p></td>
</tr>
<tr align="left" bgcolor="silver">
<td> <p>Account id: </td><td><?=$accountid;?></p></td>
</tr>
<tr align="left" bgcolor="lightgray">
<td> <p>Email: </td><td><?=$email;?></p>
</td>
</tr>
<tr align="left" bgcolor="silver">
<td> <p>Description: </td><td><?=$desc;?></p> </td>
</tr>
<tr align="left" bgcolor="lightgray">
<td> <p>Web Site: </td><td><?=$website;?></p> </td>
</tr>
<tr align="left" bgcolor="lightgray">
<td>Admin rites</td><td><input type="checkbox" name="isadmin"> (check this if you want this user to be admin) </td>
</tr>
<tr align="center">
<td> <input type="submit" name="submit" value="Approve"/></td>
<td><input type="submit" name="cancel" value="Cancel Approval"/></td>
</tr>
</table>
</form><hr>
</body>
</html>
<?php
}
//if approved
else if (isset($_POST['submit'])) {
//set approval=true
$handle = sqlite3_open($db) or die("Could not open database");
$query = "update users set approved=\"true\" where username=\"$accountid\"";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
//where whether user is given admin permission
if($_POST['isadmin']) {
$query = "update users set admin=\"true\" where username=\"$accountid\"";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
}
//inserting to db
$query = "insert into approval values(\"$accountid\",\"$username\")";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
//get email id
$query = "SELECT * FROM users where username=\"$accountid\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$row = sqlite3_fetch_array($result);
$email = $row["email"];
//generate password and send mail
$password = generate_passwd(8);
$subject = "Approval of ccan account";
$message = "Your request for ccan account id is being approved.\n\n Please use the following password to login\n Password: ".$password;
$password = md5($password);
//insert password
$query = "insert into login (username,password) values(\"$accountid\",\"$password\")";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
//sendmail
mail($email, $subject, $message, "From: $frommail");
echo "<div align=center> Successfully approved <b>$accountid</b>...</div>";
}
//if approval is canceled
else if (isset($_POST['cancel'])) {
//delete user
$handle = sqlite3_open($db) or die("Could not open database");
$query = "delete from users where username=\"$accountid\"";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
echo "<div align=center> Successfully cancelled <b>$accountid</b>...</div>";
}
function generate_passwd($length = 16) {
static $chars = '!@#$%^&*abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789';
$chars_len = strlen($chars);
for ($i = 0; $i < $length; $i++)
$password .= $chars[mt_rand(0, $chars_len - 1)];
return $password;
}
?>
\ No newline at end of file
<?php
session_start(); // start session.
if($_SESSION["slogged"] == false) {
header('Location: login.php?referer=changedetail.php');
exit();
}
else {
include('logo.html');
include('menulist.html');
include('configuration');
//get account data
$handle = sqlite3_open($db) or die("Could not open database");
$accountid = $_SESSION['susername'];
$query = "SELECT * FROM users where username=\"$accountid\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$row = sqlite3_fetch_array($result);
$name = $row["name"];
$email = $row["email"];
$website = $row["website"];
$password = '';
$repassword = '';
}
if(isset($_POST['submit'])) {
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$website = $_REQUEST['website'];
$password = $_REQUEST['password'];
$repassword = $_REQUEST['repassword'];
if(trim($name) == '') {
$errmsg = 'Please enter your name';
}
else if(trim($email) == '') {
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email)) {
$errmsg = 'Your email address is not valid';
}
if($password != '' || $repassword != '') {
if(strlen($password) < 6 || strlen($password) > 16)
$errmsg = 'Password should have length between 6 and 16';
if($password != $repassword)
$errmsg = 'Password and retype password not match';
}
}
if(trim($errmsg) != '' || !isset($_POST['submit'])) {
?>
<h3 class="firstheader" align="center">Change CCAN account</h3>
<div align="center" class="errmsg"><font color="RED"><?=$errmsg;?></font></div>
<div align="center">Note: Please leave password fields blank if you donot want to change</div>
<form method="post" align="center" action="changedetail.php">
<table align="center" width="70%" border="0" bgcolor="gray" cellpadding="8" cellspacing="1">
<tr align="left" bgcolor="lightgray">
<td><p>Full name: </p><p><input name="name" type="text" value="<?=$name;?>"/></p></td
</tr>
<tr align="left" bgcolor="silver">
<td><p>Email: </p><p><input name="email" type="text" value="<?=$email;?>"/> </p></td>
</tr>
<tr align="left" bgcolor="lightgray">
<td><p>New Password: </p><p><input name="password" type="password" value="<?=$password;?>"/></p></td>
</tr>
<tr align="left" bgcolor="silver">
<td><p>Retype Password: </p><p><input name="repassword" type="password" value="<?=$repassword;?>"/><br /></p>
</td>
</tr>
<tr align="left" bgcolor="lightgray">
<td><p>Web Site[Optional]: </p><p><input name="website" type="text" value="<?=$website;?>"/><br /></p>
</td>
</tr>
<tr align="center">
<td><input type="submit" name="submit" value="Change Account"/></td>
</tr>
</table>
</form>
<hr>
</body>
</html>
<?php
}
else {
$handle = sqlite3_open($db) or die("Could not open database");
$query = "update users set name=\"".$name."\",email=\"".$email."\",website=\"".$website."\" where username=\"$accountid\"";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$ispass = '';
if($password != '' && $repassword != '' && $password == $repassword ) {
$password = md5($password);
$query = "update login set password=\"$password\" where username=\"$accountid\"";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$ispass = "password. Please login again";
session_destroy();
}
echo "<div align=\"center\"> Sucessfully changed ".$ispass."... <//div><//body><//html>";
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
,$email));
}
?>
<?php
//path for db
$db = "db/ccan.db";
//path for repository
$repopath = "testrepo/";
//ccanlint
$ccanlint = "tools/ccanlint -d ";
//infotojson
$infotojson = "tools/infotojson ";
//create tar of all dependencies
$create_dep_tar = "../tools/create_dep_tar ";
//junk code
$junkcode = "junkcode/";
//temp folder
$tempfolder = "temp/";
//infofile
$infofile = '/_info.c';
//temp repo
$temprepo = "temprepo/";
//email from
$frommail = "ccan@ozlabs.org";
//email for admins
$ccan_admin = "g.dinesh.cse@gmail.com";
$ccan_home_dir = "ccan/";
?>
\ No newline at end of file
File added
File added
<?php
function sqlite3_num_rows($dbRes)
{
$n = 0;
while(sqlite3_fetch_array($dbRes) != '')
{
$n = $n + 1;
}
return $n;
}
?>
<?php
function createsearchindex($module, $path, $infofile, $db, $user)
{
$fh = fopen($path.$infofile, 'r') or die("Can't open file");
$title = extract_title($fh);
$desc = extract_desc($fh);
//foreach($desc as $temp)
// $alldesc = $alldesc.$temp.'\n';
$author = $user;
//storing in search db
$handle = sqlite3_open($db) or die("Could not open database");
$query = "select * from search where module=\"$module\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
if (($row = sqlite3_fetch_array($result)) == '') {
$query = "insert into search values(\"$module\",\"$user\",\"$title\",\"$alldesc\");";
}
else {
$query = "update search set title=\"$title\", desc=\"$alldesc\" where module=\"$module\";";
}
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
fclose($fh);
}
function extract_title($fh)
{
while(substr(fgets($fh), 0, 3) != '/**');
return substr(strstr(fgets($fh),'*'),1);
}
function extract_desc($fh)
{
$i = 0;
while(substr(($line = fgets($fh)), 0, 2) == ' *') {
$desc[$i] = substr(strstr($line,'*'),1);;
$i = $i + 1;
}
return $desc;
}
?>
<?php
session_start();
include('logo.html');
include('menulist.html');
include('configuration');
include('search.html');
$handle = sqlite3_open($db) or die("Could not open database");
$query = "select * from search where module=\"".$_GET['module']."\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$row = sqlite3_fetch_array($result);
if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module'].".tar")) {
chdir($repopath);
exec("tar -cvvf ".$ccan_home_dir. $_GET['module']. "/". $_GET['module'].".tar ". $ccan_home_dir.$_GET['module'], $status);
chdir("..");
}
if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module']."_dep.tar")) {
chdir($repopath);
exec($create_dep_tar." ".$ccan_home_dir.$_GET['module'], $status);
chdir("..");
}
?>
<table align="center" bgcolor="lightblue" width="70%" border="0" cellpadding="3" cellspacing="1">
<tr align="center" bgcolor="FFFFCC">
<td width="50%"><a href=<?=$repopath . $ccan_home_dir.$_GET['module']?>/<?=$_GET['module']?>.tar>Download</a></td>
<td><a href=<?=$repopath . $ccan_home_dir.$_GET['module']?>/<?=$_GET['module']?>_dep.tar>Download Dependencies</a></td>
</tr>
</table>
<table align="center" bgcolor="lightblue" width="70%" border="0" cellpadding="8" cellspacing="1">
<tr align="left" bgcolor="FFFFCC">
<td><h3>Module: </h3> <pre><?=$row['module'];?></pre> </td>
</tr>
<tr align="left" bgcolor="FFFFCC">
<td><h3>Title: </h3> <pre><?=$row['title'];?> </pre></td>
</tr>
<tr align="left" bgcolor="FFFFCC">
<td><h3>Author: </h3> <pre><a href=search.php?author=<?=$row['author'];?>><?=$row['author'];?></a></pre></td>
</tr>
<tr align="left" bgcolor="FFFFCC">
<td><h3>Description: </h3> <pre><?=$row['desc'];?></pre></td>
</tr>
</table><hr>
<?php
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Recurse
rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
}
// Clean up
$dir->close();
return rmdir($dirname);
}
function getccanadmin($db)
{
//forming admin mail addresses from data base
$handle = sqlite3_open($db) or die("Could not open database");
$query = "SELECT email FROM users where admin=\"true\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
while ($row = sqlite3_fetch_array($result))
$admin = $admin.$row[0].",";
return $admin;
}
?>
\ No newline at end of file
<html>
<head>
<title>ccan</title>
</head>
<body>
<META HTTP-EQUIV="Refresh"
CONTENT="0; URL=login.php">
</body>
</html>
<?php
session_start(); // start session.
include('configuration');
if($_SESSION['slogged'] != ''){
include('logo.html');
include('menulist.html');
echo "<br><div align=\"center\">Already logged in as ".$_SESSION['susername']."...</div>";
exit();
}
if(!isset($_POST['submit'])) {
include('logo.html');
include('menulist.html');
loginhtml("Members only. Please login to access.");
exit();
}
// get username and password
$username = $_POST['username'];
$password = $_POST['password'];
// register username and logged as session variables.
session_register("susername");
session_register("slogged");
//set session variables
$_SESSION["susername"] = $username;
$_SESSION["slogged"] = false;
// open database file
$handle = sqlite3_open($db) or die("Could not open database");
// query string
$query = "SELECT * FROM login where username=\"$username\"";
// execute query
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
// if rows exist
if (($row = sqlite3_fetch_array($result)) != '') {
if(md5($password) == $row["password"])
$valid_user = 1;
}
else {
$valid_user = 0;
}
//if not valid user
if (!($valid_user)) {
// Unset session variables.
session_unset();
include('logo.html');
include('menulist.html');
loginhtml("Incorrect login information, please try again. You must login to access.");
exit();
}
//if valid user
else {
$referer = $_GET['referer'];
$_SESSION["slogged"] = true;
if($referer != '') {
header('Location: '.$referer);
exit();
}
include('logo.html');
include('menulist.html');
echo "<br><div align=\"center\">Logged in sucessfully...<//div><//body><//html>";
}
function loginhtml($info)
{
?>
<form action="<?=$PHP_SELF.$referer?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center"><?=$info?></p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</form>
</th>
</tr>
</table><hr>
</body>
</html>
<?php
}
?>
<html>
<head>
<title>ccan</title>
<head>
<body bgcolor="FFFFCC">
<table align="center" width="100%" bgcolor="FFFFFF">
<tr>
<th>
<img src="ccan.jpg" width="250" height="80">
</th>
<th>
<h1>Comprehensive C Archieve Network <h1>
</th>
</tr>
</table>
\ No newline at end of file
<?php
session_start();
include('logo.html');
include('menulist.html');
if($_SESSION['slogged'] != '')
echo "<br><div align=\"center\">Logged out Successfully...</div>";
else
echo "<br><div align=\"center\">Please login...</div>";
session_destroy();
?>
\ No newline at end of file
<?php
session_start();
?>
<table align="center" width="100%" cellpadding="4" cellspacing="1" border="0" bgcolor="lightblue">
<tr align="left" bgcolor="CCFFCC" ><td>Welcome <?=$_SESSION['susername']?>! </td>
<td align="center">
<a href="login.php"> Login</a>
</td>
<td align="center">
<a href="requestid.php">
Request CCAN account</a>
</td>
<td align="center">
<a href="changedetail.php">
Change CCAN account detail</a>
</td>
<td align="center">
<a href="upload.php">
Upload Code</a>
</td>
<td align="center">
<a href="search.php">
Search CCAN</a>
</td>
<td align="center">
<a href="logout.php">
Logout</a>
</td>
</table>
<hr>
\ No newline at end of file
<html>
<head>
<title>CCAN Request Account</title>
</head>
<body>
<b> Thank you for registering with CCAN. You will get the password to your after approval.</b>
</body>
<?php
session_start();
include('logo.html');
include('menulist.html');
include('configuration');
if(isset($_POST['submit'])) {
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$website = $_REQUEST['website'];
$accountid = $_REQUEST['accountid'];
$description = $_REQUEST['description'];
if(trim($name) == '') {
$errmsg = 'Please enter your name';
}
else if(trim($email) == '') {
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email)) {
$errmsg = 'Your email address is not valid';
}
else if(trim($accountid) == '') {
$errmsg = 'Please enter your account id';
}
else if(strlen($accountid) < 4 || strlen($accountid) > 16) {
$errmsg = 'account id should have length between 4 and 16';
}
else if(trim($accountid) != '') {
$handle = sqlite3_open($db) or die("Could not open database");
$query = "SELECT * FROM users where username=\"$accountid\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
if (($row = sqlite3_fetch_array($result)) != '') {
$errmsg = 'Desired id already exist. Please enter different Desired id.';
}
}
else if(trim($description) == '') {
$errmsg = 'Please enter your description';
}
else if(strlen($description) < 20) {
$errmsg = 'Description should atleast be 20 characters';
}
}
if(trim($errmsg) != '' || !isset($_POST['submit'])) {
?>
<h3 class="firstheader" align="center">Request CCAN account</h3>
<div align="center" class="errmsg"><font color="RED"><?=$errmsg;?></font></div>
<form method="post" action="requestid.php">
<table align="center" width="70%" border="0" bgcolor="999999" cellpadding="4" cellspacing="1">
<tr align="left" bgcolor="lightgray">
<td> <p>Full name: </p> <p><input name="name" type="text" value="<?=$name;?>"/></p> </td>
</tr>
<tr align="left" bgcolor="silver">
<td> <p>Email: </p> <p><input name="email" type="text" value="<?=$email;?>"/> <br /></p> </td>
</tr>
<tr align="left" bgcolor="lightgray">
<td> <p>Desired ID: </p><p><input name="accountid" type="text" value="<?=$accountid;?>"/><br /></p></td>
</tr>
<tr align="left" bgcolor="silver">
<td><p> Web Site[Optional]: </p><p><input name="website" type="text" value="<?=$website;?>"/><br /></p></td>
</tr>
<tr align="left" bgcolor="lightgray">
<td><p> A short description of what you are planning to contribute: </p>
<p><textarea name="description" rows="10" cols="70" value="<?=$description;?>"> </textarea></p>
</td>
</tr>
<tr align="center">
<td> <input type="submit" name="submit" value="Request Account"/> </td>
</tr>
</table>
</form><hr>
<?php
}
else {
$handle = sqlite3_open($db) or die("Could not open database");
$query = "insert into users values(\"".$name."\",\"".$email."\",\"".$accountid."\",\"".$website."\",\"".$description."\",\"false\" ,\"false\")";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$subject = "Approval of ccan account";
$message = "There is new request for ccan account id.\n\n Please use the following link to approve http://ccan.ozlabs.org/dinesh/approval.php?accountid=".$accountid;
mail($ccan_admin, $subject, $message, "From: $email");
?>
</br><div>Thank you for registering with CCAN. You will get the password to your mail after approval.</div>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
,$email));
}
?>
<form method="post" action="search.php">
<table align="center">
<tr align="left">
<td>
Search ccan repository:
</td>
<td>
<p><input name="searchtext" type="text"/></p>
</td>
<td>
<p> <select name="searchmenu">
<option value="all">All </option>
<option value="author">Author </option>
<option value="module">Module title </option>
</select>
</p>
</td>
</tr>
<tr align="center">
<td></td>
<td align="right">
<input type="submit" name="search" value="Search"/>
</td>
<td align="left"><a href=search.php?disp=all>Display all</a></td>
</tr>
</table>
</form>
<?php
session_start();
include('logo.html');
include('menulist.html');
include('configuration');
include('searchengine.php');
include('search.html');
if(isset($_POST['search'])) {
$searchtext = $_REQUEST['searchtext'];
$in = $_REQUEST['searchmenu'];
if(trim($searchtext) == '') {
echo '<div align="center"><font color="RED">Please enter some keyword to search</font></div>';
exit();
}
}
else if($_GET['author'] != '') {
$searchtext = $_GET['author'];
$in = "author";
}
else if ($_GET['disp'] == 'all') {
$searchtext = "";
$in = "module";
}
else
exit();
$result = searchdb($searchtext, $in, $db);
echo '<table align="left" border="0" cellpadding="8" cellspacing="1">';
if($row = sqlite3_fetch_array($result))
echo "<tr><td><a href=\"dispmoduleinfo.php?module=".$row['module']."\">".$row["module"]."</a></br>".
"<a href=\"search.php?author=".$row["author"]."\">".$row["author"]."</a> : ". $row["title"]." </br> </br></td></tr>";
else
echo '<div align="center"><font color="RED"> No results found</font></div>';
while($row = sqlite3_fetch_array($result)) {
echo "<tr><td><a href=\"dispmoduleinfo.php?module=".$row['module']."\">".$row["module"]."</a></br>".
"<a href=\"search.php?author=".$row["author"]."\">".$row["author"]."</a> : ". $row["title"]." </br> </br></td></tr>";
}
echo '</table>';
?>
<?php
function searchdb($text, $in, $db)
{
//search db
$handle = sqlite3_open($db) or die("Could not open database");
if($in == 'module')
$query = "select * from search where title LIKE \"%$text%\"";
else if($in == 'author')
$query = "select * from search where author LIKE \"%$text%\"";
else
$query = "select * from search where title LIKE \"%$text%\" or author LIKE \"%$text%\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
return $result;
}
?>
\ No newline at end of file
<?php
session_start();
include('logo.html');
include('menulist.html');
include('configuration');
?>
<html>
<h3 align="center"> Upload Code</h3>
<table width="80%" align="center">
<tr>
<th>
<p>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<table align="center">
<tr align="left">
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload:
</td>
<td>
<input name="uploadedfile" type="file" /><br />
</td>
</tr>
<td></td>
<td><input type="submit" value="Upload File" /></td>
</tr>
</table>
</form>
<hr>
</html>
<?php
session_start();
include('logo.html');
include('menulist.html');
include('configuration');
include('functions.php');
include('searchengine.php');
if ($_FILES["uploadedfile"]["error"] > 0) {
echo "Error: " . $_FILES["uploadedfile"]["error"] . "<br />";
exit();
}
//list of file types supported
if($_FILES["uploadedfile"]["type"] == "application/x-gzip"
|| $_FILES["uploadedfile"]["type"] == "application/x-tar"
|| $_FILES["uploadedfile"]["type"] == "application/x-bzip"
|| $_FILES["uploadedfile"]["type"] == "application/zip") {
$folder = substr($_FILES["uploadedfile"]["name"], 0, strpos($_FILES["uploadedfile"]["name"],'.'));
move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
$tempfolder . $_FILES["uploadedfile"]["name"]);
//extracting code
if($_FILES["uploadedfile"]["type"] == "application/zip") {
exec('unzip '.$tempfolder.$_FILES["uploadedfile"]["name"].' -d '.$tempfolder, $op, $status);
}
else {
exec('tar -xf '.$tempfolder.$_FILES["uploadedfile"]["name"].' -C '.$tempfolder, $op, $status);
}
checkerror($status[0],"Error: cannot extract(tar error).");
//chmod
exec('chmod -R 0777 '. $tempfolder.$folder, $status);
checkerror($status[0],"Error: chmod execution error.");
//running ccanlint
exec($ccanlint.$tempfolder.$folder, $score, $status);
//checkerror($status,"Error: ccanlint execution error.");
//if user not logged in
if($_SESSION["slogged"] == false) {
//move to temp folder
if (file_exists($temprepo . $folder))
rmdirr($temprepo.$folder);
rename($tempfolder.$folder, $temprepo.$folder);
//send mail for review to admins
$subject = "Review: code upload at temporary repository";
$message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ".$temprepo.$folder.".\n\nOutput of ccanlint: \n";
foreach($score as $disp)
$message = $message.$disp."\n";
$toaddress = getccanadmin($db);
mail($toaddress, $subject, $message, "From: $frommail");
echo "<div align=\"center\"> Stored to temporary repository. Mail will be send to admin to get verification of the code.<//div>";
unlink($tempfolder.$_FILES["uploadedfile"]["name"]);
exit();
}
//if not junk code
if($status == 0) {
$rename = $folder;
//if module already exist
if (file_exists($repopath.$ccan_home_dir . $folder)) {
// if owner is not same
if(!(getowner($repopath.$ccan_home_dir.$folder, $db) == $_SESSION['susername'])) {
if(!file_exists($repopath . $ccan_home_dir. $folder.'-'.$_SESSION['susername']))
echo "<div align=\"center\">".$repopath . $ccan_home_dir. $folder . " already exists. Renaming to ". $folder."-".$_SESSION['susername']."</div>";
else
echo "<div align=\"center\">".$repopath . $ccan_home_dir. $folder."-".$_SESSION['susername'] . " already exists. Overwriting ". $folder."-".$_SESSION['susername']."</div>";
$rename = $folder."-".$_SESSION['susername'];
}
else
echo "<div align=\"center\">".$repopath. $ccan_home_dir. $folder. " already exists(uploaded by you). Overwriting ". $repopath. $folder."</div>";
}
//module not exist. store author to db
else {
storefileowner($repopath . $ccan_home_dir. $folder, $_SESSION['susername'], $db);
}
rmdirr($repopath. $ccan_home_dir. $rename);
rename($tempfolder.$folder, $repopath. $ccan_home_dir. $rename);
echo "<div align=\"center\"> Stored to ".$repopath . $ccan_home_dir. $rename . "</div>";
exec($infotojson . $repopath. $ccan_home_dir. $rename."/_info.c ". $repopath. $ccan_home_dir. $rename."/json_".$rename. " ". $_SESSION['susername']." ".$db, $status);
checkerror($status[0],"Error: In infotojson.");
//createsearchindex($rename, $repopath.$rename, $infofile, $db, $_SESSION['susername']);
}
//if junk code (no _info.c etc)
else {
rmdirr($junkcode.$folder.'-'.$_SESSION['susername']);
rename($tempfolder.$folder, $junkcode.$folder.'-'.$_SESSION['susername']);
if($score == '')
$msg = 'Below is details for test.';
echo "<div align=\"center\"><table><tr><td> Score for code is low. Cannot copy to repository. Moving to ". $junkcode.$folder.'-'.$_SESSION['susername']."... </br></br>". $msg ." </br></br></td></tr><tr><td>";
foreach($score as $disp)
echo "$disp</br>";
echo "</td></tr></table></div>";
}
unlink($tempfolder.$_FILES["uploadedfile"]["name"]);
}
else {
echo "<div align=\"center\"> File type not supported </div>";
exit();
}
function checkerror($status, $msg)
{
if($status != 0) {
echo "<div align=\"center\">" . $msg . "Contact ccan admin. </div>";
exit();
}
}
function getowner($filename, $db)
{
//getting owner of a file stored at db
$handle = sqlite3_open($db) or die("Could not open database");
$query = "SELECT owner FROM fileowner users where filename=\"$filename\"";
$result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
$row = sqlite3_fetch_array($result);
return $row["owner"];
}
function storefileowner($filename, $owner, $db)
{
//storing owner of a file stored at db
$handle = sqlite3_open($db) or die("Could not open database");
$query = "insert into fileowner values(\"$filename\", \"$owner\")";
$result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
}
?>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment