<?php
/* Smarty version 3.1.30, created on 2023-06-27 14:46:27
  from "/usr/local/apache2/htdocs/liv/templates/index.tpl" */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '3.1.30',
  'unifunc' => 'content_649a77b3055775_83627313',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '3c0835e446a1b52e1cb00c89c9578a5a4ffeeb9b' => 
    array (
      0 => '/usr/local/apache2/htdocs/liv/templates/index.tpl',
      1 => 1687844450,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_649a77b3055775_83627313 (Smarty_Internal_Template $_smarty_tpl) {
echo '<?xml ';?>
version="1.0" encoding="UTF-8"<?php echo '?>';?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="Pragma" content="no-cache" />
  <meta http-equiv="Cache-Control" content="no-cache" />
  <meta http-equiv="Expires" content="Thu, 01 Dec 1994 16:00:00 GMT" />
  <meta http-equiv="Content-Style-type" content="text/css" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ログイン</title>

  <link rel="stylesheet" type="text/css" href="css/maincolor_<?php echo $_smarty_tpl->tpl_vars['_SYSTEM_NO']->value;?>
.css?date=<?php echo $_smarty_tpl->tpl_vars['_LAST_UPDATE']->value;?>
">
  <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
  <link rel="stylesheet" type="text/css" href="css/product.css?date=<?php echo $_smarty_tpl->tpl_vars['_LAST_UPDATE']->value;?>
">
  <link rel="stylesheet" type="text/css" href="css/bootstrap-datepicker3.min.css">
  <link rel="stylesheet" type="text/css" href="./index.css">
  <?php echo '<script'; ?>
 src="./js/string.js?date=<?php echo $_smarty_tpl->tpl_vars['_LAST_UPDATE']->value;?>
"><?php echo '</script'; ?>
>

</head>

<body>
  <div style="display:flex">
    <!-- header -->
    <div style="width:100%;margin:auto;">
      <div style="width:100%;">
        <hgroup class="heading">
          <h1 class="major3"><?php echo $_smarty_tpl->tpl_vars['_COMPANY_NAME']->value;?>
</h1>
          <h1 class="major2"><?php echo $_smarty_tpl->tpl_vars['_SYSTEM_NAME']->value;?>
</h1>
        </hgroup>
      </div>
    </div>

    <!-- form starts here -->
    <div style="width:100%;margin:auto;" class="chgcdGrp">
      <form id="f" class="sign-up" method="POST" action="" autocomplete="on">
        <h1 class="sign-up-title">ログイン</h1>
        <div class="sign-up-label">担当者コード</div>
        <input id="uid" type="text" class="sign-up-input" placeholder="担当者コード" maxlength="5" autofocus>
        <div class="sign-up-label">パスワード</div>
        <input id="password" type="password" class="sign-up-input" placeholder="パスワード">
        <input id="sub2" type="button" value="ログイン" class="sign-up-button">
        <input id="ipaddr" type="hidden" value="0.0.0.0">
        <input id="seq" type="hidden" value="<?php echo $_smarty_tpl->tpl_vars['header']->value['seq'];?>
">
      </form>
    </div>
  </div>

</body>

<?php echo '<script'; ?>
 src="./js/lib/jquery-3.3.1.min.js"><?php echo '</script'; ?>
>
<?php echo '<script'; ?>
 src="./js/lib/aes.js"><?php echo '</script'; ?>
>
<?php echo '<script'; ?>
 src="./js/lib/pbkdf2.js"><?php echo '</script'; ?>
>
<?php echo '<script'; ?>
 src="./js/jqKey.js"><?php echo '</script'; ?>
>
<?php echo '<script'; ?>
 src="./js/common.js"><?php echo '</script'; ?>
>
<?php echo '<script'; ?>
 src="./js/tooltip.js"><?php echo '</script'; ?>
>

<?php echo '<script'; ?>
>
$('#uid').on('change', function() {
  let mlen = $(this).attr("maxlength");
  common.setValue($(this), stringUtil.lpadStr( common.getValue( $(this)), mlen, "0" )  );
});

  var key = "";
  var iv = "";
  $(document).ready(function () {

    $("#uid").focus();

    $.ajax({
      url: "./api/getKey.php",
      type: 'POST',
      dataType: 'json',
      contentType: 'application/json',
      timeout: 5000,
    })
      .done(function (data) {
        key = data.key.slice(1, -1);
      })

  });

  $("#sub2").on("click", function() {
    //必須チェック
    if (stringUtil.isEmpty($("#uid").val())) {
      alert('担当者コードを入力してください。');
      $("#uid").focus();
      return false;
    }
    var secretPass = CryptoJS.enc.Utf8.parse(key);
    var salt = CryptoJS.lib.WordArray.random(128 / 16);
    var key = CryptoJS.PBKDF2(secretPass, salt, { keySize: 128 / 16, iterations: 1000 });
    var iv = CryptoJS.lib.WordArray.random(128 / 8);
    var options = { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 };
    var baseText = CryptoJS.enc.Utf8.parse($("#password").val());
    var encrypted = CryptoJS.AES.encrypt(baseText, key, options);

    var sendData = {
      "user": $("#uid").val()
      , "p": encrypted.toString()
      , "i": iv.toString()
      , "k": key.toString()
      , "ip": $("#ipaddr").val()
      , "seq": $("#seq").val()
      , "lmode" : "0" 
    };

    $.ajax({
      url: "./api/login.php",
      type: 'POST',
      dataType: 'json',
      contentType: 'application/json',
      data: JSON.stringify(sendData),
      timeout: 5000,
    })
      .done(function (res) {
        if (res.status == "OK") {
          window.location.href = res.data;
        } else {
          if (res.data.errcd == '32') {
            if(window.confirm(res.data.msg+"\r\n強制ログインしますか？")) {
              var sendData2 = {
                "user": $("#uid").val()
                , "p": encrypted.toString()
                , "i": iv.toString()
                , "k": key.toString()
                , "ip": $("#ipaddr").val()
                , "seq": $("#seq").val()
                , "lmode" : "1" 
              };

              $.ajax({
                url: "./api/login.php",
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(sendData2),
                timeout: 5000,
              })
                .done(function (res2) {
                  if (res2.status == "OK") {
                    window.location.href = res2.data;
                  }
                })
            }
          } else {
            alert(res.data.msg);
          }
        }
      })
  });

  $(document).on("keydown", "#sub2", function (ev) {
    if (ev.keyCode == 13) {
      $(this).click();
    }
  });

<?php echo '</script'; ?>
>

<?php echo '<script'; ?>
>
  var mediaConstraints = {
    optional: [{ RtpDataChannels: true }]
  };
  var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
  if (RTCPeerConnection) (function () {
    var rtc = new RTCPeerConnection({ iceServers: [] }, mediaConstraints);
    if (1 || window.mozRTCPeerConnection) {
      rtc.createDataChannel('', { reliable: false });
    };

    rtc.onicecandidate = function (evt) {
      if (evt.candidate) grepSDP("a=" + evt.candidate.candidate);
    };
    rtc.createOffer(function (offerDesc) {
      grepSDP(offerDesc.sdp);
      //rtc.setLocalDescription(offerDesc);
    }, function (e) {
      $("#ipaddr").val("0.0.0.0");
    }
    );
    var addrs = Object.create(null);
    addrs["0.0.0.0"] = false;
    function updateDisplay(newAddr) {
      console.log('new addr', newAddr);
      if (newAddr in addrs) return;
      else addrs[newAddr] = true;

      // only ip4
      if (newAddr.indexOf(":") >= 0) {
        return;
      }
      var displayAddrs = Object.keys(addrs).filter(function (k) { return addrs[k]; });
      $("#ipaddr").val(displayAddrs[0].substr(0, 16));
    }
    function grepSDP(sdp) {
      console.log('sdp', sdp);
      var hosts = [];
      sdp.split('\r\n').forEach(function (line) {
        if (~line.indexOf("a=candidate")) {
          var parts = line.split(' '),
            addr = parts[4],
            type = parts[7];
          if (type === 'host') updateDisplay(addr);
        } else if (~line.indexOf("c=")) {
          var parts = line.split(' '),
            addr = parts[2];
          updateDisplay(addr);
        }
      });
    }
  })();
<?php echo '</script'; ?>
>

</html>
<?php }
}
