| 531 | | |
|---|
| 532 | | |
|---|
| 533 | | |
|---|
| 534 | | |
|---|
| 535 | | |
|---|
| 536 | | |
|---|
| 537 | | |
|---|
| 538 | | |
|---|
| 539 | | |
|---|
| 540 | | |
|---|
| 541 | | |
|---|
| | 539 | function login($con,$name,$passwd){ |
|---|
| | 540 | global $environmentpolicytoken; |
|---|
| | 541 | |
|---|
| | 542 | //入力内容確認 |
|---|
| | 543 | if (((mb_ereg('[^0-9a-zA-Z]', $name)) ||(mb_ereg('[^0-9a-zA-Z]', $passwd) ))){ |
|---|
| | 544 | |
|---|
| | 545 | //print "エラー処理\n"; |
|---|
| | 546 | //print "<!-- DEBUG name/passwd format error-->"; |
|---|
| | 547 | redirectlogin(); |
|---|
| | 548 | |
|---|
| | 549 | }else{ |
|---|
| | 550 | //print "正常処理\n"; |
|---|
| | 551 | //db検索 |
|---|
| | 552 | escape_string($name); |
|---|
| | 553 | escape_string($passwd); |
|---|
| | 554 | |
|---|
| | 555 | $query = " |
|---|
| | 556 | SELECT memberid ,userclass,name,passwd1 |
|---|
| | 557 | FROM foltia_envpolicy |
|---|
| | 558 | WHERE foltia_envpolicy.name = '$name' |
|---|
| | 559 | "; |
|---|
| | 560 | $useraccount = m_query($con, $query, "DBクエリに失敗しました"); |
|---|
| | 561 | $useraccountrows = pg_num_rows($useraccount); |
|---|
| | 562 | |
|---|
| | 563 | if ($useraccountrows == 1 ){ |
|---|
| | 564 | $rowdata = pg_fetch_row($useraccount, 0); |
|---|
| | 565 | $memberid = $rowdata[0]; |
|---|
| | 566 | $userclass = $rowdata[1]; |
|---|
| | 567 | $username = $rowdata[2]; |
|---|
| | 568 | $dbpasswd = $rowdata[3]; |
|---|
| | 569 | }else{ |
|---|
| | 570 | header("HTTP/1.0 401 Unauthorized"); |
|---|
| | 571 | //print "<!-- DEBUG DB record error ($useraccountrows)-->"; |
|---|
| | 572 | redirectlogin(); |
|---|
| | 573 | }//end if |
|---|
| | 574 | |
|---|
| | 575 | |
|---|
| | 576 | // passwdをdbから取りだし |
|---|
| | 577 | if ($userclass == 0){ |
|---|
| | 578 | $dbpasswd = "$dbpasswd"; |
|---|
| | 579 | }else{ |
|---|
| | 580 | // db passwdとトークンを連結し |
|---|
| | 581 | $dbpasswd = "$dbpasswd"."$environmentpolicytoken"; |
|---|
| | 582 | } |
|---|
| | 583 | //それが入力と一致すれば認証 |
|---|
| | 584 | if ($passwd == $dbpasswd) { |
|---|
| | 585 | //print "認証成功<br>$dbpasswd $passwd\n"; |
|---|
| | 586 | }else{ |
|---|
| | 587 | //print "認証失敗<br>$dbpasswd $passwd\n"; |
|---|
| | 588 | header("HTTP/1.0 401 Unauthorized"); |
|---|
| | 589 | //print "<!-- DEBUG passwd unmatch error>"; |
|---|
| | 590 | redirectlogin(); |
|---|
| | 591 | } |
|---|
| | 592 | }//end if mb_ereg |
|---|
| | 593 | }//end function login |
|---|
| | 594 | |
|---|
| | 595 | |
|---|
| | 596 | |
|---|
| | 597 | |
|---|
| | 598 | function redirectlogin(){ |
|---|
| | 599 | |
|---|
| | 600 | print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"; |
|---|
| | 601 | print "<html><head>\n"; |
|---|
| | 602 | print "<title>foltia:Invalid login</title>\n"; |
|---|
| | 603 | print "</head><body>\n"; |
|---|
| | 604 | print "<h1>Invalid login</h1>"; |
|---|
| | 605 | print "<p>foltiaヘのアクセスにはログインが必要です。新規アカウント登録は<a href=\"./accountregist.php\">こちらから。</a></p><hr>\n"; |
|---|
| | 606 | print "<address>foltia by DCC-JPL Japan/foltia Project. <a href = \"http://www.dcc-jpl.com/soft/foltia/\">http://www.dcc-jpl.com/soft/foltia/</a></address>\n"; |
|---|
| | 607 | print "</body></html>\n"; |
|---|
| | 608 | |
|---|
| | 609 | |
|---|
| | 610 | |
|---|
| | 611 | exit; |
|---|
| | 612 | }//end function redirectlogin |
|---|
| | 613 | |
|---|
| | 614 | function getuserclass($con){ |
|---|
| | 615 | global $useenvironmentpolicy; |
|---|
| | 616 | $username = $_SERVER['PHP_AUTH_USER']; |
|---|
| | 617 | |
|---|
| | 618 | if ($useenvironmentpolicy == 1){ |
|---|
| | 619 | $query = " |
|---|
| | 620 | SELECT memberid ,userclass,name,passwd1 |
|---|
| | 621 | FROM foltia_envpolicy |
|---|
| | 622 | WHERE foltia_envpolicy.name = '$username' |
|---|
| | 623 | "; |
|---|
| | 624 | $useraccount = m_query($con, $query, "DBクエリに失敗しました"); |
|---|
| | 625 | $useraccountrows = pg_num_rows($useraccount); |
|---|
| | 626 | |
|---|
| | 627 | if ($useraccountrows == 1 ){ |
|---|
| | 628 | $rowdata = pg_fetch_row($useraccount, 0); |
|---|
| | 629 | //$userclass = $rowdata[1]; |
|---|
| | 630 | return ($rowdata[1]); |
|---|
| | 631 | }else{ |
|---|
| | 632 | return (99);//エラー |
|---|
| | 633 | }//end if |
|---|
| | 634 | |
|---|
| | 635 | }else{ |
|---|
| | 636 | return (0);//環境ポリシー使わないときはつねに特権モード |
|---|
| | 637 | }//end if |
|---|
| | 638 | }//end function getuserclass |
|---|
| | 639 | |
|---|
| | 640 | |
|---|
| | 641 | |
|---|
| | 642 | function getmymemberid($con){ |
|---|
| | 643 | global $useenvironmentpolicy; |
|---|
| | 644 | $username = $_SERVER['PHP_AUTH_USER']; |
|---|
| | 645 | |
|---|
| | 646 | if ($useenvironmentpolicy == 1){ |
|---|
| | 647 | $query = " |
|---|
| | 648 | SELECT memberid ,userclass,name,passwd1 |
|---|
| | 649 | FROM foltia_envpolicy |
|---|
| | 650 | WHERE foltia_envpolicy.name = '$username' |
|---|
| | 651 | "; |
|---|
| | 652 | $useraccount = m_query($con, $query, "DBクエリに失敗しました"); |
|---|
| | 653 | $useraccountrows = pg_num_rows($useraccount); |
|---|
| | 654 | |
|---|
| | 655 | if ($useraccountrows == 1 ){ |
|---|
| | 656 | $rowdata = pg_fetch_row($useraccount, 0); |
|---|
| | 657 | //$userclass = $rowdata[1]; |
|---|
| | 658 | return ($rowdata[0]); |
|---|
| | 659 | }else{ |
|---|
| | 660 | return (-1);//エラー |
|---|
| | 661 | }//end if |
|---|
| | 662 | |
|---|
| | 663 | }else{ |
|---|
| | 664 | return (0);//環境ポリシー使わないときはつねに特権モード |
|---|
| | 665 | }//end if |
|---|
| | 666 | }//end function getuserclass |
|---|
| | 667 | |
|---|
| | 668 | |
|---|
| | 669 | function getmemberid2name($con,$memberid){ |
|---|
| | 670 | global $useenvironmentpolicy; |
|---|
| | 671 | //$username = $_SERVER['PHP_AUTH_USER']; |
|---|
| | 672 | |
|---|
| | 673 | if ($useenvironmentpolicy == 1){ |
|---|
| | 674 | $query = " |
|---|
| | 675 | SELECT memberid ,userclass,name,passwd1 |
|---|
| | 676 | FROM foltia_envpolicy |
|---|
| | 677 | WHERE foltia_envpolicy.memberid = '$memberid' |
|---|
| | 678 | "; |
|---|
| | 679 | $useraccount = m_query($con, $query, "DBクエリに失敗しました"); |
|---|
| | 680 | $useraccountrows = pg_num_rows($useraccount); |
|---|
| | 681 | |
|---|
| | 682 | if ($useraccountrows == 1 ){ |
|---|
| | 683 | $rowdata = pg_fetch_row($useraccount, 0); |
|---|
| | 684 | return ($rowdata[2]); |
|---|
| | 685 | }else{ |
|---|
| | 686 | return ("");//エラー |
|---|
| | 687 | }//end if |
|---|
| | 688 | |
|---|
| | 689 | }else{ |
|---|
| | 690 | return (""); |
|---|
| | 691 | }//end if |
|---|
| | 692 | |
|---|
| | 693 | |
|---|
| | 694 | |
|---|
| | 695 | }//end function getmemberid2name |
|---|